Skip to contentSkip to conversation

Cavium ThunderX uncore PMU support

RFC PATCH Superseded Jan Glauber 4 participants 18 messages Feb 12, 2016 – Mar 11, 2016

Subsystems (2)

v1 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

cover Cavium ThunderX uncore PMU support

Hi,

this patch series provides access to various counters on the ThunderX SOC.

For details of the implementation see patch #1.

Patches #2-7 add ther various ThunderX specific PMUs.

I did not want to put these file into arch/arm64/kernel so I added a "uncore" directory. Maybe this should be put somewhere under drivers/ instead.

Feedback welcome!

Jan

Jan Glauber (7):
arm64/perf: Basic uncore counter support for Cavium ThunderX arm64/perf: Cavium ThunderX L2C TAD uncore support arm64/perf: Cavium ThunderX L2C CBC uncore support arm64/perf: Cavium ThunderX LMC uncore support arm64/perf: Cavium ThunderX OCX LNE uncore support arm64/perf: Cavium ThunderX OCX FRC uncore support arm64/perf: Cavium ThunderX OCX TLK uncore support

 arch/arm64/kernel/Makefile                       |   1 +
 arch/arm64/kernel/uncore/Makefile                |   7 +
 arch/arm64/kernel/uncore/uncore_cavium.c         | 229 +++++++++
 arch/arm64/kernel/uncore/uncore_cavium.h         |  97 ++++
 arch/arm64/kernel/uncore/uncore_cavium_l2c_cbc.c | 239 +++++++++
 arch/arm64/kernel/uncore/uncore_cavium_l2c_tad.c | 600 +++++++++++++++++++++++
 arch/arm64/kernel/uncore/uncore_cavium_lmc.c     | 201 ++++++++
 arch/arm64/kernel/uncore/uncore_cavium_ocx_frc.c | 248 ++++++++++
 arch/arm64/kernel/uncore/uncore_cavium_ocx_lne.c | 270 ++++++++++
 arch/arm64/kernel/uncore/uncore_cavium_ocx_tlk.c | 366 ++++++++++++++
 10 files changed, 2258 insertions(+)
 create mode 100644 arch/arm64/kernel/uncore/Makefile
 create mode 100644 arch/arm64/kernel/uncore/uncore_cavium.c
 create mode 100644 arch/arm64/kernel/uncore/uncore_cavium.h
 create mode 100644 arch/arm64/kernel/uncore/uncore_cavium_l2c_cbc.c
 create mode 100644 arch/arm64/kernel/uncore/uncore_cavium_l2c_tad.c
 create mode 100644 arch/arm64/kernel/uncore/uncore_cavium_lmc.c
 create mode 100644 arch/arm64/kernel/uncore/uncore_cavium_ocx_frc.c
 create mode 100644 arch/arm64/kernel/uncore/uncore_cavium_ocx_lne.c
 create mode 100644 arch/arm64/kernel/uncore/uncore_cavium_ocx_tlk.c
Signature · 1 line
1.9.1
#1 lore raw

RFC PATCH 1/7 arm64/perf: Basic uncore counter support for Cavium ThunderX

Provide uncore facilities for non-CPU performance counter units. Based on Intel/AMD uncore pmu support.

The uncore PMUs can be found under /sys/bus/event_source/devices. All counters are exported via sysfs in the corresponding events files under the PMU directory so the perf tool can list the event names.

There are 2 points that are special in this implementation:

1) The PMU detection solely relies on PCI device detection. If a matching PCI device is found the PMU is created. The code can deal with multiple units of the same type, e.g. more than one memory controller.

2) Counters are summarized across the different units of the same type, e.g. L2C TAD 0..7 is presented as a single counter (adding the values from TAD 0 to 7). Although losing the ability to read a single value the merged values are easier to use and yield enough information.

---
 arch/arm64/kernel/Makefile               |   1 +
 arch/arm64/kernel/uncore/Makefile        |   1 +
 arch/arm64/kernel/uncore/uncore_cavium.c | 210 +++++++++++++++++++++++++++++++
 arch/arm64/kernel/uncore/uncore_cavium.h |  73 +++++++++++
 4 files changed, 285 insertions(+)
 create mode 100644 arch/arm64/kernel/uncore/Makefile
 create mode 100644 arch/arm64/kernel/uncore/uncore_cavium.c
 create mode 100644 arch/arm64/kernel/uncore/uncore_cavium.h
arch/arm64/kernel/Makefile +1 -0
index 83cd7e6..c2d2810 100644
@@ -42,6 +42,7 @@ arm64-obj-$(CONFIG_PCI)			+= pci.o
 arm64-obj-$(CONFIG_ARMV8_DEPRECATED)	+= armv8_deprecated.o
 arm64-obj-$(CONFIG_ACPI)		+= acpi.o
 arm64-obj-$(CONFIG_PARAVIRT)		+= paravirt.o
+arm64-obj-$(CONFIG_ARCH_THUNDER)	+= uncore/
 
 obj-y					+= $(arm64-obj-y) vdso/
 obj-m					+= $(arm64-obj-m)
arch/arm64/kernel/uncore/Makefile new file +1 -0
new file mode 100644
index 0000000..b9c72c2
@@ -0,0 +1 @@
+obj-$(CONFIG_ARCH_THUNDER) += uncore_cavium.o
arch/arm64/kernel/uncore/uncore_cavium.c new file +210 -0

210 lines not on this page · raw message

arch/arm64/kernel/uncore/uncore_cavium.h new file +73 -0

73 lines not on this page · raw message

Signature · 1 line
1.9.1
#11 lore raw

RFC PATCH 2/7 arm64/perf: Cavium ThunderX L2C TAD uncore support

In reply to Jan Glauber

Support counters of the L2 Cache tag and data units.

---
 arch/arm64/kernel/uncore/Makefile                |   3 +-
 arch/arm64/kernel/uncore/uncore_cavium.c         |   6 +-
 arch/arm64/kernel/uncore/uncore_cavium.h         |   6 +-
 arch/arm64/kernel/uncore/uncore_cavium_l2c_tad.c | 600 +++++++++++++++++++++++
 4 files changed, 612 insertions(+), 3 deletions(-)
 create mode 100644 arch/arm64/kernel/uncore/uncore_cavium_l2c_tad.c
arch/arm64/kernel/uncore/Makefile +2 -1
index b9c72c2..6a16caf 100644
@@ -1 +1,2 @@
-obj-$(CONFIG_ARCH_THUNDER) += uncore_cavium.o
+obj-$(CONFIG_ARCH_THUNDER) += uncore_cavium.o		\
+			      uncore_cavium_l2c_tad.o
arch/arm64/kernel/uncore/uncore_cavium.c +5 -1
index 0cfcc83..b625caf 100644
@@ -22,7 +22,10 @@ int thunder_uncore_version;
 
 struct thunder_uncore *event_to_thunder_uncore(struct perf_event *event)
 {
-	return NULL;
+	if (event->pmu->type == thunder_l2c_tad_pmu.type)
+		return thunder_uncore_l2c_tad;
+	else
+		return NULL;
 }
 
 void thunder_uncore_read(struct perf_event *event)
@@ -205,6 +208,7 @@ static int __init thunder_uncore_init(void)
 		thunder_uncore_version = 1;
 	pr_info("PMU version: %d\n", thunder_uncore_version);
 
+	thunder_uncore_l2c_tad_setup();
 	return 0;
 }
 late_initcall(thunder_uncore_init);
arch/arm64/kernel/uncore/uncore_cavium.h +5 -1
index acd121d..90e6a2d 100644
@@ -13,7 +13,7 @@
 #define pr_fmt(fmt)     "thunderx_uncore: " fmt
 
 enum uncore_type {
-	NOP_TYPE,
+	L2C_TAD_TYPE,
 };
 
 extern int thunder_uncore_version;
