Skip to contentSkip to conversation

Cavium ARM64 uncore PMU support

PATCH Applied Jan Glauber 5 participants 14 messages Sep 25, 2017 – Nov 9, 2017

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

v10 cover Cavium ARM64 uncore PMU support

Add support for various PMU counters found on the Cavium ThunderX and OcteonTx SoC.

The PMU driver provides common "uncore" functions to avoid code duplication and support adding more device PMUs (like L2 cache) in the future.

Changes to v9:
- Fix build error in first EDAC patch
- Use alphabetic ordering in some places
- Store pmu name in struct pmu
- Use devm_*
- Remove mapping of LMC events, expose hardware event numbers directly
- Simplify event removal

Changes to v8:
- Wrapper for PCI devices

Jan Glauber (7):
edac: thunderx: Remove suspend/resume support
perf: export perf_event_update_userpage() edac,soc: thunderx: Add wrapper for EDAC LMC PCI device edac,soc: thunderx: Add wrapper for EDAC OCX PCI device
perf: cavium: Support memory controller PMU counters
perf: cavium: Support transmit-link PMU counters
perf: cavium: Add Documentation

 Documentation/perf/cavium-pmu.txt |  75 +++++
 drivers/edac/Kconfig              |   3 +
 drivers/edac/thunderx_edac.c      |  92 +-----
 drivers/perf/Kconfig              |  15 +
 drivers/perf/Makefile             |   1 +
 drivers/perf/cavium_pmu.c         | 660 ++++++++++++++++++++++++++++++++++++++
 drivers/soc/Kconfig               |   1 +
 drivers/soc/Makefile              |   1 +
 drivers/soc/cavium/Kconfig        |  14 +
 drivers/soc/cavium/Makefile       |   2 +
 drivers/soc/cavium/cavium_lmc.c   |  53 +++
 drivers/soc/cavium/cavium_ocx.c   |  49 +++
 include/linux/cpuhotplug.h        |   1 +
 include/linux/soc/cavium/lmc.h    |  12 +
 include/linux/soc/cavium/ocx.h    |  12 +
 kernel/events/core.c              |   1 +
 16 files changed, 913 insertions(+), 79 deletions(-)
 create mode 100644 Documentation/perf/cavium-pmu.txt
 create mode 100644 drivers/perf/cavium_pmu.c
 create mode 100644 drivers/soc/cavium/Kconfig
 create mode 100644 drivers/soc/cavium/Makefile
 create mode 100644 drivers/soc/cavium/cavium_lmc.c
 create mode 100644 drivers/soc/cavium/cavium_ocx.c
 create mode 100644 include/linux/soc/cavium/lmc.h
 create mode 100644 include/linux/soc/cavium/ocx.h
Signature · 1 line
2.9.0.rc0.21.g7777322
#1 lore raw

PATCH v10 1/7 edac: thunderx: Remove suspend/resume support

The memory controller on ThunderX/OcteonTX systems does not support power management. Therefore remove the suspend/resume callbacks.

---
 drivers/edac/thunderx_edac.c | 25 -------------------------
 1 file changed, 25 deletions(-)
drivers/edac/thunderx_edac.c +0 -25
index f35d87519a3e..4803c6468bab 100644
@@ -639,27 +639,6 @@ static irqreturn_t thunderx_lmc_threaded_isr(int irq, void *dev_id)
 	return ret;
 }
 
-#ifdef CONFIG_PM
-static int thunderx_lmc_suspend(struct pci_dev *pdev, pm_message_t state)
-{
-	pci_save_state(pdev);
-	pci_disable_device(pdev);
-
-	pci_set_power_state(pdev, pci_choose_state(pdev, state));
-
-	return 0;
-}
-
-static int thunderx_lmc_resume(struct pci_dev *pdev)
-{
-	pci_set_power_state(pdev, PCI_D0);
-	pci_enable_wake(pdev, PCI_D0, 0);
-	pci_restore_state(pdev);
-
-	return 0;
-}
-#endif
-
 static const struct pci_device_id thunderx_lmc_pci_tbl[] = {
 	{ PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, PCI_DEVICE_ID_THUNDER_LMC) },
 	{ 0, },
@@ -834,10 +813,6 @@ static struct pci_driver thunderx_lmc_driver = {
 	.name     = "thunderx_lmc_edac",
 	.probe    = thunderx_lmc_probe,
 	.remove   = thunderx_lmc_remove,
-#ifdef CONFIG_PM
-	.suspend  = thunderx_lmc_suspend,
-	.resume   = thunderx_lmc_resume,
-#endif
 	.id_table = thunderx_lmc_pci_tbl,
 };
 
Signature · 1 line
2.9.0.rc0.21.g7777322
maintainer Applied
#2 lore raw

Re: [PATCH v10 1/7] edac: thunderx: Remove suspend/resume support

Quoted 8 lines · Jan Glauber

The memory controller on ThunderX/OcteonTX systems does not support power management. Therefore remove the suspend/resume callbacks.

---
 drivers/edac/thunderx_edac.c | 25 -------------------------
 1 file changed, 25 deletions(-)

Applied, thanks.

Signature · 4 lines
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.
#3 lore raw

PATCH v10 2/7 perf: export perf_event_update_userpage()

In reply to Jan Glauber

