diff options
| -rw-r--r-- | arch/sh/Kconfig | 13 | ||||
| -rw-r--r-- | arch/sh/oprofile/Makefile | 4 | ||||
| -rw-r--r-- | arch/sh/oprofile/common.c | 115 | ||||
| -rw-r--r-- | arch/sh/oprofile/op_impl.h | 33 |
4 files changed, 40 insertions, 125 deletions
diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig index 33990fa95af0..35b6c3f85173 100644 --- a/arch/sh/Kconfig +++ b/arch/sh/Kconfig | |||
| @@ -249,6 +249,11 @@ config ARCH_SHMOBILE | |||
| 249 | select PM | 249 | select PM |
| 250 | select PM_RUNTIME | 250 | select PM_RUNTIME |
| 251 | 251 | ||
| 252 | config CPU_HAS_PMU | ||
| 253 | depends on CPU_SH4 || CPU_SH4A | ||
| 254 | default y | ||
| 255 | bool | ||
| 256 | |||
| 252 | if SUPERH32 | 257 | if SUPERH32 |
| 253 | 258 | ||
| 254 | choice | 259 | choice |
| @@ -738,6 +743,14 @@ config GUSA_RB | |||
| 738 | LLSC, this should be more efficient than the other alternative of | 743 | LLSC, this should be more efficient than the other alternative of |
| 739 | disabling interrupts around the atomic sequence. | 744 | disabling interrupts around the atomic sequence. |
| 740 | 745 | ||
| 746 | config HW_PERF_EVENTS | ||
| 747 | bool "Enable hardware performance counter support for perf events" | ||
| 748 | depends on PERF_EVENTS && CPU_HAS_PMU | ||
| 749 | default y | ||
| 750 | help | ||
| 751 | Enable hardware performance counter support for perf events. If | ||
| 752 | disabled, perf events will use software events only. | ||
| 753 | |||
| 741 | source "drivers/sh/Kconfig" | 754 | source "drivers/sh/Kconfig" |
| 742 | 755 | ||
| 743 | endmenu | 756 | endmenu |
diff --git a/arch/sh/oprofile/Makefile b/arch/sh/oprofile/Makefile index 4886c5c1786c..e85aae73e3dc 100644 --- a/arch/sh/oprofile/Makefile +++ b/arch/sh/oprofile/Makefile | |||
| @@ -6,4 +6,8 @@ DRIVER_OBJS = $(addprefix ../../../drivers/oprofile/, \ | |||
| 6 | oprofilefs.o oprofile_stats.o \ | 6 | oprofilefs.o oprofile_stats.o \ |
| 7 | timer_int.o ) | 7 | timer_int.o ) |
| 8 | 8 | ||
| 9 | ifeq ($(CONFIG_HW_PERF_EVENTS),y) | ||
| 10 | DRIVER_OBJS += $(addprefix ../../../drivers/oprofile/, oprofile_perf.o) | ||
| 11 | endif | ||
| 12 | |||
| 9 | oprofile-y := $(DRIVER_OBJS) common.o backtrace.o | 13 | oprofile-y := $(DRIVER_OBJS) common.o backtrace.o |
diff --git a/arch/sh/oprofile/common.c b/arch/sh/oprofile/common.c index ac604937f3ee..e10d89376f9b 100644 --- a/arch/sh/oprofile/common.c +++ b/arch/sh/oprofile/common.c | |||
| @@ -17,114 +17,45 @@ | |||
| 17 | #include <linux/init.h> | 17 | #include <linux/init.h> |
| 18 | #include <linux/errno.h> | 18 | #include <linux/errno.h> |
| 19 | #include <linux/smp.h> | 19 | #include <linux/smp.h> |
| 20 | #include <linux/perf_event.h> | ||
| 20 | #include <asm/processor.h> | 21 | #include <asm/processor.h> |
| 21 | #include "op_impl.h" | ||
| 22 | |||
| 23 | static struct op_sh_model *model; | ||
| 24 | |||
| 25 | static struct op_counter_config ctr[20]; | ||
| 26 | 22 | ||
| 23 | #ifdef CONFIG_HW_PERF_EVENTS | ||
| 27 | extern void sh_backtrace(struct pt_regs * const regs, unsigned int depth); | 24 | extern void sh_backtrace(struct pt_regs * const regs, unsigned int depth); |
| 28 | 25 | ||
| 29 | static int op_sh_setup(void) | 26 | char *op_name_from_perf_id(void) |
| 30 | { | ||
| 31 | /* Pre-compute the values to stuff in the hardware registers. */ | ||
| 32 | model->reg_setup(ctr); | ||
| 33 | |||
| 34 | /* Configure the registers on all cpus. */ | ||
| 35 | on_each_cpu(model->cpu_setup, NULL, 1); | ||
| 36 | |||
| 37 | return 0; | ||
| 38 | } | ||
| 39 | |||
| 40 | static int op_sh_create_files(struct super_block *sb, struct dentry *root) | ||
| 41 | { | 27 | { |
| 42 | int i, ret = 0; | 28 | const char *pmu; |
| 29 | char buf[20]; | ||
| 30 | int size; | ||
| 43 | 31 | ||
| 44 | for (i = 0; i < model->num_counters; i++) { | 32 | pmu = perf_pmu_name(); |
| 45 | struct dentry *dir; | 33 | if (!pmu) |
| 46 | char buf[4]; | 34 | return NULL; |
| 47 | 35 | ||
| 48 | snprintf(buf, sizeof(buf), "%d", i); | 36 | size = snprintf(buf, sizeof(buf), "sh/%s", pmu); |
| 49 | dir = oprofilefs_mkdir(sb, root, buf); | 37 | if (size > -1 && size < sizeof(buf)) |
| 38 | return buf; | ||
| 50 | 39 | ||
| 51 | ret |= oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled); | 40 | return NULL; |
| 52 | ret |= oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event); | ||
| 53 | ret |= oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel); | ||
| 54 | ret |= oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user); | ||
| 55 | |||
| 56 | if (model->create_files) | ||
| 57 | ret |= model->create_files(sb, dir); | ||
| 58 | else | ||
| 59 | ret |= oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count); | ||
| 60 | |||
| 61 | /* Dummy entries */ | ||
| 62 | ret |= oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask); | ||
| 63 | } | ||
| 64 | |||
| 65 | return ret; | ||
| 66 | } | 41 | } |
| 67 | 42 | ||
| 68 | static int op_sh_start(void) | 43 | int __init oprofile_arch_init(struct oprofile_operations *ops) |
| 69 | { | 44 | { |
| 70 | /* Enable performance monitoring for all counters. */ | 45 | ops->backtrace = sh_backtrace; |
| 71 | on_each_cpu(model->cpu_start, NULL, 1); | ||
| 72 | 46 | ||
| 73 | return 0; | 47 | return oprofile_perf_init(ops); |
| 74 | } | 48 | } |
| 75 | 49 | ||
| 76 | static void op_sh_stop(void) | 50 | void __exit oprofile_arch_exit(void) |
| 77 | { | 51 | { |
| 78 | /* Disable performance monitoring for all counters. */ | 52 | oprofile_perf_exit(); |
| 79 | on_each_cpu(model->cpu_stop, NULL, 1); | ||
| 80 | } | 53 | } |
| 81 | 54 | #else | |
| 82 | int __init oprofile_arch_init(struct oprofile_operations *ops) | 55 | int __init oprofile_arch_init(struct oprofile_operations *ops) |
| 83 | { | 56 | { |
| 84 | struct op_sh_model *lmodel = NULL; | 57 | pr_info("oprofile: hardware counters not available\n"); |
| 85 | int ret; | 58 | return -ENODEV; |
| 86 | |||
| 87 | /* | ||
| 88 | * Always assign the backtrace op. If the counter initialization | ||
| 89 | * fails, we fall back to the timer which will still make use of | ||
| 90 | * this. | ||
| 91 | */ | ||
| 92 | ops->backtrace = sh_backtrace; | ||
| 93 | |||
| 94 | /* | ||
| 95 | * XXX | ||
| 96 | * | ||
| 97 | * All of the SH7750/SH-4A counters have been converted to perf, | ||
| 98 | * this infrastructure hook is left for other users until they've | ||
| 99 | * had a chance to convert over, at which point all of this | ||
| 100 | * will be deleted. | ||
| 101 | */ | ||
| 102 | |||
| 103 | if (!lmodel) | ||
| 104 | return -ENODEV; | ||
| 105 | if (!(current_cpu_data.flags & CPU_HAS_PERF_COUNTER)) | ||
| 106 | return -ENODEV; | ||
| 107 | |||
| 108 | ret = lmodel->init(); | ||
| 109 | if (unlikely(ret != 0)) | ||
| 110 | return ret; | ||
| 111 | |||
| 112 | model = lmodel; | ||
| 113 | |||
| 114 | ops->setup = op_sh_setup; | ||
| 115 | ops->create_files = op_sh_create_files; | ||
| 116 | ops->start = op_sh_start; | ||
| 117 | ops->stop = op_sh_stop; | ||
| 118 | ops->cpu_type = lmodel->cpu_type; | ||
| 119 | |||
| 120 | printk(KERN_INFO "oprofile: using %s performance monitoring.\n", | ||
| 121 | lmodel->cpu_type); | ||
| 122 | |||
| 123 | return 0; | ||
| 124 | } | ||
| 125 | |||
| 126 | void oprofile_arch_exit(void) | ||
| 127 | { | ||
| 128 | if (model && model->exit) | ||
| 129 | model->exit(); | ||
| 130 | } | 59 | } |
| 60 | void __exit oprofile_arch_exit(void) {} | ||
| 61 | #endif /* CONFIG_HW_PERF_EVENTS */ | ||
diff --git a/arch/sh/oprofile/op_impl.h b/arch/sh/oprofile/op_impl.h deleted file mode 100644 index 1244479ceb29..000000000000 --- a/arch/sh/oprofile/op_impl.h +++ /dev/null | |||
| @@ -1,33 +0,0 @@ | |||
| 1 | #ifndef __OP_IMPL_H | ||
| 2 | #define __OP_IMPL_H | ||
| 3 | |||
| 4 | /* Per-counter configuration as set via oprofilefs. */ | ||
| 5 | struct op_counter_config { | ||
| 6 | unsigned long enabled; | ||
| 7 | unsigned long event; | ||
| 8 | |||
| 9 | unsigned long count; | ||
| 10 | |||
| 11 | /* Dummy values for userspace tool compliance */ | ||
| 12 | unsigned long kernel; | ||
| 13 | unsigned long user; | ||
| 14 | unsigned long unit_mask; | ||
| 15 | }; | ||
| 16 | |||
| 17 | /* Per-architecture configury and hooks. */ | ||
| 18 | struct op_sh_model { | ||
| 19 | void (*reg_setup)(struct op_counter_config *); | ||
| 20 | int (*create_files)(struct super_block *sb, struct dentry *dir); | ||
| 21 | void (*cpu_setup)(void *dummy); | ||
| 22 | int (*init)(void); | ||
| 23 | void (*exit)(void); | ||
| 24 | void (*cpu_start)(void *args); | ||
| 25 | void (*cpu_stop)(void *args); | ||
| 26 | char *cpu_type; | ||
| 27 | unsigned char num_counters; | ||
| 28 | }; | ||
| 29 | |||
| 30 | /* arch/sh/oprofile/common.c */ | ||
| 31 | extern void sh_backtrace(struct pt_regs * const regs, unsigned int depth); | ||
| 32 | |||
| 33 | #endif /* __OP_IMPL_H */ | ||