@@ -59,6 +59,8 @@ static inline void __iomem *map_offset(unsigned long addr,
 }
 
 extern struct attribute_group thunder_uncore_attr_group;
+extern struct thunder_uncore *thunder_uncore_l2c_tad;
+extern struct pmu thunder_l2c_tad_pmu;
 
 /* Prototypes */
 struct thunder_uncore *event_to_thunder_uncore(struct perf_event *event);
@@ -71,3 +73,5 @@ int thunder_uncore_setup(struct thunder_uncore *uncore, int id,
 ssize_t thunder_events_sysfs_show(struct device *dev,
 				  struct device_attribute *attr,
 				  char *page);
+
+int thunder_uncore_l2c_tad_setup(void);
arch/arm64/kernel/uncore/uncore_cavium_l2c_tad.c new file +600 -0

600 lines not on this page · raw message

Signature · 1 line
1.9.1
#12 lore raw

RFC PATCH 3/7 arm64/perf: Cavium ThunderX L2C CBC uncore support

In reply to Jan Glauber

Support counters of the L2 cache crossbar connect.

---
 arch/arm64/kernel/uncore/Makefile                |   3 +-
 arch/arm64/kernel/uncore/uncore_cavium.c         |   3 +
 arch/arm64/kernel/uncore/uncore_cavium.h         |   4 +
 arch/arm64/kernel/uncore/uncore_cavium_l2c_cbc.c | 239 +++++++++++++++++++++++
 4 files changed, 248 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm64/kernel/uncore/uncore_cavium_l2c_cbc.c
arch/arm64/kernel/uncore/Makefile +2 -1
index 6a16caf..d52ecc9 100644
@@ -1,2 +1,3 @@
 obj-$(CONFIG_ARCH_THUNDER) += uncore_cavium.o		\
-			      uncore_cavium_l2c_tad.o
+			      uncore_cavium_l2c_tad.o	\
+			      uncore_cavium_l2c_cbc.o
arch/arm64/kernel/uncore/uncore_cavium.c +3 -0
index b625caf..0304c60 100644
@@ -24,6 +24,8 @@ struct thunder_uncore *event_to_thunder_uncore(struct perf_event *event)
 {
 	if (event->pmu->type == thunder_l2c_tad_pmu.type)
 		return thunder_uncore_l2c_tad;
+	else if (event->pmu->type == thunder_l2c_cbc_pmu.type)
+		return thunder_uncore_l2c_cbc;
 	else
 		return NULL;
 }
@@ -209,6 +211,7 @@ static int __init thunder_uncore_init(void)
 	pr_info("PMU version: %d\n", thunder_uncore_version);
 
 	thunder_uncore_l2c_tad_setup();
+	thunder_uncore_l2c_cbc_setup();
 	return 0;
 }
 late_initcall(thunder_uncore_init);
arch/arm64/kernel/uncore/uncore_cavium.h +4 -0
index 90e6a2d..74f44d7 100644
@@ -14,6 +14,7 @@
 
 enum uncore_type {
 	L2C_TAD_TYPE,
+	L2C_CBC_TYPE,
 };
 
 extern int thunder_uncore_version;
@@ -60,7 +61,9 @@ static inline void __iomem *map_offset(unsigned long addr,
 
 extern struct attribute_group thunder_uncore_attr_group;
 extern struct thunder_uncore *thunder_uncore_l2c_tad;
+extern struct thunder_uncore *thunder_uncore_l2c_cbc;
 extern struct pmu thunder_l2c_tad_pmu;
+extern struct pmu thunder_l2c_cbc_pmu;
 
 /* Prototypes */
 struct thunder_uncore *event_to_thunder_uncore(struct perf_event *event);
@@ -75,3 +78,4 @@ ssize_t thunder_events_sysfs_show(struct device *dev,
 				  char *page);
 
 int thunder_uncore_l2c_tad_setup(void);
+int thunder_uncore_l2c_cbc_setup(void);
arch/arm64/kernel/uncore/uncore_cavium_l2c_cbc.c new file +239 -0

239 lines not on this page · raw message

Signature · 1 line
1.9.1
#13 lore raw

RFC PATCH 4/7 arm64/perf: Cavium ThunderX LMC uncore support

In reply to Jan Glauber

Support counters on the DRAM controllers.

---
 arch/arm64/kernel/uncore/Makefile            |   3 +-
 arch/arm64/kernel/uncore/uncore_cavium.c     |   3 +
 arch/arm64/kernel/uncore/uncore_cavium.h     |   4 +
 arch/arm64/kernel/uncore/uncore_cavium_lmc.c | 201 +++++++++++++++++++++++++++
 4 files changed, 210 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm64/kernel/uncore/uncore_cavium_lmc.c
arch/arm64/kernel/uncore/Makefile +2 -1
index d52ecc9..81479e8 100644
@@ -1,3 +1,4 @@
 obj-$(CONFIG_ARCH_THUNDER) += uncore_cavium.o		\
 			      uncore_cavium_l2c_tad.o	\
-			      uncore_cavium_l2c_cbc.o
+			      uncore_cavium_l2c_cbc.o	\
+			      uncore_cavium_lmc.o
arch/arm64/kernel/uncore/uncore_cavium.c +3 -0
index 0304c60..a972418 100644
@@ -26,6 +26,8 @@ struct thunder_uncore *event_to_thunder_uncore(struct perf_event *event)
 		return thunder_uncore_l2c_tad;
 	else if (event->pmu->type == thunder_l2c_cbc_pmu.type)
 		return thunder_uncore_l2c_cbc;
+	else if (event->pmu->type == thunder_lmc_pmu.type)
+		return thunder_uncore_lmc;
 	else
 		return NULL;
 }
@@ -212,6 +214,7 @@ static int __init thunder_uncore_init(void)
 
 	thunder_uncore_l2c_tad_setup();
 	thunder_uncore_l2c_cbc_setup();
+	thunder_uncore_lmc_setup();
 	return 0;
 }
 late_initcall(thunder_uncore_init);
arch/arm64/kernel/uncore/uncore_cavium.h +4 -0
index 74f44d7..6e3beba 100644
@@ -15,6 +15,7 @@
 enum uncore_type {
 	L2C_TAD_TYPE,
 	L2C_CBC_TYPE,
+	LMC_TYPE,
 };
 
 extern int thunder_uncore_version;