Export perf_event_update_userpage(). This change is needed to allow building a PMU driver as a kernel module.

Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
---
 kernel/events/core.c | 1 +
 1 file changed, 1 insertion(+)
kernel/events/core.c +1 -0
index 6bc21e202ae4..162f5ba756a9 100644
@@ -4982,6 +4982,7 @@ void perf_event_update_userpage(struct perf_event *event)
 unlock:
 	rcu_read_unlock();
 }
+EXPORT_SYMBOL_GPL(perf_event_update_userpage);
 
 static int perf_mmap_fault(struct vm_fault *vmf)
 {
Signature · 1 line
2.9.0.rc0.21.g7777322
#4 lore raw

PATCH v10 3/7 edac,soc: thunderx: Add wrapper for EDAC LMC PCI device

In reply to Jan Glauber

Cavium SOCs contain a memory controller that is presented as a PCI device. This PCI device will be used by an EDAC driver and by a PMU driver.

To allow both subsystems to access the device a small wrapper is introduced that multi-plexes PCI probe and removal calls of the device to the EDAC driver.

The same mechanism will be used later to call the PMU driver.

The ThunderX EDAC driver is limited to only build as module with this patch. The reason is that with multiple users of the multi-plexer all users must be either builtin or modules.

---
 drivers/edac/Kconfig            |  2 ++
 drivers/edac/thunderx_edac.c    | 27 ++++++-----------------
 drivers/soc/Kconfig             |  1 +
 drivers/soc/Makefile            |  1 +
 drivers/soc/cavium/Kconfig      |  6 +++++
 drivers/soc/cavium/Makefile     |  1 +
 drivers/soc/cavium/cavium_lmc.c | 49 +++++++++++++++++++++++++++++++++++++++++
 include/linux/soc/cavium/lmc.h  |  9 ++++++++
 8 files changed, 76 insertions(+), 20 deletions(-)
 create mode 100644 drivers/soc/cavium/Kconfig
 create mode 100644 drivers/soc/cavium/Makefile
 create mode 100644 drivers/soc/cavium/cavium_lmc.c
 create mode 100644 include/linux/soc/cavium/lmc.h
drivers/edac/Kconfig +2 -0
index 96afb2aeed18..7330447c43d1 100644
@@ -371,6 +371,8 @@ config EDAC_THUNDERX
 	tristate "Cavium ThunderX EDAC"
 	depends on ARM64
 	depends on PCI
+	depends on m
+	select CAVIUM_LMC
 	help
 	  Support for error detection and correction on the
 	  Cavium ThunderX memory controllers (LMC), Cache
drivers/edac/thunderx_edac.c +7 -20
index 4803c6468bab..a6a89bf0a457 100644
@@ -12,6 +12,7 @@
 #include <linux/module.h>
 #include <linux/pci.h>
 #include <linux/edac.h>
+#include <linux/export.h>
 #include <linux/interrupt.h>
 #include <linux/string.h>
 #include <linux/stop_machine.h>
@@ -20,6 +21,7 @@
 #include <linux/atomic.h>
 #include <linux/bitfield.h>
 #include <linux/circ_buf.h>
+#include <linux/soc/cavium/lmc.h>
 
 #include <asm/page.h>
 
@@ -654,8 +656,7 @@ static inline int pci_dev_to_mc_idx(struct pci_dev *pdev)
 	return ret;
 }
 
