Skip to contentSkip to conversation

Cavium ThunderX uncore PMU support

PATCH Superseded Jan Glauber 5 participants 17 messages Oct 20, 2016 – Oct 28, 2016

Subsystems (2)

v3 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v3 cover Cavium ThunderX uncore PMU support

Sorry for the long time it took for re-cooking this patch set. The v3 should address all of Marks previous comments, things I didn't change are listed below.

Not changed:
- Stick to NUMA node ID to detect the socket a device belongs to but made uncore depend on CONFIG_NUMA.
- Stick to initcall for uncore framework because it is easier to do the scanning for the same type of PCI devices, also I don't know if the PCI layer would allow for several drivers to register for the same device ID.

Note:
I'm using perf_sw_context in difference to perf_invalid_context (see WARN_ON in perf_pmu_register). Reason is that with perf_invalid_context add() is never called and the counter results are shown as "unsupported" by perf. With perf_sw_context everything works as expected.

Patches are against 4.9.0-rc1

Changes to v2:
- Embedded struct pmu and killed uncore->type
- Simplified add functions
- Unified functions where possible into a common implementation
- Use arrays to translate non-contiguous counter addresses to event_id's visible to the user
- Sorted includes
- Got rid of division for previous counter values
- Removed unneeded WARN_ONs
- Use sizeof(*ptr)
- Use bool for event_valid return
- Fixed HES_STOPPED logic
- Added some design notes and improved (hopefully) comments
- Removed pass1 counter support for now
- Merged EVENT_ATTR and EVENT_PTR defines into one (unreadable) thing
- Use pmu_enable|disable to start|stop the OCX TLK counter set
- Moved cpumask into thunder_uncore struct
- Switched to new cpuhp stuff. I still don't care about the CPU location used to access an uncore device, it may cross the CCPI and we'll pay a performance penalty. We might optimize this later, for now I feel it is not worth the time optimizing it.

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

Jan Glauber (5):
arm64: perf: Basic uncore counter support for Cavium ThunderX SOC
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 TLK uncore support

 drivers/perf/Kconfig                        |  13 +
 drivers/perf/Makefile                       |   1 +
 drivers/perf/uncore/Makefile                |   5 +
 drivers/perf/uncore/uncore_cavium.c         | 355 ++++++++++++++++++++++++++
 drivers/perf/uncore/uncore_cavium.h         |  75 ++++++
 drivers/perf/uncore/uncore_cavium_l2c_cbc.c | 148 +++++++++++
 drivers/perf/uncore/uncore_cavium_l2c_tad.c | 379 ++++++++++++++++++++++++++++
 drivers/perf/uncore/uncore_cavium_lmc.c     | 118 +++++++++
 drivers/perf/uncore/uncore_cavium_ocx_tlk.c | 344 +++++++++++++++++++++++++
 include/linux/cpuhotplug.h                  |   1 +
 10 files changed, 1439 insertions(+)
 create mode 100644 drivers/perf/uncore/Makefile
 create mode 100644 drivers/perf/uncore/uncore_cavium.c
 create mode 100644 drivers/perf/uncore/uncore_cavium.h
 create mode 100644 drivers/perf/uncore/uncore_cavium_l2c_cbc.c
 create mode 100644 drivers/perf/uncore/uncore_cavium_l2c_tad.c
 create mode 100644 drivers/perf/uncore/uncore_cavium_lmc.c
 create mode 100644 drivers/perf/uncore/uncore_cavium_ocx_tlk.c
Signature · 1 line
1.9.1
#1 lore raw

PATCH v3 1/5 arm64: perf: Basic uncore counter support for Cavium ThunderX SOC

Provide "uncore" facilities for different non-CPU performance counter units.

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 some points that are special in this implementation:

1) The PMU detection 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 different units of the same type on one NUMA node but not across NUMA nodes.
For instance L2C TAD 0..7 are 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.

