diff options
Diffstat (limited to 'arch/sh/oprofile/common.c')
| -rw-r--r-- | arch/sh/oprofile/common.c | 150 |
1 files changed, 150 insertions, 0 deletions
diff --git a/arch/sh/oprofile/common.c b/arch/sh/oprofile/common.c new file mode 100644 index 000000000000..1d97d64cb95f --- /dev/null +++ b/arch/sh/oprofile/common.c | |||
| @@ -0,0 +1,150 @@ | |||
| 1 | /* | ||
| 2 | * arch/sh/oprofile/init.c | ||
| 3 | * | ||
| 4 | * Copyright (C) 2003 - 2008 Paul Mundt | ||
| 5 | * | ||
| 6 | * Based on arch/mips/oprofile/common.c: | ||
| 7 | * | ||
| 8 | * Copyright (C) 2004, 2005 Ralf Baechle | ||
| 9 | * Copyright (C) 2005 MIPS Technologies, Inc. | ||
| 10 | * | ||
| 11 | * This file is subject to the terms and conditions of the GNU General Public | ||
| 12 | * License. See the file "COPYING" in the main directory of this archive | ||
| 13 | * for more details. | ||
| 14 | */ | ||
| 15 | #include <linux/kernel.h> | ||
| 16 | #include <linux/oprofile.h> | ||
| 17 | #include <linux/init.h> | ||
| 18 | #include <linux/errno.h> | ||
| 19 | #include <linux/smp.h> | ||
| 20 | #include <asm/processor.h> | ||
| 21 | #include "op_impl.h" | ||
| 22 | |||
| 23 | extern struct op_sh_model op_model_sh7750_ops __weak; | ||
| 24 | extern struct op_sh_model op_model_sh4a_ops __weak; | ||
| 25 | |||
| 26 | static struct op_sh_model *model; | ||
| 27 | |||
| 28 | static struct op_counter_config ctr[20]; | ||
| 29 | |||
| 30 | extern void sh_backtrace(struct pt_regs * const regs, unsigned int depth); | ||
| 31 | |||
| 32 | static int op_sh_setup(void) | ||
| 33 | { | ||
| 34 | /* Pre-compute the values to stuff in the hardware registers. */ | ||
| 35 | model->reg_setup(ctr); | ||
| 36 | |||
| 37 | /* Configure the registers on all cpus. */ | ||
| 38 | on_each_cpu(model->cpu_setup, NULL, 1); | ||
| 39 | |||
| 40 | return 0; | ||
| 41 | } | ||
| 42 | |||
| 43 | static int op_sh_create_files(struct super_block *sb, struct dentry *root) | ||
| 44 | { | ||
| 45 | int i, ret = 0; | ||
| 46 | |||
| 47 | for (i = 0; i < model->num_counters; i++) { | ||
| 48 | struct dentry *dir; | ||
| 49 | char buf[4]; | ||
| 50 | |||
| 51 | snprintf(buf, sizeof(buf), "%d", i); | ||
| 52 | dir = oprofilefs_mkdir(sb, root, buf); | ||
| 53 | |||
| 54 | ret |= oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled); | ||
| 55 | ret |= oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event); | ||
| 56 | ret |= oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel); | ||
| 57 | ret |= oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user); | ||
| 58 | |||
| 59 | if (model->create_files) | ||
| 60 | ret |= model->create_files(sb, dir); | ||
| 61 | else | ||
| 62 | ret |= oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count); | ||
| 63 | |||
| 64 | /* Dummy entries */ | ||
| 65 | ret |= oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask); | ||
| 66 | } | ||
| 67 | |||
| 68 | return ret; | ||
| 69 | } | ||
| 70 | |||
| 71 | static int op_sh_start(void) | ||
| 72 | { | ||
| 73 | /* Enable performance monitoring for all counters. */ | ||
| 74 | on_each_cpu(model->cpu_start, NULL, 1); | ||
| 75 | |||
| 76 | return 0; | ||
| 77 | } | ||
| 78 | |||
| 79 | static void op_sh_stop(void) | ||
| 80 | { | ||
| 81 | /* Disable performance monitoring for all counters. */ | ||
| 82 | on_each_cpu(model->cpu_stop, NULL, 1); | ||
| 83 | } | ||
| 84 | |||
| 85 | int __init oprofile_arch_init(struct oprofile_operations *ops) | ||
| 86 | { | ||
| 87 | struct op_sh_model *lmodel = NULL; | ||
| 88 | int ret; | ||
| 89 | |||
| 90 | /* | ||
| 91 | * Always assign the backtrace op. If the counter initialization | ||
| 92 | * fails, we fall back to the timer which will still make use of | ||
| 93 | * this. | ||
| 94 | */ | ||
| 95 | ops->backtrace = sh_backtrace; | ||
| 96 | |||
| 97 | switch (current_cpu_data.type) { | ||
| 98 | /* SH-4 types */ | ||
| 99 | case CPU_SH7750: | ||
| 100 | case CPU_SH7750S: | ||
| 101 | lmodel = &op_model_sh7750_ops; | ||
| 102 | break; | ||
| 103 | |||
| 104 | /* SH-4A types */ | ||
| 105 | case CPU_SH7763: | ||
| 106 | case CPU_SH7770: | ||
| 107 | case CPU_SH7780: | ||
| 108 | case CPU_SH7781: | ||
| 109 | case CPU_SH7785: | ||
| 110 | case CPU_SH7723: | ||
| 111 | case CPU_SHX3: | ||
| 112 | lmodel = &op_model_sh4a_ops; | ||
| 113 | break; | ||
| 114 | |||
| 115 | /* SH4AL-DSP types */ | ||
| 116 | case CPU_SH7343: | ||
| 117 | case CPU_SH7722: | ||
| 118 | case CPU_SH7366: | ||
| 119 | lmodel = &op_model_sh4a_ops; | ||
| 120 | break; | ||
| 121 | } | ||
| 122 | |||
| 123 | if (!lmodel) | ||
| 124 | return -ENODEV; | ||
| 125 | if (!(current_cpu_data.flags & CPU_HAS_PERF_COUNTER)) | ||
| 126 | return -ENODEV; | ||
| 127 | |||
| 128 | ret = lmodel->init(); | ||
| 129 | if (unlikely(ret != 0)) | ||
| 130 | return ret; | ||
| 131 | |||
| 132 | model = lmodel; | ||
| 133 | |||
| 134 | ops->setup = op_sh_setup; | ||
| 135 | ops->create_files = op_sh_create_files; | ||
| 136 | ops->start = op_sh_start; | ||
| 137 | ops->stop = op_sh_stop; | ||
| 138 | ops->cpu_type = lmodel->cpu_type; | ||
| 139 | |||
| 140 | printk(KERN_INFO "oprofile: using %s performance monitoring.\n", | ||
| 141 | lmodel->cpu_type); | ||
| 142 | |||
| 143 | return 0; | ||
| 144 | } | ||
| 145 | |||
| 146 | void oprofile_arch_exit(void) | ||
| 147 | { | ||
| 148 | if (model && model->exit) | ||
| 149 | model->exit(); | ||
| 150 | } | ||