-static int thunderx_lmc_probe(struct pci_dev *pdev,
-				const struct pci_device_id *id)
+int thunderx_edac_lmc_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 {
 	struct thunderx_lmc *lmc;
 	struct edac_mc_layer layer;
@@ -795,8 +796,9 @@ static int thunderx_lmc_probe(struct pci_dev *pdev,
 
 	return ret;
 }
+EXPORT_SYMBOL_GPL(thunderx_edac_lmc_probe);
 
-static void thunderx_lmc_remove(struct pci_dev *pdev)
+void thunderx_edac_lmc_remove(struct pci_dev *pdev)
 {
 	struct mem_ctl_info *mci = pci_get_drvdata(pdev);
 	struct thunderx_lmc *lmc = mci->pvt_info;
@@ -806,15 +808,7 @@ static void thunderx_lmc_remove(struct pci_dev *pdev)
 	edac_mc_del_mc(&pdev->dev);
 	edac_mc_free(mci);
 }
-
-MODULE_DEVICE_TABLE(pci, thunderx_lmc_pci_tbl);
-
-static struct pci_driver thunderx_lmc_driver = {
-	.name     = "thunderx_lmc_edac",
-	.probe    = thunderx_lmc_probe,
-	.remove   = thunderx_lmc_remove,
-	.id_table = thunderx_lmc_pci_tbl,
-};
+EXPORT_SYMBOL_GPL(thunderx_edac_lmc_remove);
 
 /*---------------------- OCX driver ---------------------------------*/
 
@@ -2110,13 +2104,9 @@ static int __init thunderx_edac_init(void)
 {
 	int rc = 0;
 
-	rc = pci_register_driver(&thunderx_lmc_driver);
-	if (rc)
-		return rc;
-
 	rc = pci_register_driver(&thunderx_ocx_driver);
 	if (rc)
-		goto err_lmc;
+		return rc;
 
 	rc = pci_register_driver(&thunderx_l2c_driver);
 	if (rc)
@@ -2125,8 +2115,6 @@ static int __init thunderx_edac_init(void)
 	return rc;
 err_ocx:
 	pci_unregister_driver(&thunderx_ocx_driver);
-err_lmc:
-	pci_unregister_driver(&thunderx_lmc_driver);
 
 	return rc;
 }
@@ -2135,7 +2123,6 @@ static void __exit thunderx_edac_exit(void)
 {
 	pci_unregister_driver(&thunderx_l2c_driver);
 	pci_unregister_driver(&thunderx_ocx_driver);
-	pci_unregister_driver(&thunderx_lmc_driver);
 
 }
 
drivers/soc/Kconfig +1 -0
index fc9e98047421..f19f6237f336 100644
@@ -4,6 +4,7 @@ source "drivers/soc/actions/Kconfig"
 source "drivers/soc/amlogic/Kconfig"
 source "drivers/soc/atmel/Kconfig"
 source "drivers/soc/bcm/Kconfig"
+source "drivers/soc/cavium/Kconfig"
 source "drivers/soc/fsl/Kconfig"
 source "drivers/soc/imx/Kconfig"
 source "drivers/soc/mediatek/Kconfig"
drivers/soc/Makefile +1 -0
index 2fcaff864584..a2027196d0fb 100644
@@ -5,6 +5,7 @@
 obj-$(CONFIG_ARCH_ACTIONS)	+= actions/
 obj-$(CONFIG_ARCH_AT91)		+= atmel/
 obj-y				+= bcm/
+obj-$(CONFIG_ARCH_THUNDER)	+= cavium/
 obj-$(CONFIG_ARCH_DOVE)		+= dove/
 obj-$(CONFIG_MACH_DOVE)		+= dove/
 obj-y				+= fsl/
drivers/soc/cavium/Kconfig new file +6 -0
new file mode 100644
index 000000000000..46ded89fb696
@@ -0,0 +1,6 @@
+#
+# Cavium ThunderX Soc drivers
+#
+config CAVIUM_LMC
+        depends on ARCH_THUNDER
+	def_tristate m
drivers/soc/cavium/Makefile new file +1 -0
new file mode 100644
index 000000000000..4ad0c7f923fa
@@ -0,0 +1 @@
+obj-$(CONFIG_CAVIUM_LMC) += cavium_lmc.o
drivers/soc/cavium/cavium_lmc.c new file +49 -0

49 lines not on this page · raw message

include/linux/soc/cavium/lmc.h new file +9 -0
new file mode 100644
index 000000000000..336f467e154f
@@ -0,0 +1,9 @@
+#ifndef _LMC_H
+#define _LMC_H
+
+#include <linux/pci.h>
+
+int thunderx_edac_lmc_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
+void thunderx_edac_lmc_remove(struct pci_dev *pdev);
+
+#endif
Signature · 1 line
2.9.0.rc0.21.g7777322
maintainer
#5 lore raw

Re: [PATCH v10 3/7] edac,soc: thunderx: Add wrapper for EDAC LMC PCI device

Quoted 16 lines · Jan Glauber

Cavium SOCs contain a memory controller that is presented as a PCI device. This PCI device will be used by an EDAC driver and by a PMU driver.

To allow both subsystems to access the device a small wrapper is introduced that multi-plexes PCI probe and removal calls of the device to the EDAC driver.

The same mechanism will be used later to call the PMU driver.

The ThunderX EDAC driver is limited to only build as module with this patch. The reason is that with multiple users of the multi-plexer all users must be either builtin or modules.

---

...

Quoted 17 lines
drivers/soc/cavium/cavium_lmc.c new file +11 -0
new file mode 100644
index 000000000000..87248e83c55b
@@ -0,0 +1,49 @@
+/*
+ * These PCI devices contain RAS functionality and PMU counters. To allow
+ * independent RAS and PMU drivers this driver registers for the PCI devices
+ * and multi-plexes probe and removal.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright: Cavium, Inc. (C) 2017
+ *

drivers/soc/cavium/cavium_lmc.c line 21

Quoted 10 lines
drivers/soc/cavium/cavium_lmc.c new file +10 -0
+ */
+#include <linux/module.h>
+#include <linux/pci.h>
+#include <linux/soc/cavium/lmc.h>
+
+static int cvm_lmc_probe(struct pci_dev *pdev,
+			 const struct pci_device_id *ent)
+{
+	if (IS_ENABLED(CONFIG_EDAC_THUNDERX))
+		thunderx_edac_lmc_probe(pdev, ent);

You could save yourself the if (IS_ENABLED()) here by adding stubs in the lmc.h header for those functions for the !CONFIG_EDAC_THUNDERX case.

One thing I'm not clear on though, is the design of the whole thing:
cvm_lmc_probe() probes the EDAC driver during its own probe, which means, thunderx_edac needs to be loaded first. And the other things that get loaded, do the same.

What I was expecting is those small cavium_lmc.c and cavium_ocx.c wrappers to probe and register the respective PCI device and then its *users* - EDAC and PMU drivers to go and request the PCI device from them:

cavium_lmc_get_pci_dev()
cavium_ocx_get_pci_dev()

and so on. Those will be exported to modules. And the small stubs can also be built-in too.

This way you can do reference counting and whatever else.

If the above calls fail, neither EDAC nor PMU will load properly but you solve the multiplexing issue by having those wrappers arbitrate access to the PCI devices.

Because right now the wrappers are simply weakly hiding the calls into EDAC and that's exactly what I was opposing to.

Hmmm?

drivers/soc/cavium/cavium_lmc.c line 32

Quoted 11 lines
drivers/soc/cavium/cavium_lmc.c new file +11 -0
+	return 0;
+}
+
+static void cvm_lmc_remove(struct pci_dev *pdev)
+{
+	if (IS_ENABLED(CONFIG_EDAC_THUNDERX))
+		thunderx_edac_lmc_remove(pdev);
+}
+
+static const struct pci_device_id cvm_lmc_pci_table[] = {
+	{ PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, 0xa022) },

{ PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, PCI_DEVICE_ID_THUNDER_LMC) },

