Skip to contentSkip to conversation

ARM: pmu: provide a registration mechanism for IRQs

RFC PATCH New Will Deacon 1 participant 3 messages Mar 10, 2010

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover ARM: pmu: provide a registration mechanism for IRQs

This RFC patch was prompted by a discussion with Russell about the PMU IRQs for the new Versatile Express platform:

http://lists.infradead.org/pipermail/linux-arm-kernel/2010-March/010921.html

The set contains two patches, the second of which is intended purely as an example to illustrate the usage of the new framework.

All comments welcome.

Cc Russell King - ARM Linux <[email protected]>
Cc Jamie Iles <[email protected]>

Will Deacon (2):
ARM: pmu: register IRQs at runtime
ARM: Realview-PBX: register PMU IRQs during board initialisation

 arch/arm/include/asm/pmu.h            |   36 ++++++++---
 arch/arm/kernel/perf_event.c          |    6 +-
 arch/arm/kernel/pmu.c                 |  103 ++++++++++++++++++---------------
 arch/arm/mach-realview/realview_pbx.c |   15 +++++
 4 files changed, 101 insertions(+), 59 deletions(-)
#1 lore raw

RFC PATCH 1/2 ARM: 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 passed in from the board initialisation files using the pmu_device_register() function.

A further advantage of this change is that there is scope for registering different types of performance counters in the future by adding a new field to the arm_pmu_type enumeration.

---
 arch/arm/include/asm/pmu.h   |   36 +++++++++++----
 arch/arm/kernel/perf_event.c |    6 +-
 arch/arm/kernel/pmu.c        |  103 +++++++++++++++++++++++-------------------
 3 files changed, 86 insertions(+), 59 deletions(-)
arch/arm/include/asm/pmu.h +26 -10
index 2829b9f..2ded693 100644
@@ -12,22 +12,38 @@
 #ifndef __ARM_PMU_H__
 #define __ARM_PMU_H__
 
+enum arm_pmu_type {
+	ARM_PMU_DEVICE_CPU = 0,
+	ARM_NUM_PMU_DEVICES,
+};
+
 #ifdef CONFIG_CPU_HAS_PMU
 
 struct pmu_irqs {
-	const int   *irqs;
-	int	    num_irqs;
+	enum arm_pmu_type	device_type;
+	const int		*irqs;
+	int			num_irqs;
 };
 
 /**
+ * pmu_device_register() - register a new counter source with the kernel
+ *
+ * Register a new PMU device and its corresponding IRQs. Only one instance
+ * of each device type may be registered at once, but multiple IRQs can be
+ * specified in the corresponding struct pmu_irqs.
+ */
+void
+pmu_device_register(struct pmu_irqs *device);
+
+/**
  * reserve_pmu() - reserve the hardware performance counters
  *
  * Reserve the hardware performance counters in the system for exclusive use.
  * The 'struct pmu_irqs' for the system is returned on success, ERR_PTR()
  * encoded error on failure.
  */
-extern const struct pmu_irqs *
-reserve_pmu(void);
+extern struct pmu_irqs *
+reserve_pmu(enum arm_pmu_type device);
 
 /**
  * release_pmu() - Relinquish control of the performance counters
@@ -38,7 +54,7 @@ reserve_pmu(void);
  * a cookie.
  */
 extern int
-release_pmu(const struct pmu_irqs *irqs);
+release_pmu(struct pmu_irqs *irqs);
 
 /**
  * init_pmu() - Initialise the PMU.
@@ -48,24 +64,24 @@ release_pmu(const struct pmu_irqs *irqs);
  * the actual hardware initialisation.
  */
 extern int
-init_pmu(void);
+init_pmu(enum arm_pmu_type device);
 
 #else /* CONFIG_CPU_HAS_PMU */
 
-static inline const struct pmu_irqs *
-reserve_pmu(void)
+static inline struct pmu_irqs *
+reserve_pmu(enum arm_pmu_type device)
 {
 	return ERR_PTR(-ENODEV);
 }
 
 static inline int
-release_pmu(const struct pmu_irqs *irqs)
+release_pmu(struct pmu_irqs *irqs)
 {
 	return -ENODEV;
 }
 
 static inline int
-init_pmu(void)
+init_pmu(enum arm_pmu_type device)
 {
 	return -ENODEV;
 }
arch/arm/kernel/perf_event.c +3 -3
index c45a155..752ada2 100644
@@ -26,7 +26,7 @@
 #include <asm/pmu.h>
 #include <asm/stacktrace.h>
 
-static const struct pmu_irqs *pmu_irqs;
+static struct pmu_irqs *pmu_irqs;
 
 /*
  * Hardware lock to serialize accesses to PMU registers. Needed for the
@@ -317,13 +317,13 @@ armpmu_reserve_hardware(void)
 	int i;
 	int err;
 
-	pmu_irqs = reserve_pmu();
+	pmu_irqs = reserve_pmu(ARM_PMU_DEVICE_CPU);
 	if (IS_ERR(pmu_irqs)) {
 		pr_warning("unable to reserve pmu\n");
 		return PTR_ERR(pmu_irqs);
 	}
 
-	init_pmu();
+	init_pmu(ARM_PMU_DEVICE_CPU);
 
 	if (pmu_irqs->num_irqs < 1) {
 		pr_err("no irqs for PMUs defined\n");
arch/arm/kernel/pmu.c +57 -46

137 lines not on this page · raw message

Signature · 1 line
1.6.3.3
#2 lore raw

RFC PATCH 2/2 ARM: Realview-PBX: register PMU IRQs during board initialisation

This patch updates the Realview-PBX initialisation routine to register the PMU IRQs with the PMU framework in the Kernel.

---
 arch/arm/mach-realview/realview_pbx.c |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)
arch/arm/mach-realview/realview_pbx.c +15 -0
index d94857e..0d31486 100644
@@ -29,6 +29,7 @@
 #include <asm/irq.h>
 #include <asm/leds.h>
 #include <asm/mach-types.h>
+#include <asm/pmu.h>
 #include <asm/smp_twd.h>
 #include <asm/hardware/gic.h>
 #include <asm/hardware/cache-l2x0.h>
@@ -270,6 +271,19 @@ static struct resource realview_pbx_isp1761_resources[] = {
 	},
 };
 
+static const int pmu_irqs[] = {
+	IRQ_PBX_PMU_CPU0,
+	IRQ_PBX_PMU_CPU1,
+	IRQ_PBX_PMU_CPU2,
+	IRQ_PBX_PMU_CPU3,
+};
+
+static struct pmu_irqs cpu_pmu_device = {
+	.device_type		= ARM_PMU_DEVICE_CPU,
+	.irqs			= pmu_irqs,
+	.num_irqs		= ARRAY_SIZE(pmu_irqs),
+};
+
 static void __init gic_init_irq(void)
 {
 	/* ARM PBX on-board GIC */
@@ -363,6 +377,7 @@ static void __init realview_pbx_init(void)
 	platform_device_register(&realview_i2c_device);
 	platform_device_register(&realview_cf_device);
 	realview_usb_register(realview_pbx_isp1761_resources);
+	pmu_device_register(&cpu_pmu_device);
 
 	for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
 		struct amba_device *d = amba_devs[i];
Signature · 1 line
1.6.3.3