Skip to contentSkip to conversation

arm: l2x0: add PMU support

PATCH Superseded Mark Rutland 2 participants 3 messages Aug 30, 2016

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 arm: l2x0: add PMU support

The L2C-220 (AKA L220) and L2C-310 (AKA PL310) cache controllers feature a Performance Monitoring Unit (PMU), which can be useful for tuning and/or debugging. This hardware is always present and the relevant registers are accessible to non-secure accesses. Thus, no special firmware interface is necessary.

This patch adds support for the PMU, plugging into the usual perf infrastructure. The overflow interrupt is not always available (e.g. on RealView PBX A9 it is not wired up at all), and the hardware counters saturate, so the driver does not make use of this. Instead, the driver periodically polls and reset counters as required to avoid losing events due to saturation.

---
 arch/arm/include/asm/hardware/cache-l2x0.h |   9 +
 arch/arm/mm/Kconfig                        |   7 +
 arch/arm/mm/cache-l2x0.c                   | 561 +++++++++++++++++++++++++++++
 include/linux/cpuhotplug.h                 |   1 +
 4 files changed, 578 insertions(+)

Since v1 [1]:
* Use relaxed IO accessors, per Russell's comment. From testing, this can save 3% overhead in an extreme case (idle system and trivial workload).
* Add Kim's Tested-by.
Since v2 [2]:
* Trivial rebase to v4.8-rc4.
* Add Pawel's Acked-by.
* Fix l2x0_pmu_num_active_counters return type, per Will's comment.
* Update comment regarding L210 support, per Will's comment.

Mark.

[1] http://lists.infradead.org/pipermail/linux-arm-kernel/2016-August/449622.htm
[2] http://lists.infradead.org/pipermail/linux-arm-kernel/2016-August/450024.html

arch/arm/include/asm/hardware/cache-l2x0.h +9 -0
index 3a5ec1c..e476350 100644
@@ -87,6 +87,15 @@
 #define L310_CACHE_ID_RTL_R3P2		0x08
 #define L310_CACHE_ID_RTL_R3P3		0x09
 
+#define L2X0_EVENT_CNT_CTRL_ENABLE	BIT(0)
+
+#define L2X0_EVENT_CNT_CFG_SRC_SHIFT	2
+#define L2X0_EVENT_CNT_CFG_SRC_MASK	0xf
+#define L2X0_EVENT_CNT_CFG_SRC_DISABLED	0
+#define L2X0_EVENT_CNT_CFG_INT_DISABLED	0
+#define L2X0_EVENT_CNT_CFG_INT_INCR	1
+#define L2X0_EVENT_CNT_CFG_INT_OVERFLOW	2
+
 /* L2C auxiliary control register - bits common to L2C-210/220/310 */
 #define L2C_AUX_CTRL_WAY_SIZE_SHIFT		17
 #define L2C_AUX_CTRL_WAY_SIZE_MASK		(7 << 17)
arch/arm/mm/Kconfig +7 -0
index d15a7fe..0e8cbac 100644
@@ -916,6 +916,13 @@ config CACHE_L2X0
 	help
 	  This option enables the L2x0 PrimeCell.
 
+config CACHE_L2X0_PMU
+	bool "L2x0 performance monitor support" if CACHE_L2X0
+	depends on PERF_EVENTS
+	help
+	  This option enables support for the performance monitoring features
+	  of the L220 and PL310 outer cache controllers.
+
 if CACHE_L2X0
 
 config PL310_ERRATA_588369
arch/arm/mm/cache-l2x0.c +561 -0

591 lines not on this page · raw message

include/linux/cpuhotplug.h +1 -0
index 242bf53..7e1ba14 100644
@@ -86,6 +86,7 @@ enum cpuhp_state {
 	CPUHP_AP_PERF_S390_SF_ONLINE,
 	CPUHP_AP_PERF_ARM_CCI_ONLINE,
 	CPUHP_AP_PERF_ARM_CCN_ONLINE,
+	CPUHP_AP_PERF_ARM_L2X0_ONLINE,
 	CPUHP_AP_WORKQUEUE_ONLINE,
 	CPUHP_AP_RCUTREE_ONLINE,
 	CPUHP_AP_NOTIFY_ONLINE,
Signature · 1 line
1.9.1
#1 lore raw

PATCH v3 1/1 arm: l2x0: add PMU support

Quoted 12 lines · Mark Rutland

The L2C-220 (AKA L220) and L2C-310 (AKA PL310) cache controllers feature a Performance Monitoring Unit (PMU), which can be useful for tuning and/or debugging. This hardware is always present and the relevant registers are accessible to non-secure accesses. Thus, no special firmware interface is necessary.

This patch adds support for the PMU, plugging into the usual perf infrastructure. The overflow interrupt is not always available (e.g. on RealView PBX A9 it is not wired up at all), and the hardware counters saturate, so the driver does not make use of this. Instead, the driver periodically polls and reset counters as required to avoid losing events due to saturation.

...

arch/arm/mm/cache-l2x0.c int __init l2x0_of_init(u32 aux_val, u32 aux_mask) · line 2301

Quoted 7 lines
arch/arm/mm/cache-l2x0.c +7 -0
+	/*
+	 * Choose the name to identify the PMU under sysfs. This is also used
+	 * by l2x0_pmu_event_attr_is_visible to determine which events to
+	 * display, as the PL310 PMU supports a superset of L220 events.
+	 *
+	 * The L210 PMU has a different programmer's interface, and is not
+	 * supported by this driver.

This rather worries me a bit - if the L2C-210 needs a different driver, should we be putting this driver in this file, or should we be keeping it as a separate file? What if L2C-210 grows a PMU driver which is also tacked on the end of the file - it seems to me that this is rather unwieldy.

My feeling is that we've already enough random bits tacked into this file supporting all the L2C-210 related variants.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
#2 lore raw

PATCH v3 1/1 arm: l2x0: add PMU support

Quoted 28 lines · Russell King - ARM Linux
Quoted 12 lines · Mark Rutland

The L2C-220 (AKA L220) and L2C-310 (AKA PL310) cache controllers feature a Performance Monitoring Unit (PMU), which can be useful for tuning and/or debugging. This hardware is always present and the relevant registers are accessible to non-secure accesses. Thus, no special firmware interface is necessary.

This patch adds support for the PMU, plugging into the usual perf infrastructure. The overflow interrupt is not always available (e.g. on RealView PBX A9 it is not wired up at all), and the hardware counters saturate, so the driver does not make use of this. Instead, the driver periodically polls and reset counters as required to avoid losing events due to saturation.

...

arch/arm/mm/cache-l2x0.c int __init l2x0_of_init(u32 aux_val, u32 aux_mask) · line 2301

Quoted 7 lines
arch/arm/mm/cache-l2x0.c +7 -0
+	/*
+	 * Choose the name to identify the PMU under sysfs. This is also used
+	 * by l2x0_pmu_event_attr_is_visible to determine which events to
+	 * display, as the PL310 PMU supports a superset of L220 events.
+	 *
+	 * The L210 PMU has a different programmer's interface, and is not
+	 * supported by this driver.

This rather worries me a bit - if the L2C-210 needs a different driver, should we be putting this driver in this file, or should we be keeping it as a separate file? What if L2C-210 grows a PMU driver which is also tacked on the end of the file - it seems to me that this is rather unwieldy.

Quoted 2 lines

My feeling is that we've already enough random bits tacked into this file supporting all the L2C-210 related variants.

Sure. I'll see about factoring the PMU parts out into a separate file, modulo a couple of hooks for suspend/resume and init.

Thanks,
Mark.