You already have that PCI device id define.

Signature · 4 lines
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.
#6 lore raw

Re: [PATCH v10 3/7] edac,soc: thunderx: Add wrapper for EDAC LMC PCI device

Quoted 42 lines · Borislav Petkov
Quoted 16 lines · Jan Glauber

Cavium SOCs contain a memory controller that is presented as a PCI device. This PCI device will be used by an EDAC driver and by a PMU driver.

To allow both subsystems to access the device a small wrapper is introduced that multi-plexes PCI probe and removal calls of the device to the EDAC driver.

The same mechanism will be used later to call the PMU driver.

The ThunderX EDAC driver is limited to only build as module with this patch. The reason is that with multiple users of the multi-plexer all users must be either builtin or modules.

---

...

Quoted 22 lines
drivers/soc/cavium/cavium_lmc.c new file +16 -0
new file mode 100644
index 000000000000..87248e83c55b
@@ -0,0 +1,49 @@
+/*
+ * These PCI devices contain RAS functionality and PMU counters. To allow
+ * independent RAS and PMU drivers this driver registers for the PCI devices
+ * and multi-plexes probe and removal.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright: Cavium, Inc. (C) 2017
+ *
+ */
+#include <linux/module.h>
+#include <linux/pci.h>
+#include <linux/soc/cavium/lmc.h>
+
Quoted 8 lines

drivers/soc/cavium/cavium_lmc.c line 21

Quoted 5 lines
drivers/soc/cavium/cavium_lmc.c new file +5 -0
+static int cvm_lmc_probe(struct pci_dev *pdev,
+			 const struct pci_device_id *ent)
+{
+	if (IS_ENABLED(CONFIG_EDAC_THUNDERX))
+		thunderx_edac_lmc_probe(pdev, ent);

You could save yourself the if (IS_ENABLED()) here by adding stubs in the lmc.h header for those functions for the !CONFIG_EDAC_THUNDERX case.

OK.

Quoted 4 lines

One thing I'm not clear on though, is the design of the whole thing:
cvm_lmc_probe() probes the EDAC driver during its own probe, which means, thunderx_edac needs to be loaded first. And the other things that get loaded, do the same.

Yes. That seems to work fine with the limitation of not being able to have mixed build options, everything needs to be modular or built-in. So I forced all parts to be buildable only as modules.

I went for this as the simplest solution, the probing is completely synchronous and no state needs to be stored in the wrapper.

Quoted 10 lines

What I was expecting is those small cavium_lmc.c and cavium_ocx.c wrappers to probe and register the respective PCI device and then its *users* - EDAC and PMU drivers to go and request the PCI device from them:

cavium_lmc_get_pci_dev()
cavium_ocx_get_pci_dev()

and so on. Those will be exported to modules. And the small stubs can also be built-in too.

So this is the opposite approach which would be asynchronous. What I don't understand with that approach:

1. What will trigger probing the edac (or perf) driver part? Right now the trigger is the PCI device ID. If the wrapper does not call into edac how should we load the ThunderX edac/perf drivers? The only option I see is a initcall in edac/perf to look for their devices.

2. The probe & register is _very_ specific to perf/edac and very different. The only part that would fit in the wrapper is pci_enable_device(). So is that what you have in mind?

Quoted 25 lines

This way you can do reference counting and whatever else.

If the above calls fail, neither EDAC nor PMU will load properly but you solve the multiplexing issue by having those wrappers arbitrate access to the PCI devices.

Because right now the wrappers are simply weakly hiding the calls into EDAC and that's exactly what I was opposing to.

Hmmm?

drivers/soc/cavium/cavium_lmc.c line 32

Quoted 11 lines
drivers/soc/cavium/cavium_lmc.c new file +11 -0
+	return 0;
+}
+
+static void cvm_lmc_remove(struct pci_dev *pdev)
+{
+	if (IS_ENABLED(CONFIG_EDAC_THUNDERX))
+		thunderx_edac_lmc_remove(pdev);
+}
+
+static const struct pci_device_id cvm_lmc_pci_table[] = {
+	{ PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, 0xa022) },

{ PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, PCI_DEVICE_ID_THUNDER_LMC) },

Quoted 1 line

You already have that PCI device id define.

True, will use it.

Thanks for looking at this!

--Jan

Quoted 5 lines
Signature · 4 lines
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.
maintainer
#7 lore raw

Re: [PATCH v10 3/7] edac,soc: thunderx: Add wrapper for EDAC LMC PCI device

