diff options
Diffstat (limited to 'arch/arm/oprofile')
-rw-r--r-- | arch/arm/oprofile/Makefile | 4 | ||||
-rw-r--r-- | arch/arm/oprofile/common.c | 308 |
2 files changed, 10 insertions, 302 deletions
diff --git a/arch/arm/oprofile/Makefile b/arch/arm/oprofile/Makefile index e666eafed152..b2215c61cdf0 100644 --- a/arch/arm/oprofile/Makefile +++ b/arch/arm/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 | 13 | oprofile-y := $(DRIVER_OBJS) common.o |
diff --git a/arch/arm/oprofile/common.c b/arch/arm/oprofile/common.c index 0691176899ff..8aa974491dfc 100644 --- a/arch/arm/oprofile/common.c +++ b/arch/arm/oprofile/common.c | |||
@@ -25,138 +25,10 @@ | |||
25 | #include <asm/ptrace.h> | 25 | #include <asm/ptrace.h> |
26 | 26 | ||
27 | #ifdef CONFIG_HW_PERF_EVENTS | 27 | #ifdef CONFIG_HW_PERF_EVENTS |
28 | /* | 28 | char *op_name_from_perf_id(void) |
29 | * Per performance monitor configuration as set via oprofilefs. | ||
30 | */ | ||
31 | struct op_counter_config { | ||
32 | unsigned long count; | ||
33 | unsigned long enabled; | ||
34 | unsigned long event; | ||
35 | unsigned long unit_mask; | ||
36 | unsigned long kernel; | ||
37 | unsigned long user; | ||
38 | struct perf_event_attr attr; | ||
39 | }; | ||
40 | |||
41 | static int op_arm_enabled; | ||
42 | static DEFINE_MUTEX(op_arm_mutex); | ||
43 | |||
44 | static struct op_counter_config *counter_config; | ||
45 | static struct perf_event **perf_events[nr_cpumask_bits]; | ||
46 | static int perf_num_counters; | ||
47 | |||
48 | /* | ||
49 | * Overflow callback for oprofile. | ||
50 | */ | ||
51 | static void op_overflow_handler(struct perf_event *event, int unused, | ||
52 | struct perf_sample_data *data, struct pt_regs *regs) | ||
53 | { | ||
54 | int id; | ||
55 | u32 cpu = smp_processor_id(); | ||
56 | |||
57 | for (id = 0; id < perf_num_counters; ++id) | ||
58 | if (perf_events[cpu][id] == event) | ||
59 | break; | ||
60 | |||
61 | if (id != perf_num_counters) | ||
62 | oprofile_add_sample(regs, id); | ||
63 | else | ||
64 | pr_warning("oprofile: ignoring spurious overflow " | ||
65 | "on cpu %u\n", cpu); | ||
66 | } | ||
67 | |||
68 | /* | ||
69 | * Called by op_arm_setup to create perf attributes to mirror the oprofile | ||
70 | * settings in counter_config. Attributes are created as `pinned' events and | ||
71 | * so are permanently scheduled on the PMU. | ||
72 | */ | ||
73 | static void op_perf_setup(void) | ||
74 | { | ||
75 | int i; | ||
76 | u32 size = sizeof(struct perf_event_attr); | ||
77 | struct perf_event_attr *attr; | ||
78 | |||
79 | for (i = 0; i < perf_num_counters; ++i) { | ||
80 | attr = &counter_config[i].attr; | ||
81 | memset(attr, 0, size); | ||
82 | attr->type = PERF_TYPE_RAW; | ||
83 | attr->size = size; | ||
84 | attr->config = counter_config[i].event; | ||
85 | attr->sample_period = counter_config[i].count; | ||
86 | attr->pinned = 1; | ||
87 | } | ||
88 | } | ||
89 | |||
90 | static int op_create_counter(int cpu, int event) | ||
91 | { | ||
92 | int ret = 0; | ||
93 | struct perf_event *pevent; | ||
94 | |||
95 | if (!counter_config[event].enabled || (perf_events[cpu][event] != NULL)) | ||
96 | return ret; | ||
97 | |||
98 | pevent = perf_event_create_kernel_counter(&counter_config[event].attr, | ||
99 | cpu, -1, | ||
100 | op_overflow_handler); | ||
101 | |||
102 | if (IS_ERR(pevent)) { | ||
103 | ret = PTR_ERR(pevent); | ||
104 | } else if (pevent->state != PERF_EVENT_STATE_ACTIVE) { | ||
105 | pr_warning("oprofile: failed to enable event %d " | ||
106 | "on CPU %d\n", event, cpu); | ||
107 | ret = -EBUSY; | ||
108 | } else { | ||
109 | perf_events[cpu][event] = pevent; | ||
110 | } | ||
111 | |||
112 | return ret; | ||
113 | } | ||
114 | |||
115 | static void op_destroy_counter(int cpu, int event) | ||
116 | { | ||
117 | struct perf_event *pevent = perf_events[cpu][event]; | ||
118 | |||
119 | if (pevent) { | ||
120 | perf_event_release_kernel(pevent); | ||
121 | perf_events[cpu][event] = NULL; | ||
122 | } | ||
123 | } | ||
124 | |||
125 | /* | ||
126 | * Called by op_arm_start to create active perf events based on the | ||
127 | * perviously configured attributes. | ||
128 | */ | ||
129 | static int op_perf_start(void) | ||
130 | { | ||
131 | int cpu, event, ret = 0; | ||
132 | |||
133 | for_each_online_cpu(cpu) { | ||
134 | for (event = 0; event < perf_num_counters; ++event) { | ||
135 | ret = op_create_counter(cpu, event); | ||
136 | if (ret) | ||
137 | goto out; | ||
138 | } | ||
139 | } | ||
140 | |||
141 | out: | ||
142 | return ret; | ||
143 | } | ||
144 | |||
145 | /* | ||
146 | * Called by op_arm_stop at the end of a profiling run. | ||
147 | */ | ||
148 | static void op_perf_stop(void) | ||
149 | { | 29 | { |
150 | int cpu, event; | 30 | enum arm_perf_pmu_ids id = armpmu_get_pmu_id(); |
151 | 31 | ||
152 | for_each_online_cpu(cpu) | ||
153 | for (event = 0; event < perf_num_counters; ++event) | ||
154 | op_destroy_counter(cpu, event); | ||
155 | } | ||
156 | |||
157 | |||
158 | static char *op_name_from_perf_id(enum arm_perf_pmu_ids id) | ||
159 | { | ||
160 | switch (id) { | 32 | switch (id) { |
161 | case ARM_PERF_PMU_ID_XSCALE1: | 33 | case ARM_PERF_PMU_ID_XSCALE1: |
162 | return "arm/xscale1"; | 34 | return "arm/xscale1"; |
@@ -175,116 +47,6 @@ static char *op_name_from_perf_id(enum arm_perf_pmu_ids id) | |||
175 | } | 47 | } |
176 | } | 48 | } |
177 | 49 | ||
178 | static int op_arm_create_files(struct super_block *sb, struct dentry *root) | ||
179 | { | ||
180 | unsigned int i; | ||
181 | |||
182 | for (i = 0; i < perf_num_counters; i++) { | ||
183 | struct dentry *dir; | ||
184 | char buf[4]; | ||
185 | |||
186 | snprintf(buf, sizeof buf, "%d", i); | ||
187 | dir = oprofilefs_mkdir(sb, root, buf); | ||
188 | oprofilefs_create_ulong(sb, dir, "enabled", &counter_config[i].enabled); | ||
189 | oprofilefs_create_ulong(sb, dir, "event", &counter_config[i].event); | ||
190 | oprofilefs_create_ulong(sb, dir, "count", &counter_config[i].count); | ||
191 | oprofilefs_create_ulong(sb, dir, "unit_mask", &counter_config[i].unit_mask); | ||
192 | oprofilefs_create_ulong(sb, dir, "kernel", &counter_config[i].kernel); | ||
193 | oprofilefs_create_ulong(sb, dir, "user", &counter_config[i].user); | ||
194 | } | ||
195 | |||
196 | return 0; | ||
197 | } | ||
198 | |||
199 | static int op_arm_setup(void) | ||
200 | { | ||
201 | spin_lock(&oprofilefs_lock); | ||
202 | op_perf_setup(); | ||
203 | spin_unlock(&oprofilefs_lock); | ||
204 | return 0; | ||
205 | } | ||
206 | |||
207 | static int op_arm_start(void) | ||
208 | { | ||
209 | int ret = -EBUSY; | ||
210 | |||
211 | mutex_lock(&op_arm_mutex); | ||
212 | if (!op_arm_enabled) { | ||
213 | ret = 0; | ||
214 | op_perf_start(); | ||
215 | op_arm_enabled = 1; | ||
216 | } | ||
217 | mutex_unlock(&op_arm_mutex); | ||
218 | return ret; | ||
219 | } | ||
220 | |||
221 | static void op_arm_stop(void) | ||
222 | { | ||
223 | mutex_lock(&op_arm_mutex); | ||
224 | if (op_arm_enabled) | ||
225 | op_perf_stop(); | ||
226 | op_arm_enabled = 0; | ||
227 | mutex_unlock(&op_arm_mutex); | ||
228 | } | ||
229 | |||
230 | #ifdef CONFIG_PM | ||
231 | static int op_arm_suspend(struct platform_device *dev, pm_message_t state) | ||
232 | { | ||
233 | mutex_lock(&op_arm_mutex); | ||
234 | if (op_arm_enabled) | ||
235 | op_perf_stop(); | ||
236 | mutex_unlock(&op_arm_mutex); | ||
237 | return 0; | ||
238 | } | ||
239 | |||
240 | static int op_arm_resume(struct platform_device *dev) | ||
241 | { | ||
242 | mutex_lock(&op_arm_mutex); | ||
243 | if (op_arm_enabled && op_perf_start()) | ||
244 | op_arm_enabled = 0; | ||
245 | mutex_unlock(&op_arm_mutex); | ||
246 | return 0; | ||
247 | } | ||
248 | |||
249 | static struct platform_driver oprofile_driver = { | ||
250 | .driver = { | ||
251 | .name = "arm-oprofile", | ||
252 | }, | ||
253 | .resume = op_arm_resume, | ||
254 | .suspend = op_arm_suspend, | ||
255 | }; | ||
256 | |||
257 | static struct platform_device *oprofile_pdev; | ||
258 | |||
259 | static int __init init_driverfs(void) | ||
260 | { | ||
261 | int ret; | ||
262 | |||
263 | ret = platform_driver_register(&oprofile_driver); | ||
264 | if (ret) | ||
265 | goto out; | ||
266 | |||
267 | oprofile_pdev = platform_device_register_simple( | ||
268 | oprofile_driver.driver.name, 0, NULL, 0); | ||
269 | if (IS_ERR(oprofile_pdev)) { | ||
270 | ret = PTR_ERR(oprofile_pdev); | ||
271 | platform_driver_unregister(&oprofile_driver); | ||
272 | } | ||
273 | |||
274 | out: | ||
275 | return ret; | ||
276 | } | ||
277 | |||
278 | static void exit_driverfs(void) | ||
279 | { | ||
280 | platform_device_unregister(oprofile_pdev); | ||
281 | platform_driver_unregister(&oprofile_driver); | ||
282 | } | ||
283 | #else | ||
284 | static int __init init_driverfs(void) { return 0; } | ||
285 | #define exit_driverfs() do { } while (0) | ||
286 | #endif /* CONFIG_PM */ | ||
287 | |||
288 | static int report_trace(struct stackframe *frame, void *d) | 50 | static int report_trace(struct stackframe *frame, void *d) |
289 | { | 51 | { |
290 | unsigned int *depth = d; | 52 | unsigned int *depth = d; |
@@ -349,72 +111,14 @@ static void arm_backtrace(struct pt_regs * const regs, unsigned int depth) | |||
349 | 111 | ||
350 | int __init oprofile_arch_init(struct oprofile_operations *ops) | 112 | int __init oprofile_arch_init(struct oprofile_operations *ops) |
351 | { | 113 | { |
352 | int cpu, ret = 0; | ||
353 | |||
354 | perf_num_counters = armpmu_get_max_events(); | ||
355 | |||
356 | counter_config = kcalloc(perf_num_counters, | ||
357 | sizeof(struct op_counter_config), GFP_KERNEL); | ||
358 | |||
359 | if (!counter_config) { | ||
360 | pr_info("oprofile: failed to allocate %d " | ||
361 | "counters\n", perf_num_counters); | ||
362 | return -ENOMEM; | ||
363 | } | ||
364 | |||
365 | ret = init_driverfs(); | ||
366 | if (ret) { | ||
367 | kfree(counter_config); | ||
368 | return ret; | ||
369 | } | ||
370 | |||
371 | for_each_possible_cpu(cpu) { | ||
372 | perf_events[cpu] = kcalloc(perf_num_counters, | ||
373 | sizeof(struct perf_event *), GFP_KERNEL); | ||
374 | if (!perf_events[cpu]) { | ||
375 | pr_info("oprofile: failed to allocate %d perf events " | ||
376 | "for cpu %d\n", perf_num_counters, cpu); | ||
377 | while (--cpu >= 0) | ||
378 | kfree(perf_events[cpu]); | ||
379 | return -ENOMEM; | ||
380 | } | ||
381 | } | ||
382 | |||
383 | ops->backtrace = arm_backtrace; | 114 | ops->backtrace = arm_backtrace; |
384 | ops->create_files = op_arm_create_files; | ||
385 | ops->setup = op_arm_setup; | ||
386 | ops->start = op_arm_start; | ||
387 | ops->stop = op_arm_stop; | ||
388 | ops->shutdown = op_arm_stop; | ||
389 | ops->cpu_type = op_name_from_perf_id(armpmu_get_pmu_id()); | ||
390 | |||
391 | if (!ops->cpu_type) | ||
392 | ret = -ENODEV; | ||
393 | else | ||
394 | pr_info("oprofile: using %s\n", ops->cpu_type); | ||
395 | 115 | ||
396 | return ret; | 116 | return oprofile_perf_init(ops); |
397 | } | 117 | } |
398 | 118 | ||
399 | void oprofile_arch_exit(void) | 119 | void __exit oprofile_arch_exit(void) |
400 | { | 120 | { |
401 | int cpu, id; | 121 | oprofile_perf_exit(); |
402 | struct perf_event *event; | ||
403 | |||
404 | if (*perf_events) { | ||
405 | exit_driverfs(); | ||
406 | for_each_possible_cpu(cpu) { | ||
407 | for (id = 0; id < perf_num_counters; ++id) { | ||
408 | event = perf_events[cpu][id]; | ||
409 | if (event != NULL) | ||
410 | perf_event_release_kernel(event); | ||
411 | } | ||
412 | kfree(perf_events[cpu]); | ||
413 | } | ||
414 | } | ||
415 | |||
416 | if (counter_config) | ||
417 | kfree(counter_config); | ||
418 | } | 122 | } |
419 | #else | 123 | #else |
420 | int __init oprofile_arch_init(struct oprofile_operations *ops) | 124 | int __init oprofile_arch_init(struct oprofile_operations *ops) |
@@ -422,5 +126,5 @@ int __init oprofile_arch_init(struct oprofile_operations *ops) | |||
422 | pr_info("oprofile: hardware counters not available\n"); | 126 | pr_info("oprofile: hardware counters not available\n"); |
423 | return -ENODEV; | 127 | return -ENODEV; |
424 | } | 128 | } |
425 | void oprofile_arch_exit(void) {} | 129 | void __exit oprofile_arch_exit(void) {} |
426 | #endif /* CONFIG_HW_PERF_EVENTS */ | 130 | #endif /* CONFIG_HW_PERF_EVENTS */ |