3) The counters are not CPU related. A random CPU is picked regardless of the NUMA node. There is a small performance penalty for accessing counters on a remote note but reading a performance counter is a slow operation anyway.

---
 drivers/perf/Kconfig                |  13 ++
 drivers/perf/Makefile               |   1 +
 drivers/perf/uncore/Makefile        |   1 +
 drivers/perf/uncore/uncore_cavium.c | 351 ++++++++++++++++++++++++++++++++++++
 drivers/perf/uncore/uncore_cavium.h |  71 ++++++++
 include/linux/cpuhotplug.h          |   1 +
 6 files changed, 438 insertions(+)
 create mode 100644 drivers/perf/uncore/Makefile
 create mode 100644 drivers/perf/uncore/uncore_cavium.c
 create mode 100644 drivers/perf/uncore/uncore_cavium.h
drivers/perf/Kconfig +13 -0
index 4d5c5f9..3266c87 100644
@@ -19,4 +19,17 @@ config XGENE_PMU
         help
           Say y if you want to use APM X-Gene SoC performance monitors.
 
+config UNCORE_PMU
+	bool
+
+config UNCORE_PMU_CAVIUM
+	depends on PERF_EVENTS && NUMA && ARM64
+	bool "Cavium uncore PMU support"
+	select UNCORE_PMU
+	default y
+	help
+	  Say y if you want to access performance counters of subsystems
+	  on a Cavium SOC like cache controller, memory controller or
+	  processor interconnect.
+
 endmenu
drivers/perf/Makefile +1 -0
index b116e98..144374b 100644
@@ -1,2 +1,3 @@
 obj-$(CONFIG_ARM_PMU) += arm_pmu.o
+obj-y += uncore/
 obj-$(CONFIG_XGENE_PMU) += xgene_pmu.o
drivers/perf/uncore/Makefile new file +1 -0
new file mode 100644
index 0000000..6130e18
@@ -0,0 +1 @@
+obj-$(CONFIG_UNCORE_PMU_CAVIUM) += uncore_cavium.o
drivers/perf/uncore/uncore_cavium.c new file +351 -0

351 lines not on this page · raw message

drivers/perf/uncore/uncore_cavium.h new file +71 -0

71 lines not on this page · raw message

include/linux/cpuhotplug.h +1 -0
index 9b207a8..370a7a2 100644
@@ -117,6 +117,7 @@ enum cpuhp_state {
 	CPUHP_AP_PERF_ARM_CCI_ONLINE,
 	CPUHP_AP_PERF_ARM_CCN_ONLINE,
 	CPUHP_AP_PERF_ARM_L2X0_ONLINE,
+	CPUHP_AP_UNCORE_CAVIUM_ONLINE,
 	CPUHP_AP_WORKQUEUE_ONLINE,
 	CPUHP_AP_RCUTREE_ONLINE,
 	CPUHP_AP_NOTIFY_ONLINE,
Signature · 1 line
1.9.1
#2 lore raw

PATCH v3 2/5 arm64: perf: Cavium ThunderX L2C TAD uncore support

In reply to Jan Glauber

Support counters of the L2 Cache tag and data units.

---
 drivers/perf/uncore/Makefile                |   3 +-
 drivers/perf/uncore/uncore_cavium.c         |   1 +
 drivers/perf/uncore/uncore_cavium.h         |   1 +
 drivers/perf/uncore/uncore_cavium_l2c_tad.c | 379 ++++++++++++++++++++++++++++
 4 files changed, 383 insertions(+), 1 deletion(-)
 create mode 100644 drivers/perf/uncore/uncore_cavium_l2c_tad.c
drivers/perf/uncore/Makefile +2 -1
index 6130e18..90850a2 100644
@@ -1 +1,2 @@
-obj-$(CONFIG_UNCORE_PMU_CAVIUM) += uncore_cavium.o
+obj-$(CONFIG_UNCORE_PMU_CAVIUM) += uncore_cavium.o		\
+				   uncore_cavium_l2c_tad.o
drivers/perf/uncore/uncore_cavium.c +1 -0
index a7b4277..15e1aec 100644
@@ -346,6 +346,7 @@ static int __init thunder_uncore_init(void)
 	if (ret)
 		return ret;
 
+	thunder_uncore_l2c_tad_setup();
 	return 0;
 }
 late_initcall(thunder_uncore_init);
