Skip to contentSkip to conversation

qcom: add l2 cache perf events driver

PATCH Superseded Neil Leeder 3 participants 7 messages Aug 4, 2016 – Aug 8, 2016

Subsystems (2)

v2 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v2 cover qcom: add l2 cache perf events driver

This adds a new dynamic PMU to the perf events framework to program and control the L2 cache PMUs in some Qualcomm Technologies SOCs.

The driver exports formatting and event information to sysfs so it can be used by the perf user space tools with the syntax:
perf stat -a -e l2cache_0/event=0x42/

Qualcomm Technologies PMUs have events arranged in a matrix of rows and columns. Only one event can be enabled from each column at once. This is enforced by the filter_match callback.

changes from v1:

Add the l2-accessors patch to this patchset, previously posted separately. Remove sampling and per-task functionality for this uncore PMU. Use cpumask to replace code which filtered events to one cpu per slice. Replace manual event filtering with filter_match callback.
Use a separate used_mask for event groups.
Add hotplug notifier for CPU and irq migration.
Remove extraneous synchronisation instructions.
Other miscellaneous cleanup.

Neil Leeder (2):
soc: qcom: provide mechanism for drivers to access L2 registers
soc: qcom: add l2 cache perf events driver

 drivers/soc/qcom/Kconfig               |  19 +
 drivers/soc/qcom/Makefile              |   2 +
 drivers/soc/qcom/l2-accessors.c        |  66 +++
 drivers/soc/qcom/perf_event_l2.c       | 839 +++++++++++++++++++++++++++++++++
 include/linux/soc/qcom/l2-accessors.h  |  20 +
 include/linux/soc/qcom/perf_event_l2.h |  81 ++++
 6 files changed, 1027 insertions(+)
 create mode 100644 drivers/soc/qcom/l2-accessors.c
 create mode 100644 drivers/soc/qcom/perf_event_l2.c
 create mode 100644 include/linux/soc/qcom/l2-accessors.h
 create mode 100644 include/linux/soc/qcom/perf_event_l2.h
Signature · 3 lines
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project.
#1 lore raw

PATCH v2 1/2 soc: qcom: provide mechanism for drivers to access L2 registers

L2 registers are accessed using a select register and data register pair. To prevent multiple concurrent writes to the select register by independent drivers, the write to the select register and the associated access of the data register are protected with a lock. All drivers accessing the L2 registers use the set and get functions provided by l2-accessors to ensure correct reads and writes to L2 registers.

---
 drivers/soc/qcom/Kconfig              |  9 +++++
 drivers/soc/qcom/Makefile             |  1 +
 drivers/soc/qcom/l2-accessors.c       | 66 +++++++++++++++++++++++++++++++++++
 include/linux/soc/qcom/l2-accessors.h | 20 +++++++++++
 4 files changed, 96 insertions(+)
 create mode 100644 drivers/soc/qcom/l2-accessors.c
 create mode 100644 include/linux/soc/qcom/l2-accessors.h
drivers/soc/qcom/Kconfig +9 -0
index 461b387..21ec616 100644
@@ -10,6 +10,15 @@ config QCOM_GSBI
           functions for connecting the underlying serial UART, SPI, and I2C
           devices to the output pins.
 
+config QCOM_L2_ACCESSORS
+	bool "Qualcomm Technologies L2-cache accessors"
+	depends on ARCH_QCOM && ARM64
+	help
+	  Say y here to enable support for the Qualcomm Technologies
+	  L2 accessors.
+	  Provides support for accessing registers in the L2 cache
+	  for Qualcomm Technologies chips.
+
 config QCOM_PM
 	bool "Qualcomm Power Management"
 	depends on ARCH_QCOM && !ARM64
drivers/soc/qcom/Makefile +1 -0
index fdd664e..6ef29b9 100644
@@ -1,4 +1,5 @@
 obj-$(CONFIG_QCOM_GSBI)	+=	qcom_gsbi.o
+obj-$(CONFIG_QCOM_L2_ACCESSORS) += l2-accessors.o
 obj-$(CONFIG_QCOM_PM)	+=	spm.o
 obj-$(CONFIG_QCOM_SMD) +=	smd.o
 obj-$(CONFIG_QCOM_SMD_RPM)	+= smd-rpm.o
drivers/soc/qcom/l2-accessors.c new file +66 -0

66 lines not on this page · raw message