Quoted 2 lines · Jan Glauber

I went for this as the simplest solution, the probing is completely synchronous and no state needs to be stored in the wrapper.

What state would you need to store? The wrapper simply gives out the struct pci_dev * to the callers or NULL if not present.

Quoted 4 lines

1. What will trigger probing the edac (or perf) driver part? Right now the trigger is the PCI device ID. If the wrapper does not call into edac how should we load the ThunderX edac/perf drivers? The only option I see is a initcall in edac/perf to look for their devices.

The wrapper loads on the PCI dev ID. EDAC loads later and calls the wrapper function to get the struct pci_dev *. Simple.

Quoted 3 lines

2. The probe & register is _very_ specific to perf/edac and very different. The only part that would fit in the wrapper is pci_enable_device(). So is that what you have in mind?

No, see above. Instead of getting the PCI device IDs from the PCI core, you use the wrapper, which gets those from the PCI core. Thus it is called a "wrapper". :)

Signature · 4 lines
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.
#8 lore raw

PATCH v10 4/7 edac,soc: thunderx: Add wrapper for EDAC OCX PCI device

In reply to Jan Glauber

Cavium SOCs contain an processor interconnect that is presented as a PCI device. This PCI device will be used by an EDAC driver and by a PMU driver.

To allow both subsystems to access the device a small wrapper is introduced that multi-plexes PCI probe and removal calls of the device to the EDAC driver.

---
 drivers/edac/Kconfig            |  1 +
 drivers/edac/thunderx_edac.c    | 42 +++++++-------------------------------
 drivers/soc/cavium/Kconfig      |  4 ++++
 drivers/soc/cavium/Makefile     |  1 +
 drivers/soc/cavium/cavium_ocx.c | 45 +++++++++++++++++++++++++++++++++++++++++
 include/linux/soc/cavium/ocx.h  |  9 +++++++++
 6 files changed, 67 insertions(+), 35 deletions(-)
 create mode 100644 drivers/soc/cavium/cavium_ocx.c
 create mode 100644 include/linux/soc/cavium/ocx.h
drivers/edac/Kconfig +1 -0
index 7330447c43d1..830421208374 100644
@@ -373,6 +373,7 @@ config EDAC_THUNDERX
 	depends on PCI
 	depends on m
 	select CAVIUM_LMC
+	select CAVIUM_OCX
 	help
 	  Support for error detection and correction on the
 	  Cavium ThunderX memory controllers (LMC), Cache
drivers/edac/thunderx_edac.c +7 -35

90 lines not on this page · raw message

drivers/soc/cavium/Kconfig +4 -0
index 46ded89fb696..fe56503d20f4 100644
@@ -4,3 +4,7 @@
 config CAVIUM_LMC
         depends on ARCH_THUNDER
 	def_tristate m
+
+config CAVIUM_OCX
+	depends on ARCH_THUNDER
+	def_tristate m
drivers/soc/cavium/Makefile +1 -0
index 4ad0c7f923fa..bf7ba252ebb1 100644
@@ -1 +1,2 @@
 obj-$(CONFIG_CAVIUM_LMC) += cavium_lmc.o
+obj-$(CONFIG_CAVIUM_OCX) += cavium_ocx.o
drivers/soc/cavium/cavium_ocx.c new file +45 -0

45 lines not on this page · raw message

include/linux/soc/cavium/ocx.h new file +9 -0
new file mode 100644
index 000000000000..29f55b3d3171
@@ -0,0 +1,9 @@
+#ifndef _OCX_H
+#define _OCX_H
+
+#include <linux/pci.h>
+
+int thunderx_edac_ocx_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
+void thunderx_edac_ocx_remove(struct pci_dev *pdev);
+
+#endif
Signature · 1 line
2.9.0.rc0.21.g7777322
#9 lore raw

PATCH v10 5/7 perf: cavium: Support memory controller PMU counters

In reply to Jan Glauber

Add support for the PMU counters on Cavium SOC memory controllers.

This patch also adds generic functions to allow supporting more devices with PMU counters.

Properties of the LMC PMU counters:
- not stoppable
- fixed purpose
- read-only
- one PCI device per memory controller

---
 drivers/perf/Kconfig            |   8 +
 drivers/perf/Makefile           |   1 +
 drivers/perf/cavium_pmu.c       | 430 ++++++++++++++++++++++++++++++++++++++++
 drivers/soc/cavium/cavium_lmc.c |   4 +
 include/linux/cpuhotplug.h      |   1 +
 include/linux/soc/cavium/lmc.h  |   3 +
 6 files changed, 447 insertions(+)
 create mode 100644 drivers/perf/cavium_pmu.c
drivers/perf/Kconfig +8 -0
index e5197ffb7422..a787562c5432 100644
@@ -43,4 +43,12 @@ config XGENE_PMU
         help
           Say y if you want to use APM X-Gene SoC performance monitors.
 
+config CAVIUM_PMU_LMC
+	tristate "Cavium SOC memory controller PMU"
+	depends on ARCH_THUNDER && m
+	select CAVIUM_LMC
+	help
+	  Provides PMU counters for the memory controller on
+	  Cavium ThunderX or OcteonTX SOCs.
+
 endmenu