@@ -62,8 +63,10 @@ static inline void __iomem *map_offset(unsigned long addr,
 extern struct attribute_group thunder_uncore_attr_group;
 extern struct thunder_uncore *thunder_uncore_l2c_tad;
 extern struct thunder_uncore *thunder_uncore_l2c_cbc;
+extern struct thunder_uncore *thunder_uncore_lmc;
 extern struct pmu thunder_l2c_tad_pmu;
 extern struct pmu thunder_l2c_cbc_pmu;
+extern struct pmu thunder_lmc_pmu;
 
 /* Prototypes */
 struct thunder_uncore *event_to_thunder_uncore(struct perf_event *event);
@@ -79,3 +82,4 @@ ssize_t thunder_events_sysfs_show(struct device *dev,
 
 int thunder_uncore_l2c_tad_setup(void);
 int thunder_uncore_l2c_cbc_setup(void);
+int thunder_uncore_lmc_setup(void);
arch/arm64/kernel/uncore/uncore_cavium_lmc.c new file +201 -0

201 lines not on this page · raw message

Signature · 1 line
1.9.1
#14 lore raw

RFC PATCH 5/7 arm64/perf: Cavium ThunderX OCX LNE uncore support

In reply to Jan Glauber

Support counters for the CCPI Interface controller (OCX) lanes.

---
 arch/arm64/kernel/uncore/Makefile                |   3 +-
 arch/arm64/kernel/uncore/uncore_cavium.c         |   3 +
 arch/arm64/kernel/uncore/uncore_cavium.h         |   4 +
 arch/arm64/kernel/uncore/uncore_cavium_ocx_lne.c | 270 +++++++++++++++++++++++
 4 files changed, 279 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm64/kernel/uncore/uncore_cavium_ocx_lne.c
arch/arm64/kernel/uncore/Makefile +2 -1
index 81479e8..da39f452 100644
@@ -1,4 +1,5 @@
 obj-$(CONFIG_ARCH_THUNDER) += uncore_cavium.o		\
 			      uncore_cavium_l2c_tad.o	\
 			      uncore_cavium_l2c_cbc.o	\
-			      uncore_cavium_lmc.o
+			      uncore_cavium_lmc.o	\
+			      uncore_cavium_ocx_lne.o
arch/arm64/kernel/uncore/uncore_cavium.c +3 -0
index a972418..f2fbdea 100644
@@ -28,6 +28,8 @@ struct thunder_uncore *event_to_thunder_uncore(struct perf_event *event)
 		return thunder_uncore_l2c_cbc;
 	else if (event->pmu->type == thunder_lmc_pmu.type)
 		return thunder_uncore_lmc;
+	else if (event->pmu->type == thunder_ocx_lne_pmu.type)
+		return thunder_uncore_ocx_lne;
 	else
 		return NULL;
 }
@@ -215,6 +217,7 @@ static int __init thunder_uncore_init(void)
 	thunder_uncore_l2c_tad_setup();
 	thunder_uncore_l2c_cbc_setup();
 	thunder_uncore_lmc_setup();
+	thunder_uncore_ocx_lne_setup();
 	return 0;
 }
 late_initcall(thunder_uncore_init);
arch/arm64/kernel/uncore/uncore_cavium.h +4 -0
index 6e3beba..b9bcb42 100644
@@ -16,6 +16,7 @@ enum uncore_type {
 	L2C_TAD_TYPE,
 	L2C_CBC_TYPE,
 	LMC_TYPE,
+	OCX_LNE_TYPE,
 };
 
 extern int thunder_uncore_version;
@@ -64,9 +65,11 @@ extern struct attribute_group thunder_uncore_attr_group;
 extern struct thunder_uncore *thunder_uncore_l2c_tad;
 extern struct thunder_uncore *thunder_uncore_l2c_cbc;
 extern struct thunder_uncore *thunder_uncore_lmc;
+extern struct thunder_uncore *thunder_uncore_ocx_lne;
 extern struct pmu thunder_l2c_tad_pmu;
 extern struct pmu thunder_l2c_cbc_pmu;
 extern struct pmu thunder_lmc_pmu;
+extern struct pmu thunder_ocx_lne_pmu;
 
 /* Prototypes */
 struct thunder_uncore *event_to_thunder_uncore(struct perf_event *event);
@@ -83,3 +86,4 @@ ssize_t thunder_events_sysfs_show(struct device *dev,
 int thunder_uncore_l2c_tad_setup(void);
 int thunder_uncore_l2c_cbc_setup(void);
 int thunder_uncore_lmc_setup(void);
+int thunder_uncore_ocx_lne_setup(void);
arch/arm64/kernel/uncore/uncore_cavium_ocx_lne.c new file +270 -0

270 lines not on this page · raw message

Signature · 1 line
1.9.1
#15 lore raw

RFC PATCH 6/7 arm64/perf: Cavium ThunderX OCX FRC uncore support

In reply to Jan Glauber

Support for the OCX alignment counters.

---
 arch/arm64/kernel/uncore/Makefile                |   3 +-
 arch/arm64/kernel/uncore/uncore_cavium.c         |   3 +
 arch/arm64/kernel/uncore/uncore_cavium.h         |   4 +
 arch/arm64/kernel/uncore/uncore_cavium_ocx_frc.c | 248 +++++++++++++++++++++++
 4 files changed, 257 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm64/kernel/uncore/uncore_cavium_ocx_frc.c
arch/arm64/kernel/uncore/Makefile +2 -1
index da39f452..752af39 100644
@@ -2,4 +2,5 @@ obj-$(CONFIG_ARCH_THUNDER) += uncore_cavium.o		\
 			      uncore_cavium_l2c_tad.o	\
 			      uncore_cavium_l2c_cbc.o	\
 			      uncore_cavium_lmc.o	\
-			      uncore_cavium_ocx_lne.o
+			      uncore_cavium_ocx_lne.o	\
+			      uncore_cavium_ocx_frc.o
arch/arm64/kernel/uncore/uncore_cavium.c +3 -0
index f2fbdea..9fed1d6 100644
@@ -30,6 +30,8 @@ struct thunder_uncore *event_to_thunder_uncore(struct perf_event *event)
 		return thunder_uncore_lmc;
 	else if (event->pmu->type == thunder_ocx_lne_pmu.type)
 		return thunder_uncore_ocx_lne;
+	else if (event->pmu->type == thunder_ocx_frc_pmu.type)
+		return thunder_uncore_ocx_frc;
 	else
 		return NULL;
 }
@@ -218,6 +220,7 @@ static int __init thunder_uncore_init(void)
 	thunder_uncore_l2c_cbc_setup();
 	thunder_uncore_lmc_setup();
 	thunder_uncore_ocx_lne_setup();
+	thunder_uncore_ocx_frc_setup();
 	return 0;
 }
 late_initcall(thunder_uncore_init);
arch/arm64/kernel/uncore/uncore_cavium.h +4 -0
index b9bcb42..07bd4f4 100644
@@ -17,6 +17,7 @@ enum uncore_type {
 	L2C_CBC_TYPE,
 	LMC_TYPE,
 	OCX_LNE_TYPE,
+	OCX_FRC_TYPE,
 };
 
 extern int thunder_uncore_version;
@@ -66,10 +67,12 @@ extern struct thunder_uncore *thunder_uncore_l2c_tad;
 extern struct thunder_uncore *thunder_uncore_l2c_cbc;
 extern struct thunder_uncore *thunder_uncore_lmc;
 extern struct thunder_uncore *thunder_uncore_ocx_lne;
+extern struct thunder_uncore *thunder_uncore_ocx_frc;
 extern struct pmu thunder_l2c_tad_pmu;
 extern struct pmu thunder_l2c_cbc_pmu;
 extern struct pmu thunder_lmc_pmu;
 extern struct pmu thunder_ocx_lne_pmu;
+extern struct pmu thunder_ocx_frc_pmu;
 
 /* Prototypes */
 struct thunder_uncore *event_to_thunder_uncore(struct perf_event *event);
@@ -87,3 +90,4 @@ int thunder_uncore_l2c_tad_setup(void);
 int thunder_uncore_l2c_cbc_setup(void);
 int thunder_uncore_lmc_setup(void);
 int thunder_uncore_ocx_lne_setup(void);
+int thunder_uncore_ocx_frc_setup(void);
arch/arm64/kernel/uncore/uncore_cavium_ocx_frc.c new file +248 -0

248 lines not on this page · raw message

Signature · 1 line
1.9.1
#16 lore raw

RFC PATCH 7/7 arm64/perf: Cavium ThunderX OCX TLK uncore support

In reply to Jan Glauber

Support for the OCX transmit link counters.