include/linux/soc/qcom/l2-accessors.h new file +20 -0
new file mode 100644
index 0000000..e51b72a
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2011-2016 The Linux Foundation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef __QCOM_L2_ACCESSORS_H
+#define __QCOM_L2_ACCESSORS_H
+
+void set_l2_indirect_reg(u64 reg_addr, u64 val);
+u64 get_l2_indirect_reg(u64 reg_addr);
+
+#endif
Signature · 3 lines
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project.
#2 lore raw

Re: [PATCH v2 1/2] soc: qcom: provide mechanism for drivers to access L2 registers

Quoted 7 lines · Neil Leeder

L2 registers are accessed using a select register and data register pair. To prevent multiple concurrent writes to the select register by independent drivers, the write to the select register and the associated access of the data register are protected with a lock. All drivers accessing the L2 registers use the set and get functions provided by l2-accessors to ensure correct reads and writes to L2 registers.

As of this series, this is only used by the PMU driver. Which other drivers do you plan to use this for?

If there's nothing else planned at the moment, it would be nicer to fold these into the PMU driver.

[...]

drivers/soc/qcom/Kconfig config QCOM_GSBI · line 20

Quoted 8 lines
drivers/soc/qcom/Kconfig +8 -0
+config QCOM_L2_ACCESSORS
+	bool "Qualcomm Technologies L2-cache accessors"
+	depends on ARCH_QCOM && ARM64
+	help
+	  Say y here to enable support for the Qualcomm Technologies
+	  L2 accessors.
+	  Provides support for accessing registers in the L2 cache
+	  for Qualcomm Technologies chips.

Which chips have this?

Have drivers select this as necessary. There's no reason for this to be used-selectable given this is trivial common infrastructure.

[...]

drivers/soc/qcom/l2-accessors.c line 18

Quoted 5 lines
drivers/soc/qcom/l2-accessors.c new file +5 -0
+#include <linux/spinlock.h>
+#include <linux/export.h>
+#include <linux/soc/qcom/l2-accessors.h>
+#include <asm/cputype.h>
+#include <asm/sysreg.h>

Nit: please sort these alphabetically.

[...]

Quoted 1 line

+EXPORT_SYMBOL(set_l2_indirect_reg);

The PMU driver isn't a module, so this doesn't need to be exported. Until there's a modular user, please get rid of EXPORT_SYMBOL.

Quoted 1 line

+EXPORT_SYMBOL(get_l2_indirect_reg);

Likewise.

Thanks,
Mark.

#3 lore raw

Re: [PATCH v2 1/2] soc: qcom: provide mechanism for drivers to access L2 registers

Quoted 9 lines · Mark Rutland
Quoted 7 lines · Neil Leeder

L2 registers are accessed using a select register and data register pair. To prevent multiple concurrent writes to the select register by independent drivers, the write to the select register and the associated access of the data register are protected with a lock. All drivers accessing the L2 registers use the set and get functions provided by l2-accessors to ensure correct reads and writes to L2 registers.

Quoted 6 lines

As of this series, this is only used by the PMU driver. Which other drivers do you plan to use this for?

If there's nothing else planned at the moment, it would be nicer to fold these into the PMU driver.

I see a couple of other drivers on codeaurora.org using it: the Error Reporting (ERP) driver and an adaptive clock generator. I'd guess they'll be submitted to LKML but they're not mine so I don't know when.

As the purpose of this is to be the common interface for multiple drivers to stop them walking over each other, I think it makes sense to keep it separate.

Quoted 12 lines

[...]

drivers/soc/qcom/Kconfig config QCOM_GSBI · line 20

Quoted 8 lines
drivers/soc/qcom/Kconfig +8 -0
+config QCOM_L2_ACCESSORS
+	bool "Qualcomm Technologies L2-cache accessors"
+	depends on ARCH_QCOM && ARM64
+	help
+	  Say y here to enable support for the Qualcomm Technologies
+	  L2 accessors.
+	  Provides support for accessing registers in the L2 cache
+	  for Qualcomm Technologies chips.

Which chips have this?

Qualcomm Technologies ARM64 chips, so currently QDF24xx family and anything Kryo based. I'd assume any future chip families as well. Given the 'depends on' line, I wasn't sure there was any benefit to essentially duplicating that in the help text.

Quoted 3 lines

Have drivers select this as necessary. There's no reason for this to be used-selectable given this is trivial common infrastructure.