drivers/perf/uncore/uncore_cavium.h +1 -0
index b5d64b5..70a8214 100644
@@ -69,3 +69,4 @@ 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);
drivers/perf/uncore/uncore_cavium_l2c_tad.c new file +379 -0

379 lines not on this page · raw message

Signature · 1 line
1.9.1
#3 lore raw

PATCH v3 3/5 arm64: perf: Cavium ThunderX L2C CBC uncore support

In reply to Jan Glauber

Support counters of the L2 cache crossbar connect.

---
 drivers/perf/uncore/Makefile                |   3 +-
 drivers/perf/uncore/uncore_cavium.c         |   1 +
 drivers/perf/uncore/uncore_cavium.h         |   1 +
 drivers/perf/uncore/uncore_cavium_l2c_cbc.c | 148 ++++++++++++++++++++++++++++
 4 files changed, 152 insertions(+), 1 deletion(-)
 create mode 100644 drivers/perf/uncore/uncore_cavium_l2c_cbc.c
drivers/perf/uncore/Makefile +2 -1
index 90850a2..d5ef3db 100644
@@ -1,2 +1,3 @@
 obj-$(CONFIG_UNCORE_PMU_CAVIUM) += uncore_cavium.o		\
-				   uncore_cavium_l2c_tad.o
+				   uncore_cavium_l2c_tad.o	\
+				   uncore_cavium_l2c_cbc.o
drivers/perf/uncore/uncore_cavium.c +1 -0
index 15e1aec..051f0fa 100644
@@ -347,6 +347,7 @@ static int __init thunder_uncore_init(void)
 		return ret;
 
 	thunder_uncore_l2c_tad_setup();
+	thunder_uncore_l2c_cbc_setup();
 	return 0;
 }
 late_initcall(thunder_uncore_init);
drivers/perf/uncore/uncore_cavium.h +1 -0
index 70a8214..91d674a 100644
@@ -70,3 +70,4 @@ ssize_t thunder_events_sysfs_show(struct device *dev,
 				  struct device_attribute *attr,
 				  char *page);
 int thunder_uncore_l2c_tad_setup(void);
+int thunder_uncore_l2c_cbc_setup(void);
drivers/perf/uncore/uncore_cavium_l2c_cbc.c new file +148 -0

148 lines not on this page · raw message

Signature · 1 line
1.9.1
#4 lore raw

PATCH v3 4/5 arm64: perf: Cavium ThunderX LMC uncore support

In reply to Jan Glauber

Support counters on the DRAM controllers.

---
 drivers/perf/uncore/Makefile            |   3 +-
 drivers/perf/uncore/uncore_cavium.c     |   1 +
 drivers/perf/uncore/uncore_cavium.h     |   1 +
 drivers/perf/uncore/uncore_cavium_lmc.c | 118 ++++++++++++++++++++++++++++++++
 4 files changed, 122 insertions(+), 1 deletion(-)
 create mode 100644 drivers/perf/uncore/uncore_cavium_lmc.c
drivers/perf/uncore/Makefile +2 -1
index d5ef3db..ef04a2b9 100644
@@ -1,3 +1,4 @@
 obj-$(CONFIG_UNCORE_PMU_CAVIUM) += uncore_cavium.o		\
 				   uncore_cavium_l2c_tad.o	\