---
 arch/arm64/kernel/uncore/Makefile                |   3 +-
 arch/arm64/kernel/uncore/uncore_cavium.c         |   3 +
 arch/arm64/kernel/uncore/uncore_cavium.h         |   4 +
 arch/arm64/kernel/uncore/uncore_cavium_ocx_tlk.c | 366 +++++++++++++++++++++++
 4 files changed, 375 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm64/kernel/uncore/uncore_cavium_ocx_tlk.c
arch/arm64/kernel/uncore/Makefile +2 -1
index 752af39..a267800 100644
@@ -3,4 +3,5 @@ obj-$(CONFIG_ARCH_THUNDER) += uncore_cavium.o		\
 			      uncore_cavium_l2c_cbc.o	\
 			      uncore_cavium_lmc.o	\
 			      uncore_cavium_ocx_lne.o	\
-			      uncore_cavium_ocx_frc.o
+			      uncore_cavium_ocx_frc.o	\
+			      uncore_cavium_ocx_tlk.o
arch/arm64/kernel/uncore/uncore_cavium.c +3 -0
index 9fed1d6..e2edb7a4 100644
@@ -32,6 +32,8 @@ struct thunder_uncore *event_to_thunder_uncore(struct perf_event *event)
 		return thunder_uncore_ocx_lne;
 	else if (event->pmu->type == thunder_ocx_frc_pmu.type)
 		return thunder_uncore_ocx_frc;
+	else if (event->pmu->type == thunder_ocx_tlk_pmu.type)
+		return thunder_uncore_ocx_tlk;
 	else
 		return NULL;
 }
@@ -221,6 +223,7 @@ static int __init thunder_uncore_init(void)
 	thunder_uncore_lmc_setup();
 	thunder_uncore_ocx_lne_setup();
 	thunder_uncore_ocx_frc_setup();
+	thunder_uncore_ocx_tlk_setup();
 	return 0;
 }
 late_initcall(thunder_uncore_init);
arch/arm64/kernel/uncore/uncore_cavium.h +4 -0
index 07bd4f4..f312d41 100644
@@ -18,6 +18,7 @@ enum uncore_type {
 	LMC_TYPE,
 	OCX_LNE_TYPE,
 	OCX_FRC_TYPE,
+	OCX_TLK_TYPE,
 };
 
 extern int thunder_uncore_version;
@@ -68,11 +69,13 @@ extern struct thunder_uncore *thunder_uncore_l2c_cbc;
 extern struct thunder_uncore *thunder_uncore_lmc;
 extern struct thunder_uncore *thunder_uncore_ocx_lne;
 extern struct thunder_uncore *thunder_uncore_ocx_frc;
+extern struct thunder_uncore *thunder_uncore_ocx_tlk;
 extern struct pmu thunder_l2c_tad_pmu;
 extern struct pmu thunder_l2c_cbc_pmu;
 extern struct pmu thunder_lmc_pmu;
 extern struct pmu thunder_ocx_lne_pmu;
 extern struct pmu thunder_ocx_frc_pmu;
+extern struct pmu thunder_ocx_tlk_pmu;
 
 /* Prototypes */
 struct thunder_uncore *event_to_thunder_uncore(struct perf_event *event);
@@ -91,3 +94,4 @@ int thunder_uncore_l2c_cbc_setup(void);
 int thunder_uncore_lmc_setup(void);
 int thunder_uncore_ocx_lne_setup(void);
 int thunder_uncore_ocx_frc_setup(void);
+int thunder_uncore_ocx_tlk_setup(void);
arch/arm64/kernel/uncore/uncore_cavium_ocx_tlk.c new file +366 -0

366 lines not on this page · raw message

Signature · 1 line
1.9.1
reviewer
#17 lore raw
In reply to Jan Glauber
Quoted 11 lines · Jan Glauber

Hi,

this patch series provides access to various counters on the ThunderX SOC.

For details of the implementation see patch #1.

Patches #2-7 add ther various ThunderX specific PMUs.

I did not want to put these file into arch/arm64/kernel so I added a "uncore" directory. Maybe this should be put somewhere under drivers/ instead.

This is probably better suited to drivers/perf/, or drivers/bus/ (where CCN and CCI perf drivers live).

Mark.

reviewer
#2 lore raw

Re: [RFC PATCH 1/7] arm64/perf: Basic uncore counter support for Cavium ThunderX

In reply to Jan Glauber
Quoted 6 lines · Jan Glauber

Provide uncore facilities for non-CPU performance counter units. Based on Intel/AMD uncore pmu support.

The uncore PMUs can be found under /sys/bus/event_source/devices. All counters are exported via sysfs in the corresponding events files under the PMU directory so the perf tool can list the event names.

It turns out that "uncore" covers quite a lot of things.

Where exactly do the see counters live? system, socket, cluster?

Are there potentially multiple instances of a given PMU in the system? e.g. might each clutster have an instance of an L2 PMU?

If I turn off a set of CPUs, do any "uncore" PMUs lost context or become inaccessible?

Otherwise, are they associated with some power domain?

Quoted 6 lines

There are 2 points that are special in this implementation:

1) The PMU detection solely relies on PCI device detection. If a matching PCI device is found the PMU is created. The code can deal with multiple units of the same type, e.g. more than one memory controller.

I see below that the driver has an initcall that runs regardless of whether the PCI device exists, and looks at the MIDR. That's clearly not string PCI device detection.

Why is this not a true PCI driver that only gets probed if the PCI device exists?

Quoted 5 lines

2) Counters are summarized across the different units of the same type, e.g. L2C TAD 0..7 is presented as a single counter (adding the values from TAD 0 to 7). Although losing the ability to read a single value the merged values are easier to use and yield enough information.

I'm not sure I follow this. What is easier? What are you doing, and what are you comparing that with to say that your approach is easier?

It sounds like it should be possible to handle multiple counters like this, so I don't follow why you want to amalgamate them in-kernel.

[...]

Review

Quoted 2 lines
(quoted diff) +2 -0
+#include <asm/cpufeature.h>
+#include <asm/cputype.h>

I don't see why you should need these two if this is truly an uncore device probed solely from PCI.

arch/arm64/kernel/uncore/uncore_cavium.c line 39

Quoted 12 lines
arch/arm64/kernel/uncore/uncore_cavium.c new file +12 -0
+void thunder_uncore_read(struct perf_event *event)
+{
+	struct thunder_uncore *uncore = event_to_thunder_uncore(event);
+	struct hw_perf_event *hwc = &event->hw;
+	u64 prev, new = 0;
+	s64 delta;
+	int i;
+
+	/*
+	 * since we do not enable counter overflow interrupts,
+	 * we do not have to worry about prev_count changing on us
+	 */

Without overflow interrupts, how do you ensure that you account for overflow in a reasonable time window (i.e. before the counter runs past its initial value)?

arch/arm64/kernel/uncore/uncore_cavium.c line 45

Quoted 6 lines
arch/arm64/kernel/uncore/uncore_cavium.c new file +6 -0
+
+	prev = local64_read(&hwc->prev_count);
+
+	/* read counter values from all units */
+	for (i = 0; i < uncore->nr_units; i++)
+		new += readq(map_offset(hwc->event_base, uncore, i));

There's no bit to determine whether an overflow occurred?

Quoted 10 lines
arch/arm64/kernel/uncore/uncore_cavium.c new file +10 -0
+
+	local64_set(&hwc->prev_count, new);
+	delta = new - prev;
+	local64_add(delta, &event->count);
+}
+
+void thunder_uncore_del(struct perf_event *event, int flags)
+{
+	struct thunder_uncore *uncore = event_to_thunder_uncore(event);
+	struct hw_perf_event *hwc = &event->hw;

arch/arm64/kernel/uncore/uncore_cavium.c line 65

Quoted 10 lines
arch/arm64/kernel/uncore/uncore_cavium.c new file +10 -0
+	int i;
+
+	event->pmu->stop(event, PERF_EF_UPDATE);
+
+	for (i = 0; i < uncore->num_counters; i++) {
+		if (cmpxchg(&uncore->events[i], event, NULL) == event)
+			break;
+	}
+	hwc->idx = -1;
+}

