diff options
author | Will Deacon <will.deacon@arm.com> | 2010-04-29 12:13:24 -0400 |
---|---|---|
committer | Russell King <rmk+kernel@arm.linux.org.uk> | 2010-05-17 06:53:57 -0400 |
commit | 49c006b93769a86bec2b32b9234abf016ac0d50e (patch) | |
tree | 6784e69f48186c6edc6e9130fc1680a31cec0ce4 | |
parent | c39e52a793f5599582dbacf4d8f62634a492f79e (diff) |
ARM: 6064/1: pmu: register IRQs at runtime
The current PMU infrastructure for ARM requires that the IRQs for the PMU
device are fixed at compile time and are selected based on the ARCH_ or MACH_ flags. This has the disadvantage of tying the Kernel down to a
particular board as far as profiling is concerned.
This patch replaces the compile-time IRQ registration with a runtime mechanism which allows the IRQs to be registered with the framework as
a platform_device.
A further advantage of this change is that there is scope for registering
different types of performance counters in the future by changing the id
of the platform_device and attaching different resources to it.
Acked-by: Jamie Iles <jamie.iles@picochip.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
-rw-r--r-- | arch/arm/include/asm/pmu.h | 27 | ||||
-rw-r--r-- | arch/arm/kernel/perf_event.c | 52 | ||||
-rw-r--r-- | arch/arm/kernel/pmu.c | 127 |
3 files changed, 126 insertions, 80 deletions
diff --git a/arch/arm/include/asm/pmu.h b/arch/arm/include/asm/pmu.h index 44bec1f02cb0..8ccea012722c 100644 --- a/arch/arm/include/asm/pmu.h +++ b/arch/arm/include/asm/pmu.h | |||
@@ -19,31 +19,26 @@ enum arm_pmu_type { | |||
19 | 19 | ||
20 | #ifdef CONFIG_CPU_HAS_PMU | 20 | #ifdef CONFIG_CPU_HAS_PMU |
21 | 21 | ||
22 | struct pmu_irqs { | ||
23 | const int *irqs; | ||
24 | int num_irqs; | ||
25 | }; | ||
26 | |||
27 | /** | 22 | /** |
28 | * reserve_pmu() - reserve the hardware performance counters | 23 | * reserve_pmu() - reserve the hardware performance counters |
29 | * | 24 | * |
30 | * Reserve the hardware performance counters in the system for exclusive use. | 25 | * Reserve the hardware performance counters in the system for exclusive use. |
31 | * The 'struct pmu_irqs' for the system is returned on success, ERR_PTR() | 26 | * The platform_device for the system is returned on success, ERR_PTR() |
32 | * encoded error on failure. | 27 | * encoded error on failure. |
33 | */ | 28 | */ |
34 | extern const struct pmu_irqs * | 29 | extern struct platform_device * |
35 | reserve_pmu(void); | 30 | reserve_pmu(enum arm_pmu_type device); |
36 | 31 | ||
37 | /** | 32 | /** |
38 | * release_pmu() - Relinquish control of the performance counters | 33 | * release_pmu() - Relinquish control of the performance counters |
39 | * | 34 | * |
40 | * Release the performance counters and allow someone else to use them. | 35 | * Release the performance counters and allow someone else to use them. |
41 | * Callers must have disabled the counters and released IRQs before calling | 36 | * Callers must have disabled the counters and released IRQs before calling |
42 | * this. The 'struct pmu_irqs' returned from reserve_pmu() must be passed as | 37 | * this. The platform_device returned from reserve_pmu() must be passed as |
43 | * a cookie. | 38 | * a cookie. |
44 | */ | 39 | */ |
45 | extern int | 40 | extern int |
46 | release_pmu(const struct pmu_irqs *irqs); | 41 | release_pmu(struct platform_device *pdev); |
47 | 42 | ||
48 | /** | 43 | /** |
49 | * init_pmu() - Initialise the PMU. | 44 | * init_pmu() - Initialise the PMU. |
@@ -53,24 +48,26 @@ release_pmu(const struct pmu_irqs *irqs); | |||
53 | * the actual hardware initialisation. | 48 | * the actual hardware initialisation. |
54 | */ | 49 | */ |
55 | extern int | 50 | extern int |
56 | init_pmu(void); | 51 | init_pmu(enum arm_pmu_type device); |
57 | 52 | ||
58 | #else /* CONFIG_CPU_HAS_PMU */ | 53 | #else /* CONFIG_CPU_HAS_PMU */ |
59 | 54 | ||
60 | static inline const struct pmu_irqs * | 55 | #include <linux/err.h> |
61 | reserve_pmu(void) | 56 | |
57 | static inline struct platform_device * | ||
58 | reserve_pmu(enum arm_pmu_type device) | ||
62 | { | 59 | { |
63 | return ERR_PTR(-ENODEV); | 60 | return ERR_PTR(-ENODEV); |
64 | } | 61 | } |
65 | 62 | ||
66 | static inline int | 63 | static inline int |
67 | release_pmu(const struct pmu_irqs *irqs) | 64 | release_pmu(struct platform_device *pdev) |
68 | { | 65 | { |
69 | return -ENODEV; | 66 | return -ENODEV; |
70 | } | 67 | } |
71 | 68 | ||
72 | static inline int | 69 | static inline int |
73 | init_pmu(void) | 70 | init_pmu(enum arm_pmu_type device) |
74 | { | 71 | { |
75 | return -ENODEV; | 72 | return -ENODEV; |
76 | } | 73 | } |
diff --git a/arch/arm/kernel/perf_event.c b/arch/arm/kernel/perf_event.c index 9e70f2053f9a..89a77fcb13e3 100644 --- a/arch/arm/kernel/perf_event.c +++ b/arch/arm/kernel/perf_event.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/interrupt.h> | 17 | #include <linux/interrupt.h> |
18 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
19 | #include <linux/perf_event.h> | 19 | #include <linux/perf_event.h> |
20 | #include <linux/platform_device.h> | ||
20 | #include <linux/spinlock.h> | 21 | #include <linux/spinlock.h> |
21 | #include <linux/uaccess.h> | 22 | #include <linux/uaccess.h> |
22 | 23 | ||
@@ -26,7 +27,7 @@ | |||
26 | #include <asm/pmu.h> | 27 | #include <asm/pmu.h> |
27 | #include <asm/stacktrace.h> | 28 | #include <asm/stacktrace.h> |
28 | 29 | ||
29 | static const struct pmu_irqs *pmu_irqs; | 30 | static struct platform_device *pmu_device; |
30 | 31 | ||
31 | /* | 32 | /* |
32 | * Hardware lock to serialize accesses to PMU registers. Needed for the | 33 | * Hardware lock to serialize accesses to PMU registers. Needed for the |
@@ -314,38 +315,44 @@ validate_group(struct perf_event *event) | |||
314 | static int | 315 | static int |
315 | armpmu_reserve_hardware(void) | 316 | armpmu_reserve_hardware(void) |
316 | { | 317 | { |
317 | int i; | 318 | int i, err = -ENODEV, irq; |
318 | int err; | ||
319 | 319 | ||
320 | pmu_irqs = reserve_pmu(); | 320 | pmu_device = reserve_pmu(ARM_PMU_DEVICE_CPU); |
321 | if (IS_ERR(pmu_irqs)) { | 321 | if (IS_ERR(pmu_device)) { |
322 | pr_warning("unable to reserve pmu\n"); | 322 | pr_warning("unable to reserve pmu\n"); |
323 | return PTR_ERR(pmu_irqs); | 323 | return PTR_ERR(pmu_device); |
324 | } | 324 | } |
325 | 325 | ||
326 | init_pmu(); | 326 | init_pmu(ARM_PMU_DEVICE_CPU); |
327 | 327 | ||
328 | if (pmu_irqs->num_irqs < 1) { | 328 | if (pmu_device->num_resources < 1) { |
329 | pr_err("no irqs for PMUs defined\n"); | 329 | pr_err("no irqs for PMUs defined\n"); |
330 | return -ENODEV; | 330 | return -ENODEV; |
331 | } | 331 | } |
332 | 332 | ||
333 | for (i = 0; i < pmu_irqs->num_irqs; ++i) { | 333 | for (i = 0; i < pmu_device->num_resources; ++i) { |
334 | err = request_irq(pmu_irqs->irqs[i], armpmu->handle_irq, | 334 | irq = platform_get_irq(pmu_device, i); |
335 | if (irq < 0) | ||
336 | continue; | ||
337 | |||
338 | err = request_irq(irq, armpmu->handle_irq, | ||
335 | IRQF_DISABLED | IRQF_NOBALANCING, | 339 | IRQF_DISABLED | IRQF_NOBALANCING, |
336 | "armpmu", NULL); | 340 | "armpmu", NULL); |
337 | if (err) { | 341 | if (err) { |
338 | pr_warning("unable to request IRQ%d for ARM " | 342 | pr_warning("unable to request IRQ%d for ARM perf " |
339 | "perf counters\n", pmu_irqs->irqs[i]); | 343 | "counters\n", irq); |
340 | break; | 344 | break; |
341 | } | 345 | } |
342 | } | 346 | } |
343 | 347 | ||
344 | if (err) { | 348 | if (err) { |
345 | for (i = i - 1; i >= 0; --i) | 349 | for (i = i - 1; i >= 0; --i) { |
346 | free_irq(pmu_irqs->irqs[i], NULL); | 350 | irq = platform_get_irq(pmu_device, i); |
347 | release_pmu(pmu_irqs); | 351 | if (irq >= 0) |
348 | pmu_irqs = NULL; | 352 | free_irq(irq, NULL); |
353 | } | ||
354 | release_pmu(pmu_device); | ||
355 | pmu_device = NULL; | ||
349 | } | 356 | } |
350 | 357 | ||
351 | return err; | 358 | return err; |
@@ -354,14 +361,17 @@ armpmu_reserve_hardware(void) | |||
354 | static void | 361 | static void |
355 | armpmu_release_hardware(void) | 362 | armpmu_release_hardware(void) |
356 | { | 363 | { |
357 | int i; | 364 | int i, irq; |
358 | 365 | ||
359 | for (i = pmu_irqs->num_irqs - 1; i >= 0; --i) | 366 | for (i = pmu_device->num_resources - 1; i >= 0; --i) { |
360 | free_irq(pmu_irqs->irqs[i], NULL); | 367 | irq = platform_get_irq(pmu_device, i); |
368 | if (irq >= 0) | ||
369 | free_irq(irq, NULL); | ||
370 | } | ||
361 | armpmu->stop(); | 371 | armpmu->stop(); |
362 | 372 | ||
363 | release_pmu(pmu_irqs); | 373 | release_pmu(pmu_device); |
364 | pmu_irqs = NULL; | 374 | pmu_device = NULL; |
365 | } | 375 | } |
366 | 376 | ||
367 | static atomic_t active_events = ATOMIC_INIT(0); | 377 | static atomic_t active_events = ATOMIC_INIT(0); |
diff --git a/arch/arm/kernel/pmu.c b/arch/arm/kernel/pmu.c index a124312e343f..b8af96ea62e6 100644 --- a/arch/arm/kernel/pmu.c +++ b/arch/arm/kernel/pmu.c | |||
@@ -2,6 +2,7 @@ | |||
2 | * linux/arch/arm/kernel/pmu.c | 2 | * linux/arch/arm/kernel/pmu.c |
3 | * | 3 | * |
4 | * Copyright (C) 2009 picoChip Designs Ltd, Jamie Iles | 4 | * Copyright (C) 2009 picoChip Designs Ltd, Jamie Iles |
5 | * Copyright (C) 2010 ARM Ltd, Will Deacon | ||
5 | * | 6 | * |
6 | * This program is free software; you can redistribute it and/or modify | 7 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License version 2 as | 8 | * it under the terms of the GNU General Public License version 2 as |
@@ -9,65 +10,78 @@ | |||
9 | * | 10 | * |
10 | */ | 11 | */ |
11 | 12 | ||
13 | #define pr_fmt(fmt) "PMU: " fmt | ||
14 | |||
12 | #include <linux/cpumask.h> | 15 | #include <linux/cpumask.h> |
13 | #include <linux/err.h> | 16 | #include <linux/err.h> |
14 | #include <linux/interrupt.h> | 17 | #include <linux/interrupt.h> |
15 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
16 | #include <linux/module.h> | 19 | #include <linux/module.h> |
20 | #include <linux/platform_device.h> | ||
17 | 21 | ||
18 | #include <asm/pmu.h> | 22 | #include <asm/pmu.h> |
19 | 23 | ||
20 | /* | 24 | static volatile long pmu_lock; |
21 | * Define the IRQs for the system. We could use something like a platform | 25 | |
22 | * device but that seems fairly heavyweight for this. Also, the performance | 26 | static struct platform_device *pmu_devices[ARM_NUM_PMU_DEVICES]; |
23 | * counters can't be removed or hotplugged. | 27 | |
24 | * | 28 | static int __devinit pmu_device_probe(struct platform_device *pdev) |
25 | * Ordering is important: init_pmu() will use the ordering to set the affinity | 29 | { |
26 | * to the corresponding core. e.g. the first interrupt will go to cpu 0, the | 30 | |
27 | * second goes to cpu 1 etc. | 31 | if (pdev->id < 0 || pdev->id >= ARM_NUM_PMU_DEVICES) { |
28 | */ | 32 | pr_warning("received registration request for unknown " |
29 | static const int irqs[] = { | 33 | "device %d\n", pdev->id); |
30 | #if defined(CONFIG_ARCH_OMAP2) | 34 | return -EINVAL; |
31 | 3, | 35 | } |
32 | #elif defined(CONFIG_ARCH_BCMRING) | 36 | |
33 | IRQ_PMUIRQ, | 37 | if (pmu_devices[pdev->id]) |
34 | #elif defined(CONFIG_MACH_REALVIEW_EB) | 38 | pr_warning("registering new PMU device type %d overwrites " |
35 | IRQ_EB11MP_PMU_CPU0, | 39 | "previous registration!\n", pdev->id); |
36 | IRQ_EB11MP_PMU_CPU1, | 40 | else |
37 | IRQ_EB11MP_PMU_CPU2, | 41 | pr_info("registered new PMU device of type %d\n", |
38 | IRQ_EB11MP_PMU_CPU3, | 42 | pdev->id); |
39 | #elif defined(CONFIG_ARCH_OMAP3) | ||
40 | INT_34XX_BENCH_MPU_EMUL, | ||
41 | #elif defined(CONFIG_ARCH_IOP32X) | ||
42 | IRQ_IOP32X_CORE_PMU, | ||
43 | #elif defined(CONFIG_ARCH_IOP33X) | ||
44 | IRQ_IOP33X_CORE_PMU, | ||
45 | #elif defined(CONFIG_ARCH_PXA) | ||
46 | IRQ_PMU, | ||
47 | #endif | ||
48 | }; | ||
49 | 43 | ||
50 | static const struct pmu_irqs pmu_irqs = { | 44 | pmu_devices[pdev->id] = pdev; |
51 | .irqs = irqs, | 45 | return 0; |
52 | .num_irqs = ARRAY_SIZE(irqs), | 46 | } |
47 | |||
48 | static struct platform_driver pmu_driver = { | ||
49 | .driver = { | ||
50 | .name = "arm-pmu", | ||
51 | }, | ||
52 | .probe = pmu_device_probe, | ||
53 | }; | 53 | }; |
54 | 54 | ||
55 | static volatile long pmu_lock; | 55 | static int __init register_pmu_driver(void) |
56 | { | ||
57 | return platform_driver_register(&pmu_driver); | ||
58 | } | ||
59 | device_initcall(register_pmu_driver); | ||
56 | 60 | ||
57 | const struct pmu_irqs * | 61 | struct platform_device * |
58 | reserve_pmu(void) | 62 | reserve_pmu(enum arm_pmu_type device) |
59 | { | 63 | { |
60 | return test_and_set_bit_lock(0, &pmu_lock) ? ERR_PTR(-EBUSY) : | 64 | struct platform_device *pdev; |
61 | &pmu_irqs; | 65 | |
66 | if (test_and_set_bit_lock(device, &pmu_lock)) { | ||
67 | pdev = ERR_PTR(-EBUSY); | ||
68 | } else if (pmu_devices[device] == NULL) { | ||
69 | clear_bit_unlock(device, &pmu_lock); | ||
70 | pdev = ERR_PTR(-ENODEV); | ||
71 | } else { | ||
72 | pdev = pmu_devices[device]; | ||
73 | } | ||
74 | |||
75 | return pdev; | ||
62 | } | 76 | } |
63 | EXPORT_SYMBOL_GPL(reserve_pmu); | 77 | EXPORT_SYMBOL_GPL(reserve_pmu); |
64 | 78 | ||
65 | int | 79 | int |
66 | release_pmu(const struct pmu_irqs *irqs) | 80 | release_pmu(struct platform_device *pdev) |
67 | { | 81 | { |
68 | if (WARN_ON(irqs != &pmu_irqs)) | 82 | if (WARN_ON(pdev != pmu_devices[pdev->id])) |
69 | return -EINVAL; | 83 | return -EINVAL; |
70 | clear_bit_unlock(0, &pmu_lock); | 84 | clear_bit_unlock(pdev->id, &pmu_lock); |
71 | return 0; | 85 | return 0; |
72 | } | 86 | } |
73 | EXPORT_SYMBOL_GPL(release_pmu); | 87 | EXPORT_SYMBOL_GPL(release_pmu); |
@@ -87,17 +101,42 @@ set_irq_affinity(int irq, | |||
87 | #endif | 101 | #endif |
88 | } | 102 | } |
89 | 103 | ||
90 | int | 104 | static int |
91 | init_pmu(void) | 105 | init_cpu_pmu(void) |
92 | { | 106 | { |
93 | int i, err = 0; | 107 | int i, err = 0; |
108 | struct platform_device *pdev = pmu_devices[ARM_PMU_DEVICE_CPU]; | ||
109 | |||
110 | if (!pdev) { | ||
111 | err = -ENODEV; | ||
112 | goto out; | ||
113 | } | ||
94 | 114 | ||
95 | for (i = 0; i < pmu_irqs.num_irqs; ++i) { | 115 | for (i = 0; i < pdev->num_resources; ++i) { |
96 | err = set_irq_affinity(pmu_irqs.irqs[i], i); | 116 | err = set_irq_affinity(platform_get_irq(pdev, i), i); |
97 | if (err) | 117 | if (err) |
98 | break; | 118 | break; |
99 | } | 119 | } |
100 | 120 | ||
121 | out: | ||
122 | return err; | ||
123 | } | ||
124 | |||
125 | int | ||
126 | init_pmu(enum arm_pmu_type device) | ||
127 | { | ||
128 | int err = 0; | ||
129 | |||
130 | switch (device) { | ||
131 | case ARM_PMU_DEVICE_CPU: | ||
132 | err = init_cpu_pmu(); | ||
133 | break; | ||
134 | default: | ||
135 | pr_warning("attempt to initialise unknown device %d\n", | ||
136 | device); | ||
137 | err = -EINVAL; | ||
138 | } | ||
139 | |||
101 | return err; | 140 | return err; |
102 | } | 141 | } |
103 | EXPORT_SYMBOL_GPL(init_pmu); | 142 | EXPORT_SYMBOL_GPL(init_pmu); |