OK, I'll fix that

Quoted 10 lines

[...]

drivers/soc/qcom/l2-accessors.c line 18

Quoted 5 lines
drivers/soc/qcom/l2-accessors.c new file +5 -0
+#include <linux/spinlock.h>
+#include <linux/export.h>
+#include <linux/soc/qcom/l2-accessors.h>
+#include <asm/cputype.h>
+#include <asm/sysreg.h>

Nit: please sort these alphabetically.

OK

Quoted 11 lines

[...]

Quoted 1 line

+EXPORT_SYMBOL(set_l2_indirect_reg);

The PMU driver isn't a module, so this doesn't need to be exported. Until there's a modular user, please get rid of EXPORT_SYMBOL.

Quoted 1 line

+EXPORT_SYMBOL(get_l2_indirect_reg);

Likewise.

OK to both of these.

Quoted 4 lines

Thanks,
Mark.

Thank you for the comments.
Neil

Signature · 3 lines
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project.
#4 lore raw

PATCH v2 2/2 soc: qcom: add l2 cache perf events driver

In reply to Neil Leeder

Adds perf events support for L2 cache PMU.

The L2 cache PMU driver is named 'l2cache_0' and can be used with perf events to profile L2 events such as cache hits and misses.

---
 drivers/soc/qcom/Kconfig               |  10 +
 drivers/soc/qcom/Makefile              |   1 +
 drivers/soc/qcom/perf_event_l2.c       | 839 +++++++++++++++++++++++++++++++++
 include/linux/soc/qcom/perf_event_l2.h |  81 ++++
 4 files changed, 931 insertions(+)
 create mode 100644 drivers/soc/qcom/perf_event_l2.c
 create mode 100644 include/linux/soc/qcom/perf_event_l2.h
drivers/soc/qcom/Kconfig +10 -0
index 21ec616..0b5ddb9 100644
@@ -19,6 +19,16 @@ config QCOM_L2_ACCESSORS
 	  Provides support for accessing registers in the L2 cache
 	  for Qualcomm Technologies chips.
 
+config QCOM_PERF_EVENTS_L2
+	bool "Qualcomm Technologies L2-cache perf events"
+	depends on ARCH_QCOM && HW_PERF_EVENTS && ACPI
+	select QCOM_L2_ACCESSORS
+	  help
+	  Provides support for the L2 cache performance monitor unit (PMU)
+	  in Qualcomm Technologies processors.
+	  Adds the L2 cache PMU into the perf events subsystem for
+	  monitoring L2 cache events.
+
 config QCOM_PM
 	bool "Qualcomm Power Management"
 	depends on ARCH_QCOM && !ARM64
drivers/soc/qcom/Makefile +1 -0
index 6ef29b9..c8e89ca9 100644
@@ -1,5 +1,6 @@
 obj-$(CONFIG_QCOM_GSBI)	+=	qcom_gsbi.o
 obj-$(CONFIG_QCOM_L2_ACCESSORS) += l2-accessors.o
+obj-$(CONFIG_QCOM_PERF_EVENTS_L2)	+= perf_event_l2.o
 obj-$(CONFIG_QCOM_PM)	+=	spm.o
 obj-$(CONFIG_QCOM_SMD) +=	smd.o
 obj-$(CONFIG_QCOM_SMD_RPM)	+= smd-rpm.o
drivers/soc/qcom/perf_event_l2.c new file +839 -0

839 lines not on this page · raw message

include/linux/soc/qcom/perf_event_l2.h new file +81 -0

81 lines not on this page · raw message

Signature · 2 lines
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
#5 lore raw

Re: [PATCH v2 2/2] soc: qcom: add l2 cache perf events driver

Quoted 21 lines · Neil Leeder

Adds perf events support for L2 cache PMU.

The L2 cache PMU driver is named 'l2cache_0' and can be used with perf events to profile L2 events such as cache hits and misses.

---
 drivers/soc/qcom/Kconfig               |  10 +
 drivers/soc/qcom/Makefile              |   1 +
 drivers/soc/qcom/perf_event_l2.c       | 839 +++++++++++++++++++++++++++++++++
 include/linux/soc/qcom/perf_event_l2.h |  81 ++++
 4 files changed, 931 insertions(+)
 create mode 100644 drivers/soc/qcom/perf_event_l2.c
 create mode 100644 include/linux/soc/qcom/perf_event_l2.h