Why not just place the event at uncode->events[hwc->idx] ?

Theat way removing the event is trivial.

Quoted 10 lines
arch/arm64/kernel/uncore/uncore_cavium.c new file +10 -0
+int thunder_uncore_event_init(struct perf_event *event)
+{
+	struct hw_perf_event *hwc = &event->hw;
+	struct thunder_uncore *uncore;
+
+	if (event->attr.type != event->pmu->type)
+		return -ENOENT;
+
+	/* we do not support sampling */
+	if (is_sampling_event(event))

arch/arm64/kernel/uncore/uncore_cavium.c line 86

Quoted 10 lines
arch/arm64/kernel/uncore/uncore_cavium.c new file +10 -0
+		return -EINVAL;
+
+	/* counters do not have these bits */
+	if (event->attr.exclude_user	||
+	    event->attr.exclude_kernel	||
+	    event->attr.exclude_host	||
+	    event->attr.exclude_guest	||
+	    event->attr.exclude_hv	||
+	    event->attr.exclude_idle)
+		return -EINVAL;

We should _really_ make these features opt-in at the core level. It's crazy that each and every PMU drivers has to explicitly test and reject things it doesn't support.

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	/* and we do not enable counter overflow interrupts */

That statement raises far more questions than it answers.

_why_ do we not user overflow interrupts?

arch/arm64/kernel/uncore/uncore_cavium.c line 99

Quoted 11 lines
arch/arm64/kernel/uncore/uncore_cavium.c new file +11 -0
+
+	uncore = event_to_thunder_uncore(event);
+	if (!uncore)
+		return -ENODEV;
+	if (!uncore->event_valid(event->attr.config))
+		return -EINVAL;
+
+	hwc->config = event->attr.config;
+	hwc->idx = -1;
+
+	/* and we don't care about CPU */

Actually, you do. You want the perf core to serialize accesses via the same CPU, so all events _must_ be targetted at the same CPU. Otherwise there are a tonne of problems you don't even want to think about.

You _must_ ensure this kernel-side, regardless of what the perf tool happens to do.

See the arm-cci and arm-ccn drivers for an example.

You can also follow the migration approach used there to allow you to retain counting across a hotplug.

[...]

Quoted 8 lines
arch/arm64/kernel/uncore/uncore_cavium.c new file +8 -0
+static int __init thunder_uncore_init(void)
+{
+	unsigned long implementor = read_cpuid_implementor();
+	unsigned long part_number = read_cpuid_part_number();
+	u32 variant;
+
+	if (implementor != ARM_CPU_IMP_CAVIUM ||
+	    part_number != CAVIUM_CPU_PART_THUNDERX)

arch/arm64/kernel/uncore/uncore_cavium.c line 209

Quoted 10 lines
arch/arm64/kernel/uncore/uncore_cavium.c new file +10 -0
+		return -ENODEV;
+
+	/* detect pass2 which contains different counters */
+	variant = MIDR_VARIANT(read_cpuid_id());
+	if (variant == 1)
+		thunder_uncore_version = 1;
+	pr_info("PMU version: %d\n", thunder_uncore_version);
+
+	return 0;
+}

You should call out these differences in the commmit message.

Mark.

#3 lore raw

Re: [RFC PATCH 1/7] arm64/perf: Basic uncore counter support for Cavium ThunderX

Quoted 1 line · Mark Rutland

On Fri, Feb 12, 2016 at 05:55:06PM +0100, Jan Glauber wrote:

[...]

Quoted 6 lines
Quoted 5 lines

2) Counters are summarized across the different units of the same type, e.g. L2C TAD 0..7 is presented as a single counter (adding the values from TAD 0 to 7). Although losing the ability to read a single value the merged values are easier to use and yield enough information.

Quoted 6 lines

I'm not sure I follow this. What is easier? What are you doing, and what are you comparing that with to say that your approach is easier?

It sounds like it should be possible to handle multiple counters like this, so I don't follow why you want to amalgamate them in-kernel.

The values of the individual counters are close to meaningless. The only thing that is meaningful to someone reading the counters is the aggregate sum of all the counts.

Quoted 8 lines

[...]

Review

Quoted 2 lines
(quoted diff) +2 -0
+#include <asm/cpufeature.h>
+#include <asm/cputype.h>

I don't see why you should need these two if this is truly an uncore device probed solely from PCI.

Quoted 16 lines

arch/arm64/kernel/uncore/uncore_cavium.c line 39

Quoted 12 lines
arch/arm64/kernel/uncore/uncore_cavium.c new file +12 -0
+void thunder_uncore_read(struct perf_event *event)
+{
+	struct thunder_uncore *uncore = event_to_thunder_uncore(event);
+	struct hw_perf_event *hwc = &event->hw;
+	u64 prev, new = 0;
+	s64 delta;
+	int i;
+
+	/*
+	 * since we do not enable counter overflow interrupts,
+	 * we do not have to worry about prev_count changing on us
+	 */

Without overflow interrupts, how do you ensure that you account for overflow in a reasonable time window (i.e. before the counter runs past its initial value)?

Two reasons:

1) There are no interrupts.

2) The counters are 64-bit, they never overflow.

Quoted 9 lines

arch/arm64/kernel/uncore/uncore_cavium.c line 45

Quoted 7 lines
arch/arm64/kernel/uncore/uncore_cavium.c new file +6 -0
+
+	prev = local64_read(&hwc->prev_count);
+
+	/* read counter values from all units */
+	for (i = 0; i < uncore->nr_units; i++)
+		new += readq(map_offset(hwc->event_base, uncore, i));

There's no bit to determine whether an overflow occurred?

No.

Quoted 51 lines
Quoted 11 lines
arch/arm64/kernel/uncore/uncore_cavium.c new file +10 -0
+
+	local64_set(&hwc->prev_count, new);
+	delta = new - prev;
+	local64_add(delta, &event->count);
+}
+
+void thunder_uncore_del(struct perf_event *event, int flags)
+{
+	struct thunder_uncore *uncore = event_to_thunder_uncore(event);
+	struct hw_perf_event *hwc = &event->hw;

arch/arm64/kernel/uncore/uncore_cavium.c line 65

Quoted 10 lines
arch/arm64/kernel/uncore/uncore_cavium.c new file +10 -0
+	int i;
+
+	event->pmu->stop(event, PERF_EF_UPDATE);
+
+	for (i = 0; i < uncore->num_counters; i++) {
+		if (cmpxchg(&uncore->events[i], event, NULL) == event)
+			break;
+	}
+	hwc->idx = -1;
+}

Why not just place the event at uncode->events[hwc->idx] ?

Theat way removing the event is trivial.