-				   uncore_cavium_l2c_cbc.o
+				   uncore_cavium_l2c_cbc.o	\
+				   uncore_cavium_lmc.o
drivers/perf/uncore/uncore_cavium.c +1 -0
index 051f0fa..fd9e49e 100644
@@ -348,6 +348,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);
drivers/perf/uncore/uncore_cavium.h +1 -0
index 91d674a..3897586 100644
@@ -71,3 +71,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);
+int thunder_uncore_lmc_setup(void);
drivers/perf/uncore/uncore_cavium_lmc.c new file +118 -0

118 lines not on this page · raw message

Signature · 1 line
1.9.1
#5 lore raw

PATCH v3 5/5 arm64: perf: Cavium ThunderX OCX TLK uncore support

In reply to Jan Glauber

Support for the OCX transmit link counters.

---
 drivers/perf/uncore/Makefile                |   3 +-
 drivers/perf/uncore/uncore_cavium.c         |   1 +
 drivers/perf/uncore/uncore_cavium.h         |   1 +
 drivers/perf/uncore/uncore_cavium_ocx_tlk.c | 344 ++++++++++++++++++++++++++++
 4 files changed, 348 insertions(+), 1 deletion(-)
 create mode 100644 drivers/perf/uncore/uncore_cavium_ocx_tlk.c
drivers/perf/uncore/Makefile +2 -1
index ef04a2b9..7e2e8e5 100644
@@ -1,4 +1,5 @@
 obj-$(CONFIG_UNCORE_PMU_CAVIUM) += uncore_cavium.o		\
 				   uncore_cavium_l2c_tad.o	\
 				   uncore_cavium_l2c_cbc.o	\
-				   uncore_cavium_lmc.o
+				   uncore_cavium_lmc.o		\
+				   uncore_cavium_ocx_tlk.o
drivers/perf/uncore/uncore_cavium.c +1 -0
index fd9e49e..46ced45 100644
@@ -349,6 +349,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_tlk_setup();
 	return 0;
 }
 late_initcall(thunder_uncore_init);
drivers/perf/uncore/uncore_cavium.h +1 -0
index 3897586..43ab426 100644
@@ -72,3 +72,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_tlk_setup(void);
drivers/perf/uncore/uncore_cavium_ocx_tlk.c new file +344 -0

344 lines not on this page · raw message

Signature · 1 line
1.9.1
maintainer
#6 lore raw
In reply to Jan Glauber
Quoted 5 lines · Jan Glauber

Note:
I'm using perf_sw_context in difference to perf_invalid_context (see WARN_ON in perf_pmu_register). Reason is that with perf_invalid_context add() is never called and the counter results are shown as "unsupported" by perf. With perf_sw_context everything works as expected.

What?! All the uncore PMUs use perf_invalid_context. What doesn't work for you?

maintainer
#7 lore raw
Quoted 9 lines · Peter Zijlstra
Quoted 5 lines · Jan Glauber

Note:
I'm using perf_sw_context in difference to perf_invalid_context (see WARN_ON in perf_pmu_register). Reason is that with perf_invalid_context add() is never called and the counter results are shown as "unsupported" by perf. With perf_sw_context everything works as expected.

What?! All the uncore PMUs use perf_invalid_context. What doesn't work for you?

I think there's general confusion over the use of invalid context. Perhaps we could clear that up with:

#define perf_uncore_context perf_invalid_context

and

s/perf_hw_context/perf_cpu_hw_context/

Mark.

maintainer
#8 lore raw
Quoted 11 lines · Mark Rutland
Quoted 9 lines · Peter Zijlstra
Quoted 5 lines · Jan Glauber

Note:
I'm using perf_sw_context in difference to perf_invalid_context (see WARN_ON in perf_pmu_register). Reason is that with perf_invalid_context add() is never called and the counter results are shown as "unsupported" by perf. With perf_sw_context everything works as expected.

What?! All the uncore PMUs use perf_invalid_context. What doesn't work for you?

Quoted 8 lines

I think there's general confusion over the use of invalid context. Perhaps we could clear that up with:

