Skip to contentSkip to conversation

perf: qcom: Add L3 cache PMU driver

PATCH Superseded Agustin Vega-Frias 2 participants 4 messages Mar 17, 2017 – Mar 23, 2017

Subsystems (4)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 perf: qcom: Add L3 cache PMU driver

This adds a new dynamic PMU to the Perf Events framework to program and control the L3 cache PMUs in some Qualcomm Technologies SOCs.

The driver supports a distributed cache architecture where the overall cache for a socket is comprised of multiple slices each with its own PMU. Access to each individual PMU is provided even though all CPUs share all the slices. User space needs to aggregate to individual counts to provide a global picture.

The driver exports formatting and event information to sysfs so it can be used by the perf user space tools with the syntaxes:
perf stat -a -e l3cache_0_0/read-miss/
perf stat -a -e l3cache_0_0/event=0x21/

---
 Documentation/perf/qcom_l3_pmu.txt |  25 ++
 drivers/perf/Kconfig               |  10 +
 drivers/perf/Makefile              |   1 +
 drivers/perf/qcom_l3_pmu.c         | 825 +++++++++++++++++++++++++++++++++++++
 include/linux/cpuhotplug.h         |   1 +
 5 files changed, 862 insertions(+)
 create mode 100644 Documentation/perf/qcom_l3_pmu.txt
 create mode 100644 drivers/perf/qcom_l3_pmu.c
Documentation/perf/qcom_l3_pmu.txt new file +25 -0
new file mode 100644
index 0000000..96b3a94
@@ -0,0 +1,25 @@
+Qualcomm Datacenter Technologies L3 Cache Performance Monitoring Unit (PMU)
+===========================================================================
+
+This driver supports the L3 cache PMUs found in Qualcomm Datacenter Technologies
+Centriq SoCs. The L3 cache on these SOCs is composed of multiple slices, shared
+by all cores within a socket. Each slice is exposed as a separate uncore perf
+PMU with device name l3cache_<socket>_<instance>. User space is responsible
+for aggregating across slices.
+
+The driver provides a description of its available events and configuration
+options in sysfs, see /sys/devices/l3cache*. Given that these are uncore PMUs
+the driver also exposes a "cpumask" sysfs attribute which contains a mask
+consisting of one CPU per socket which will be used to handle all the PMU
+events on that socket.
+
+The hardware implements 32bit event counters and has a flat 8bit event space
+exposed via the "event" format attribute. In addition to the 32bit physical
+counters the driver supports virtual 64bit hardware counters by using hardware
+counter chaining. This feature is exposed via the "lc" (long counter) format
+flag. E.g.:
+
+  perf stat -e l3cache_0_0/read-miss,lc/
+
+Given that these are uncore PMUs the driver does not support sampling, therefore
+"perf record" will not work. Per-task perf sessions are not supported.
drivers/perf/Kconfig +10 -0
index 9365190..c436e0d 100644
@@ -21,6 +21,16 @@ config QCOM_L2_PMU
 	  Adds the L2 cache PMU into the perf events subsystem for
 	  monitoring L2 cache events.
 
+config QCOM_L3_PMU
+	bool "Qualcomm Technologies L3-cache PMU"
+	depends on ARCH_QCOM && ARM64 && PERF_EVENTS && ACPI
+	select QCOM_IRQ_COMBINER
+	help
+	   Provides support for the L3 cache performance monitor unit (PMU)
+	   in Qualcomm Technologies processors.
+	   Adds the L3 cache PMU into the perf events subsystem for
+	   monitoring L3 cache events.
+
 config XGENE_PMU
         depends on PERF_EVENTS && ARCH_XGENE
         bool "APM X-Gene SoC PMU"
drivers/perf/Makefile +1 -0
index ef24833..ef0c6b2 100644
@@ -1,3 +1,4 @@
 obj-$(CONFIG_ARM_PMU) += arm_pmu.o
 obj-$(CONFIG_QCOM_L2_PMU)	+= qcom_l2_pmu.o
+obj-$(CONFIG_QCOM_L3_PMU) += qcom_l3_pmu.o
 obj-$(CONFIG_XGENE_PMU) += xgene_pmu.o
drivers/perf/qcom_l3_pmu.c new file +825 -0

825 lines not on this page · raw message