Quoted 10 lines
arch/arm64/kernel/uncore/uncore_cavium.c new file +10 -0
+int thunder_uncore_event_init(struct perf_event *event)
+{
+	struct hw_perf_event *hwc = &event->hw;
+	struct thunder_uncore *uncore;
+
+	if (event->attr.type != event->pmu->type)
+		return -ENOENT;
+
+	/* we do not support sampling */
+	if (is_sampling_event(event))

arch/arm64/kernel/uncore/uncore_cavium.c line 86

Quoted 10 lines
arch/arm64/kernel/uncore/uncore_cavium.c new file +10 -0
+		return -EINVAL;
+
+	/* counters do not have these bits */
+	if (event->attr.exclude_user	||
+	    event->attr.exclude_kernel	||
+	    event->attr.exclude_host	||
+	    event->attr.exclude_guest	||
+	    event->attr.exclude_hv	||
+	    event->attr.exclude_idle)
+		return -EINVAL;

We should _really_ make these features opt-in at the core level. It's crazy that each and every PMU drivers has to explicitly test and reject things it doesn't support.

Quoted 6 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	/* and we do not enable counter overflow interrupts */

That statement raises far more questions than it answers.

_why_ do we not user overflow interrupts?

As stated above, there are *no* overflow interrupts.

The events we are counting cannot be attributed to any one (or even any) CPU, they run asynchronous to the CPU, so even if there were interrupts, they would be meaningless.

David Daney

reviewer
#4 lore raw

Re: [RFC PATCH 1/7] arm64/perf: Basic uncore counter support for Cavium ThunderX

Quoted 12 lines · David Daney
Quoted 1 line · Mark Rutland

On Fri, Feb 12, 2016 at 05:55:06PM +0100, Jan Glauber wrote:

[...]

Quoted 9 lines
Quoted 5 lines

2) Counters are summarized across the different units of the same type, e.g. L2C TAD 0..7 is presented as a single counter (adding the values from TAD 0 to 7). Although losing the ability to read a single value the merged values are easier to use and yield enough information.

I'm not sure I follow this. What is easier? What are you doing, and what are you comparing that with to say that your approach is easier?

Quoted 7 lines
Quoted 3 lines

It sounds like it should be possible to handle multiple counters like this, so I don't follow why you want to amalgamate them in-kernel.

The values of the individual counters are close to meaningless. The only thing that is meaningful to someone reading the counters is the aggregate sum of all the counts.

I obviously know nowhere near enough about your system to say with certainty, but it may turn out that being able to track counters individually is useful for some profiling/debugging scenario. How meaningful the individual counts are really depends on what you're trying to figure out.

If you believe that aggregate values are sufficient, then I'm happy to leave that as-is.

Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
arch/arm64/kernel/uncore/uncore_cavium.c new file +8 -0
+void thunder_uncore_read(struct perf_event *event)
+{
+	struct thunder_uncore *uncore = event_to_thunder_uncore(event);
+	struct hw_perf_event *hwc = &event->hw;
+	u64 prev, new = 0;
+	s64 delta;
+	int i;
+
Quoted 8 lines

arch/arm64/kernel/uncore/uncore_cavium.c line 39

Quoted 4 lines
arch/arm64/kernel/uncore/uncore_cavium.c new file +4 -0
+	/*
+	 * since we do not enable counter overflow interrupts,
+	 * we do not have to worry about prev_count changing on us
+	 */

Without overflow interrupts, how do you ensure that you account for overflow in a reasonable time window (i.e. before the counter runs past its initial value)?

Quoted 5 lines

Two reasons:

1) There are no interrupts.

2) The counters are 64-bit, they never overflow.

Ok. Please point this out in the comment so that reviewers aren't misled. Stating that we don't enable an interrupt implies that said interrupt exists.

Quoted 7 lines
Quoted 5 lines

arch/arm64/kernel/uncore/uncore_cavium.c line 88

Quoted 1 line
arch/arm64/kernel/uncore/uncore_cavium.c new file +1 -0
+	/* and we do not enable counter overflow interrupts */

That statement raises far more questions than it answers.

_why_ do we not user overflow interrupts?

As stated above, there are *no* overflow interrupts.

Ok. As stated above, please fix this comment to not mislead.

Quoted 3 lines

The events we are counting cannot be attributed to any one (or even any) CPU, they run asynchronous to the CPU, so even if there were interrupts, they would be meaningless.

Yes, they are meaningless w.r.t. the state of an arbitrary CPU.

Were they to exist you could use them to drive other snapshotting of the state of the uncore PMU, to get an idea of the frequency/stability of events over time, etc. Userspace might then decide to snapshot other whole system state based on events fed to it.

That's moot if they don't exist.

Mark.

#5 lore raw

Re: [RFC PATCH 1/7] arm64/perf: Basic uncore counter support for Cavium ThunderX

In reply to Mark Rutland

Hi Mark,

thanks for reviewing! I'll need several mails to address all questions.

Quoted 11 lines · Mark Rutland
Quoted 6 lines · Jan Glauber

Provide uncore facilities for non-CPU performance counter units. Based on Intel/AMD uncore pmu support.

The uncore PMUs can be found under /sys/bus/event_source/devices. All counters are exported via sysfs in the corresponding events files under the PMU directory so the perf tool can list the event names.

It turns out that "uncore" covers quite a lot of things.

Where exactly do the see counters live? system, socket, cluster?

Neither cluster nor socket, so I would say system. Where a system may consist of 2 nodes that mostly appear as one system.

Quoted 2 lines

Are there potentially multiple instances of a given PMU in the system? e.g. might each clutster have an instance of an L2 PMU?

Yes.

Quoted 2 lines

If I turn off a set of CPUs, do any "uncore" PMUs lost context or become inaccessible?

No, they are not related to CPUs.

[...]

Quoted 6 lines
Quoted 5 lines

1) The PMU detection solely relies on PCI device detection. If a matching PCI device is found the PMU is created. The code can deal with multiple units of the same type, e.g. more than one memory controller.

Quoted 6 lines

I see below that the driver has an initcall that runs regardless of whether the PCI device exists, and looks at the MIDR. That's clearly not string PCI device detection.

Why is this not a true PCI driver that only gets probed if the PCI device exists?

It is not a PCI driver because there are already drivers like edac that will access these PCI devices. The uncore driver only accesses the performance counters, which are not used by the other drivers.

[...]

Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+#include <asm/cpufeature.h>
+#include <asm/cputype.h>

I don't see why you should need these two if this is truly an uncore device probed solely from PCI.

There are several passes of the hardware that have the same PCI device ID. Therefore I need the CPU variant to distinguish them. This could be done _after_ the PCI device is found but I found it easier to implement the check once in the common setup function.

[...]