#define perf_uncore_context perf_invalid_context

and

s/perf_hw_context/perf_cpu_hw_context/

What might be missing is the fact that these are _TASK_ contexts.

New names might clarify things a little though.

maintainer
#9 lore raw
Quoted 11 lines · Peter Zijlstra
Quoted 8 lines · Mark Rutland

I think there's general confusion over the use of invalid context. Perhaps we could clear that up with:

#define perf_uncore_context perf_invalid_context

and

s/perf_hw_context/perf_cpu_hw_context/

What might be missing is the fact that these are _TASK_ contexts.

Yes, that too.

Quoted 1 line

New names might clarify things a little though.

I'll add that to the list of cleanup/rework I've been meaning to look at.

Thanks,
Mark.

#10 lore raw
In reply to Peter Zijlstra
Quoted 9 lines · Peter Zijlstra
Quoted 5 lines · Jan Glauber

Note:
I'm using perf_sw_context in difference to perf_invalid_context (see WARN_ON in perf_pmu_register). Reason is that with perf_invalid_context add() is never called and the counter results are shown as "unsupported" by perf. With perf_sw_context everything works as expected.

What?! All the uncore PMUs use perf_invalid_context. What doesn't work for you?

As I said, perf reports the values as "unsupported". But as Mark pointed out, I wasn't using -a switch, just "perf stat -e \thunderx_lmc\blah\ -- ...".

#11 lore raw
In reply to Peter Zijlstra
Quoted 9 lines · Peter Zijlstra
Quoted 5 lines · Jan Glauber

Note:
I'm using perf_sw_context in difference to perf_invalid_context (see WARN_ON in perf_pmu_register). Reason is that with perf_invalid_context add() is never called and the counter results are shown as "unsupported" by perf. With perf_sw_context everything works as expected.

What?! All the uncore PMUs use perf_invalid_context. What doesn't work for you?

OK, so using perf_invalid_context and "-a" seems to work.

But I must say that I hate that from a user perspective. The user needs to know about the type of PMU behind the event and then provide "-a" or get a "<not supported" as counter value?

maintainer
#12 lore raw
Quoted 8 lines · Jan Glauber
Quoted 7 lines · Peter Zijlstra
Quoted 5 lines · Jan Glauber

Note:
I'm using perf_sw_context in difference to perf_invalid_context (see WARN_ON in perf_pmu_register). Reason is that with perf_invalid_context add() is never called and the counter results are shown as "unsupported" by perf. With perf_sw_context everything works as expected.

Quoted 8 lines
Quoted 2 lines

What?! All the uncore PMUs use perf_invalid_context. What doesn't work for you?

OK, so using perf_invalid_context and "-a" seems to work.

But I must say that I hate that from a user perspective. The user needs to know about the type of PMU behind the event and then provide "-a" or get a "<not supported" as counter value?

This really boils down to the fact that users really had better know what they're on about.

There's only so much you can let clueless people do.

The fact is, they already _manually_ select your (uncore) PMU, so they had then better also know what its limitations are.

#13 lore raw
In reply to Jan Glauber
Quoted 8 lines · Jan Glauber
Quoted 7 lines · Peter Zijlstra
Quoted 5 lines · Jan Glauber

Note:
I'm using perf_sw_context in difference to perf_invalid_context (see WARN_ON in perf_pmu_register). Reason is that with perf_invalid_context add() is never called and the counter results are shown as "unsupported" by perf. With perf_sw_context everything works as expected.

Quoted 8 lines
Quoted 2 lines

What?! All the uncore PMUs use perf_invalid_context. What doesn't work for you?

OK, so using perf_invalid_context and "-a" seems to work.

But I must say that I hate that from a user perspective. The user needs to know about the type of PMU behind the event and then provide "-a" or get a "<not supported" as counter value?