drivers/soc/qcom/Kconfig +0 -0
index 21ec616..0b5ddb9 100644

drivers/soc/qcom/Kconfig config QCOM_L2_ACCESSORS · line 23

Quoted 5 lines
drivers/soc/qcom/Kconfig +2 -0
@@ -19,6 +19,16 @@ config QCOM_L2_ACCESSORS
          Provides support for accessing registers in the L2 cache
          for Qualcomm Technologies chips.
 
+config QCOM_PERF_EVENTS_L2
+       bool "Qualcomm Technologies L2-cache perf events"

Since this is a bool, you shouldn't need module.h in your driver or any MODULE_<xyz> tags (if there are any).

Thanks,
Paul.
--

Quoted 53 lines
drivers/soc/qcom/Kconfig +8 -0
+       depends on ARCH_QCOM && HW_PERF_EVENTS && ACPI
+       select QCOM_L2_ACCESSORS
+         help
+         Provides support for the L2 cache performance monitor unit (PMU)
+         in Qualcomm Technologies processors.
+         Adds the L2 cache PMU into the perf events subsystem for
+         monitoring L2 cache events.
+
 config QCOM_PM
        bool "Qualcomm Power Management"
        depends on ARCH_QCOM && !ARM64
drivers/soc/qcom/Makefile +1 -0
index 6ef29b9..c8e89ca9 100644
@@ -1,5 +1,6 @@
 obj-$(CONFIG_QCOM_GSBI)        +=      qcom_gsbi.o
 obj-$(CONFIG_QCOM_L2_ACCESSORS) += l2-accessors.o
+obj-$(CONFIG_QCOM_PERF_EVENTS_L2)      += perf_event_l2.o
 obj-$(CONFIG_QCOM_PM)  +=      spm.o
 obj-$(CONFIG_QCOM_SMD) +=      smd.o
 obj-$(CONFIG_QCOM_SMD_RPM)     += smd-rpm.o
drivers/soc/qcom/perf_event_l2.c new file +25 -0
new file mode 100644
index 0000000..54c6790
@@ -0,0 +1,839 @@
+/* Copyright (c) 2015,2016 The Linux Foundation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+#define pr_fmt(fmt) "l2 perfevents: " fmt
+
+#include <linux/module.h>
+#include <linux/bitops.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/irq.h>
+#include <linux/list.h>
+#include <linux/acpi.h>
+#include <linux/perf_event.h>
+#include <linux/platform_device.h>
+#include <linux/soc/qcom/perf_event_l2.h>
+#include <linux/soc/qcom/l2-accessors.h>
+#include <linux/topology.h>
#6 lore raw

Re: [PATCH v2 2/2] soc: qcom: add l2 cache perf events driver

Quoted 31 lines · Paul Gortmaker
Quoted 21 lines · Neil Leeder

Adds perf events support for L2 cache PMU.

The L2 cache PMU driver is named 'l2cache_0' and can be used with perf events to profile L2 events such as cache hits and misses.

---
 drivers/soc/qcom/Kconfig               |  10 +
 drivers/soc/qcom/Makefile              |   1 +
 drivers/soc/qcom/perf_event_l2.c       | 839 +++++++++++++++++++++++++++++++++
 include/linux/soc/qcom/perf_event_l2.h |  81 ++++
 4 files changed, 931 insertions(+)
 create mode 100644 drivers/soc/qcom/perf_event_l2.c
 create mode 100644 include/linux/soc/qcom/perf_event_l2.h
drivers/soc/qcom/Kconfig +0 -0
index 21ec616..0b5ddb9 100644

drivers/soc/qcom/Kconfig config QCOM_L2_ACCESSORS · line 23

Quoted 5 lines
drivers/soc/qcom/Kconfig +2 -0
@@ -19,6 +19,16 @@ config QCOM_L2_ACCESSORS
          Provides support for accessing registers in the L2 cache
          for Qualcomm Technologies chips.
 
+config QCOM_PERF_EVENTS_L2
+       bool "Qualcomm Technologies L2-cache perf events"

Since this is a bool, you shouldn't need module.h in your driver or any MODULE_<xyz> tags (if there are any).

Quoted 3 lines

Thanks,
Paul.
--

You're right - I'll clean up the include list and sort it alphabetically while I'm at it.

Thanks,
Neil

Signature · 3 lines
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project.