drivers/perf/Makefile +1 -0
index 6420bd4394d5..cd616785047f 100644
@@ -1,5 +1,6 @@
 obj-$(CONFIG_ARM_PMU) += arm_pmu.o arm_pmu_platform.o
 obj-$(CONFIG_ARM_PMU_ACPI) += arm_pmu_acpi.o
+obj-$(CONFIG_CAVIUM_PMU_LMC) += cavium_pmu.o
 obj-$(CONFIG_QCOM_L2_PMU)	+= qcom_l2_pmu.o
 obj-$(CONFIG_QCOM_L3_PMU) += qcom_l3_pmu.o
 obj-$(CONFIG_XGENE_PMU) += xgene_pmu.o
drivers/perf/cavium_pmu.c new file +430 -0

430 lines not on this page · raw message

drivers/soc/cavium/cavium_lmc.c +4 -0
index 87248e83c55b..d21d59c24321 100644
@@ -17,6 +17,8 @@
 static int cvm_lmc_probe(struct pci_dev *pdev,
 			 const struct pci_device_id *ent)
 {
+	if (IS_ENABLED(CONFIG_CAVIUM_PMU_LMC))
+		cvm_lmc_pmu_probe(pdev, ent);
 	if (IS_ENABLED(CONFIG_EDAC_THUNDERX))
 		thunderx_edac_lmc_probe(pdev, ent);
 	return 0;
@@ -24,6 +26,8 @@ static int cvm_lmc_probe(struct pci_dev *pdev,
 
 static void cvm_lmc_remove(struct pci_dev *pdev)
 {
+	if (IS_ENABLED(CONFIG_CAVIUM_PMU_LMC))
+		cvm_lmc_pmu_remove(pdev);
 	if (IS_ENABLED(CONFIG_EDAC_THUNDERX))
 		thunderx_edac_lmc_remove(pdev);
 }
include/linux/cpuhotplug.h +1 -0
index f24bfb2b9a2d..3362c158fe5c 100644
@@ -134,6 +134,7 @@ enum cpuhp_state {
 	CPUHP_AP_PERF_S390_SF_ONLINE,
 	CPUHP_AP_PERF_ARM_CCI_ONLINE,
 	CPUHP_AP_PERF_ARM_CCN_ONLINE,
+	CPUHP_AP_PERF_ARM_CVM_ONLINE,
 	CPUHP_AP_PERF_ARM_L2X0_ONLINE,
 	CPUHP_AP_PERF_ARM_QCOM_L2_ONLINE,
 	CPUHP_AP_PERF_ARM_QCOM_L3_ONLINE,
include/linux/soc/cavium/lmc.h +3 -0
index 336f467e154f..e5ad6507fd36 100644
@@ -3,6 +3,9 @@
 
 #include <linux/pci.h>
 
+int cvm_lmc_pmu_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
+void cvm_lmc_pmu_remove(struct pci_dev *pdev);
+
 int thunderx_edac_lmc_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
 void thunderx_edac_lmc_remove(struct pci_dev *pdev);
 
Signature · 1 line
2.9.0.rc0.21.g7777322
#10 lore raw

Re: [PATCH v10 5/7] perf: cavium: Support memory controller PMU counters

Quoted 47 lines · Jan Glauber

Add support for the PMU counters on Cavium SOC memory controllers.

This patch also adds generic functions to allow supporting more devices with PMU counters.

Properties of the LMC PMU counters:
- not stoppable
- fixed purpose
- read-only
- one PCI device per memory controller

---
  drivers/perf/Kconfig            |   8 +
  drivers/perf/Makefile           |   1 +
  drivers/perf/cavium_pmu.c       | 430 ++++++++++++++++++++++++++++++++++++++++
  drivers/soc/cavium/cavium_lmc.c |   4 +
  include/linux/cpuhotplug.h      |   1 +
  include/linux/soc/cavium/lmc.h  |   3 +
  6 files changed, 447 insertions(+)

create mode 100644 drivers/perf/cavium_pmu.c

drivers/perf/cavium_pmu.c new file +25 -0
+int cvm_lmc_pmu_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
+{
+	struct cvm_pmu_dev *next, *lmc;
+	int nr = 0, ret = -ENOMEM;
+	char *name;
+
+	lmc = devm_kzalloc(&pdev->dev, sizeof(*lmc), GFP_KERNEL);
+	if (!lmc)
+		return -ENOMEM;
+
+	lmc->map = devm_ioremap(&pdev->dev, pci_resource_start(pdev, 0),
+				pci_resource_len(pdev, 0));
+	if (!lmc->map)
+		return -EINVAL;
+
+	list_for_each_entry(next, &cvm_pmu_lmcs, entry)
+		nr++;
+	name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "lmc%d", nr);
+	if (!name)
+		return -ENOMEM;
+
+	lmc->pdev = pdev;
+	lmc->num_counters = ARRAY_SIZE(cvm_pmu_lmc_events_attr) - 1;
+	lmc->pmu = (struct pmu) {
+		.task_ctx_nr    = perf_invalid_context,

drivers/perf/cavium_pmu.c line 363

Quoted 10 lines
drivers/perf/cavium_pmu.c new file +10 -0
+		.name		= name,
+		.event_init	= cvm_pmu_event_init,
+		.add		= cvm_pmu_lmc_add,
+		.del		= cvm_pmu_del,
+		.start		= cvm_pmu_start,
+		.stop		= cvm_pmu_stop,
+		.read		= cvm_pmu_read,
+		.attr_groups	= cvm_pmu_lmc_attr_groups,
+	};
+

You need to fill in the "module" field of the PMU to prevent the module from being unloaded while the PMU is active.

See :

http://lists.infradead.org/pipermail/linux-arm-kernel/2017-November/540647.html

Suzuki

#11 lore raw

PATCH v10 6/7 perf: cavium: Support transmit-link PMU counters

In reply to Jan Glauber

Add support for the transmit-link (OCX TLK) PMU counters found on Caviums SOCs with a processor interconnect.

Properties of the OCX TLK counters:
- per-unit control
- fixed purpose
- writable
- one PCI device with multiple TLK units

---
 drivers/perf/Kconfig            |   7 ++
 drivers/perf/cavium_pmu.c       | 230 ++++++++++++++++++++++++++++++++++++++++
 drivers/soc/cavium/Kconfig      |   4 +
 drivers/soc/cavium/cavium_ocx.c |   4 +
 include/linux/soc/cavium/ocx.h  |   3 +
 5 files changed, 248 insertions(+)
drivers/perf/Kconfig +7 -0
index a787562c5432..efb2ace649c1 100644
@@ -51,4 +51,11 @@ config CAVIUM_PMU_LMC
 	  Provides PMU counters for the memory controller on
 	  Cavium ThunderX or OcteonTX SOCs.
 
+config CAVIUM_PMU_OCX_TLK
+	tristate "Cavium ThunderX interconnect PMU"
+	depends on ARCH_THUNDER && m
+	select CAVIUM_OCX
+	help
+	  Provides PMU counters for the processor interconnect on
+	  Cavium ThunderX processors.
 endmenu
drivers/perf/cavium_pmu.c +230 -0

245 lines not on this page · raw message

drivers/soc/cavium/Kconfig +4 -0
index fe56503d20f4..2c7406872b18 100644
@@ -8,3 +8,7 @@ config CAVIUM_LMC
 config CAVIUM_OCX
 	depends on ARCH_THUNDER
 	def_tristate m
+
+config CAVIUM_OCX
+        depends on ARCH_THUNDER
+	def_tristate m
drivers/soc/cavium/cavium_ocx.c +4 -0
index fa3341b0744f..de1ad146c0dd 100644
@@ -13,6 +13,8 @@
 static int cvm_ocx_probe(struct pci_dev *pdev,
 			 const struct pci_device_id *ent)
 {
+	if (IS_ENABLED(CONFIG_CAVIUM_PMU_OCX_TLK))
+		cvm_ocx_tlk_pmu_probe(pdev, ent);
 	if (IS_ENABLED(CONFIG_EDAC_THUNDERX))
 		thunderx_edac_ocx_probe(pdev, ent);
 	return 0;
@@ -20,6 +22,8 @@ static int cvm_ocx_probe(struct pci_dev *pdev,
 
 static void cvm_ocx_remove(struct pci_dev *pdev)
 {
+	if (IS_ENABLED(CONFIG_CAVIUM_PMU_OCX_TLK))
+		cvm_ocx_tlk_pmu_remove(pdev);
 	if (IS_ENABLED(CONFIG_EDAC_THUNDERX))
 		thunderx_edac_ocx_remove(pdev);
 }
include/linux/soc/cavium/ocx.h +3 -0
index 29f55b3d3171..f7b2caada671 100644
@@ -3,6 +3,9 @@
 
 #include <linux/pci.h>
 
+int cvm_ocx_tlk_pmu_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
+void cvm_ocx_tlk_pmu_remove(struct pci_dev *pdev);
+
 int thunderx_edac_ocx_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
 void thunderx_edac_ocx_remove(struct pci_dev *pdev);
 
Signature · 1 line
2.9.0.rc0.21.g7777322
#12 lore raw

Re: [PATCH v10 6/7] perf: cavium: Support transmit-link PMU counters

Quoted 10 lines · On Mon, 25 Sep 2017 14:35:01 +0200 Jan Glauber <[email protected]> wrote:

Add support for the transmit-link (OCX TLK) PMU counters found on Caviums SOCs with a processor interconnect.

Properties of the OCX TLK counters:
- per-unit control
- fixed purpose
- writable
- one PCI device with multiple TLK units

Something odd happened in
drivers/soc/cavium/Kconfig...

Otherwise whole series looks sensible to me.

Jonathan

Quoted 8 lines
---
 drivers/perf/Kconfig            |   7 ++
 drivers/perf/cavium_pmu.c       | 230 ++++++++++++++++++++++++++++++++++++++++
 drivers/soc/cavium/Kconfig      |   4 +
 drivers/soc/cavium/cavium_ocx.c |   4 +
 include/linux/soc/cavium/ocx.h  |   3 +
 5 files changed, 248 insertions(+)

<snip>

Quoted 8 lines

static int __init cvm_pmu_init(void)
{

drivers/perf/cavium_pmu.c +0 -0
 	INIT_LIST_HEAD(&cvm_pmu_lmcs);
drivers/soc/cavium/Kconfig +0 -0
index fe56503d20f4..2c7406872b18 100644

drivers/soc/cavium/Kconfig config CAVIUM_LMC · line 14

Quoted 7 lines
drivers/soc/cavium/Kconfig +4 -0
@@ -8,3 +8,7 @@ config CAVIUM_LMC
 config CAVIUM_OCX
 	depends on ARCH_THUNDER
 	def_tristate m
+
+config CAVIUM_OCX
+        depends on ARCH_THUNDER
+	def_tristate m

Something odd going on here...

Quoted 36 lines
drivers/soc/cavium/cavium_ocx.c +4 -0
index fa3341b0744f..de1ad146c0dd 100644
@@ -13,6 +13,8 @@
 static int cvm_ocx_probe(struct pci_dev *pdev,
 			 const struct pci_device_id *ent)
 {
+	if (IS_ENABLED(CONFIG_CAVIUM_PMU_OCX_TLK))
+		cvm_ocx_tlk_pmu_probe(pdev, ent);
 	if (IS_ENABLED(CONFIG_EDAC_THUNDERX))
 		thunderx_edac_ocx_probe(pdev, ent);
 	return 0;
@@ -20,6 +22,8 @@ static int cvm_ocx_probe(struct pci_dev *pdev,
 
 static void cvm_ocx_remove(struct pci_dev *pdev)
 {
+	if (IS_ENABLED(CONFIG_CAVIUM_PMU_OCX_TLK))
+		cvm_ocx_tlk_pmu_remove(pdev);
 	if (IS_ENABLED(CONFIG_EDAC_THUNDERX))
 		thunderx_edac_ocx_remove(pdev);
 }
include/linux/soc/cavium/ocx.h +3 -0
index 29f55b3d3171..f7b2caada671 100644
@@ -3,6 +3,9 @@
 
 #include <linux/pci.h>
 
+int cvm_ocx_tlk_pmu_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
+void cvm_ocx_tlk_pmu_remove(struct pci_dev *pdev);
+
 int thunderx_edac_ocx_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
 void thunderx_edac_ocx_remove(struct pci_dev *pdev);
 
#13 lore raw

PATCH v10 7/7 perf: cavium: Add Documentation

In reply to Jan Glauber

Document Cavium SoC PMUs.

---
 Documentation/perf/cavium-pmu.txt | 75 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)
 create mode 100644 Documentation/perf/cavium-pmu.txt
Documentation/perf/cavium-pmu.txt new file +75 -0
new file mode 100644
index 000000000000..6fbf824ee4fd
@@ -0,0 +1,75 @@
+Cavium ThunderX and OcteonTx Performance Monitoring Unit (PMU)
+==============================================================
+
+Cavium SoCs contain various system devices such as L2 caches, processor
+interconnect and memory controllers. Unfortunately the PMU counters
+are not following a common design so each device has a slightly different
+approach how to control and use the PMU counters.
+
+Common properties of all devices carrying PMU counters:
+- The devices are PCI devices and the counters are embedded somewhere
+  in the PCI register space.
+- All counters are 64 bit wide.
+- There are no overflow interrupts (unnecessary because of the 64 bit wide
+  counters).
+
+Properties depending on the device type:
+- How to start/stop the counters
+- Programmable vs. fixed purpose counters
+- Stoppable vs. always running counters
+- Independent vs. grouped counters
+- Read-only vs. writable counters
+- PCI device to PMU group relationship
+
+
+Devices with PMU counters
+-------------------------
+
+Memory controller (LMC):
+- one PCI device per LMC
+- fixed-purpose counters
+- always running counters without start/stop/reset control
+- read-only counters
+
+CCPI interface controller (OCX) Transmit link (TLK) counters:
+- writable counters
+- only one PCI device exposes multiple TLK units (3 units on T88)
+- start/stop control per unit
+- only present on multi-socket systems
+
+PMU (perf) driver
+-----------------
+
+The cavium-pmu driver registers several perf PMU drivers. Each of the perf
+driver provides description of its available events and configuration options
+in sysfs, see /sys/devices/<lmcX/ocx_tlkX>/.
+
+The "format" directory describes format of the config (event ID),
+The "events" directory shows the names of the events and provides configuration
+templates for all supported event types that can be used with perf tool. For
+example, "lmc0/dclk_cnt/" is an equivalent of "lmc0/config=2/".
+
+Each perf driver also provides a "cpumask" sysfs attribute, which contains a
+single CPU ID of the processor which will be used to handle all the PMU events.
+
+Example for perf tool use:
+
+ / # perf list | grep -e lmc
+   lmc0/bank_conflict1/                               [Kernel PMU event]
+   lmc0/bank_conflict2/                               [Kernel PMU event]
+   lmc0/dclk_cnt/                                     [Kernel PMU event]
+   lmc0/ifb_cnt/                                      [Kernel PMU event]
+   lmc0/ops_cnt/                                      [Kernel PMU event]
+
+ / # perf stat -a -e lmc0/ops_cnt/,lmc0/dclk_cnt/ -- sleep 1
+
+   Performance counter stats for 'system wide':
+
+             176,133      lmc0/ops_cnt/                                               
+         670,243,653      lmc0/dclk_cnt/                                              
+
+         1.005479295 seconds time elapsed
+
+The driver does not support sampling, therefore "perf record" will
+not work. System wide mode ("-a") must be used as per-task (without "-a")
+perf sessions are not supported.
Signature · 1 line
2.9.0.rc0.21.g7777322