Quoted 16 lines
Quoted 16 lines
arch/arm64/kernel/uncore/uncore_cavium.c new file +16 -0
+int thunder_uncore_event_init(struct perf_event *event)
+{
+	struct hw_perf_event *hwc = &event->hw;
+	struct thunder_uncore *uncore;
+
+	if (event->attr.type != event->pmu->type)
+		return -ENOENT;
+
+	/* we do not support sampling */
+	if (is_sampling_event(event))
+		return -EINVAL;
+
+	/* counters do not have these bits */
+	if (event->attr.exclude_user	||
+	    event->attr.exclude_kernel	||
+	    event->attr.exclude_host	||
Quoted 8 lines

arch/arm64/kernel/uncore/uncore_cavium.c line 86

Quoted 4 lines
arch/arm64/kernel/uncore/uncore_cavium.c new file +4 -0
+	    event->attr.exclude_guest	||
+	    event->attr.exclude_hv	||
+	    event->attr.exclude_idle)
+		return -EINVAL;

We should _really_ make these features opt-in at the core level. It's crazy that each and every PMU drivers has to explicitly test and reject things it doesn't support.

Completely agreed. Also, every sample code I looked at did check for other bits...

[...]

Quoted 7 lines
Quoted 7 lines
arch/arm64/kernel/uncore/uncore_cavium.c new file +7 -0
+
+	uncore = event_to_thunder_uncore(event);
+	if (!uncore)
+		return -ENODEV;
+	if (!uncore->event_valid(event->attr.config))
+		return -EINVAL;
+
Quoted 8 lines

arch/arm64/kernel/uncore/uncore_cavium.c line 99

Quoted 4 lines
arch/arm64/kernel/uncore/uncore_cavium.c new file +4 -0
+	hwc->config = event->attr.config;
+	hwc->idx = -1;
+
+	/* and we don't care about CPU */

Actually, you do. You want the perf core to serialize accesses via the same CPU, so all events _must_ be targetted at the same CPU. Otherwise there are a tonne of problems you don't even want to think about.

I found that perf added the events on every CPU in the system. Because the uncore events are not CPU related I wanted to avoid this. Setting cpumask to -1 did not work. Therefore I added a single CPU in the cpumask, see thunder_uncore_attr_show_cpumask().

Quoted 22 lines

You _must_ ensure this kernel-side, regardless of what the perf tool happens to do.

See the arm-cci and arm-ccn drivers for an example.

You can also follow the migration approach used there to allow you to retain counting across a hotplug.

[...]

Quoted 12 lines
arch/arm64/kernel/uncore/uncore_cavium.c new file +12 -0
+static int __init thunder_uncore_init(void)
+{
+	unsigned long implementor = read_cpuid_implementor();
+	unsigned long part_number = read_cpuid_part_number();
+	u32 variant;
+
+	if (implementor != ARM_CPU_IMP_CAVIUM ||
+	    part_number != CAVIUM_CPU_PART_THUNDERX)
+		return -ENODEV;
+
+	/* detect pass2 which contains different counters */
+	variant = MIDR_VARIANT(read_cpuid_id());
Quoted 8 lines

arch/arm64/kernel/uncore/uncore_cavium.c line 209

Quoted 6 lines
arch/arm64/kernel/uncore/uncore_cavium.c new file +6 -0
+	if (variant == 1)
+		thunder_uncore_version = 1;
+	pr_info("PMU version: %d\n", thunder_uncore_version);
+
+	return 0;
+}

You should call out these differences in the commmit message.

OK

Quoted 1 line

Mark.

Thanks, Jan

reviewer
#6 lore raw

Re: [RFC PATCH 1/7] arm64/perf: Basic uncore counter support for Cavium ThunderX

Quoted 23 lines · Jan Glauber

Hi Mark,

thanks for reviewing! I'll need several mails to address all questions.

Quoted 11 lines · Mark Rutland
Quoted 6 lines · Jan Glauber

Provide uncore facilities for non-CPU performance counter units. Based on Intel/AMD uncore pmu support.

The uncore PMUs can be found under /sys/bus/event_source/devices. All counters are exported via sysfs in the corresponding events files under the PMU directory so the perf tool can list the event names.

It turns out that "uncore" covers quite a lot of things.

Where exactly do the see counters live? system, socket, cluster?

Neither cluster nor socket, so I would say system. Where a system may consist of 2 nodes that mostly appear as one system.

Quoted 2 lines

Are there potentially multiple instances of a given PMU in the system? e.g. might each clutster have an instance of an L2 PMU?

Quoted 6 lines

Yes.

Quoted 2 lines

If I turn off a set of CPUs, do any "uncore" PMUs lost context or become inaccessible?

No, they are not related to CPUs.

Ok. So I should be able to concurrently hotplug random CPUs on/off while this driver is running, without issues? No registers might be clock-gated or similar?

I appreciate that they are not "related" to particular CPUs as such.

Quoted 9 lines
Quoted 9 lines
Quoted 4 lines

1) The PMU detection solely relies on PCI device detection. If a matching PCI device is found the PMU is created. The code can deal with multiple units of the same type, e.g. more than one memory controller.

I see below that the driver has an initcall that runs regardless of whether the PCI device exists, and looks at the MIDR. That's clearly not string PCI device detection.

Quoted 6 lines
Quoted 2 lines

Why is this not a true PCI driver that only gets probed if the PCI device exists?

It is not a PCI driver because there are already drivers like edac that will access these PCI devices. The uncore driver only accesses the performance counters, which are not used by the other drivers.

Several drivers are accessing the same device?

That sounds somewhat scary.

Quoted 10 lines
Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+#include <asm/cpufeature.h>
+#include <asm/cputype.h>

I don't see why you should need these two if this is truly an uncore device probed solely from PCI.

There are several passes of the hardware that have the same PCI device ID. Therefore I need the CPU variant to distinguish them. This could be done _after_ the PCI device is found but I found it easier to implement the check once in the common setup function.

Ok. Please call that out in the commit message.

Quoted 50 lines
Quoted 16 lines
Quoted 16 lines
arch/arm64/kernel/uncore/uncore_cavium.c new file +16 -0
+int thunder_uncore_event_init(struct perf_event *event)
+{
+	struct hw_perf_event *hwc = &event->hw;
+	struct thunder_uncore *uncore;
+
+	if (event->attr.type != event->pmu->type)
+		return -ENOENT;
+
+	/* we do not support sampling */
+	if (is_sampling_event(event))
+		return -EINVAL;
+
+	/* counters do not have these bits */
+	if (event->attr.exclude_user	||
+	    event->attr.exclude_kernel	||
+	    event->attr.exclude_host	||
Quoted 8 lines

arch/arm64/kernel/uncore/uncore_cavium.c line 86

Quoted 4 lines
arch/arm64/kernel/uncore/uncore_cavium.c new file +4 -0
+	    event->attr.exclude_guest	||
+	    event->attr.exclude_hv	||
+	    event->attr.exclude_idle)
+		return -EINVAL;

We should _really_ make these features opt-in at the core level. It's crazy that each and every PMU drivers has to explicitly test and reject things it doesn't support.

Completely agreed. Also, every sample code I looked at did check for other bits...

[...]

Quoted 7 lines
Quoted 7 lines
arch/arm64/kernel/uncore/uncore_cavium.c new file +7 -0
+
+	uncore = event_to_thunder_uncore(event);
+	if (!uncore)
+		return -ENODEV;
+	if (!uncore->event_valid(event->attr.config))
+		return -EINVAL;
+
Quoted 8 lines

arch/arm64/kernel/uncore/uncore_cavium.c line 99

Quoted 4 lines
arch/arm64/kernel/uncore/uncore_cavium.c new file +4 -0
+	hwc->config = event->attr.config;
+	hwc->idx = -1;
+
+	/* and we don't care about CPU */

Actually, you do. You want the perf core to serialize accesses via the same CPU, so all events _must_ be targetted at the same CPU. Otherwise there are a tonne of problems you don't even want to think about.

I found that perf added the events on every CPU in the system. Because the uncore events are not CPU related I wanted to avoid this. Setting cpumask to -1 did not work. Therefore I added a single CPU in the cpumask, see thunder_uncore_attr_show_cpumask().

Quoted 4 lines · which is why I
Quoted 4 lines

You _must_ ensure this kernel-side, regardless of what the perf tool happens to do.

See the arm-cci and arm-ccn drivers for an example.

Take a look at drivers/bus/arm-cci.c; specifically, what we do in cci_pmu_event_init and cci_pmu_cpu_notifier.

This is the same thing that's done for x86 system PMUs. Take a look at uncore_pmu_event_init in arch/x86/kernel/cpu/perf_event_intel_uncore.c.

Otherwise there are a number of situations where userspace might open events on different CPUs, and you get some freaky results because the perf core expects accesses to a PMU and its related data structures to be strictly serialised through _some_ CPU (even if that CPU is arbitrarily chosen).

For example, if CPU 0 was offline when one event was opened, then cpu0 was hotplugged, then a second event was opened, there would be an event in the CPU1 context and another in the CPU0 context. Modification to the PMU state is done per CPU-context in the core, and these would race against each other given the lack of serialisation. Even with sufficient locking to prevent outright corruption, things like event rotation would race leading to very non-deterministic results.

Thanks,
Mark.

reviewer
#7 lore raw

Re: [RFC PATCH 1/7] arm64/perf: Basic uncore counter support for Cavium ThunderX

Quoted 25 lines · Mark Rutland
Quoted 19 lines
Quoted 6 lines
Quoted 6 lines
arch/arm64/kernel/uncore/uncore_cavium.c new file +6 -0
+	uncore = event_to_thunder_uncore(event);
+	if (!uncore)
+		return -ENODEV;
+	if (!uncore->event_valid(event->attr.config))
+		return -EINVAL;
+
Quoted 8 lines

arch/arm64/kernel/uncore/uncore_cavium.c line 99

Quoted 4 lines
arch/arm64/kernel/uncore/uncore_cavium.c new file +4 -0
+	hwc->config = event->attr.config;
+	hwc->idx = -1;
+
+	/* and we don't care about CPU */

Actually, you do. You want the perf core to serialize accesses via the same CPU, so all events _must_ be targetted at the same CPU. Otherwise there are a tonne of problems you don't even want to think about.

I found that perf added the events on every CPU in the system. Because the uncore events are not CPU related I wanted to avoid this. Setting cpumask to -1 did not work. Therefore I added a single CPU in the cpumask, see thunder_uncore_attr_show_cpumask().

Quoted 3 lines · which is why I
Quoted 3 lines

You _must_ ensure this kernel-side, regardless of what the perf tool happens to do.

Quoted 7 lines
Quoted 1 line
Quoted 1 line

See the arm-cci and arm-ccn drivers for an example.

Take a look at drivers/bus/arm-cci.c; specifically, what we do in cci_pmu_event_init and cci_pmu_cpu_notifier.

This is the same thing that's done for x86 system PMUs. Take a look at uncore_pmu_event_init in arch/x86/kernel/cpu/perf_event_intel_uncore.c.

I note that we still have an open TODO rather than a call to perf_pmu_migrate_context.

The better example is arm_ccn_pmu_cpu_notifier in drivers/bus/arm-ccn.c.

Mark.

#8 lore raw

Re: [RFC PATCH 1/7] arm64/perf: Basic uncore counter support for Cavium ThunderX

In reply to Mark Rutland
Quoted 12 lines · Mark Rutland
Quoted 12 lines
Quoted 11 lines
Quoted 4 lines

1) The PMU detection solely relies on PCI device detection. If a matching PCI device is found the PMU is created. The code can deal with multiple units of the same type, e.g. more than one memory controller.

