Loading arch/arm/kernel/perf_event.c +6 −0 Original line number Original line Diff line number Diff line Loading @@ -123,6 +123,12 @@ armpmu_get_max_events(void) } } EXPORT_SYMBOL_GPL(armpmu_get_max_events); EXPORT_SYMBOL_GPL(armpmu_get_max_events); int perf_num_counters(void) { return armpmu_get_max_events(); } EXPORT_SYMBOL_GPL(perf_num_counters); #define HW_OP_UNSUPPORTED 0xFFFF #define HW_OP_UNSUPPORTED 0xFFFF #define C(_x) \ #define C(_x) \ Loading arch/arm/oprofile/Makefile +4 −0 Original line number Original line Diff line number Diff line Loading @@ -6,4 +6,8 @@ DRIVER_OBJS = $(addprefix ../../../drivers/oprofile/, \ oprofilefs.o oprofile_stats.o \ oprofilefs.o oprofile_stats.o \ timer_int.o ) timer_int.o ) ifeq ($(CONFIG_HW_PERF_EVENTS),y) DRIVER_OBJS += $(addprefix ../../../drivers/oprofile/, oprofile_perf.o) endif oprofile-y := $(DRIVER_OBJS) common.o oprofile-y := $(DRIVER_OBJS) common.o arch/arm/oprofile/common.c +7 −306 Original line number Original line Diff line number Diff line Loading @@ -25,138 +25,10 @@ #include <asm/ptrace.h> #include <asm/ptrace.h> #ifdef CONFIG_HW_PERF_EVENTS #ifdef CONFIG_HW_PERF_EVENTS /* char *op_name_from_perf_id(void) * Per performance monitor configuration as set via oprofilefs. */ struct op_counter_config { unsigned long count; unsigned long enabled; unsigned long event; unsigned long unit_mask; unsigned long kernel; unsigned long user; struct perf_event_attr attr; }; static int op_arm_enabled; static DEFINE_MUTEX(op_arm_mutex); static struct op_counter_config *counter_config; static struct perf_event **perf_events[nr_cpumask_bits]; static int perf_num_counters; /* * Overflow callback for oprofile. */ static void op_overflow_handler(struct perf_event *event, int unused, struct perf_sample_data *data, struct pt_regs *regs) { int id; u32 cpu = smp_processor_id(); for (id = 0; id < perf_num_counters; ++id) if (perf_events[cpu][id] == event) break; if (id != perf_num_counters) oprofile_add_sample(regs, id); else pr_warning("oprofile: ignoring spurious overflow " "on cpu %u\n", cpu); } /* * Called by op_arm_setup to create perf attributes to mirror the oprofile * settings in counter_config. Attributes are created as `pinned' events and * so are permanently scheduled on the PMU. */ static void op_perf_setup(void) { int i; u32 size = sizeof(struct perf_event_attr); struct perf_event_attr *attr; for (i = 0; i < perf_num_counters; ++i) { attr = &counter_config[i].attr; memset(attr, 0, size); attr->type = PERF_TYPE_RAW; attr->size = size; attr->config = counter_config[i].event; attr->sample_period = counter_config[i].count; attr->pinned = 1; } } static int op_create_counter(int cpu, int event) { struct perf_event *pevent; if (!counter_config[event].enabled || perf_events[cpu][event]) return 0; pevent = perf_event_create_kernel_counter(&counter_config[event].attr, cpu, -1, op_overflow_handler); if (IS_ERR(pevent)) return PTR_ERR(pevent); if (pevent->state != PERF_EVENT_STATE_ACTIVE) { perf_event_release_kernel(pevent); pr_warning("oprofile: failed to enable event %d " "on CPU %d\n", event, cpu); return -EBUSY; } perf_events[cpu][event] = pevent; return 0; } static void op_destroy_counter(int cpu, int event) { struct perf_event *pevent = perf_events[cpu][event]; if (pevent) { perf_event_release_kernel(pevent); perf_events[cpu][event] = NULL; } } /* * Called by op_arm_start to create active perf events based on the * perviously configured attributes. */ static int op_perf_start(void) { { int cpu, event, ret = 0; enum arm_perf_pmu_ids id = armpmu_get_pmu_id(); for_each_online_cpu(cpu) { for (event = 0; event < perf_num_counters; ++event) { ret = op_create_counter(cpu, event); if (ret) return ret; } } return ret; } /* * Called by op_arm_stop at the end of a profiling run. */ static void op_perf_stop(void) { int cpu, event; for_each_online_cpu(cpu) for (event = 0; event < perf_num_counters; ++event) op_destroy_counter(cpu, event); } static char *op_name_from_perf_id(enum arm_perf_pmu_ids id) { switch (id) { switch (id) { case ARM_PERF_PMU_ID_XSCALE1: case ARM_PERF_PMU_ID_XSCALE1: return "arm/xscale1"; return "arm/xscale1"; Loading @@ -175,115 +47,6 @@ static char *op_name_from_perf_id(enum arm_perf_pmu_ids id) } } } } static int op_arm_create_files(struct super_block *sb, struct dentry *root) { unsigned int i; for (i = 0; i < perf_num_counters; i++) { struct dentry *dir; char buf[4]; snprintf(buf, sizeof buf, "%d", i); dir = oprofilefs_mkdir(sb, root, buf); oprofilefs_create_ulong(sb, dir, "enabled", &counter_config[i].enabled); oprofilefs_create_ulong(sb, dir, "event", &counter_config[i].event); oprofilefs_create_ulong(sb, dir, "count", &counter_config[i].count); oprofilefs_create_ulong(sb, dir, "unit_mask", &counter_config[i].unit_mask); oprofilefs_create_ulong(sb, dir, "kernel", &counter_config[i].kernel); oprofilefs_create_ulong(sb, dir, "user", &counter_config[i].user); } return 0; } static int op_arm_setup(void) { spin_lock(&oprofilefs_lock); op_perf_setup(); spin_unlock(&oprofilefs_lock); return 0; } static int op_arm_start(void) { int ret = -EBUSY; mutex_lock(&op_arm_mutex); if (!op_arm_enabled) { ret = 0; op_perf_start(); op_arm_enabled = 1; } mutex_unlock(&op_arm_mutex); return ret; } static void op_arm_stop(void) { mutex_lock(&op_arm_mutex); if (op_arm_enabled) op_perf_stop(); op_arm_enabled = 0; mutex_unlock(&op_arm_mutex); } #ifdef CONFIG_PM static int op_arm_suspend(struct platform_device *dev, pm_message_t state) { mutex_lock(&op_arm_mutex); if (op_arm_enabled) op_perf_stop(); mutex_unlock(&op_arm_mutex); return 0; } static int op_arm_resume(struct platform_device *dev) { mutex_lock(&op_arm_mutex); if (op_arm_enabled && op_perf_start()) op_arm_enabled = 0; mutex_unlock(&op_arm_mutex); return 0; } static struct platform_driver oprofile_driver = { .driver = { .name = "arm-oprofile", }, .resume = op_arm_resume, .suspend = op_arm_suspend, }; static struct platform_device *oprofile_pdev; static int __init init_driverfs(void) { int ret; ret = platform_driver_register(&oprofile_driver); if (ret) return ret; oprofile_pdev = platform_device_register_simple( oprofile_driver.driver.name, 0, NULL, 0); if (IS_ERR(oprofile_pdev)) { ret = PTR_ERR(oprofile_pdev); platform_driver_unregister(&oprofile_driver); } return ret; } static void __exit exit_driverfs(void) { platform_device_unregister(oprofile_pdev); platform_driver_unregister(&oprofile_driver); } #else static int __init init_driverfs(void) { return 0; } #define exit_driverfs() do { } while (0) #endif /* CONFIG_PM */ static int report_trace(struct stackframe *frame, void *d) static int report_trace(struct stackframe *frame, void *d) { { unsigned int *depth = d; unsigned int *depth = d; Loading Loading @@ -346,79 +109,17 @@ static void arm_backtrace(struct pt_regs * const regs, unsigned int depth) tail = user_backtrace(tail); tail = user_backtrace(tail); } } void oprofile_arch_exit(void) { int cpu, id; struct perf_event *event; for_each_possible_cpu(cpu) { for (id = 0; id < perf_num_counters; ++id) { event = perf_events[cpu][id]; if (event) perf_event_release_kernel(event); } kfree(perf_events[cpu]); } kfree(counter_config); exit_driverfs(); } int __init oprofile_arch_init(struct oprofile_operations *ops) int __init oprofile_arch_init(struct oprofile_operations *ops) { { int cpu, ret = 0; ret = init_driverfs(); if (ret) return ret; memset(&perf_events, 0, sizeof(perf_events)); perf_num_counters = armpmu_get_max_events(); counter_config = kcalloc(perf_num_counters, sizeof(struct op_counter_config), GFP_KERNEL); if (!counter_config) { pr_info("oprofile: failed to allocate %d " "counters\n", perf_num_counters); ret = -ENOMEM; perf_num_counters = 0; goto out; } for_each_possible_cpu(cpu) { perf_events[cpu] = kcalloc(perf_num_counters, sizeof(struct perf_event *), GFP_KERNEL); if (!perf_events[cpu]) { pr_info("oprofile: failed to allocate %d perf events " "for cpu %d\n", perf_num_counters, cpu); ret = -ENOMEM; goto out; } } ops->backtrace = arm_backtrace; ops->backtrace = arm_backtrace; ops->create_files = op_arm_create_files; ops->setup = op_arm_setup; ops->start = op_arm_start; ops->stop = op_arm_stop; ops->shutdown = op_arm_stop; ops->cpu_type = op_name_from_perf_id(armpmu_get_pmu_id()); if (!ops->cpu_type) ret = -ENODEV; else pr_info("oprofile: using %s\n", ops->cpu_type); out: return oprofile_perf_init(ops); if (ret) oprofile_arch_exit(); return ret; } } void __exit oprofile_arch_exit(void) { oprofile_perf_exit(); } #else #else int __init oprofile_arch_init(struct oprofile_operations *ops) int __init oprofile_arch_init(struct oprofile_operations *ops) { { Loading arch/sh/Kconfig +13 −0 Original line number Original line Diff line number Diff line Loading @@ -249,6 +249,11 @@ config ARCH_SHMOBILE select PM select PM select PM_RUNTIME select PM_RUNTIME config CPU_HAS_PMU depends on CPU_SH4 || CPU_SH4A default y bool if SUPERH32 if SUPERH32 choice choice Loading Loading @@ -738,6 +743,14 @@ config GUSA_RB LLSC, this should be more efficient than the other alternative of LLSC, this should be more efficient than the other alternative of disabling interrupts around the atomic sequence. disabling interrupts around the atomic sequence. config HW_PERF_EVENTS bool "Enable hardware performance counter support for perf events" depends on PERF_EVENTS && CPU_HAS_PMU default y help Enable hardware performance counter support for perf events. If disabled, perf events will use software events only. source "drivers/sh/Kconfig" source "drivers/sh/Kconfig" endmenu endmenu Loading arch/sh/kernel/perf_event.c +18 −0 Original line number Original line Diff line number Diff line Loading @@ -59,6 +59,24 @@ static inline int sh_pmu_initialized(void) return !!sh_pmu; return !!sh_pmu; } } const char *perf_pmu_name(void) { if (!sh_pmu) return NULL; return sh_pmu->name; } EXPORT_SYMBOL_GPL(perf_pmu_name); int perf_num_counters(void) { if (!sh_pmu) return 0; return sh_pmu->num_events; } EXPORT_SYMBOL_GPL(perf_num_counters); /* /* * Release the PMU if this is the last perf_event. * Release the PMU if this is the last perf_event. */ */ Loading Loading
arch/arm/kernel/perf_event.c +6 −0 Original line number Original line Diff line number Diff line Loading @@ -123,6 +123,12 @@ armpmu_get_max_events(void) } } EXPORT_SYMBOL_GPL(armpmu_get_max_events); EXPORT_SYMBOL_GPL(armpmu_get_max_events); int perf_num_counters(void) { return armpmu_get_max_events(); } EXPORT_SYMBOL_GPL(perf_num_counters); #define HW_OP_UNSUPPORTED 0xFFFF #define HW_OP_UNSUPPORTED 0xFFFF #define C(_x) \ #define C(_x) \ Loading
arch/arm/oprofile/Makefile +4 −0 Original line number Original line Diff line number Diff line Loading @@ -6,4 +6,8 @@ DRIVER_OBJS = $(addprefix ../../../drivers/oprofile/, \ oprofilefs.o oprofile_stats.o \ oprofilefs.o oprofile_stats.o \ timer_int.o ) timer_int.o ) ifeq ($(CONFIG_HW_PERF_EVENTS),y) DRIVER_OBJS += $(addprefix ../../../drivers/oprofile/, oprofile_perf.o) endif oprofile-y := $(DRIVER_OBJS) common.o oprofile-y := $(DRIVER_OBJS) common.o
arch/arm/oprofile/common.c +7 −306 Original line number Original line Diff line number Diff line Loading @@ -25,138 +25,10 @@ #include <asm/ptrace.h> #include <asm/ptrace.h> #ifdef CONFIG_HW_PERF_EVENTS #ifdef CONFIG_HW_PERF_EVENTS /* char *op_name_from_perf_id(void) * Per performance monitor configuration as set via oprofilefs. */ struct op_counter_config { unsigned long count; unsigned long enabled; unsigned long event; unsigned long unit_mask; unsigned long kernel; unsigned long user; struct perf_event_attr attr; }; static int op_arm_enabled; static DEFINE_MUTEX(op_arm_mutex); static struct op_counter_config *counter_config; static struct perf_event **perf_events[nr_cpumask_bits]; static int perf_num_counters; /* * Overflow callback for oprofile. */ static void op_overflow_handler(struct perf_event *event, int unused, struct perf_sample_data *data, struct pt_regs *regs) { int id; u32 cpu = smp_processor_id(); for (id = 0; id < perf_num_counters; ++id) if (perf_events[cpu][id] == event) break; if (id != perf_num_counters) oprofile_add_sample(regs, id); else pr_warning("oprofile: ignoring spurious overflow " "on cpu %u\n", cpu); } /* * Called by op_arm_setup to create perf attributes to mirror the oprofile * settings in counter_config. Attributes are created as `pinned' events and * so are permanently scheduled on the PMU. */ static void op_perf_setup(void) { int i; u32 size = sizeof(struct perf_event_attr); struct perf_event_attr *attr; for (i = 0; i < perf_num_counters; ++i) { attr = &counter_config[i].attr; memset(attr, 0, size); attr->type = PERF_TYPE_RAW; attr->size = size; attr->config = counter_config[i].event; attr->sample_period = counter_config[i].count; attr->pinned = 1; } } static int op_create_counter(int cpu, int event) { struct perf_event *pevent; if (!counter_config[event].enabled || perf_events[cpu][event]) return 0; pevent = perf_event_create_kernel_counter(&counter_config[event].attr, cpu, -1, op_overflow_handler); if (IS_ERR(pevent)) return PTR_ERR(pevent); if (pevent->state != PERF_EVENT_STATE_ACTIVE) { perf_event_release_kernel(pevent); pr_warning("oprofile: failed to enable event %d " "on CPU %d\n", event, cpu); return -EBUSY; } perf_events[cpu][event] = pevent; return 0; } static void op_destroy_counter(int cpu, int event) { struct perf_event *pevent = perf_events[cpu][event]; if (pevent) { perf_event_release_kernel(pevent); perf_events[cpu][event] = NULL; } } /* * Called by op_arm_start to create active perf events based on the * perviously configured attributes. */ static int op_perf_start(void) { { int cpu, event, ret = 0; enum arm_perf_pmu_ids id = armpmu_get_pmu_id(); for_each_online_cpu(cpu) { for (event = 0; event < perf_num_counters; ++event) { ret = op_create_counter(cpu, event); if (ret) return ret; } } return ret; } /* * Called by op_arm_stop at the end of a profiling run. */ static void op_perf_stop(void) { int cpu, event; for_each_online_cpu(cpu) for (event = 0; event < perf_num_counters; ++event) op_destroy_counter(cpu, event); } static char *op_name_from_perf_id(enum arm_perf_pmu_ids id) { switch (id) { switch (id) { case ARM_PERF_PMU_ID_XSCALE1: case ARM_PERF_PMU_ID_XSCALE1: return "arm/xscale1"; return "arm/xscale1"; Loading @@ -175,115 +47,6 @@ static char *op_name_from_perf_id(enum arm_perf_pmu_ids id) } } } } static int op_arm_create_files(struct super_block *sb, struct dentry *root) { unsigned int i; for (i = 0; i < perf_num_counters; i++) { struct dentry *dir; char buf[4]; snprintf(buf, sizeof buf, "%d", i); dir = oprofilefs_mkdir(sb, root, buf); oprofilefs_create_ulong(sb, dir, "enabled", &counter_config[i].enabled); oprofilefs_create_ulong(sb, dir, "event", &counter_config[i].event); oprofilefs_create_ulong(sb, dir, "count", &counter_config[i].count); oprofilefs_create_ulong(sb, dir, "unit_mask", &counter_config[i].unit_mask); oprofilefs_create_ulong(sb, dir, "kernel", &counter_config[i].kernel); oprofilefs_create_ulong(sb, dir, "user", &counter_config[i].user); } return 0; } static int op_arm_setup(void) { spin_lock(&oprofilefs_lock); op_perf_setup(); spin_unlock(&oprofilefs_lock); return 0; } static int op_arm_start(void) { int ret = -EBUSY; mutex_lock(&op_arm_mutex); if (!op_arm_enabled) { ret = 0; op_perf_start(); op_arm_enabled = 1; } mutex_unlock(&op_arm_mutex); return ret; } static void op_arm_stop(void) { mutex_lock(&op_arm_mutex); if (op_arm_enabled) op_perf_stop(); op_arm_enabled = 0; mutex_unlock(&op_arm_mutex); } #ifdef CONFIG_PM static int op_arm_suspend(struct platform_device *dev, pm_message_t state) { mutex_lock(&op_arm_mutex); if (op_arm_enabled) op_perf_stop(); mutex_unlock(&op_arm_mutex); return 0; } static int op_arm_resume(struct platform_device *dev) { mutex_lock(&op_arm_mutex); if (op_arm_enabled && op_perf_start()) op_arm_enabled = 0; mutex_unlock(&op_arm_mutex); return 0; } static struct platform_driver oprofile_driver = { .driver = { .name = "arm-oprofile", }, .resume = op_arm_resume, .suspend = op_arm_suspend, }; static struct platform_device *oprofile_pdev; static int __init init_driverfs(void) { int ret; ret = platform_driver_register(&oprofile_driver); if (ret) return ret; oprofile_pdev = platform_device_register_simple( oprofile_driver.driver.name, 0, NULL, 0); if (IS_ERR(oprofile_pdev)) { ret = PTR_ERR(oprofile_pdev); platform_driver_unregister(&oprofile_driver); } return ret; } static void __exit exit_driverfs(void) { platform_device_unregister(oprofile_pdev); platform_driver_unregister(&oprofile_driver); } #else static int __init init_driverfs(void) { return 0; } #define exit_driverfs() do { } while (0) #endif /* CONFIG_PM */ static int report_trace(struct stackframe *frame, void *d) static int report_trace(struct stackframe *frame, void *d) { { unsigned int *depth = d; unsigned int *depth = d; Loading Loading @@ -346,79 +109,17 @@ static void arm_backtrace(struct pt_regs * const regs, unsigned int depth) tail = user_backtrace(tail); tail = user_backtrace(tail); } } void oprofile_arch_exit(void) { int cpu, id; struct perf_event *event; for_each_possible_cpu(cpu) { for (id = 0; id < perf_num_counters; ++id) { event = perf_events[cpu][id]; if (event) perf_event_release_kernel(event); } kfree(perf_events[cpu]); } kfree(counter_config); exit_driverfs(); } int __init oprofile_arch_init(struct oprofile_operations *ops) int __init oprofile_arch_init(struct oprofile_operations *ops) { { int cpu, ret = 0; ret = init_driverfs(); if (ret) return ret; memset(&perf_events, 0, sizeof(perf_events)); perf_num_counters = armpmu_get_max_events(); counter_config = kcalloc(perf_num_counters, sizeof(struct op_counter_config), GFP_KERNEL); if (!counter_config) { pr_info("oprofile: failed to allocate %d " "counters\n", perf_num_counters); ret = -ENOMEM; perf_num_counters = 0; goto out; } for_each_possible_cpu(cpu) { perf_events[cpu] = kcalloc(perf_num_counters, sizeof(struct perf_event *), GFP_KERNEL); if (!perf_events[cpu]) { pr_info("oprofile: failed to allocate %d perf events " "for cpu %d\n", perf_num_counters, cpu); ret = -ENOMEM; goto out; } } ops->backtrace = arm_backtrace; ops->backtrace = arm_backtrace; ops->create_files = op_arm_create_files; ops->setup = op_arm_setup; ops->start = op_arm_start; ops->stop = op_arm_stop; ops->shutdown = op_arm_stop; ops->cpu_type = op_name_from_perf_id(armpmu_get_pmu_id()); if (!ops->cpu_type) ret = -ENODEV; else pr_info("oprofile: using %s\n", ops->cpu_type); out: return oprofile_perf_init(ops); if (ret) oprofile_arch_exit(); return ret; } } void __exit oprofile_arch_exit(void) { oprofile_perf_exit(); } #else #else int __init oprofile_arch_init(struct oprofile_operations *ops) int __init oprofile_arch_init(struct oprofile_operations *ops) { { Loading
arch/sh/Kconfig +13 −0 Original line number Original line Diff line number Diff line Loading @@ -249,6 +249,11 @@ config ARCH_SHMOBILE select PM select PM select PM_RUNTIME select PM_RUNTIME config CPU_HAS_PMU depends on CPU_SH4 || CPU_SH4A default y bool if SUPERH32 if SUPERH32 choice choice Loading Loading @@ -738,6 +743,14 @@ config GUSA_RB LLSC, this should be more efficient than the other alternative of LLSC, this should be more efficient than the other alternative of disabling interrupts around the atomic sequence. disabling interrupts around the atomic sequence. config HW_PERF_EVENTS bool "Enable hardware performance counter support for perf events" depends on PERF_EVENTS && CPU_HAS_PMU default y help Enable hardware performance counter support for perf events. If disabled, perf events will use software events only. source "drivers/sh/Kconfig" source "drivers/sh/Kconfig" endmenu endmenu Loading
arch/sh/kernel/perf_event.c +18 −0 Original line number Original line Diff line number Diff line Loading @@ -59,6 +59,24 @@ static inline int sh_pmu_initialized(void) return !!sh_pmu; return !!sh_pmu; } } const char *perf_pmu_name(void) { if (!sh_pmu) return NULL; return sh_pmu->name; } EXPORT_SYMBOL_GPL(perf_pmu_name); int perf_num_counters(void) { if (!sh_pmu) return 0; return sh_pmu->num_events; } EXPORT_SYMBOL_GPL(perf_num_counters); /* /* * Release the PMU if this is the last perf_event. * Release the PMU if this is the last perf_event. */ */ Loading