include/linux/cpuhotplug.h +1 -0
index 62d240e..cfcfab3 100644
@@ -137,6 +137,7 @@ enum cpuhp_state {
 	CPUHP_AP_PERF_ARM_CCN_ONLINE,
 	CPUHP_AP_PERF_ARM_L2X0_ONLINE,
 	CPUHP_AP_PERF_ARM_QCOM_L2_ONLINE,
+	CPUHP_AP_PERF_ARM_QCOM_L3_ONLINE,
 	CPUHP_AP_WORKQUEUE_ONLINE,
 	CPUHP_AP_RCUTREE_ONLINE,
 	CPUHP_AP_ONLINE_DYN,
Signature · 2 lines
Qualcomm Datacenter Technologies, Inc. on behalf of the Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
#1 lore raw
Quoted 18 lines · Agustin Vega-Frias

This adds a new dynamic PMU to the Perf Events framework to program and control the L3 cache PMUs in some Qualcomm Technologies SOCs.

The driver supports a distributed cache architecture where the overall cache for a socket is comprised of multiple slices each with its own PMU.
Access to each individual PMU is provided even though all CPUs share all
the slices. User space needs to aggregate to individual counts to provide
a global picture.

The driver exports formatting and event information to sysfs so it can be used by the perf user space tools with the syntaxes:

   perf stat -a -e l3cache_0_0/read-miss/
   perf stat -a -e l3cache_0_0/event=0x21/
Quoted 10 lines
---
 Documentation/perf/qcom_l3_pmu.txt |  25 ++
 drivers/perf/Kconfig               |  10 +
 drivers/perf/Makefile              |   1 +
 drivers/perf/qcom_l3_pmu.c         | 825 
+++++++++++++++++++++++++++++++++++++
 include/linux/cpuhotplug.h         |   1 +
 5 files changed, 862 insertions(+)
 create mode 100644 Documentation/perf/qcom_l3_pmu.txt
 create mode 100644 drivers/perf/qcom_l3_pmu.c

This was built and tested on top of v4.11-rc2.
The perf fuzzer was run overnight and no stability issues were found.

Signature · 4 lines
Qualcomm Datacenter Technologies, Inc. on behalf of the Qualcomm 
Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a 
Linux Foundation Collaborative Project.
maintainer
#2 lore raw
In reply to Agustin Vega-Frias

Hi Agustin,

Structurally, this looks good to me.

I have a few minor comments below; with those fixed up I think this is ready to merge.

drivers/perf/qcom_l3_pmu.c line 40

Quoted 8 lines · Agustin Vega-Frias
drivers/perf/qcom_l3_pmu.c new file +8 -0
+/*
+ * General constants
+ */
+
+/* Number of counters on each PMU */
+#define L3_NUM_COUNTERS  8
+/* Mask for the event type field within perf_event_attr.config and EVTYPE reg */
+#define L3_MAX_EVTYPE    0xFF

Given it's a mask, it would be better to name this L3_EVTYPE_MASK.

Perhaps L3_EVTYPE_MASK, then?

[...]

drivers/perf/qcom_l3_pmu.c line 86

Quoted 2 lines
drivers/perf/qcom_l3_pmu.c new file +2 -0
+/* L3_HML3_PM_EVTYPEx */
+#define EVSEL(__val)          ((u32)((__val) & 0xFF))

This cast can go.

[...]

drivers/perf/qcom_l3_pmu.c line 93

Quoted 3 lines
drivers/perf/qcom_l3_pmu.c new file +3 -0
+/* L3_M_BC_CR */
+#define BC_RESET              (((u32)1) << 1)
+#define BC_ENABLE             ((u32)1)

The u32 cast is somewhat unusual. Can we please do this as:

#define BC_RESET (1UL << 1)
#define BC_ENABLE (1UL << 0)

drivers/perf/qcom_l3_pmu.c line 99

Quoted 6 lines
drivers/perf/qcom_l3_pmu.c new file +6 -0
+
+/* L3_M_BC_SATROLL_CR */
+#define BC_SATROLL_CR_RESET   (0)
+
+/* L3_M_BC_CNTENSET */
+#define PMCNTENSET(__cntr)    (((u32)1) << ((__cntr) & 0x7))

Likewise:

#define PMCNTENSET(__cntr (1UL << ((__cntr) & 0x7))

... and so on for the other definitions of this form.

[...]

drivers/perf/qcom_l3_pmu.c line 134

Quoted 11 lines
drivers/perf/qcom_l3_pmu.c new file +11 -0
+/*
+ * Events
+ */
+
+#define L3_CYCLES		0x01
+#define L3_READ_HIT		0x20
+#define L3_READ_MISS		0x21
+#define L3_READ_HIT_D		0x22
+#define L3_READ_MISS_D		0x23
+#define L3_WRITE_HIT		0x24
+#define L3_WRITE_MISS		0x25

Can we please Please give these a L3_EVT_ (or L3_EVENT_) prefix?

Then we can add a NONE event for the odd counter in the long conter case.

[...]

drivers/perf/qcom_l3_pmu.c line 183

Quoted 9 lines
drivers/perf/qcom_l3_pmu.c new file +9 -0
+struct l3cache_event_ops {
+	struct perf_event	*event;
+	/* Called to start event monitoring */
+	void (*start)(struct perf_event *event);
+	/* Called to stop event monitoring */
+	void (*stop)(struct perf_event *event, int flags);
+	/* Called to update the perf_event */
+	void (*update)(struct perf_event *event);
+};

I believe the event field can go.

Quoted 10 lines

+/*
+ * Implementation of long counter operations
+ *
+ * 64bit counters are implemented by chaining two of the 32bit physical
+ * counters. The PMU only supports chaining of adjacent even/odd pairs
+ * and for simplicity the driver always configures the odd counter to
+ * count the overflows of the lower-numbered even counter. Note that since
+ * the resulting hardware counter is 64bits no IRQs are required to maintain
+ * the software counter which is also 64bits.
+ */

This is a really useful comment; thanks for putting this together!

drivers/perf/qcom_l3_pmu.c line 204

Quoted 10 lines
drivers/perf/qcom_l3_pmu.c new file +10 -0
+
+static void qcom_l3_cache__64bit_counter_start(struct perf_event *event)
+{
+	struct l3cache_pmu *l3pmu = to_l3cache_pmu(event->pmu);
+	int idx = event->hw.idx;
+	u32 evsel = get_event_type(event);
+	u32 gang = readl_relaxed(l3pmu->regs + L3_M_BC_GANG);
+
+	/* Set the odd counter to count the overflows of the even counter */
+	writel_relaxed(gang | GANG_EN(idx + 1), l3pmu->regs + L3_M_BC_GANG);

Not a big deal, but could we organise this like:

	/* Set the odd counter to count the overflows of the even counter */
	gang = readl_relaxed(l3pmu->regs + L3_M_BC_GANG);
	gang |= GANG_EN(idx + 1);
	writel_relaxed(gang, l3pmu->regs + L3_M_BC_GANG);

... it makes it a little easier to spot the precise manipulation of the register value, and easier to spot that this is an RMW sequence for the same register.

drivers/perf/qcom_l3_pmu.c line 209

Quoted 5 lines
drivers/perf/qcom_l3_pmu.c new file +5 -0
+
+	/* Initialize the hardware counters and reset prev_count*/
+	local64_set(&event->hw.prev_count, 0);
+	writel_relaxed(0, l3pmu->regs + L3_HML3_PM_EVCNTR(idx+1));
+	writel_relaxed(0, l3pmu->regs + L3_HML3_PM_EVCNTR(idx));

Nit: please use spaces around binary operators, i.e. s/idx+1/idx + 1/g.

[...]

drivers/perf/qcom_l3_pmu.c line 245

Quoted 6 lines
drivers/perf/qcom_l3_pmu.c new file +6 -0
+static void qcom_l3_cache__64bit_counter_update(struct perf_event *event)
+{
+	struct l3cache_pmu *l3pmu = to_l3cache_pmu(event->pmu);
+	int idx = event->hw.idx;
+	u32 hi, lo;
+	u64 prev, now;

Nit: s/now/new/ so as to match other drivers.

[...]

drivers/perf/qcom_l3_pmu.c line 263

Quoted 5 lines
drivers/perf/qcom_l3_pmu.c new file +5 -0
+struct l3cache_event_ops event_ops_long = {
+	.start = qcom_l3_cache__64bit_counter_start,
+	.stop = qcom_l3_cache__64bit_counter_stop,
+	.update = qcom_l3_cache__64bit_counter_update,
+};

Please make this static const.

drivers/perf/qcom_l3_pmu.c line 335

Quoted 5 lines
drivers/perf/qcom_l3_pmu.c new file +5 -0
+struct l3cache_event_ops event_ops_std = {
+	.start = qcom_l3_cache__32bit_counter_start,
+	.stop = qcom_l3_cache__32bit_counter_stop,
+	.update = qcom_l3_cache__32bit_counter_update,
+};

Likewise, please make this static const.

drivers/perf/qcom_l3_pmu.c line 338

Quoted 3 lines
drivers/perf/qcom_l3_pmu.c new file +3 -0
+
+/* Retrieve the appropriate operations for the given event */
+static struct l3cache_event_ops *l3cache_event_get_ops(struct perf_event *event)

This will need to return a const pointer for the ops changes above.

[...]

drivers/perf/qcom_l3_pmu.c line 724

Quoted 6 lines
drivers/perf/qcom_l3_pmu.c new file +6 -0
+static int qcom_l3_cache_pmu_probe(struct platform_device *pdev)
+{
+	struct l3cache_pmu *l3pmu;
+	struct acpi_device *acpi_dev;
+	struct resource *memrc;
+	int rc;

Nit: please use ret rather than rc. I'd like to align the PMU drivers on this convention.

Thanks,
Mark.

#3 lore raw
Quoted 7 lines · Mark Rutland

Hi Agustin,

Structurally, this looks good to me.

I have a few minor comments below; with those fixed up I think this is ready to merge.

Thanks Mark, I'll spin V5 ASAP.

Agustin

Signature · 4 lines
Qualcomm Datacenter Technologies, Inc. on behalf of the Qualcomm 
Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a 
Linux Foundation Collaborative Project.