I see below that the driver has an initcall that runs regardless of whether the PCI device exists, and looks at the MIDR. That's clearly not string PCI device detection.

Why is this not a true PCI driver that only gets probed if the PCI device exists?

Quoted 7 lines
Quoted 3 lines

It is not a PCI driver because there are already drivers like edac that will access these PCI devices. The uncore driver only accesses the performance counters, which are not used by the other drivers.

Several drivers are accessing the same device?

That sounds somewhat scary.

I've double checked that the edac drivers do not access the performance counters at all. It felt cleaner to me to keep the performance counter code seperated from edac.

Jan

#9 lore raw

Re: [RFC PATCH 1/7] arm64/perf: Basic uncore counter support for Cavium ThunderX

In reply to Mark Rutland
Quoted 8 lines · Mark Rutland
Quoted 6 lines · Jan Glauber

Provide uncore facilities for non-CPU performance counter units. Based on Intel/AMD uncore pmu support.

The uncore PMUs can be found under /sys/bus/event_source/devices. All counters are exported via sysfs in the corresponding events files under the PMU directory so the perf tool can list the event names.

Quoted 6 lines

It turns out that "uncore" covers quite a lot of things.

Where exactly do the see counters live? system, socket, cluster?

Are there potentially multiple instances of a given PMU in the system? e.g. might each clutster have an instance of an L2 PMU?

Thinking twice about the multi-node systems I would like to change the implementation to not merge counters across nodes. There might be value in having the counters per node and also performance wise it would be better to merge counters only on the local node.

I'll introduce a node sysfs attribute that can be combined with the event and fill the node with the numa id.

[...]

Quoted 2 lines

Otherwise, are they associated with some power domain?

No, power domains are not used for the "uncore" related devices. These devices are currently always on.

Jan

#10 lore raw

Re: [RFC PATCH 1/7] arm64/perf: Basic uncore counter support for Cavium ThunderX

In reply to Mark Rutland
Quoted 1 line · Mark Rutland

On Fri, Feb 12, 2016 at 05:55:06PM +0100, Jan Glauber wrote:

[...]

Quoted 16 lines
Quoted 16 lines
(quoted diff) +16 -0
+int thunder_uncore_event_init(struct perf_event *event)
+{
+	struct hw_perf_event *hwc = &event->hw;
+	struct thunder_uncore *uncore;
+
+	if (event->attr.type != event->pmu->type)
+		return -ENOENT;
+
+	/* we do not support sampling */
+	if (is_sampling_event(event))
+		return -EINVAL;
+
+	/* counters do not have these bits */
+	if (event->attr.exclude_user	||
+	    event->attr.exclude_kernel	||
+	    event->attr.exclude_host	||
Quoted 9 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+	    event->attr.exclude_guest	||
+	    event->attr.exclude_hv	||
+	    event->attr.exclude_idle)
+		return -EINVAL;

We should _really_ make these features opt-in at the core level. It's crazy that each and every PMU drivers has to explicitly test and reject things it doesn't support.

Looking at the exclude_* feature handling in pmu->event_init under arch/ shows lots of differences. Just as an example, exclude_idle returns sometimes -EINVAL, sometimes -EPERM while other archs ignore it and one silently deletes the flag.

So it looks hard to me to move the exclude handling into perf core while keeping the per-arch differences. And if we don't and return an error on the perf_event_open syscall in a newer kernel for an exclude bit that was previously ignored it will be a user-space regression, right?

Looking only at the uncore drivers (plus drivers/bus/arm-cc*) it looks like they all don't support any exclude bits but the handling here differs also. The table shows the current behaviour, X means the requested exclude flag is refused.

user kernel host guest hv idle
---------------------------------------------------------------------

x86 uncore intel        |  X      X                      X       X
x86 uncore intel snb    |  X      X      X       X       X       X
x86 uncore intel cqm    |  X      X      X       X       X       X
x86 uncore intel cstate |  X      X      X       X       X       X
x86 uncore intel rapl   |  X      X      X       X       X       X
x86 uncore amd          |  X      X      X       X
x86 uncore amd iommu    |  X      X      X       X
x86 uncore amd ibs      |  X      X      X       X       X       X
arm bus cci             |  X      X      X       X       X       X
arm bus ccn             |  X      X                      X       X

----------------------------------------------------------------------

How about simply adding a helper function to include/linux/perf_event.h that checks if _any_ of the exclude bits is set? We could then simplify the check-for-any exclude flag to:

if (any_exclude_set(event))

	return -EINVAL;

What's your opinion?

Jan

---

include/linux/perf_event.h +12 -0
index f5c5a3f..0eacdba0 100644
@@ -849,6 +849,18 @@ static inline bool is_sampling_event(struct perf_event *event)
 	return event->attr.sample_period != 0;
 }
 
+static inline int any_exclude_set(struct perf_event *event)
+{
+	if (event->attr.exclude_user	||
+	    event->attr.exclude_kernel	||
+	    event->attr.exclude_host	||
+	    event->attr.exclude_guest	||
+	    event->attr.exclude_hv	||
+	    event->attr.exclude_idle)
+		return 1;
+	return 0;
+}
+
 /*
  * Return 1 for a software event, 0 for a hardware event
  */