Sure, but in the interest of getting *something* merged, can we start off using perf_invalid_context and then have the discussion about whether or not this can be extended later on, please? If your PMU is a shared resource amongst CPUs, it maybe that all you want is a better error message from the perf tool (but again, this can come later!).

Will

#14 lore raw
Quoted 18 lines · Will Deacon
Quoted 8 lines · Jan Glauber
Quoted 7 lines · Peter Zijlstra
Quoted 5 lines · Jan Glauber

Note:
I'm using perf_sw_context in difference to perf_invalid_context (see WARN_ON in perf_pmu_register). Reason is that with perf_invalid_context add() is never called and the counter results are shown as "unsupported" by perf. With perf_sw_context everything works as expected.

Quoted 8 lines
Quoted 2 lines

What?! All the uncore PMUs use perf_invalid_context. What doesn't work for you?

OK, so using perf_invalid_context and "-a" seems to work.

But I must say that I hate that from a user perspective. The user needs to know about the type of PMU behind the event and then provide "-a" or get a "<not supported" as counter value?

Quoted 5 lines

Sure, but in the interest of getting *something* merged, can we start off using perf_invalid_context and then have the discussion about whether or not this can be extended later on, please? If your PMU is a shared resource amongst CPUs, it maybe that all you want is a better error message from the perf tool (but again, this can come later!).

If that is the only obstacle I can repost with perf_sw_context (or do a follow-up patch). After all it works, it is just "clueless" people like me that are not aware of the required switches.

--Jan

Quoted 1 line

Will

maintainer
#15 lore raw
Quoted 25 lines · Jan Glauber
Quoted 18 lines · Will Deacon
Quoted 8 lines · Jan Glauber
Quoted 7 lines · Peter Zijlstra
Quoted 5 lines · Jan Glauber

Note:
I'm using perf_sw_context in difference to perf_invalid_context (see WARN_ON in perf_pmu_register). Reason is that with perf_invalid_context add() is never called and the counter results are shown as "unsupported" by perf. With perf_sw_context everything works as expected.

Quoted 8 lines
Quoted 2 lines

What?! All the uncore PMUs use perf_invalid_context. What doesn't work for you?

OK, so using perf_invalid_context and "-a" seems to work.

But I must say that I hate that from a user perspective. The user needs to know about the type of PMU behind the event and then provide "-a" or get a "<not supported" as counter value?

Quoted 5 lines

Sure, but in the interest of getting *something* merged, can we start off using perf_invalid_context and then have the discussion about whether or not this can be extended later on, please? If your PMU is a shared resource amongst CPUs, it maybe that all you want is a better error message from the perf tool (but again, this can come later!).

Quoted 3 lines

If that is the only obstacle I can repost with perf_sw_context (or do a follow-up patch). After all it works, it is just "clueless" people like me that are not aware of the required switches.

Please send a version using perf_invalid_context (which I assume is what you meant above).

Thanks,
Mark.

maintainer
#16 lore raw
In reply to Jan Glauber
Quoted 11 lines · Jan Glauber

Sorry for the long time it took for re-cooking this patch set. The v3 should address all of Marks previous comments, things I didn't change are listed below.

Not changed:
- Stick to NUMA node ID to detect the socket a device belongs to but made uncore depend on CONFIG_NUMA.
- Stick to initcall for uncore framework because it is easier to do the scanning for the same type of PCI devices, also I don't know if the PCI layer would allow for several drivers to register for the same device ID.

Quoted 5 lines

Note:
I'm using perf_sw_context in difference to perf_invalid_context (see WARN_ON in perf_pmu_register). Reason is that with perf_invalid_context add() is never called and the counter results are shown as "unsupported" by perf. With perf_sw_context everything works as expected.

I take it you were tryign to open per-task, non system-wide events?

As a shared resource, per-task events do not make sense, and thus using perf_sw_context does not make sense.

I take it If you expose a cpumask, and open the event in system-wide mode (passing '-a' to perf tool), things should work even if using perf_invalid_context.

Thanks,
Mark.