linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] Add support for HiSilicon SoC uncore PMU
@ 2023-05-31 10:46 Junhao He
  2023-05-31 10:46 ` [PATCH v2 1/3] drivers/perf: hisi: Add support for HiSilicon H60PA and PAv3 PMU driver Junhao He
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Junhao He @ 2023-05-31 10:46 UTC (permalink / raw)
  To: will, jonathan.cameron, linux-kernel, mark.rutland
  Cc: linux-arm-kernel, linux-doc, linuxarm, yangyicong, shenyang39,
	prime.zeng, hejunhao3

Add support for HiSilicon UC/H60PA/PAv3 PMU driver.

PAv3 PMU: Compared with the PAv2 PMU, the PAv3 PMU has different event. The
version of PMU version register is used to distinguish the v2 and v3.

H60PA PMU: The H60PA PMU and PA are two different devices. The H60PA PMU
supports higher bandwidth, and the PA PMU delay is relatively low.
Different HIDs are used to distinguish the delay.

UC PMU: Each cluster is integrated with a unified cache (UC) PMU, which
provides consistency between NUMA and UMA domains. It sits between
L2 and the memory system.

Change since v1:
- Improve according to Yicong's suggestion
- Fixes build warning of "-Wmissing-prototypes"
Link: https://lore.kernel.org/lkml/20230523131825.6102-1-hejunhao3@huawei.com/

Junhao He (3):
  drivers/perf: hisi: Add support for HiSilicon H60PA and PAv3 PMU
    driver
  drivers/perf: hisi: Add support for HiSilicon UC PMU driver
  docs: perf: Add new description for HiSilicon UC PMU

 Documentation/admin-guide/perf/hisi-pmu.rst |   8 +
 drivers/perf/hisilicon/Makefile             |   2 +-
 drivers/perf/hisilicon/hisi_uncore_pa_pmu.c | 142 ++++-
 drivers/perf/hisilicon/hisi_uncore_pmu.c    |   4 +-
 drivers/perf/hisilicon/hisi_uncore_pmu.h    |  15 +
 drivers/perf/hisilicon/hisi_uncore_uc_pmu.c | 577 ++++++++++++++++++++
 6 files changed, 731 insertions(+), 17 deletions(-)
 create mode 100644 drivers/perf/hisilicon/hisi_uncore_uc_pmu.c

-- 
2.33.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 1/3] drivers/perf: hisi: Add support for HiSilicon H60PA and PAv3 PMU driver
  2023-05-31 10:46 [PATCH v2 0/3] Add support for HiSilicon SoC uncore PMU Junhao He
@ 2023-05-31 10:46 ` Junhao He
  2023-05-31 15:45   ` Jonathan Cameron
  2023-06-01  6:40   ` Yicong Yang
  2023-05-31 10:46 ` [PATCH v2 2/3] drivers/perf: hisi: Add support for HiSilicon UC " Junhao He
  2023-05-31 10:46 ` [PATCH v2 3/3] docs: perf: Add new description for HiSilicon UC PMU Junhao He
  2 siblings, 2 replies; 12+ messages in thread
From: Junhao He @ 2023-05-31 10:46 UTC (permalink / raw)
  To: will, jonathan.cameron, linux-kernel, mark.rutland
  Cc: linux-arm-kernel, linux-doc, linuxarm, yangyicong, shenyang39,
	prime.zeng, hejunhao3

Compared to the original PA device, H60PA offers higher bandwidth.
The H60PA is a new device and we use HID to differentiate them.

The events supported by PAv3 and PAv2 are different. They use the
same HID. The PMU version register is used in the driver to
distinguish different versions.

For each H60PA PMU, except for the overflow interrupt register, other
functions of the H60PA PMU are the same as the original PA PMU module.
It has 8-programable counters and each counter is free-running.
Interrupt is supported to handle counter (64-bits) overflow.

Signed-off-by: Junhao He <hejunhao3@huawei.com>
---
 drivers/perf/hisilicon/hisi_uncore_pa_pmu.c | 142 +++++++++++++++++---
 drivers/perf/hisilicon/hisi_uncore_pmu.h    |   9 ++
 2 files changed, 136 insertions(+), 15 deletions(-)

diff --git a/drivers/perf/hisilicon/hisi_uncore_pa_pmu.c b/drivers/perf/hisilicon/hisi_uncore_pa_pmu.c
index 71b6687d6696..c1b7180aadc1 100644
--- a/drivers/perf/hisilicon/hisi_uncore_pa_pmu.c
+++ b/drivers/perf/hisilicon/hisi_uncore_pa_pmu.c
@@ -22,9 +22,15 @@
 #define PA_TT_CTRL			0x1c08
 #define PA_TGTID_CTRL			0x1c14
 #define PA_SRCID_CTRL			0x1c18
+
+/* H32 PA interrupt registers */
 #define PA_INT_MASK			0x1c70
 #define PA_INT_STATUS			0x1c78
 #define PA_INT_CLEAR			0x1c7c
+
+#define H60PA_INT_STATUS		0x1c70
+#define H60PA_INT_MASK			0x1c74
+
 #define PA_EVENT_TYPE0			0x1c80
 #define PA_PMU_VERSION			0x1cf0
 #define PA_EVENT_CNT0_L			0x1d00
@@ -46,6 +52,12 @@ HISI_PMU_EVENT_ATTR_EXTRACTOR(srcid_cmd, config1, 32, 22);
 HISI_PMU_EVENT_ATTR_EXTRACTOR(srcid_msk, config1, 43, 33);
 HISI_PMU_EVENT_ATTR_EXTRACTOR(tracetag_en, config1, 44, 44);
 
+struct hisi_pa_pmu_int_regs {
+	u32 mask_offset;
+	u32 clear_offset;
+	u32 status_offset;
+};
+
 static void hisi_pa_pmu_enable_tracetag(struct perf_event *event)
 {
 	struct hisi_pmu *pa_pmu = to_hisi_pmu(event->pmu);
@@ -219,44 +231,50 @@ static void hisi_pa_pmu_disable_counter(struct hisi_pmu *pa_pmu,
 static void hisi_pa_pmu_enable_counter_int(struct hisi_pmu *pa_pmu,
 					   struct hw_perf_event *hwc)
 {
+	struct hisi_pa_pmu_int_regs *regs = pa_pmu->dev_info->private;
 	u32 val;
 
 	/* Write 0 to enable interrupt */
-	val = readl(pa_pmu->base + PA_INT_MASK);
+	val = readl(pa_pmu->base + regs->mask_offset);
 	val &= ~(1 << hwc->idx);
-	writel(val, pa_pmu->base + PA_INT_MASK);
+	writel(val, pa_pmu->base + regs->mask_offset);
 }
 
 static void hisi_pa_pmu_disable_counter_int(struct hisi_pmu *pa_pmu,
 					    struct hw_perf_event *hwc)
 {
+	struct hisi_pa_pmu_int_regs *regs = pa_pmu->dev_info->private;
 	u32 val;
 
 	/* Write 1 to mask interrupt */
-	val = readl(pa_pmu->base + PA_INT_MASK);
+	val = readl(pa_pmu->base + regs->mask_offset);
 	val |= 1 << hwc->idx;
-	writel(val, pa_pmu->base + PA_INT_MASK);
+	writel(val, pa_pmu->base + regs->mask_offset);
 }
 
 static u32 hisi_pa_pmu_get_int_status(struct hisi_pmu *pa_pmu)
 {
-	return readl(pa_pmu->base + PA_INT_STATUS);
+	struct hisi_pa_pmu_int_regs *regs = pa_pmu->dev_info->private;
+
+	return readl(pa_pmu->base + regs->status_offset);
 }
 
 static void hisi_pa_pmu_clear_int_status(struct hisi_pmu *pa_pmu, int idx)
 {
-	writel(1 << idx, pa_pmu->base + PA_INT_CLEAR);
-}
+	struct hisi_pa_pmu_int_regs *regs = pa_pmu->dev_info->private;
 
-static const struct acpi_device_id hisi_pa_pmu_acpi_match[] = {
-	{ "HISI0273", },
-	{}
-};
-MODULE_DEVICE_TABLE(acpi, hisi_pa_pmu_acpi_match);
+	writel(1 << idx, pa_pmu->base + regs->clear_offset);
+}
 
 static int hisi_pa_pmu_init_data(struct platform_device *pdev,
 				   struct hisi_pmu *pa_pmu)
 {
+	const struct hisi_pmu_dev_info *pa_pmu_info;
+
+	pa_pmu_info = device_get_match_data(&pdev->dev);
+	if (!pa_pmu_info)
+		return -ENODEV;
+
 	/*
 	 * As PA PMU is in a SICL, use the SICL_ID and the index ID
 	 * to identify the PA PMU.
@@ -284,6 +302,15 @@ static int hisi_pa_pmu_init_data(struct platform_device *pdev,
 
 	pa_pmu->identifier = readl(pa_pmu->base + PA_PMU_VERSION);
 
+	/* When running on v3 or later, returns the largest version supported */
+	if (pa_pmu->identifier >= HISI_PMU_V3)
+		pa_pmu->dev_info = &pa_pmu_info[2];
+	else if (HISI_PMU_V2)
+		pa_pmu->dev_info = &pa_pmu_info[1];
+
+	if (!pa_pmu->dev_info || !pa_pmu->dev_info->name)
+		return -EINVAL;
+
 	return 0;
 }
 
@@ -314,6 +341,32 @@ static const struct attribute_group hisi_pa_pmu_v2_events_group = {
 	.attrs = hisi_pa_pmu_v2_events_attr,
 };
 
+static struct attribute *hisi_pa_pmu_v3_events_attr[] = {
+	HISI_PMU_EVENT_ATTR(tx_req,	0x0),
+	HISI_PMU_EVENT_ATTR(tx_dat,	0x1),
+	HISI_PMU_EVENT_ATTR(tx_snp,	0x2),
+	HISI_PMU_EVENT_ATTR(rx_req,	0x7),
+	HISI_PMU_EVENT_ATTR(rx_dat,	0x8),
+	HISI_PMU_EVENT_ATTR(rx_snp,	0x9),
+	NULL
+};
+
+static const struct attribute_group hisi_pa_pmu_v3_events_group = {
+	.name = "events",
+	.attrs = hisi_pa_pmu_v3_events_attr,
+};
+
+static struct attribute *hisi_h60pa_pmu_events_attr[] = {
+	HISI_PMU_EVENT_ATTR(rx_flit,	0x50),
+	HISI_PMU_EVENT_ATTR(tx_flit,	0x65),
+	NULL
+};
+
+static const struct attribute_group hisi_h60pa_pmu_events_group = {
+	.name = "events",
+	.attrs = hisi_h60pa_pmu_events_attr,
+};
+
 static DEVICE_ATTR(cpumask, 0444, hisi_cpumask_sysfs_show, NULL);
 
 static struct attribute *hisi_pa_pmu_cpumask_attrs[] = {
@@ -345,6 +398,57 @@ static const struct attribute_group *hisi_pa_pmu_v2_attr_groups[] = {
 	NULL
 };
 
+static const struct attribute_group *hisi_pa_pmu_v3_attr_groups[] = {
+	&hisi_pa_pmu_v2_format_group,
+	&hisi_pa_pmu_v3_events_group,
+	&hisi_pa_pmu_cpumask_attr_group,
+	&hisi_pa_pmu_identifier_group,
+	NULL
+};
+
+static struct hisi_pa_pmu_int_regs hisi_pa_pmu_regs = {
+	.mask_offset = PA_INT_MASK,
+	.clear_offset = PA_INT_CLEAR,
+	.status_offset = PA_INT_STATUS,
+};
+
+static const struct hisi_pmu_dev_info hisi_h32pa[] = {
+	[1] = {
+		.name = "pa",
+		.attr_groups = hisi_pa_pmu_v2_attr_groups,
+		.private = &hisi_pa_pmu_regs,
+	},
+	[2] = {
+		.name = "pa",
+		.attr_groups = hisi_pa_pmu_v3_attr_groups,
+		.private = &hisi_pa_pmu_regs,
+	},
+	{}
+};
+
+static const struct attribute_group *hisi_h60pa_pmu_attr_groups[] = {
+	&hisi_pa_pmu_v2_format_group,
+	&hisi_h60pa_pmu_events_group,
+	&hisi_pa_pmu_cpumask_attr_group,
+	&hisi_pa_pmu_identifier_group,
+	NULL
+};
+
+static struct hisi_pa_pmu_int_regs hisi_h60pa_pmu_regs = {
+	.mask_offset = H60PA_INT_MASK,
+	.clear_offset = H60PA_INT_STATUS, /* Clear on write */
+	.status_offset = H60PA_INT_STATUS,
+};
+
+static const struct hisi_pmu_dev_info hisi_h60pa[] = {
+	[1] = {
+		.name = "h60pa",
+		.attr_groups = hisi_h60pa_pmu_attr_groups,
+		.private = &hisi_h60pa_pmu_regs,
+	},
+	{}
+};
+
 static const struct hisi_uncore_ops hisi_uncore_pa_ops = {
 	.write_evtype		= hisi_pa_pmu_write_evtype,
 	.get_event_idx		= hisi_uncore_pmu_get_event_idx,
@@ -375,7 +479,7 @@ static int hisi_pa_pmu_dev_probe(struct platform_device *pdev,
 	if (ret)
 		return ret;
 
-	pa_pmu->pmu_events.attr_groups = hisi_pa_pmu_v2_attr_groups;
+	pa_pmu->pmu_events.attr_groups = pa_pmu->dev_info->attr_groups;
 	pa_pmu->num_counters = PA_NR_COUNTERS;
 	pa_pmu->ops = &hisi_uncore_pa_ops;
 	pa_pmu->check_event = 0xB0;
@@ -400,8 +504,9 @@ static int hisi_pa_pmu_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "hisi_sicl%u_pa%u",
-			      pa_pmu->sicl_id, pa_pmu->index_id);
+	name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "hisi_sicl%d_%s%u",
+			      pa_pmu->sicl_id, pa_pmu->dev_info->name,
+			      pa_pmu->index_id);
 	if (!name)
 		return -ENOMEM;
 
@@ -435,6 +540,13 @@ static int hisi_pa_pmu_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static const struct acpi_device_id hisi_pa_pmu_acpi_match[] = {
+	{ "HISI0273", (kernel_ulong_t)hisi_h32pa },
+	{ "HISI0274", (kernel_ulong_t)hisi_h60pa },
+	{}
+};
+MODULE_DEVICE_TABLE(acpi, hisi_pa_pmu_acpi_match);
+
 static struct platform_driver hisi_pa_pmu_driver = {
 	.driver = {
 		.name = "hisi_pa_pmu",
diff --git a/drivers/perf/hisilicon/hisi_uncore_pmu.h b/drivers/perf/hisilicon/hisi_uncore_pmu.h
index 07890a8e96ca..a8d6d6905f3f 100644
--- a/drivers/perf/hisilicon/hisi_uncore_pmu.h
+++ b/drivers/perf/hisilicon/hisi_uncore_pmu.h
@@ -24,6 +24,7 @@
 #define pr_fmt(fmt)     "hisi_pmu: " fmt
 
 #define HISI_PMU_V2		0x30
+#define HISI_PMU_V3		0x40
 #define HISI_MAX_COUNTERS 0x10
 #define to_hisi_pmu(p)	(container_of(p, struct hisi_pmu, pmu))
 
@@ -62,6 +63,13 @@ struct hisi_uncore_ops {
 	void (*disable_filter)(struct perf_event *event);
 };
 
+/* Describes the HISI PMU chip features information */
+struct hisi_pmu_dev_info {
+	const char *name;
+	const struct attribute_group **attr_groups;
+	void *private;
+};
+
 struct hisi_pmu_hwevents {
 	struct perf_event *hw_events[HISI_MAX_COUNTERS];
 	DECLARE_BITMAP(used_mask, HISI_MAX_COUNTERS);
@@ -72,6 +80,7 @@ struct hisi_pmu_hwevents {
 struct hisi_pmu {
 	struct pmu pmu;
 	const struct hisi_uncore_ops *ops;
+	const struct hisi_pmu_dev_info *dev_info;
 	struct hisi_pmu_hwevents pmu_events;
 	/* associated_cpus: All CPUs associated with the PMU */
 	cpumask_t associated_cpus;
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 2/3] drivers/perf: hisi: Add support for HiSilicon UC PMU driver
  2023-05-31 10:46 [PATCH v2 0/3] Add support for HiSilicon SoC uncore PMU Junhao He
  2023-05-31 10:46 ` [PATCH v2 1/3] drivers/perf: hisi: Add support for HiSilicon H60PA and PAv3 PMU driver Junhao He
@ 2023-05-31 10:46 ` Junhao He
  2023-05-31 15:59   ` Jonathan Cameron
  2023-06-01  6:41   ` Yicong Yang
  2023-05-31 10:46 ` [PATCH v2 3/3] docs: perf: Add new description for HiSilicon UC PMU Junhao He
  2 siblings, 2 replies; 12+ messages in thread
From: Junhao He @ 2023-05-31 10:46 UTC (permalink / raw)
  To: will, jonathan.cameron, linux-kernel, mark.rutland
  Cc: linux-arm-kernel, linux-doc, linuxarm, yangyicong, shenyang39,
	prime.zeng, hejunhao3

On HiSilicon Hip09 platform, there is a UC (unified cache) module
on each chip SCCL (Super CPU Cluster). UC is a cache that provides
coherence between NUMA and UMA domains. It is located between L2
and Memory System. While PA uncore PMU model is the same as other
Hip09 PMU modules and many PMU events are supported. Let's support
the PMU driver using the HiSilicon uncore PMU framework.

* rd_req_en : rd_req_en is the abbreviation of read request tracetag enable
and allows user to count only read operations.
details are listed in the hisi-pmu document.

* srcid_en & srcid: allows user to filter statistics that come from
specific CPU/ICL by configuration source ID.

* uring_channel: Allows users to filter statistical information based on
the specified tx request uring channel.
uring_channel only supported events: [0x47 ~ 0x59].

Signed-off-by: Junhao He <hejunhao3@huawei.com>
---
 drivers/perf/hisilicon/Makefile             |   2 +-
 drivers/perf/hisilicon/hisi_uncore_pmu.c    |   4 +-
 drivers/perf/hisilicon/hisi_uncore_pmu.h    |   6 +
 drivers/perf/hisilicon/hisi_uncore_uc_pmu.c | 577 ++++++++++++++++++++
 4 files changed, 587 insertions(+), 2 deletions(-)
 create mode 100644 drivers/perf/hisilicon/hisi_uncore_uc_pmu.c

diff --git a/drivers/perf/hisilicon/Makefile b/drivers/perf/hisilicon/Makefile
index 4d2c9abe3372..48dcc8381ea7 100644
--- a/drivers/perf/hisilicon/Makefile
+++ b/drivers/perf/hisilicon/Makefile
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 obj-$(CONFIG_HISI_PMU) += hisi_uncore_pmu.o hisi_uncore_l3c_pmu.o \
 			  hisi_uncore_hha_pmu.o hisi_uncore_ddrc_pmu.o hisi_uncore_sllc_pmu.o \
-			  hisi_uncore_pa_pmu.o hisi_uncore_cpa_pmu.o
+			  hisi_uncore_pa_pmu.o hisi_uncore_cpa_pmu.o hisi_uncore_uc_pmu.o
 
 obj-$(CONFIG_HISI_PCIE_PMU) += hisi_pcie_pmu.o
 obj-$(CONFIG_HNS3_PMU) += hns3_pmu.o
diff --git a/drivers/perf/hisilicon/hisi_uncore_pmu.c b/drivers/perf/hisilicon/hisi_uncore_pmu.c
index 2823f381930d..04031450d5fe 100644
--- a/drivers/perf/hisilicon/hisi_uncore_pmu.c
+++ b/drivers/perf/hisilicon/hisi_uncore_pmu.c
@@ -20,7 +20,6 @@
 
 #include "hisi_uncore_pmu.h"
 
-#define HISI_GET_EVENTID(ev) (ev->hw.config_base & 0xff)
 #define HISI_MAX_PERIOD(nr) (GENMASK_ULL((nr) - 1, 0))
 
 /*
@@ -226,6 +225,9 @@ int hisi_uncore_pmu_event_init(struct perf_event *event)
 	hwc->idx		= -1;
 	hwc->config_base	= event->attr.config;
 
+	if (hisi_pmu->ops->check_filter && hisi_pmu->ops->check_filter(event))
+		return -EINVAL;
+
 	/* Enforce to use the same CPU for all events in this PMU */
 	event->cpu = hisi_pmu->on_cpu;
 
diff --git a/drivers/perf/hisilicon/hisi_uncore_pmu.h b/drivers/perf/hisilicon/hisi_uncore_pmu.h
index a8d6d6905f3f..27b6122aa486 100644
--- a/drivers/perf/hisilicon/hisi_uncore_pmu.h
+++ b/drivers/perf/hisilicon/hisi_uncore_pmu.h
@@ -44,9 +44,15 @@
 		return FIELD_GET(GENMASK_ULL(hi, lo), event->attr.config);  \
 	}
 
+#define HISI_GET_EVENTID(ev) (ev->hw.config_base & 0xff)
+
+#define HISI_PMU_EVTYPE_BITS		8
+#define HISI_PMU_EVTYPE_SHIFT(idx)	((idx) % 4 * HISI_PMU_EVTYPE_BITS)
+
 struct hisi_pmu;
 
 struct hisi_uncore_ops {
+	int (*check_filter)(struct perf_event *event);
 	void (*write_evtype)(struct hisi_pmu *, int, u32);
 	int (*get_event_idx)(struct perf_event *);
 	u64 (*read_counter)(struct hisi_pmu *, struct hw_perf_event *);
diff --git a/drivers/perf/hisilicon/hisi_uncore_uc_pmu.c b/drivers/perf/hisilicon/hisi_uncore_uc_pmu.c
new file mode 100644
index 000000000000..d27f28584fd7
--- /dev/null
+++ b/drivers/perf/hisilicon/hisi_uncore_uc_pmu.c
@@ -0,0 +1,577 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * HiSilicon SoC UC (unified cache) uncore Hardware event counters support
+ *
+ * Copyright (C) 2023 HiSilicon Limited
+ *
+ * This code is based on the uncore PMUs like hisi_uncore_l3c_pmu.
+ */
+#include <linux/cpuhotplug.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/list.h>
+#include <linux/mod_devicetable.h>
+#include <linux/property.h>
+
+#include "hisi_uncore_pmu.h"
+
+/* Dynamic CPU hotplug state used by UC PMU */
+static enum cpuhp_state hisi_uc_pmu_online;
+
+/* UC register definition */
+#define HISI_UC_INT_MASK_REG		0x0800
+#define HISI_UC_INT_STS_REG		0x0808
+#define HISI_UC_INT_CLEAR_REG		0x080c
+#define HISI_UC_TRACETAG_CTRL_REG	0x1b2c
+#define HISI_UC_TRACETAG_REQ_MSK	GENMASK(9, 7)
+#define HISI_UC_TRACETAG_MARK_EN	BIT(0)
+#define HISI_UC_TRACETAG_REQ_EN		(HISI_UC_TRACETAG_MARK_EN | BIT(2))
+#define HISI_UC_TRACETAG_SRCID_EN	BIT(3)
+#define HISI_UC_SRCID_CTRL_REG		0x1b40
+#define HISI_UC_SRCID_MSK		GENMASK(14, 1)
+#define HISI_UC_EVENT_CTRL_REG		0x1c00
+#define HISI_UC_EVENT_TRACETAG_EN	BIT(29)
+#define HISI_UC_EVENT_URING_MSK		GENMASK(28, 27)
+#define HISI_UC_EVENT_GLB_EN		BIT(26)
+#define HISI_UC_VERSION_REG		0x1cf0
+#define HISI_UC_EVTYPE_REGn(n)		(0x1d00 + (n) * 4)
+#define HISI_UC_EVTYPE_MASK		GENMASK(7, 0)
+#define HISI_UC_CNTR_REGn(n)		(0x1e00 + (n) * 8)
+
+#define HISI_UC_NR_COUNTERS		0x8
+#define HISI_UC_V2_NR_EVENTS		0xFF
+#define HISI_UC_CNTR_REG_BITS		64
+
+#define HISI_UC_RD_REQ_TRACETAG		0x4
+#define HISI_UC_URING_EVENT_MIN		0x47
+#define HISI_UC_URING_EVENT_MAX		0x59
+
+HISI_PMU_EVENT_ATTR_EXTRACTOR(rd_req_en, config1, 0, 0);
+HISI_PMU_EVENT_ATTR_EXTRACTOR(uring_channel, config1, 5, 4);
+HISI_PMU_EVENT_ATTR_EXTRACTOR(srcid, config1, 19, 6);
+HISI_PMU_EVENT_ATTR_EXTRACTOR(srcid_en, config1, 20, 20);
+
+static int hisi_uc_pmu_check_filter(struct perf_event *event)
+{
+	struct hisi_pmu *uc_pmu = to_hisi_pmu(event->pmu);
+
+	if (hisi_get_srcid_en(event) && !hisi_get_rd_req_en(event)) {
+		dev_err(uc_pmu->dev,
+			"Failed to set srcid: depending on read request enabled!\n");
+		return -EINVAL;
+	}
+
+	if (!hisi_get_uring_channel(event))
+		return 0;
+
+	if ((HISI_GET_EVENTID(event) < HISI_UC_URING_EVENT_MIN) ||
+	    (HISI_GET_EVENTID(event) > HISI_UC_URING_EVENT_MAX))
+		dev_warn(uc_pmu->dev,
+			 "Only events: [%#x ~ %#x] support channel filtering!",
+			 HISI_UC_URING_EVENT_MIN, HISI_UC_URING_EVENT_MAX);
+
+	return 0;
+}
+
+static void hisi_uc_pmu_config_req_tracetag(struct perf_event *event)
+{
+	struct hisi_pmu *uc_pmu = to_hisi_pmu(event->pmu);
+	u32 val;
+
+	if (!hisi_get_rd_req_en(event))
+		return;
+
+	val = readl(uc_pmu->base + HISI_UC_TRACETAG_CTRL_REG);
+
+	/* The request-type has been configured */
+	if (FIELD_GET(HISI_UC_TRACETAG_REQ_MSK, val) == HISI_UC_RD_REQ_TRACETAG)
+		return;
+
+	/* Set request-type for tracetag, only read request is supported! */
+	val &= ~HISI_UC_TRACETAG_REQ_MSK;
+	val |= FIELD_PREP(HISI_UC_TRACETAG_REQ_MSK, HISI_UC_RD_REQ_TRACETAG);
+	val |= HISI_UC_TRACETAG_REQ_EN;
+	writel(val, uc_pmu->base + HISI_UC_TRACETAG_CTRL_REG);
+}
+
+static void hisi_uc_pmu_clear_req_tracetag(struct perf_event *event)
+{
+	struct hisi_pmu *uc_pmu = to_hisi_pmu(event->pmu);
+	u32 val;
+
+	if (!hisi_get_rd_req_en(event))
+		return;
+
+	val = readl(uc_pmu->base + HISI_UC_TRACETAG_CTRL_REG);
+
+	/* Do nothing, the request-type tracetag has been cleaned up */
+	if (FIELD_GET(HISI_UC_TRACETAG_REQ_MSK, val) == 0)
+		return;
+
+	/* Clear request-type */
+	val &= ~HISI_UC_TRACETAG_REQ_MSK;
+	val &= ~HISI_UC_TRACETAG_REQ_EN;
+	writel(val, uc_pmu->base + HISI_UC_TRACETAG_CTRL_REG);
+}
+
+static void hisi_uc_pmu_config_srcid_tracetag(struct perf_event *event)
+{
+	struct hisi_pmu *uc_pmu = to_hisi_pmu(event->pmu);
+	u32 val;
+
+	if (!hisi_get_srcid_en(event))
+		return;
+
+	val = readl(uc_pmu->base + HISI_UC_TRACETAG_CTRL_REG);
+
+	/* Do nothing, the source id has been configured */
+	if (FIELD_GET(HISI_UC_TRACETAG_SRCID_EN, val))
+		return;
+
+	/* Enable source id tracetag */
+	val |= HISI_UC_TRACETAG_SRCID_EN;
+	writel(val, uc_pmu->base + HISI_UC_TRACETAG_CTRL_REG);
+
+	val = readl(uc_pmu->base + HISI_UC_SRCID_CTRL_REG);
+	val &= ~HISI_UC_SRCID_MSK;
+	val |= FIELD_PREP(HISI_UC_SRCID_MSK, hisi_get_srcid(event));
+	writel(val, uc_pmu->base + HISI_UC_SRCID_CTRL_REG);
+
+	/* Depend on request-type tracetag enabled */
+	hisi_uc_pmu_config_req_tracetag(event);
+}
+
+static void hisi_uc_pmu_clear_srcid_tracetag(struct perf_event *event)
+{
+	struct hisi_pmu *uc_pmu = to_hisi_pmu(event->pmu);
+	u32 val;
+
+	if (!hisi_get_srcid_en(event))
+		return;
+
+	val = readl(uc_pmu->base + HISI_UC_TRACETAG_CTRL_REG);
+
+	/* Do nothing, the source id has been cleaned up */
+	if (FIELD_GET(HISI_UC_TRACETAG_SRCID_EN, val) == 0)
+		return;
+
+	hisi_uc_pmu_clear_req_tracetag(event);
+
+	/* Disable source id tracetag */
+	val &= ~HISI_UC_TRACETAG_SRCID_EN;
+	writel(val, uc_pmu->base + HISI_UC_TRACETAG_CTRL_REG);
+
+	val = readl(uc_pmu->base + HISI_UC_SRCID_CTRL_REG);
+	val &= ~HISI_UC_SRCID_MSK;
+	writel(val, uc_pmu->base + HISI_UC_SRCID_CTRL_REG);
+}
+
+static void hisi_uc_pmu_config_uring_channel(struct perf_event *event)
+{
+	struct hisi_pmu *uc_pmu = to_hisi_pmu(event->pmu);
+	u32 uring_channel = hisi_get_uring_channel(event);
+	u32 val;
+
+	/* Do nothing if not being set or is set explicitly to zero (default) */
+	if (uring_channel == 0)
+		return;
+
+	val = readl(uc_pmu->base + HISI_UC_EVENT_CTRL_REG);
+
+	/* Do nothing, the uring_channel has been configured */
+	if (uring_channel == FIELD_GET(HISI_UC_EVENT_URING_MSK, val))
+		return;
+
+	val &= ~HISI_UC_EVENT_URING_MSK;
+	val |= FIELD_PREP(HISI_UC_EVENT_URING_MSK, uring_channel);
+	writel(val, uc_pmu->base + HISI_UC_EVENT_CTRL_REG);
+}
+
+static void hisi_uc_pmu_clear_uring_channel(struct perf_event *event)
+{
+	struct hisi_pmu *uc_pmu = to_hisi_pmu(event->pmu);
+	u32 val;
+
+	/* Do nothing if not being set or is set explicitly to zero (default) */
+	if (hisi_get_uring_channel(event) == 0)
+		return;
+
+	val = readl(uc_pmu->base + HISI_UC_EVENT_CTRL_REG);
+
+	/* Do nothing, the uring_channel has been cleaned up */
+	if (FIELD_GET(HISI_UC_EVENT_URING_MSK, val) == 0)
+		return;
+
+	val &= ~HISI_UC_EVENT_URING_MSK;
+	writel(val, uc_pmu->base + HISI_UC_EVENT_CTRL_REG);
+}
+
+static void hisi_uc_pmu_enable_filter(struct perf_event *event)
+{
+	if (event->attr.config1 == 0)
+		return;
+
+	hisi_uc_pmu_config_uring_channel(event);
+	hisi_uc_pmu_config_req_tracetag(event);
+	hisi_uc_pmu_config_srcid_tracetag(event);
+}
+
+static void hisi_uc_pmu_disable_filter(struct perf_event *event)
+{
+	if (event->attr.config1 == 0)
+		return;
+
+	hisi_uc_pmu_clear_srcid_tracetag(event);
+	hisi_uc_pmu_clear_req_tracetag(event);
+	hisi_uc_pmu_clear_uring_channel(event);
+}
+
+static void hisi_uc_pmu_write_evtype(struct hisi_pmu *uc_pmu, int idx, u32 type)
+{
+	u32 val;
+
+	/*
+	 * Select the appropriate event select register.
+	 * There are 2 32-bit event select registers for the
+	 * 8 hardware counters, each event code is 8-bit wide.
+	 */
+	val = readl(uc_pmu->base + HISI_UC_EVTYPE_REGn(idx / 4));
+	val &= ~(HISI_UC_EVTYPE_MASK << HISI_PMU_EVTYPE_SHIFT(idx));
+	val |= (type << HISI_PMU_EVTYPE_SHIFT(idx));
+	writel(val, uc_pmu->base + HISI_UC_EVTYPE_REGn(idx / 4));
+}
+
+static void hisi_uc_pmu_start_counters(struct hisi_pmu *uc_pmu)
+{
+	u32 val;
+
+	val = readl(uc_pmu->base + HISI_UC_EVENT_CTRL_REG);
+	val |= HISI_UC_EVENT_GLB_EN;
+	writel(val, uc_pmu->base + HISI_UC_EVENT_CTRL_REG);
+}
+
+static void hisi_uc_pmu_stop_counters(struct hisi_pmu *uc_pmu)
+{
+	u32 val;
+
+	val = readl(uc_pmu->base + HISI_UC_EVENT_CTRL_REG);
+	val &= ~HISI_UC_EVENT_GLB_EN;
+	writel(val, uc_pmu->base + HISI_UC_EVENT_CTRL_REG);
+}
+
+static void hisi_uc_pmu_enable_counter(struct hisi_pmu *uc_pmu,
+					struct hw_perf_event *hwc)
+{
+	u32 val;
+
+	/* Enable counter index */
+	val = readl(uc_pmu->base + HISI_UC_EVENT_CTRL_REG);
+	val |= (1 << hwc->idx);
+	writel(val, uc_pmu->base + HISI_UC_EVENT_CTRL_REG);
+}
+
+static void hisi_uc_pmu_disable_counter(struct hisi_pmu *uc_pmu,
+					struct hw_perf_event *hwc)
+{
+	u32 val;
+
+	/* Clear counter index */
+	val = readl(uc_pmu->base + HISI_UC_EVENT_CTRL_REG);
+	val &= ~(1 << hwc->idx);
+	writel(val, uc_pmu->base + HISI_UC_EVENT_CTRL_REG);
+}
+
+static u64 hisi_uc_pmu_read_counter(struct hisi_pmu *uc_pmu,
+				    struct hw_perf_event *hwc)
+{
+	return readq(uc_pmu->base + HISI_UC_CNTR_REGn(hwc->idx));
+}
+
+static void hisi_uc_pmu_write_counter(struct hisi_pmu *uc_pmu,
+				      struct hw_perf_event *hwc, u64 val)
+{
+	hisi_uc_pmu_start_counters(uc_pmu);
+	writeq(val, uc_pmu->base + HISI_UC_CNTR_REGn(hwc->idx));
+}
+
+static void hisi_uc_pmu_enable_counter_int(struct hisi_pmu *uc_pmu,
+					   struct hw_perf_event *hwc)
+{
+	u32 val;
+
+	val = readl(uc_pmu->base + HISI_UC_INT_MASK_REG);
+	val &= ~(1 << hwc->idx);
+	writel(val, uc_pmu->base + HISI_UC_INT_MASK_REG);
+}
+
+static void hisi_uc_pmu_disable_counter_int(struct hisi_pmu *uc_pmu,
+					    struct hw_perf_event *hwc)
+{
+	u32 val;
+
+	val = readl(uc_pmu->base + HISI_UC_INT_MASK_REG);
+	val |= (1 << hwc->idx);
+	writel(val, uc_pmu->base + HISI_UC_INT_MASK_REG);
+}
+
+static u32 hisi_uc_pmu_get_int_status(struct hisi_pmu *uc_pmu)
+{
+	return readl(uc_pmu->base + HISI_UC_INT_STS_REG);
+}
+
+static void hisi_uc_pmu_clear_int_status(struct hisi_pmu *uc_pmu, int idx)
+{
+	writel(1 << idx, uc_pmu->base + HISI_UC_INT_CLEAR_REG);
+}
+
+static int hisi_uc_pmu_init_data(struct platform_device *pdev,
+				 struct hisi_pmu *uc_pmu)
+{
+	/*
+	 * Use SCCL (Super CPU Cluster) ID and CCL (CPU Cluster) ID to
+	 * identify the topology information of UC PMU devices in the chip.
+	 */
+	if (device_property_read_u32(&pdev->dev, "hisilicon,scl-id",
+				     &uc_pmu->sccl_id)) {
+		dev_err(&pdev->dev, "Can not read uc sccl-id!\n");
+		return -EINVAL;
+	}
+
+	if (device_property_read_u32(&pdev->dev, "hisilicon,ccl-id",
+				     &uc_pmu->ccl_id)) {
+		dev_err(&pdev->dev, "Can not read uc ccl-id!\n");
+		return -EINVAL;
+	}
+
+	if (device_property_read_u32(&pdev->dev, "hisilicon,sub-id",
+				     &uc_pmu->sub_id)) {
+		dev_err(&pdev->dev, "Can not read sub-id!\n");
+		return -EINVAL;
+	}
+
+	uc_pmu->base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(uc_pmu->base)) {
+		dev_err(&pdev->dev, "ioremap failed for uc_pmu resource\n");
+		return PTR_ERR(uc_pmu->base);
+	}
+
+	uc_pmu->identifier = readl(uc_pmu->base + HISI_UC_VERSION_REG);
+
+	return 0;
+}
+
+static struct attribute *hisi_uc_pmu_format_attr[] = {
+	HISI_PMU_FORMAT_ATTR(event, "config:0-7"),
+	HISI_PMU_FORMAT_ATTR(rd_req_en, "config1:0-0"),
+	HISI_PMU_FORMAT_ATTR(uring_channel, "config1:4-5"),
+	HISI_PMU_FORMAT_ATTR(srcid, "config1:6-19"),
+	HISI_PMU_FORMAT_ATTR(srcid_en, "config1:20-20"),
+	NULL
+};
+
+static const struct attribute_group hisi_uc_pmu_format_group = {
+	.name = "format",
+	.attrs = hisi_uc_pmu_format_attr,
+};
+
+static struct attribute *hisi_uc_pmu_events_attr[] = {
+	HISI_PMU_EVENT_ATTR(sq_time,		0x00),
+	HISI_PMU_EVENT_ATTR(pq_time,		0x01),
+	HISI_PMU_EVENT_ATTR(hbm_time,		0x02),
+	HISI_PMU_EVENT_ATTR(iq_comp_time_cring,	0x03),
+	HISI_PMU_EVENT_ATTR(iq_comp_time_uring,	0x05),
+	HISI_PMU_EVENT_ATTR(cpu_rd,		0x10),
+	HISI_PMU_EVENT_ATTR(cpu_rd64,		0x17),
+	HISI_PMU_EVENT_ATTR(cpu_rs64,		0x19),
+	HISI_PMU_EVENT_ATTR(cpu_mru,		0x1a),
+	HISI_PMU_EVENT_ATTR(cycles,		0x9c),
+	HISI_PMU_EVENT_ATTR(spipe_hit,		0xb3),
+	HISI_PMU_EVENT_ATTR(hpipe_hit,		0xdb),
+	HISI_PMU_EVENT_ATTR(cring_rxdat_cnt,	0xfa),
+	HISI_PMU_EVENT_ATTR(cring_txdat_cnt,	0xfb),
+	HISI_PMU_EVENT_ATTR(uring_rxdat_cnt,	0xfc),
+	HISI_PMU_EVENT_ATTR(uring_txdat_cnt,	0xfd),
+	NULL
+};
+
+static const struct attribute_group hisi_uc_pmu_events_group = {
+	.name = "events",
+	.attrs = hisi_uc_pmu_events_attr,
+};
+
+static DEVICE_ATTR(cpumask, 0444, hisi_cpumask_sysfs_show, NULL);
+
+static struct attribute *hisi_uc_pmu_cpumask_attrs[] = {
+	&dev_attr_cpumask.attr,
+	NULL,
+};
+
+static const struct attribute_group hisi_uc_pmu_cpumask_attr_group = {
+	.attrs = hisi_uc_pmu_cpumask_attrs,
+};
+
+static struct device_attribute hisi_uc_pmu_identifier_attr =
+	__ATTR(identifier, 0444, hisi_uncore_pmu_identifier_attr_show, NULL);
+
+static struct attribute *hisi_uc_pmu_identifier_attrs[] = {
+	&hisi_uc_pmu_identifier_attr.attr,
+	NULL
+};
+
+static const struct attribute_group hisi_uc_pmu_identifier_group = {
+	.attrs = hisi_uc_pmu_identifier_attrs,
+};
+
+static const struct attribute_group *hisi_uc_pmu_attr_groups[] = {
+	&hisi_uc_pmu_format_group,
+	&hisi_uc_pmu_events_group,
+	&hisi_uc_pmu_cpumask_attr_group,
+	&hisi_uc_pmu_identifier_group,
+	NULL
+};
+
+static const struct hisi_uncore_ops hisi_uncore_uc_pmu_ops = {
+	.check_filter		= hisi_uc_pmu_check_filter,
+	.write_evtype		= hisi_uc_pmu_write_evtype,
+	.get_event_idx		= hisi_uncore_pmu_get_event_idx,
+	.start_counters		= hisi_uc_pmu_start_counters,
+	.stop_counters		= hisi_uc_pmu_stop_counters,
+	.enable_counter		= hisi_uc_pmu_enable_counter,
+	.disable_counter	= hisi_uc_pmu_disable_counter,
+	.enable_counter_int	= hisi_uc_pmu_enable_counter_int,
+	.disable_counter_int	= hisi_uc_pmu_disable_counter_int,
+	.write_counter		= hisi_uc_pmu_write_counter,
+	.read_counter		= hisi_uc_pmu_read_counter,
+	.get_int_status		= hisi_uc_pmu_get_int_status,
+	.clear_int_status	= hisi_uc_pmu_clear_int_status,
+	.enable_filter		= hisi_uc_pmu_enable_filter,
+	.disable_filter		= hisi_uc_pmu_disable_filter,
+};
+
+static int hisi_uc_pmu_dev_probe(struct platform_device *pdev,
+				 struct hisi_pmu *uc_pmu)
+{
+	int ret;
+
+	ret = hisi_uc_pmu_init_data(pdev, uc_pmu);
+	if (ret)
+		return ret;
+
+	ret = hisi_uncore_pmu_init_irq(uc_pmu, pdev);
+	if (ret)
+		return ret;
+
+	uc_pmu->pmu_events.attr_groups = hisi_uc_pmu_attr_groups;
+	uc_pmu->check_event = HISI_UC_EVTYPE_MASK;
+	uc_pmu->ops = &hisi_uncore_uc_pmu_ops;
+	uc_pmu->counter_bits = HISI_UC_CNTR_REG_BITS;
+	uc_pmu->num_counters = HISI_UC_NR_COUNTERS;
+	uc_pmu->dev = &pdev->dev;
+	uc_pmu->on_cpu = -1;
+
+	return 0;
+}
+
+static void hisi_uc_pmu_remove_cpuhp_instance(void *hotplug_node)
+{
+	cpuhp_state_remove_instance_nocalls(hisi_uc_pmu_online, hotplug_node);
+}
+
+static void hisi_uc_pmu_unregister_pmu(void *pmu)
+{
+	perf_pmu_unregister(pmu);
+}
+
+static int hisi_uc_pmu_probe(struct platform_device *pdev)
+{
+	struct hisi_pmu *uc_pmu;
+	char *name;
+	int ret;
+
+	uc_pmu = devm_kzalloc(&pdev->dev, sizeof(*uc_pmu), GFP_KERNEL);
+	if (!uc_pmu)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, uc_pmu);
+
+	ret = hisi_uc_pmu_dev_probe(pdev, uc_pmu);
+	if (ret)
+		return ret;
+
+	name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "hisi_sccl%d_uc%d_%u",
+			      uc_pmu->sccl_id, uc_pmu->ccl_id, uc_pmu->sub_id);
+	if (!name)
+		return -ENOMEM;
+
+	ret = cpuhp_state_add_instance(hisi_uc_pmu_online, &uc_pmu->node);
+	if (ret)
+		return dev_err_probe(&pdev->dev, ret, "Error registering hotplug\n");
+
+	ret = devm_add_action_or_reset(&pdev->dev,
+				       hisi_uc_pmu_remove_cpuhp_instance,
+				       &uc_pmu->node);
+	if (ret)
+		return ret;
+
+	hisi_pmu_init(uc_pmu, THIS_MODULE);
+
+	ret = perf_pmu_register(&uc_pmu->pmu, name, -1);
+	if (ret)
+		return ret;
+
+	return devm_add_action_or_reset(&pdev->dev,
+					hisi_uc_pmu_unregister_pmu,
+					&uc_pmu->pmu);
+}
+
+static const struct acpi_device_id hisi_uc_pmu_acpi_match[] = {
+	{ "HISI0291", },
+	{}
+};
+MODULE_DEVICE_TABLE(acpi, hisi_uc_pmu_acpi_match);
+
+static struct platform_driver hisi_uc_pmu_driver = {
+	.driver = {
+		.name = "hisi_uc_pmu",
+		.acpi_match_table = hisi_uc_pmu_acpi_match,
+		/*
+		 * We have not worked out a safe bind/unbind process,
+		 * so this is not supported yet.
+		 */
+		.suppress_bind_attrs = true,
+	},
+	.probe = hisi_uc_pmu_probe,
+};
+
+static int __init hisi_uc_pmu_module_init(void)
+{
+	int ret;
+
+	ret = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN,
+				      "perf/hisi/uc:online",
+				      hisi_uncore_pmu_online_cpu,
+				      hisi_uncore_pmu_offline_cpu);
+	if (ret < 0) {
+		pr_err("UC PMU: Error setup hotplug, ret = %d\n", ret);
+		return ret;
+	}
+	hisi_uc_pmu_online = ret;
+
+	ret = platform_driver_register(&hisi_uc_pmu_driver);
+	if (ret)
+		cpuhp_remove_multi_state(hisi_uc_pmu_online);
+
+	return ret;
+}
+module_init(hisi_uc_pmu_module_init);
+
+static void __exit hisi_uc_pmu_module_exit(void)
+{
+	platform_driver_unregister(&hisi_uc_pmu_driver);
+	cpuhp_remove_multi_state(hisi_uc_pmu_online);
+}
+module_exit(hisi_uc_pmu_module_exit);
+
+MODULE_DESCRIPTION("HiSilicon SoC UC uncore PMU driver");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Junhao He <hejunhao3@huawei.com>");
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 3/3] docs: perf: Add new description for HiSilicon UC PMU
  2023-05-31 10:46 [PATCH v2 0/3] Add support for HiSilicon SoC uncore PMU Junhao He
  2023-05-31 10:46 ` [PATCH v2 1/3] drivers/perf: hisi: Add support for HiSilicon H60PA and PAv3 PMU driver Junhao He
  2023-05-31 10:46 ` [PATCH v2 2/3] drivers/perf: hisi: Add support for HiSilicon UC " Junhao He
@ 2023-05-31 10:46 ` Junhao He
  2023-05-31 16:00   ` Jonathan Cameron
  2023-06-01  6:44   ` Yicong Yang
  2 siblings, 2 replies; 12+ messages in thread
From: Junhao He @ 2023-05-31 10:46 UTC (permalink / raw)
  To: will, jonathan.cameron, linux-kernel, mark.rutland
  Cc: linux-arm-kernel, linux-doc, linuxarm, yangyicong, shenyang39,
	prime.zeng, hejunhao3

A new function is added on HiSilicon uncore UC PMU.

The UC PMU support to filter statistical information based on
the specified tx request uring channel. Make user configuration
through "uring_channel" parameter.
Document them to provide guidance on how to use them.

Signed-off-by: Junhao He <hejunhao3@huawei.com>
---
 Documentation/admin-guide/perf/hisi-pmu.rst | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/Documentation/admin-guide/perf/hisi-pmu.rst b/Documentation/admin-guide/perf/hisi-pmu.rst
index 546979360513..939a524fa1d6 100644
--- a/Documentation/admin-guide/perf/hisi-pmu.rst
+++ b/Documentation/admin-guide/perf/hisi-pmu.rst
@@ -98,6 +98,14 @@ CCL/ICL-ID. For I/O die, the ICL-ID is followed by:
 5'b00011: HAC_ICL;
 5'b10000: PCIe_ICL;
 
+(e) uring_channel: UC PMU events 0x47~0x59 supports filtering by tx request
+uring channel. It is 2 bits. Some important codes are as follows:
+2'b11: count the events which sent to the uring_ext (MATA) channel;
+2'b01: is the same as 2'b11;
+2'b10: count the events which sent to the uring (non-MATA) channel;
+2'b00: default value, count the events which sent to the both uring and
+       uring_ext channel;
+
 Users could configure IDs to count data come from specific CCL/ICL, by setting
 srcid_cmd & srcid_msk, and data desitined for specific CCL/ICL by setting
 tgtid_cmd & tgtid_msk. A set bit in srcid_msk/tgtid_msk means the PMU will not
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/3] drivers/perf: hisi: Add support for HiSilicon H60PA and PAv3 PMU driver
  2023-05-31 10:46 ` [PATCH v2 1/3] drivers/perf: hisi: Add support for HiSilicon H60PA and PAv3 PMU driver Junhao He
@ 2023-05-31 15:45   ` Jonathan Cameron
  2023-06-01  6:40   ` Yicong Yang
  1 sibling, 0 replies; 12+ messages in thread
From: Jonathan Cameron @ 2023-05-31 15:45 UTC (permalink / raw)
  To: Junhao He
  Cc: will, linux-kernel, mark.rutland, linux-arm-kernel, linux-doc,
	linuxarm, yangyicong, shenyang39, prime.zeng

On Wed, 31 May 2023 18:46:23 +0800
Junhao He <hejunhao3@huawei.com> wrote:

> Compared to the original PA device, H60PA offers higher bandwidth.
> The H60PA is a new device and we use HID to differentiate them.
> 
> The events supported by PAv3 and PAv2 are different. They use the
> same HID. The PMU version register is used in the driver to
> distinguish different versions.
> 
> For each H60PA PMU, except for the overflow interrupt register, other
> functions of the H60PA PMU are the same as the original PA PMU module.
> It has 8-programable counters and each counter is free-running.
> Interrupt is supported to handle counter (64-bits) overflow.
> 
> Signed-off-by: Junhao He <hejunhao3@huawei.com>

Hi,

I would have slightly preferred to see the refactoring done as a first
patch and then the new device supported added in a second, but as that
second patch would only be a few lines I don't mind that much.

The result looks fine to me.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 2/3] drivers/perf: hisi: Add support for HiSilicon UC PMU driver
  2023-05-31 10:46 ` [PATCH v2 2/3] drivers/perf: hisi: Add support for HiSilicon UC " Junhao He
@ 2023-05-31 15:59   ` Jonathan Cameron
  2023-06-01  6:53     ` Yicong Yang
  2023-06-07 11:00     ` hejunhao
  2023-06-01  6:41   ` Yicong Yang
  1 sibling, 2 replies; 12+ messages in thread
From: Jonathan Cameron @ 2023-05-31 15:59 UTC (permalink / raw)
  To: Junhao He
  Cc: will, linux-kernel, mark.rutland, linux-arm-kernel, linux-doc,
	linuxarm, yangyicong, shenyang39, prime.zeng

On Wed, 31 May 2023 18:46:24 +0800
Junhao He <hejunhao3@huawei.com> wrote:

Hi Junhao,

A few small comments inline.

> On HiSilicon Hip09 platform, there is a UC (unified cache) module
> on each chip SCCL (Super CPU Cluster). UC is a cache that provides
> coherence between NUMA and UMA domains. It is located between L2
> and Memory System. While PA uncore PMU model is the same as other
> Hip09 PMU modules and many PMU events are supported. 

I don't follow what this sentence means.  Normally you'd have
While A, B is different..


> Let's support
> the PMU driver using the HiSilicon uncore PMU framework.
> 
> * rd_req_en : rd_req_en is the abbreviation of read request tracetag enable
> and allows user to count only read operations.
> details are listed in the hisi-pmu document.
Details are .. Also no need for the ine break
  and allows user to count only read operations. Details are listed
  in the hisi-pmu document at ....

> 
> * srcid_en & srcid: allows user to filter statistics that come from

Allows
for consistency with the uring_channel description that follows.

> specific CPU/ICL by configuration source ID.
> 
> * uring_channel: Allows users to filter statistical information based on
> the specified tx request uring channel.
> uring_channel only supported events: [0x47 ~ 0x59].
> 
> Signed-off-by: Junhao He <hejunhao3@huawei.com>


> diff --git a/drivers/perf/hisilicon/hisi_uncore_uc_pmu.c b/drivers/perf/hisilicon/hisi_uncore_uc_pmu.c
> new file mode 100644
> index 000000000000..d27f28584fd7
> --- /dev/null
> +++ b/drivers/perf/hisilicon/hisi_uncore_uc_pmu.c
> @@ -0,0 +1,577 @@
...




> +static int hisi_uc_pmu_init_data(struct platform_device *pdev,
> +				 struct hisi_pmu *uc_pmu)
> +{
> +	/*
> +	 * Use SCCL (Super CPU Cluster) ID and CCL (CPU Cluster) ID to
> +	 * identify the topology information of UC PMU devices in the chip.
> +	 */

From patch description, I'd assume there is only one of these
per sccl so why do we care about the cluster level or the sub-id?
Perhaps that description is missleading?

> +	if (device_property_read_u32(&pdev->dev, "hisilicon,scl-id",
> +				     &uc_pmu->sccl_id)) {
> +		dev_err(&pdev->dev, "Can not read uc sccl-id!\n");
> +		return -EINVAL;
> +	}
> +
> +	if (device_property_read_u32(&pdev->dev, "hisilicon,ccl-id",
> +				     &uc_pmu->ccl_id)) {
> +		dev_err(&pdev->dev, "Can not read uc ccl-id!\n");
> +		return -EINVAL;
> +	}
> +
> +	if (device_property_read_u32(&pdev->dev, "hisilicon,sub-id",
> +				     &uc_pmu->sub_id)) {
> +		dev_err(&pdev->dev, "Can not read sub-id!\n");
> +		return -EINVAL;
> +	}
> +
> +	uc_pmu->base = devm_platform_ioremap_resource(pdev, 0);
> +	if (IS_ERR(uc_pmu->base)) {
> +		dev_err(&pdev->dev, "ioremap failed for uc_pmu resource\n");
> +		return PTR_ERR(uc_pmu->base);
> +	}
> +
> +	uc_pmu->identifier = readl(uc_pmu->base + HISI_UC_VERSION_REG);
> +
> +	return 0;
> +}


> +static struct platform_driver hisi_uc_pmu_driver = {
> +	.driver = {
> +		.name = "hisi_uc_pmu",
> +		.acpi_match_table = hisi_uc_pmu_acpi_match,
> +		/*
> +		 * We have not worked out a safe bind/unbind process,
> +		 * so this is not supported yet.

If you can reference more info on this that would be great.
Perhaps a thread talking about why?

> +		 */
> +		.suppress_bind_attrs = true,
> +	},
> +	.probe = hisi_uc_pmu_probe,
> +};

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 3/3] docs: perf: Add new description for HiSilicon UC PMU
  2023-05-31 10:46 ` [PATCH v2 3/3] docs: perf: Add new description for HiSilicon UC PMU Junhao He
@ 2023-05-31 16:00   ` Jonathan Cameron
  2023-06-01  6:44   ` Yicong Yang
  1 sibling, 0 replies; 12+ messages in thread
From: Jonathan Cameron @ 2023-05-31 16:00 UTC (permalink / raw)
  To: Junhao He
  Cc: will, linux-kernel, mark.rutland, linux-arm-kernel, linux-doc,
	linuxarm, yangyicong, shenyang39, prime.zeng

On Wed, 31 May 2023 18:46:25 +0800
Junhao He <hejunhao3@huawei.com> wrote:

> A new function is added on HiSilicon uncore UC PMU.
> 
> The UC PMU support to filter statistical information based on
> the specified tx request uring channel. Make user configuration
> through "uring_channel" parameter.
> Document them to provide guidance on how to use them.
> 
> Signed-off-by: Junhao He <hejunhao3@huawei.com>
Seems reasonable to me.
Reviewed-by: Jonathan Cameron <Jonthan.Cameron@huawei.com>

> ---
>  Documentation/admin-guide/perf/hisi-pmu.rst | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/Documentation/admin-guide/perf/hisi-pmu.rst b/Documentation/admin-guide/perf/hisi-pmu.rst
> index 546979360513..939a524fa1d6 100644
> --- a/Documentation/admin-guide/perf/hisi-pmu.rst
> +++ b/Documentation/admin-guide/perf/hisi-pmu.rst
> @@ -98,6 +98,14 @@ CCL/ICL-ID. For I/O die, the ICL-ID is followed by:
>  5'b00011: HAC_ICL;
>  5'b10000: PCIe_ICL;
>  
> +(e) uring_channel: UC PMU events 0x47~0x59 supports filtering by tx request
> +uring channel. It is 2 bits. Some important codes are as follows:
> +2'b11: count the events which sent to the uring_ext (MATA) channel;
> +2'b01: is the same as 2'b11;
> +2'b10: count the events which sent to the uring (non-MATA) channel;
> +2'b00: default value, count the events which sent to the both uring and
> +       uring_ext channel;
> +
>  Users could configure IDs to count data come from specific CCL/ICL, by setting
>  srcid_cmd & srcid_msk, and data desitined for specific CCL/ICL by setting
>  tgtid_cmd & tgtid_msk. A set bit in srcid_msk/tgtid_msk means the PMU will not


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/3] drivers/perf: hisi: Add support for HiSilicon H60PA and PAv3 PMU driver
  2023-05-31 10:46 ` [PATCH v2 1/3] drivers/perf: hisi: Add support for HiSilicon H60PA and PAv3 PMU driver Junhao He
  2023-05-31 15:45   ` Jonathan Cameron
@ 2023-06-01  6:40   ` Yicong Yang
  1 sibling, 0 replies; 12+ messages in thread
From: Yicong Yang @ 2023-06-01  6:40 UTC (permalink / raw)
  To: Junhao He, will, jonathan.cameron, linux-kernel, mark.rutland
  Cc: yangyicong, linux-arm-kernel, linux-doc, linuxarm, shenyang39,
	prime.zeng

On 2023/5/31 18:46, Junhao He wrote:
> Compared to the original PA device, H60PA offers higher bandwidth.
> The H60PA is a new device and we use HID to differentiate them.
> 
> The events supported by PAv3 and PAv2 are different. They use the
> same HID. The PMU version register is used in the driver to
> distinguish different versions.
> 
> For each H60PA PMU, except for the overflow interrupt register, other
> functions of the H60PA PMU are the same as the original PA PMU module.
> It has 8-programable counters and each counter is free-running.
> Interrupt is supported to handle counter (64-bits) overflow.
> 
> Signed-off-by: Junhao He <hejunhao3@huawei.com>

Reviewed-by: Yicong Yang <yangyicong@hisilicon.com>

> ---
>  drivers/perf/hisilicon/hisi_uncore_pa_pmu.c | 142 +++++++++++++++++---
>  drivers/perf/hisilicon/hisi_uncore_pmu.h    |   9 ++
>  2 files changed, 136 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/perf/hisilicon/hisi_uncore_pa_pmu.c b/drivers/perf/hisilicon/hisi_uncore_pa_pmu.c
> index 71b6687d6696..c1b7180aadc1 100644
> --- a/drivers/perf/hisilicon/hisi_uncore_pa_pmu.c
> +++ b/drivers/perf/hisilicon/hisi_uncore_pa_pmu.c
> @@ -22,9 +22,15 @@
>  #define PA_TT_CTRL			0x1c08
>  #define PA_TGTID_CTRL			0x1c14
>  #define PA_SRCID_CTRL			0x1c18
> +
> +/* H32 PA interrupt registers */
>  #define PA_INT_MASK			0x1c70
>  #define PA_INT_STATUS			0x1c78
>  #define PA_INT_CLEAR			0x1c7c
> +
> +#define H60PA_INT_STATUS		0x1c70
> +#define H60PA_INT_MASK			0x1c74
> +
>  #define PA_EVENT_TYPE0			0x1c80
>  #define PA_PMU_VERSION			0x1cf0
>  #define PA_EVENT_CNT0_L			0x1d00
> @@ -46,6 +52,12 @@ HISI_PMU_EVENT_ATTR_EXTRACTOR(srcid_cmd, config1, 32, 22);
>  HISI_PMU_EVENT_ATTR_EXTRACTOR(srcid_msk, config1, 43, 33);
>  HISI_PMU_EVENT_ATTR_EXTRACTOR(tracetag_en, config1, 44, 44);
>  
> +struct hisi_pa_pmu_int_regs {
> +	u32 mask_offset;
> +	u32 clear_offset;
> +	u32 status_offset;
> +};
> +
>  static void hisi_pa_pmu_enable_tracetag(struct perf_event *event)
>  {
>  	struct hisi_pmu *pa_pmu = to_hisi_pmu(event->pmu);
> @@ -219,44 +231,50 @@ static void hisi_pa_pmu_disable_counter(struct hisi_pmu *pa_pmu,
>  static void hisi_pa_pmu_enable_counter_int(struct hisi_pmu *pa_pmu,
>  					   struct hw_perf_event *hwc)
>  {
> +	struct hisi_pa_pmu_int_regs *regs = pa_pmu->dev_info->private;
>  	u32 val;
>  
>  	/* Write 0 to enable interrupt */
> -	val = readl(pa_pmu->base + PA_INT_MASK);
> +	val = readl(pa_pmu->base + regs->mask_offset);
>  	val &= ~(1 << hwc->idx);
> -	writel(val, pa_pmu->base + PA_INT_MASK);
> +	writel(val, pa_pmu->base + regs->mask_offset);
>  }
>  
>  static void hisi_pa_pmu_disable_counter_int(struct hisi_pmu *pa_pmu,
>  					    struct hw_perf_event *hwc)
>  {
> +	struct hisi_pa_pmu_int_regs *regs = pa_pmu->dev_info->private;
>  	u32 val;
>  
>  	/* Write 1 to mask interrupt */
> -	val = readl(pa_pmu->base + PA_INT_MASK);
> +	val = readl(pa_pmu->base + regs->mask_offset);
>  	val |= 1 << hwc->idx;
> -	writel(val, pa_pmu->base + PA_INT_MASK);
> +	writel(val, pa_pmu->base + regs->mask_offset);
>  }
>  
>  static u32 hisi_pa_pmu_get_int_status(struct hisi_pmu *pa_pmu)
>  {
> -	return readl(pa_pmu->base + PA_INT_STATUS);
> +	struct hisi_pa_pmu_int_regs *regs = pa_pmu->dev_info->private;
> +
> +	return readl(pa_pmu->base + regs->status_offset);
>  }
>  
>  static void hisi_pa_pmu_clear_int_status(struct hisi_pmu *pa_pmu, int idx)
>  {
> -	writel(1 << idx, pa_pmu->base + PA_INT_CLEAR);
> -}
> +	struct hisi_pa_pmu_int_regs *regs = pa_pmu->dev_info->private;
>  
> -static const struct acpi_device_id hisi_pa_pmu_acpi_match[] = {
> -	{ "HISI0273", },
> -	{}
> -};
> -MODULE_DEVICE_TABLE(acpi, hisi_pa_pmu_acpi_match);
> +	writel(1 << idx, pa_pmu->base + regs->clear_offset);
> +}
>  
>  static int hisi_pa_pmu_init_data(struct platform_device *pdev,
>  				   struct hisi_pmu *pa_pmu)
>  {
> +	const struct hisi_pmu_dev_info *pa_pmu_info;
> +
> +	pa_pmu_info = device_get_match_data(&pdev->dev);
> +	if (!pa_pmu_info)
> +		return -ENODEV;
> +
>  	/*
>  	 * As PA PMU is in a SICL, use the SICL_ID and the index ID
>  	 * to identify the PA PMU.
> @@ -284,6 +302,15 @@ static int hisi_pa_pmu_init_data(struct platform_device *pdev,
>  
>  	pa_pmu->identifier = readl(pa_pmu->base + PA_PMU_VERSION);
>  
> +	/* When running on v3 or later, returns the largest version supported */
> +	if (pa_pmu->identifier >= HISI_PMU_V3)
> +		pa_pmu->dev_info = &pa_pmu_info[2];
> +	else if (HISI_PMU_V2)
> +		pa_pmu->dev_info = &pa_pmu_info[1];
> +
> +	if (!pa_pmu->dev_info || !pa_pmu->dev_info->name)
> +		return -EINVAL;
> +
>  	return 0;
>  }
>  
> @@ -314,6 +341,32 @@ static const struct attribute_group hisi_pa_pmu_v2_events_group = {
>  	.attrs = hisi_pa_pmu_v2_events_attr,
>  };
>  
> +static struct attribute *hisi_pa_pmu_v3_events_attr[] = {
> +	HISI_PMU_EVENT_ATTR(tx_req,	0x0),
> +	HISI_PMU_EVENT_ATTR(tx_dat,	0x1),
> +	HISI_PMU_EVENT_ATTR(tx_snp,	0x2),
> +	HISI_PMU_EVENT_ATTR(rx_req,	0x7),
> +	HISI_PMU_EVENT_ATTR(rx_dat,	0x8),
> +	HISI_PMU_EVENT_ATTR(rx_snp,	0x9),
> +	NULL
> +};
> +
> +static const struct attribute_group hisi_pa_pmu_v3_events_group = {
> +	.name = "events",
> +	.attrs = hisi_pa_pmu_v3_events_attr,
> +};
> +
> +static struct attribute *hisi_h60pa_pmu_events_attr[] = {
> +	HISI_PMU_EVENT_ATTR(rx_flit,	0x50),
> +	HISI_PMU_EVENT_ATTR(tx_flit,	0x65),
> +	NULL
> +};
> +
> +static const struct attribute_group hisi_h60pa_pmu_events_group = {
> +	.name = "events",
> +	.attrs = hisi_h60pa_pmu_events_attr,
> +};
> +
>  static DEVICE_ATTR(cpumask, 0444, hisi_cpumask_sysfs_show, NULL);
>  
>  static struct attribute *hisi_pa_pmu_cpumask_attrs[] = {
> @@ -345,6 +398,57 @@ static const struct attribute_group *hisi_pa_pmu_v2_attr_groups[] = {
>  	NULL
>  };
>  
> +static const struct attribute_group *hisi_pa_pmu_v3_attr_groups[] = {
> +	&hisi_pa_pmu_v2_format_group,
> +	&hisi_pa_pmu_v3_events_group,
> +	&hisi_pa_pmu_cpumask_attr_group,
> +	&hisi_pa_pmu_identifier_group,
> +	NULL
> +};
> +
> +static struct hisi_pa_pmu_int_regs hisi_pa_pmu_regs = {
> +	.mask_offset = PA_INT_MASK,
> +	.clear_offset = PA_INT_CLEAR,
> +	.status_offset = PA_INT_STATUS,
> +};
> +
> +static const struct hisi_pmu_dev_info hisi_h32pa[] = {
> +	[1] = {
> +		.name = "pa",
> +		.attr_groups = hisi_pa_pmu_v2_attr_groups,
> +		.private = &hisi_pa_pmu_regs,
> +	},
> +	[2] = {
> +		.name = "pa",
> +		.attr_groups = hisi_pa_pmu_v3_attr_groups,
> +		.private = &hisi_pa_pmu_regs,
> +	},
> +	{}
> +};
> +
> +static const struct attribute_group *hisi_h60pa_pmu_attr_groups[] = {
> +	&hisi_pa_pmu_v2_format_group,
> +	&hisi_h60pa_pmu_events_group,
> +	&hisi_pa_pmu_cpumask_attr_group,
> +	&hisi_pa_pmu_identifier_group,
> +	NULL
> +};
> +
> +static struct hisi_pa_pmu_int_regs hisi_h60pa_pmu_regs = {
> +	.mask_offset = H60PA_INT_MASK,
> +	.clear_offset = H60PA_INT_STATUS, /* Clear on write */
> +	.status_offset = H60PA_INT_STATUS,
> +};
> +
> +static const struct hisi_pmu_dev_info hisi_h60pa[] = {
> +	[1] = {
> +		.name = "h60pa",
> +		.attr_groups = hisi_h60pa_pmu_attr_groups,
> +		.private = &hisi_h60pa_pmu_regs,
> +	},
> +	{}
> +};
> +
>  static const struct hisi_uncore_ops hisi_uncore_pa_ops = {
>  	.write_evtype		= hisi_pa_pmu_write_evtype,
>  	.get_event_idx		= hisi_uncore_pmu_get_event_idx,
> @@ -375,7 +479,7 @@ static int hisi_pa_pmu_dev_probe(struct platform_device *pdev,
>  	if (ret)
>  		return ret;
>  
> -	pa_pmu->pmu_events.attr_groups = hisi_pa_pmu_v2_attr_groups;
> +	pa_pmu->pmu_events.attr_groups = pa_pmu->dev_info->attr_groups;
>  	pa_pmu->num_counters = PA_NR_COUNTERS;
>  	pa_pmu->ops = &hisi_uncore_pa_ops;
>  	pa_pmu->check_event = 0xB0;
> @@ -400,8 +504,9 @@ static int hisi_pa_pmu_probe(struct platform_device *pdev)
>  	if (ret)
>  		return ret;
>  
> -	name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "hisi_sicl%u_pa%u",
> -			      pa_pmu->sicl_id, pa_pmu->index_id);
> +	name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "hisi_sicl%d_%s%u",
> +			      pa_pmu->sicl_id, pa_pmu->dev_info->name,
> +			      pa_pmu->index_id);
>  	if (!name)
>  		return -ENOMEM;
>  
> @@ -435,6 +540,13 @@ static int hisi_pa_pmu_remove(struct platform_device *pdev)
>  	return 0;
>  }
>  
> +static const struct acpi_device_id hisi_pa_pmu_acpi_match[] = {
> +	{ "HISI0273", (kernel_ulong_t)hisi_h32pa },
> +	{ "HISI0274", (kernel_ulong_t)hisi_h60pa },
> +	{}
> +};
> +MODULE_DEVICE_TABLE(acpi, hisi_pa_pmu_acpi_match);
> +
>  static struct platform_driver hisi_pa_pmu_driver = {
>  	.driver = {
>  		.name = "hisi_pa_pmu",
> diff --git a/drivers/perf/hisilicon/hisi_uncore_pmu.h b/drivers/perf/hisilicon/hisi_uncore_pmu.h
> index 07890a8e96ca..a8d6d6905f3f 100644
> --- a/drivers/perf/hisilicon/hisi_uncore_pmu.h
> +++ b/drivers/perf/hisilicon/hisi_uncore_pmu.h
> @@ -24,6 +24,7 @@
>  #define pr_fmt(fmt)     "hisi_pmu: " fmt
>  
>  #define HISI_PMU_V2		0x30
> +#define HISI_PMU_V3		0x40
>  #define HISI_MAX_COUNTERS 0x10
>  #define to_hisi_pmu(p)	(container_of(p, struct hisi_pmu, pmu))
>  
> @@ -62,6 +63,13 @@ struct hisi_uncore_ops {
>  	void (*disable_filter)(struct perf_event *event);
>  };
>  
> +/* Describes the HISI PMU chip features information */
> +struct hisi_pmu_dev_info {
> +	const char *name;
> +	const struct attribute_group **attr_groups;
> +	void *private;
> +};
> +
>  struct hisi_pmu_hwevents {
>  	struct perf_event *hw_events[HISI_MAX_COUNTERS];
>  	DECLARE_BITMAP(used_mask, HISI_MAX_COUNTERS);
> @@ -72,6 +80,7 @@ struct hisi_pmu_hwevents {
>  struct hisi_pmu {
>  	struct pmu pmu;
>  	const struct hisi_uncore_ops *ops;
> +	const struct hisi_pmu_dev_info *dev_info;
>  	struct hisi_pmu_hwevents pmu_events;
>  	/* associated_cpus: All CPUs associated with the PMU */
>  	cpumask_t associated_cpus;
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 2/3] drivers/perf: hisi: Add support for HiSilicon UC PMU driver
  2023-05-31 10:46 ` [PATCH v2 2/3] drivers/perf: hisi: Add support for HiSilicon UC " Junhao He
  2023-05-31 15:59   ` Jonathan Cameron
@ 2023-06-01  6:41   ` Yicong Yang
  1 sibling, 0 replies; 12+ messages in thread
From: Yicong Yang @ 2023-06-01  6:41 UTC (permalink / raw)
  To: Junhao He, will, jonathan.cameron, linux-kernel, mark.rutland
  Cc: yangyicong, linux-arm-kernel, linux-doc, linuxarm, shenyang39,
	prime.zeng

n 2023/5/31 18:46, Junhao He wrote:
> On HiSilicon Hip09 platform, there is a UC (unified cache) module
> on each chip SCCL (Super CPU Cluster). UC is a cache that provides
> coherence between NUMA and UMA domains. It is located between L2
> and Memory System. While PA uncore PMU model is the same as other
> Hip09 PMU modules and many PMU events are supported. Let's support
> the PMU driver using the HiSilicon uncore PMU framework.
> 
> * rd_req_en : rd_req_en is the abbreviation of read request tracetag enable
> and allows user to count only read operations.
> details are listed in the hisi-pmu document.
> 
> * srcid_en & srcid: allows user to filter statistics that come from
> specific CPU/ICL by configuration source ID.
> 
> * uring_channel: Allows users to filter statistical information based on
> the specified tx request uring channel.
> uring_channel only supported events: [0x47 ~ 0x59].
> 
> Signed-off-by: Junhao He <hejunhao3@huawei.com>

Since my comments get addressed, so

Reviewed-by: Yicong Yang <yangyicong@hisilicon.com>

> ---
>  drivers/perf/hisilicon/Makefile             |   2 +-
>  drivers/perf/hisilicon/hisi_uncore_pmu.c    |   4 +-
>  drivers/perf/hisilicon/hisi_uncore_pmu.h    |   6 +
>  drivers/perf/hisilicon/hisi_uncore_uc_pmu.c | 577 ++++++++++++++++++++
>  4 files changed, 587 insertions(+), 2 deletions(-)
>  create mode 100644 drivers/perf/hisilicon/hisi_uncore_uc_pmu.c
> 
> diff --git a/drivers/perf/hisilicon/Makefile b/drivers/perf/hisilicon/Makefile
> index 4d2c9abe3372..48dcc8381ea7 100644
> --- a/drivers/perf/hisilicon/Makefile
> +++ b/drivers/perf/hisilicon/Makefile
> @@ -1,7 +1,7 @@
>  # SPDX-License-Identifier: GPL-2.0-only
>  obj-$(CONFIG_HISI_PMU) += hisi_uncore_pmu.o hisi_uncore_l3c_pmu.o \
>  			  hisi_uncore_hha_pmu.o hisi_uncore_ddrc_pmu.o hisi_uncore_sllc_pmu.o \
> -			  hisi_uncore_pa_pmu.o hisi_uncore_cpa_pmu.o
> +			  hisi_uncore_pa_pmu.o hisi_uncore_cpa_pmu.o hisi_uncore_uc_pmu.o
>  
>  obj-$(CONFIG_HISI_PCIE_PMU) += hisi_pcie_pmu.o
>  obj-$(CONFIG_HNS3_PMU) += hns3_pmu.o
> diff --git a/drivers/perf/hisilicon/hisi_uncore_pmu.c b/drivers/perf/hisilicon/hisi_uncore_pmu.c
> index 2823f381930d..04031450d5fe 100644
> --- a/drivers/perf/hisilicon/hisi_uncore_pmu.c
> +++ b/drivers/perf/hisilicon/hisi_uncore_pmu.c
> @@ -20,7 +20,6 @@
>  
>  #include "hisi_uncore_pmu.h"
>  
> -#define HISI_GET_EVENTID(ev) (ev->hw.config_base & 0xff)
>  #define HISI_MAX_PERIOD(nr) (GENMASK_ULL((nr) - 1, 0))
>  
>  /*
> @@ -226,6 +225,9 @@ int hisi_uncore_pmu_event_init(struct perf_event *event)
>  	hwc->idx		= -1;
>  	hwc->config_base	= event->attr.config;
>  
> +	if (hisi_pmu->ops->check_filter && hisi_pmu->ops->check_filter(event))
> +		return -EINVAL;
> +
>  	/* Enforce to use the same CPU for all events in this PMU */
>  	event->cpu = hisi_pmu->on_cpu;
>  
> diff --git a/drivers/perf/hisilicon/hisi_uncore_pmu.h b/drivers/perf/hisilicon/hisi_uncore_pmu.h
> index a8d6d6905f3f..27b6122aa486 100644
> --- a/drivers/perf/hisilicon/hisi_uncore_pmu.h
> +++ b/drivers/perf/hisilicon/hisi_uncore_pmu.h
> @@ -44,9 +44,15 @@
>  		return FIELD_GET(GENMASK_ULL(hi, lo), event->attr.config);  \
>  	}
>  
> +#define HISI_GET_EVENTID(ev) (ev->hw.config_base & 0xff)
> +
> +#define HISI_PMU_EVTYPE_BITS		8
> +#define HISI_PMU_EVTYPE_SHIFT(idx)	((idx) % 4 * HISI_PMU_EVTYPE_BITS)
> +
>  struct hisi_pmu;
>  
>  struct hisi_uncore_ops {
> +	int (*check_filter)(struct perf_event *event);
>  	void (*write_evtype)(struct hisi_pmu *, int, u32);
>  	int (*get_event_idx)(struct perf_event *);
>  	u64 (*read_counter)(struct hisi_pmu *, struct hw_perf_event *);
> diff --git a/drivers/perf/hisilicon/hisi_uncore_uc_pmu.c b/drivers/perf/hisilicon/hisi_uncore_uc_pmu.c
> new file mode 100644
> index 000000000000..d27f28584fd7
> --- /dev/null
> +++ b/drivers/perf/hisilicon/hisi_uncore_uc_pmu.c
> @@ -0,0 +1,577 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * HiSilicon SoC UC (unified cache) uncore Hardware event counters support
> + *
> + * Copyright (C) 2023 HiSilicon Limited
> + *
> + * This code is based on the uncore PMUs like hisi_uncore_l3c_pmu.
> + */
> +#include <linux/cpuhotplug.h>
> +#include <linux/interrupt.h>
> +#include <linux/irq.h>
> +#include <linux/list.h>
> +#include <linux/mod_devicetable.h>
> +#include <linux/property.h>
> +
> +#include "hisi_uncore_pmu.h"
> +
> +/* Dynamic CPU hotplug state used by UC PMU */
> +static enum cpuhp_state hisi_uc_pmu_online;
> +
> +/* UC register definition */
> +#define HISI_UC_INT_MASK_REG		0x0800
> +#define HISI_UC_INT_STS_REG		0x0808
> +#define HISI_UC_INT_CLEAR_REG		0x080c
> +#define HISI_UC_TRACETAG_CTRL_REG	0x1b2c
> +#define HISI_UC_TRACETAG_REQ_MSK	GENMASK(9, 7)
> +#define HISI_UC_TRACETAG_MARK_EN	BIT(0)
> +#define HISI_UC_TRACETAG_REQ_EN		(HISI_UC_TRACETAG_MARK_EN | BIT(2))
> +#define HISI_UC_TRACETAG_SRCID_EN	BIT(3)
> +#define HISI_UC_SRCID_CTRL_REG		0x1b40
> +#define HISI_UC_SRCID_MSK		GENMASK(14, 1)
> +#define HISI_UC_EVENT_CTRL_REG		0x1c00
> +#define HISI_UC_EVENT_TRACETAG_EN	BIT(29)
> +#define HISI_UC_EVENT_URING_MSK		GENMASK(28, 27)
> +#define HISI_UC_EVENT_GLB_EN		BIT(26)
> +#define HISI_UC_VERSION_REG		0x1cf0
> +#define HISI_UC_EVTYPE_REGn(n)		(0x1d00 + (n) * 4)
> +#define HISI_UC_EVTYPE_MASK		GENMASK(7, 0)
> +#define HISI_UC_CNTR_REGn(n)		(0x1e00 + (n) * 8)
> +
> +#define HISI_UC_NR_COUNTERS		0x8
> +#define HISI_UC_V2_NR_EVENTS		0xFF
> +#define HISI_UC_CNTR_REG_BITS		64
> +
> +#define HISI_UC_RD_REQ_TRACETAG		0x4
> +#define HISI_UC_URING_EVENT_MIN		0x47
> +#define HISI_UC_URING_EVENT_MAX		0x59
> +
> +HISI_PMU_EVENT_ATTR_EXTRACTOR(rd_req_en, config1, 0, 0);
> +HISI_PMU_EVENT_ATTR_EXTRACTOR(uring_channel, config1, 5, 4);
> +HISI_PMU_EVENT_ATTR_EXTRACTOR(srcid, config1, 19, 6);
> +HISI_PMU_EVENT_ATTR_EXTRACTOR(srcid_en, config1, 20, 20);
> +
> +static int hisi_uc_pmu_check_filter(struct perf_event *event)
> +{
> +	struct hisi_pmu *uc_pmu = to_hisi_pmu(event->pmu);
> +
> +	if (hisi_get_srcid_en(event) && !hisi_get_rd_req_en(event)) {
> +		dev_err(uc_pmu->dev,
> +			"Failed to set srcid: depending on read request enabled!\n");
> +		return -EINVAL;
> +	}
> +
> +	if (!hisi_get_uring_channel(event))
> +		return 0;
> +
> +	if ((HISI_GET_EVENTID(event) < HISI_UC_URING_EVENT_MIN) ||
> +	    (HISI_GET_EVENTID(event) > HISI_UC_URING_EVENT_MAX))
> +		dev_warn(uc_pmu->dev,
> +			 "Only events: [%#x ~ %#x] support channel filtering!",
> +			 HISI_UC_URING_EVENT_MIN, HISI_UC_URING_EVENT_MAX);
> +
> +	return 0;
> +}
> +
> +static void hisi_uc_pmu_config_req_tracetag(struct perf_event *event)
> +{
> +	struct hisi_pmu *uc_pmu = to_hisi_pmu(event->pmu);
> +	u32 val;
> +
> +	if (!hisi_get_rd_req_en(event))
> +		return;
> +
> +	val = readl(uc_pmu->base + HISI_UC_TRACETAG_CTRL_REG);
> +
> +	/* The request-type has been configured */
> +	if (FIELD_GET(HISI_UC_TRACETAG_REQ_MSK, val) == HISI_UC_RD_REQ_TRACETAG)
> +		return;
> +
> +	/* Set request-type for tracetag, only read request is supported! */
> +	val &= ~HISI_UC_TRACETAG_REQ_MSK;
> +	val |= FIELD_PREP(HISI_UC_TRACETAG_REQ_MSK, HISI_UC_RD_REQ_TRACETAG);
> +	val |= HISI_UC_TRACETAG_REQ_EN;
> +	writel(val, uc_pmu->base + HISI_UC_TRACETAG_CTRL_REG);
> +}
> +
> +static void hisi_uc_pmu_clear_req_tracetag(struct perf_event *event)
> +{
> +	struct hisi_pmu *uc_pmu = to_hisi_pmu(event->pmu);
> +	u32 val;
> +
> +	if (!hisi_get_rd_req_en(event))
> +		return;
> +
> +	val = readl(uc_pmu->base + HISI_UC_TRACETAG_CTRL_REG);
> +
> +	/* Do nothing, the request-type tracetag has been cleaned up */
> +	if (FIELD_GET(HISI_UC_TRACETAG_REQ_MSK, val) == 0)
> +		return;
> +
> +	/* Clear request-type */
> +	val &= ~HISI_UC_TRACETAG_REQ_MSK;
> +	val &= ~HISI_UC_TRACETAG_REQ_EN;
> +	writel(val, uc_pmu->base + HISI_UC_TRACETAG_CTRL_REG);
> +}
> +
> +static void hisi_uc_pmu_config_srcid_tracetag(struct perf_event *event)
> +{
> +	struct hisi_pmu *uc_pmu = to_hisi_pmu(event->pmu);
> +	u32 val;
> +
> +	if (!hisi_get_srcid_en(event))
> +		return;
> +
> +	val = readl(uc_pmu->base + HISI_UC_TRACETAG_CTRL_REG);
> +
> +	/* Do nothing, the source id has been configured */
> +	if (FIELD_GET(HISI_UC_TRACETAG_SRCID_EN, val))
> +		return;
> +
> +	/* Enable source id tracetag */
> +	val |= HISI_UC_TRACETAG_SRCID_EN;
> +	writel(val, uc_pmu->base + HISI_UC_TRACETAG_CTRL_REG);
> +
> +	val = readl(uc_pmu->base + HISI_UC_SRCID_CTRL_REG);
> +	val &= ~HISI_UC_SRCID_MSK;
> +	val |= FIELD_PREP(HISI_UC_SRCID_MSK, hisi_get_srcid(event));
> +	writel(val, uc_pmu->base + HISI_UC_SRCID_CTRL_REG);
> +
> +	/* Depend on request-type tracetag enabled */
> +	hisi_uc_pmu_config_req_tracetag(event);
> +}
> +
> +static void hisi_uc_pmu_clear_srcid_tracetag(struct perf_event *event)
> +{
> +	struct hisi_pmu *uc_pmu = to_hisi_pmu(event->pmu);
> +	u32 val;
> +
> +	if (!hisi_get_srcid_en(event))
> +		return;
> +
> +	val = readl(uc_pmu->base + HISI_UC_TRACETAG_CTRL_REG);
> +
> +	/* Do nothing, the source id has been cleaned up */
> +	if (FIELD_GET(HISI_UC_TRACETAG_SRCID_EN, val) == 0)
> +		return;
> +
> +	hisi_uc_pmu_clear_req_tracetag(event);
> +
> +	/* Disable source id tracetag */
> +	val &= ~HISI_UC_TRACETAG_SRCID_EN;
> +	writel(val, uc_pmu->base + HISI_UC_TRACETAG_CTRL_REG);
> +
> +	val = readl(uc_pmu->base + HISI_UC_SRCID_CTRL_REG);
> +	val &= ~HISI_UC_SRCID_MSK;
> +	writel(val, uc_pmu->base + HISI_UC_SRCID_CTRL_REG);
> +}
> +
> +static void hisi_uc_pmu_config_uring_channel(struct perf_event *event)
> +{
> +	struct hisi_pmu *uc_pmu = to_hisi_pmu(event->pmu);
> +	u32 uring_channel = hisi_get_uring_channel(event);
> +	u32 val;
> +
> +	/* Do nothing if not being set or is set explicitly to zero (default) */
> +	if (uring_channel == 0)
> +		return;
> +
> +	val = readl(uc_pmu->base + HISI_UC_EVENT_CTRL_REG);
> +
> +	/* Do nothing, the uring_channel has been configured */
> +	if (uring_channel == FIELD_GET(HISI_UC_EVENT_URING_MSK, val))
> +		return;
> +
> +	val &= ~HISI_UC_EVENT_URING_MSK;
> +	val |= FIELD_PREP(HISI_UC_EVENT_URING_MSK, uring_channel);
> +	writel(val, uc_pmu->base + HISI_UC_EVENT_CTRL_REG);
> +}
> +
> +static void hisi_uc_pmu_clear_uring_channel(struct perf_event *event)
> +{
> +	struct hisi_pmu *uc_pmu = to_hisi_pmu(event->pmu);
> +	u32 val;
> +
> +	/* Do nothing if not being set or is set explicitly to zero (default) */
> +	if (hisi_get_uring_channel(event) == 0)
> +		return;
> +
> +	val = readl(uc_pmu->base + HISI_UC_EVENT_CTRL_REG);
> +
> +	/* Do nothing, the uring_channel has been cleaned up */
> +	if (FIELD_GET(HISI_UC_EVENT_URING_MSK, val) == 0)
> +		return;
> +
> +	val &= ~HISI_UC_EVENT_URING_MSK;
> +	writel(val, uc_pmu->base + HISI_UC_EVENT_CTRL_REG);
> +}
> +
> +static void hisi_uc_pmu_enable_filter(struct perf_event *event)
> +{
> +	if (event->attr.config1 == 0)
> +		return;
> +
> +	hisi_uc_pmu_config_uring_channel(event);
> +	hisi_uc_pmu_config_req_tracetag(event);
> +	hisi_uc_pmu_config_srcid_tracetag(event);
> +}
> +
> +static void hisi_uc_pmu_disable_filter(struct perf_event *event)
> +{
> +	if (event->attr.config1 == 0)
> +		return;
> +
> +	hisi_uc_pmu_clear_srcid_tracetag(event);
> +	hisi_uc_pmu_clear_req_tracetag(event);
> +	hisi_uc_pmu_clear_uring_channel(event);
> +}
> +
> +static void hisi_uc_pmu_write_evtype(struct hisi_pmu *uc_pmu, int idx, u32 type)
> +{
> +	u32 val;
> +
> +	/*
> +	 * Select the appropriate event select register.
> +	 * There are 2 32-bit event select registers for the
> +	 * 8 hardware counters, each event code is 8-bit wide.
> +	 */
> +	val = readl(uc_pmu->base + HISI_UC_EVTYPE_REGn(idx / 4));
> +	val &= ~(HISI_UC_EVTYPE_MASK << HISI_PMU_EVTYPE_SHIFT(idx));
> +	val |= (type << HISI_PMU_EVTYPE_SHIFT(idx));
> +	writel(val, uc_pmu->base + HISI_UC_EVTYPE_REGn(idx / 4));
> +}
> +
> +static void hisi_uc_pmu_start_counters(struct hisi_pmu *uc_pmu)
> +{
> +	u32 val;
> +
> +	val = readl(uc_pmu->base + HISI_UC_EVENT_CTRL_REG);
> +	val |= HISI_UC_EVENT_GLB_EN;
> +	writel(val, uc_pmu->base + HISI_UC_EVENT_CTRL_REG);
> +}
> +
> +static void hisi_uc_pmu_stop_counters(struct hisi_pmu *uc_pmu)
> +{
> +	u32 val;
> +
> +	val = readl(uc_pmu->base + HISI_UC_EVENT_CTRL_REG);
> +	val &= ~HISI_UC_EVENT_GLB_EN;
> +	writel(val, uc_pmu->base + HISI_UC_EVENT_CTRL_REG);
> +}
> +
> +static void hisi_uc_pmu_enable_counter(struct hisi_pmu *uc_pmu,
> +					struct hw_perf_event *hwc)
> +{
> +	u32 val;
> +
> +	/* Enable counter index */
> +	val = readl(uc_pmu->base + HISI_UC_EVENT_CTRL_REG);
> +	val |= (1 << hwc->idx);
> +	writel(val, uc_pmu->base + HISI_UC_EVENT_CTRL_REG);
> +}
> +
> +static void hisi_uc_pmu_disable_counter(struct hisi_pmu *uc_pmu,
> +					struct hw_perf_event *hwc)
> +{
> +	u32 val;
> +
> +	/* Clear counter index */
> +	val = readl(uc_pmu->base + HISI_UC_EVENT_CTRL_REG);
> +	val &= ~(1 << hwc->idx);
> +	writel(val, uc_pmu->base + HISI_UC_EVENT_CTRL_REG);
> +}
> +
> +static u64 hisi_uc_pmu_read_counter(struct hisi_pmu *uc_pmu,
> +				    struct hw_perf_event *hwc)
> +{
> +	return readq(uc_pmu->base + HISI_UC_CNTR_REGn(hwc->idx));
> +}
> +
> +static void hisi_uc_pmu_write_counter(struct hisi_pmu *uc_pmu,
> +				      struct hw_perf_event *hwc, u64 val)
> +{
> +	hisi_uc_pmu_start_counters(uc_pmu);
> +	writeq(val, uc_pmu->base + HISI_UC_CNTR_REGn(hwc->idx));
> +}
> +
> +static void hisi_uc_pmu_enable_counter_int(struct hisi_pmu *uc_pmu,
> +					   struct hw_perf_event *hwc)
> +{
> +	u32 val;
> +
> +	val = readl(uc_pmu->base + HISI_UC_INT_MASK_REG);
> +	val &= ~(1 << hwc->idx);
> +	writel(val, uc_pmu->base + HISI_UC_INT_MASK_REG);
> +}
> +
> +static void hisi_uc_pmu_disable_counter_int(struct hisi_pmu *uc_pmu,
> +					    struct hw_perf_event *hwc)
> +{
> +	u32 val;
> +
> +	val = readl(uc_pmu->base + HISI_UC_INT_MASK_REG);
> +	val |= (1 << hwc->idx);
> +	writel(val, uc_pmu->base + HISI_UC_INT_MASK_REG);
> +}
> +
> +static u32 hisi_uc_pmu_get_int_status(struct hisi_pmu *uc_pmu)
> +{
> +	return readl(uc_pmu->base + HISI_UC_INT_STS_REG);
> +}
> +
> +static void hisi_uc_pmu_clear_int_status(struct hisi_pmu *uc_pmu, int idx)
> +{
> +	writel(1 << idx, uc_pmu->base + HISI_UC_INT_CLEAR_REG);
> +}
> +
> +static int hisi_uc_pmu_init_data(struct platform_device *pdev,
> +				 struct hisi_pmu *uc_pmu)
> +{
> +	/*
> +	 * Use SCCL (Super CPU Cluster) ID and CCL (CPU Cluster) ID to
> +	 * identify the topology information of UC PMU devices in the chip.
> +	 */
> +	if (device_property_read_u32(&pdev->dev, "hisilicon,scl-id",
> +				     &uc_pmu->sccl_id)) {
> +		dev_err(&pdev->dev, "Can not read uc sccl-id!\n");
> +		return -EINVAL;
> +	}
> +
> +	if (device_property_read_u32(&pdev->dev, "hisilicon,ccl-id",
> +				     &uc_pmu->ccl_id)) {
> +		dev_err(&pdev->dev, "Can not read uc ccl-id!\n");
> +		return -EINVAL;
> +	}
> +
> +	if (device_property_read_u32(&pdev->dev, "hisilicon,sub-id",
> +				     &uc_pmu->sub_id)) {
> +		dev_err(&pdev->dev, "Can not read sub-id!\n");
> +		return -EINVAL;
> +	}
> +
> +	uc_pmu->base = devm_platform_ioremap_resource(pdev, 0);
> +	if (IS_ERR(uc_pmu->base)) {
> +		dev_err(&pdev->dev, "ioremap failed for uc_pmu resource\n");
> +		return PTR_ERR(uc_pmu->base);
> +	}
> +
> +	uc_pmu->identifier = readl(uc_pmu->base + HISI_UC_VERSION_REG);
> +
> +	return 0;
> +}
> +
> +static struct attribute *hisi_uc_pmu_format_attr[] = {
> +	HISI_PMU_FORMAT_ATTR(event, "config:0-7"),
> +	HISI_PMU_FORMAT_ATTR(rd_req_en, "config1:0-0"),
> +	HISI_PMU_FORMAT_ATTR(uring_channel, "config1:4-5"),
> +	HISI_PMU_FORMAT_ATTR(srcid, "config1:6-19"),
> +	HISI_PMU_FORMAT_ATTR(srcid_en, "config1:20-20"),
> +	NULL
> +};
> +
> +static const struct attribute_group hisi_uc_pmu_format_group = {
> +	.name = "format",
> +	.attrs = hisi_uc_pmu_format_attr,
> +};
> +
> +static struct attribute *hisi_uc_pmu_events_attr[] = {
> +	HISI_PMU_EVENT_ATTR(sq_time,		0x00),
> +	HISI_PMU_EVENT_ATTR(pq_time,		0x01),
> +	HISI_PMU_EVENT_ATTR(hbm_time,		0x02),
> +	HISI_PMU_EVENT_ATTR(iq_comp_time_cring,	0x03),
> +	HISI_PMU_EVENT_ATTR(iq_comp_time_uring,	0x05),
> +	HISI_PMU_EVENT_ATTR(cpu_rd,		0x10),
> +	HISI_PMU_EVENT_ATTR(cpu_rd64,		0x17),
> +	HISI_PMU_EVENT_ATTR(cpu_rs64,		0x19),
> +	HISI_PMU_EVENT_ATTR(cpu_mru,		0x1a),
> +	HISI_PMU_EVENT_ATTR(cycles,		0x9c),
> +	HISI_PMU_EVENT_ATTR(spipe_hit,		0xb3),
> +	HISI_PMU_EVENT_ATTR(hpipe_hit,		0xdb),
> +	HISI_PMU_EVENT_ATTR(cring_rxdat_cnt,	0xfa),
> +	HISI_PMU_EVENT_ATTR(cring_txdat_cnt,	0xfb),
> +	HISI_PMU_EVENT_ATTR(uring_rxdat_cnt,	0xfc),
> +	HISI_PMU_EVENT_ATTR(uring_txdat_cnt,	0xfd),
> +	NULL
> +};
> +
> +static const struct attribute_group hisi_uc_pmu_events_group = {
> +	.name = "events",
> +	.attrs = hisi_uc_pmu_events_attr,
> +};
> +
> +static DEVICE_ATTR(cpumask, 0444, hisi_cpumask_sysfs_show, NULL);
> +
> +static struct attribute *hisi_uc_pmu_cpumask_attrs[] = {
> +	&dev_attr_cpumask.attr,
> +	NULL,
> +};
> +
> +static const struct attribute_group hisi_uc_pmu_cpumask_attr_group = {
> +	.attrs = hisi_uc_pmu_cpumask_attrs,
> +};
> +
> +static struct device_attribute hisi_uc_pmu_identifier_attr =
> +	__ATTR(identifier, 0444, hisi_uncore_pmu_identifier_attr_show, NULL);
> +
> +static struct attribute *hisi_uc_pmu_identifier_attrs[] = {
> +	&hisi_uc_pmu_identifier_attr.attr,
> +	NULL
> +};
> +
> +static const struct attribute_group hisi_uc_pmu_identifier_group = {
> +	.attrs = hisi_uc_pmu_identifier_attrs,
> +};
> +
> +static const struct attribute_group *hisi_uc_pmu_attr_groups[] = {
> +	&hisi_uc_pmu_format_group,
> +	&hisi_uc_pmu_events_group,
> +	&hisi_uc_pmu_cpumask_attr_group,
> +	&hisi_uc_pmu_identifier_group,
> +	NULL
> +};
> +
> +static const struct hisi_uncore_ops hisi_uncore_uc_pmu_ops = {
> +	.check_filter		= hisi_uc_pmu_check_filter,
> +	.write_evtype		= hisi_uc_pmu_write_evtype,
> +	.get_event_idx		= hisi_uncore_pmu_get_event_idx,
> +	.start_counters		= hisi_uc_pmu_start_counters,
> +	.stop_counters		= hisi_uc_pmu_stop_counters,
> +	.enable_counter		= hisi_uc_pmu_enable_counter,
> +	.disable_counter	= hisi_uc_pmu_disable_counter,
> +	.enable_counter_int	= hisi_uc_pmu_enable_counter_int,
> +	.disable_counter_int	= hisi_uc_pmu_disable_counter_int,
> +	.write_counter		= hisi_uc_pmu_write_counter,
> +	.read_counter		= hisi_uc_pmu_read_counter,
> +	.get_int_status		= hisi_uc_pmu_get_int_status,
> +	.clear_int_status	= hisi_uc_pmu_clear_int_status,
> +	.enable_filter		= hisi_uc_pmu_enable_filter,
> +	.disable_filter		= hisi_uc_pmu_disable_filter,
> +};
> +
> +static int hisi_uc_pmu_dev_probe(struct platform_device *pdev,
> +				 struct hisi_pmu *uc_pmu)
> +{
> +	int ret;
> +
> +	ret = hisi_uc_pmu_init_data(pdev, uc_pmu);
> +	if (ret)
> +		return ret;
> +
> +	ret = hisi_uncore_pmu_init_irq(uc_pmu, pdev);
> +	if (ret)
> +		return ret;
> +
> +	uc_pmu->pmu_events.attr_groups = hisi_uc_pmu_attr_groups;
> +	uc_pmu->check_event = HISI_UC_EVTYPE_MASK;
> +	uc_pmu->ops = &hisi_uncore_uc_pmu_ops;
> +	uc_pmu->counter_bits = HISI_UC_CNTR_REG_BITS;
> +	uc_pmu->num_counters = HISI_UC_NR_COUNTERS;
> +	uc_pmu->dev = &pdev->dev;
> +	uc_pmu->on_cpu = -1;
> +
> +	return 0;
> +}
> +
> +static void hisi_uc_pmu_remove_cpuhp_instance(void *hotplug_node)
> +{
> +	cpuhp_state_remove_instance_nocalls(hisi_uc_pmu_online, hotplug_node);
> +}
> +
> +static void hisi_uc_pmu_unregister_pmu(void *pmu)
> +{
> +	perf_pmu_unregister(pmu);
> +}
> +
> +static int hisi_uc_pmu_probe(struct platform_device *pdev)
> +{
> +	struct hisi_pmu *uc_pmu;
> +	char *name;
> +	int ret;
> +
> +	uc_pmu = devm_kzalloc(&pdev->dev, sizeof(*uc_pmu), GFP_KERNEL);
> +	if (!uc_pmu)
> +		return -ENOMEM;
> +
> +	platform_set_drvdata(pdev, uc_pmu);
> +
> +	ret = hisi_uc_pmu_dev_probe(pdev, uc_pmu);
> +	if (ret)
> +		return ret;
> +
> +	name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "hisi_sccl%d_uc%d_%u",
> +			      uc_pmu->sccl_id, uc_pmu->ccl_id, uc_pmu->sub_id);
> +	if (!name)
> +		return -ENOMEM;
> +
> +	ret = cpuhp_state_add_instance(hisi_uc_pmu_online, &uc_pmu->node);
> +	if (ret)
> +		return dev_err_probe(&pdev->dev, ret, "Error registering hotplug\n");
> +
> +	ret = devm_add_action_or_reset(&pdev->dev,
> +				       hisi_uc_pmu_remove_cpuhp_instance,
> +				       &uc_pmu->node);
> +	if (ret)
> +		return ret;
> +
> +	hisi_pmu_init(uc_pmu, THIS_MODULE);
> +
> +	ret = perf_pmu_register(&uc_pmu->pmu, name, -1);
> +	if (ret)
> +		return ret;
> +
> +	return devm_add_action_or_reset(&pdev->dev,
> +					hisi_uc_pmu_unregister_pmu,
> +					&uc_pmu->pmu);
> +}
> +
> +static const struct acpi_device_id hisi_uc_pmu_acpi_match[] = {
> +	{ "HISI0291", },
> +	{}
> +};
> +MODULE_DEVICE_TABLE(acpi, hisi_uc_pmu_acpi_match);
> +
> +static struct platform_driver hisi_uc_pmu_driver = {
> +	.driver = {
> +		.name = "hisi_uc_pmu",
> +		.acpi_match_table = hisi_uc_pmu_acpi_match,
> +		/*
> +		 * We have not worked out a safe bind/unbind process,
> +		 * so this is not supported yet.
> +		 */
> +		.suppress_bind_attrs = true,
> +	},
> +	.probe = hisi_uc_pmu_probe,
> +};
> +
> +static int __init hisi_uc_pmu_module_init(void)
> +{
> +	int ret;
> +
> +	ret = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN,
> +				      "perf/hisi/uc:online",
> +				      hisi_uncore_pmu_online_cpu,
> +				      hisi_uncore_pmu_offline_cpu);
> +	if (ret < 0) {
> +		pr_err("UC PMU: Error setup hotplug, ret = %d\n", ret);
> +		return ret;
> +	}
> +	hisi_uc_pmu_online = ret;
> +
> +	ret = platform_driver_register(&hisi_uc_pmu_driver);
> +	if (ret)
> +		cpuhp_remove_multi_state(hisi_uc_pmu_online);
> +
> +	return ret;
> +}
> +module_init(hisi_uc_pmu_module_init);
> +
> +static void __exit hisi_uc_pmu_module_exit(void)
> +{
> +	platform_driver_unregister(&hisi_uc_pmu_driver);
> +	cpuhp_remove_multi_state(hisi_uc_pmu_online);
> +}
> +module_exit(hisi_uc_pmu_module_exit);
> +
> +MODULE_DESCRIPTION("HiSilicon SoC UC uncore PMU driver");
> +MODULE_LICENSE("GPL");
> +MODULE_AUTHOR("Junhao He <hejunhao3@huawei.com>");
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 3/3] docs: perf: Add new description for HiSilicon UC PMU
  2023-05-31 10:46 ` [PATCH v2 3/3] docs: perf: Add new description for HiSilicon UC PMU Junhao He
  2023-05-31 16:00   ` Jonathan Cameron
@ 2023-06-01  6:44   ` Yicong Yang
  1 sibling, 0 replies; 12+ messages in thread
From: Yicong Yang @ 2023-06-01  6:44 UTC (permalink / raw)
  To: Junhao He, will, jonathan.cameron, linux-kernel, mark.rutland
  Cc: yangyicong, linux-arm-kernel, linux-doc, linuxarm, shenyang39,
	prime.zeng

On 2023/5/31 18:46, Junhao He wrote:
> A new function is added on HiSilicon uncore UC PMU.
> 
> The UC PMU support to filter statistical information based on
> the specified tx request uring channel. Make user configuration
> through "uring_channel" parameter.
> Document them to provide guidance on how to use them.
> 
> Signed-off-by: Junhao He <hejunhao3@huawei.com>

I still prefer this in the same patch with the driver support, anyway
the docs alone looks good to me.

Reviewed-by: Yicong Yang <yangyicong@hisilicon.com>

> ---
>  Documentation/admin-guide/perf/hisi-pmu.rst | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/Documentation/admin-guide/perf/hisi-pmu.rst b/Documentation/admin-guide/perf/hisi-pmu.rst
> index 546979360513..939a524fa1d6 100644
> --- a/Documentation/admin-guide/perf/hisi-pmu.rst
> +++ b/Documentation/admin-guide/perf/hisi-pmu.rst
> @@ -98,6 +98,14 @@ CCL/ICL-ID. For I/O die, the ICL-ID is followed by:
>  5'b00011: HAC_ICL;
>  5'b10000: PCIe_ICL;
>  
> +(e) uring_channel: UC PMU events 0x47~0x59 supports filtering by tx request
> +uring channel. It is 2 bits. Some important codes are as follows:
> +2'b11: count the events which sent to the uring_ext (MATA) channel;
> +2'b01: is the same as 2'b11;
> +2'b10: count the events which sent to the uring (non-MATA) channel;
> +2'b00: default value, count the events which sent to the both uring and
> +       uring_ext channel;
> +
>  Users could configure IDs to count data come from specific CCL/ICL, by setting
>  srcid_cmd & srcid_msk, and data desitined for specific CCL/ICL by setting
>  tgtid_cmd & tgtid_msk. A set bit in srcid_msk/tgtid_msk means the PMU will not
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 2/3] drivers/perf: hisi: Add support for HiSilicon UC PMU driver
  2023-05-31 15:59   ` Jonathan Cameron
@ 2023-06-01  6:53     ` Yicong Yang
  2023-06-07 11:00     ` hejunhao
  1 sibling, 0 replies; 12+ messages in thread
From: Yicong Yang @ 2023-06-01  6:53 UTC (permalink / raw)
  To: Jonathan Cameron, Junhao He
  Cc: will, linux-kernel, mark.rutland, linux-arm-kernel, linux-doc,
	yangyicong, shenyang39, prime.zeng, yangyicong, Linuxarm

On 2023/5/31 23:59, Jonathan Cameron wrote:
> On Wed, 31 May 2023 18:46:24 +0800
> Junhao He <hejunhao3@huawei.com> wrote:
> 
> Hi Junhao,
> 
> A few small comments inline.
> 
>> On HiSilicon Hip09 platform, there is a UC (unified cache) module
>> on each chip SCCL (Super CPU Cluster). UC is a cache that provides
>> coherence between NUMA and UMA domains. It is located between L2
>> and Memory System. While PA uncore PMU model is the same as other
>> Hip09 PMU modules and many PMU events are supported. 
> 
> I don't follow what this sentence means.  Normally you'd have
> While A, B is different..
> 
> 
>> Let's support
>> the PMU driver using the HiSilicon uncore PMU framework.
>>
>> * rd_req_en : rd_req_en is the abbreviation of read request tracetag enable
>> and allows user to count only read operations.
>> details are listed in the hisi-pmu document.
> Details are .. Also no need for the ine break
>   and allows user to count only read operations. Details are listed
>   in the hisi-pmu document at ....
> 
>>
>> * srcid_en & srcid: allows user to filter statistics that come from
> 
> Allows
> for consistency with the uring_channel description that follows.
> 
>> specific CPU/ICL by configuration source ID.
>>
>> * uring_channel: Allows users to filter statistical information based on
>> the specified tx request uring channel.
>> uring_channel only supported events: [0x47 ~ 0x59].
>>
>> Signed-off-by: Junhao He <hejunhao3@huawei.com>
> 
> 
>> diff --git a/drivers/perf/hisilicon/hisi_uncore_uc_pmu.c b/drivers/perf/hisilicon/hisi_uncore_uc_pmu.c
>> new file mode 100644
>> index 000000000000..d27f28584fd7
>> --- /dev/null
>> +++ b/drivers/perf/hisilicon/hisi_uncore_uc_pmu.c
>> @@ -0,0 +1,577 @@
> ...
> 
> 
> 
> 
>> +static int hisi_uc_pmu_init_data(struct platform_device *pdev,
>> +				 struct hisi_pmu *uc_pmu)
>> +{
>> +	/*
>> +	 * Use SCCL (Super CPU Cluster) ID and CCL (CPU Cluster) ID to
>> +	 * identify the topology information of UC PMU devices in the chip.
>> +	 */
> 
>>From patch description, I'd assume there is only one of these
> per sccl so why do we care about the cluster level or the sub-id?
> Perhaps that description is missleading?
> 
>> +	if (device_property_read_u32(&pdev->dev, "hisilicon,scl-id",
>> +				     &uc_pmu->sccl_id)) {
>> +		dev_err(&pdev->dev, "Can not read uc sccl-id!\n");
>> +		return -EINVAL;
>> +	}
>> +
>> +	if (device_property_read_u32(&pdev->dev, "hisilicon,ccl-id",
>> +				     &uc_pmu->ccl_id)) {
>> +		dev_err(&pdev->dev, "Can not read uc ccl-id!\n");
>> +		return -EINVAL;
>> +	}
>> +
>> +	if (device_property_read_u32(&pdev->dev, "hisilicon,sub-id",
>> +				     &uc_pmu->sub_id)) {
>> +		dev_err(&pdev->dev, "Can not read sub-id!\n");
>> +		return -EINVAL;
>> +	}
>> +
>> +	uc_pmu->base = devm_platform_ioremap_resource(pdev, 0);
>> +	if (IS_ERR(uc_pmu->base)) {
>> +		dev_err(&pdev->dev, "ioremap failed for uc_pmu resource\n");
>> +		return PTR_ERR(uc_pmu->base);
>> +	}
>> +
>> +	uc_pmu->identifier = readl(uc_pmu->base + HISI_UC_VERSION_REG);
>> +
>> +	return 0;
>> +}
> 
> 
>> +static struct platform_driver hisi_uc_pmu_driver = {
>> +	.driver = {
>> +		.name = "hisi_uc_pmu",
>> +		.acpi_match_table = hisi_uc_pmu_acpi_match,
>> +		/*
>> +		 * We have not worked out a safe bind/unbind process,
>> +		 * so this is not supported yet.
> 
> If you can reference more info on this that would be great.
> Perhaps a thread talking about why?
> 

We handle like this from this patch,
https://lore.kernel.org/linux-arm-kernel/1594975763-32966-1-git-send-email-liuqi115@huawei.com/

>> +		 */
>> +		.suppress_bind_attrs = true,
>> +	},
>> +	.probe = hisi_uc_pmu_probe,
>> +};
> .
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 2/3] drivers/perf: hisi: Add support for HiSilicon UC PMU driver
  2023-05-31 15:59   ` Jonathan Cameron
  2023-06-01  6:53     ` Yicong Yang
@ 2023-06-07 11:00     ` hejunhao
  1 sibling, 0 replies; 12+ messages in thread
From: hejunhao @ 2023-06-07 11:00 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: will, linux-kernel, mark.rutland, linux-arm-kernel, linux-doc,
	linuxarm, yangyicong, shenyang39, prime.zeng

Hi Jonathan,


On 2023/5/31 23:59, Jonathan Cameron wrote:
> On Wed, 31 May 2023 18:46:24 +0800
> Junhao He <hejunhao3@huawei.com> wrote:
>
> Hi Junhao,
>
> A few small comments inline.
>
>> On HiSilicon Hip09 platform, there is a UC (unified cache) module
>> on each chip SCCL (Super CPU Cluster). UC is a cache that provides
>> coherence between NUMA and UMA domains. It is located between L2
>> and Memory System. While PA uncore PMU model is the same as other
>> Hip09 PMU modules and many PMU events are supported.
> I don't follow what this sentence means.  Normally you'd have
> While A, B is different..
>

Ok, will fix it.

>> Let's support
>> the PMU driver using the HiSilicon uncore PMU framework.
>>
>> * rd_req_en : rd_req_en is the abbreviation of read request tracetag enable
>> and allows user to count only read operations.
>> details are listed in the hisi-pmu document.
> Details are .. Also no need for the ine break
>    and allows user to count only read operations. Details are listed
>    in the hisi-pmu document at ....

Thanks, I'm going to replace this

>> * srcid_en & srcid: allows user to filter statistics that come from
> Allows
> for consistency with the uring_channel description that follows.

Yes, I will do that.

>> specific CPU/ICL by configuration source ID.
>>
>> * uring_channel: Allows users to filter statistical information based on
>> the specified tx request uring channel.
>> uring_channel only supported events: [0x47 ~ 0x59].
>>
>> Signed-off-by: Junhao He <hejunhao3@huawei.com>
>
>> diff --git a/drivers/perf/hisilicon/hisi_uncore_uc_pmu.c b/drivers/perf/hisilicon/hisi_uncore_uc_pmu.c
>> new file mode 100644
>> index 000000000000..d27f28584fd7
>> --- /dev/null
>> +++ b/drivers/perf/hisilicon/hisi_uncore_uc_pmu.c
>> @@ -0,0 +1,577 @@
> ...
>
>
>
>
>> +static int hisi_uc_pmu_init_data(struct platform_device *pdev,
>> +				 struct hisi_pmu *uc_pmu)
>> +{
>> +	/*
>> +	 * Use SCCL (Super CPU Cluster) ID and CCL (CPU Cluster) ID to
>> +	 * identify the topology information of UC PMU devices in the chip.
>> +	 */
> >From patch description, I'd assume there is only one of these
> per sccl so why do we care about the cluster level or the sub-id?
> Perhaps that description is missleading?

They have some CCLs per SCCL and then 4 uc pmu per CCL.
The patch description is misleading and I will fix this in the next release.
Thanks.

>> +	if (device_property_read_u32(&pdev->dev, "hisilicon,scl-id",
>> +				     &uc_pmu->sccl_id)) {
>> +		dev_err(&pdev->dev, "Can not read uc sccl-id!\n");
>> +		return -EINVAL;
>> +	}
>> +
>> +	if (device_property_read_u32(&pdev->dev, "hisilicon,ccl-id",
>> +				     &uc_pmu->ccl_id)) {
>> +		dev_err(&pdev->dev, "Can not read uc ccl-id!\n");
>> +		return -EINVAL;
>> +	}
>> +
>> +	if (device_property_read_u32(&pdev->dev, "hisilicon,sub-id",
>> +				     &uc_pmu->sub_id)) {
>> +		dev_err(&pdev->dev, "Can not read sub-id!\n");
>> +		return -EINVAL;
>> +	}
>> +
>> +	uc_pmu->base = devm_platform_ioremap_resource(pdev, 0);
>> +	if (IS_ERR(uc_pmu->base)) {
>> +		dev_err(&pdev->dev, "ioremap failed for uc_pmu resource\n");
>> +		return PTR_ERR(uc_pmu->base);
>> +	}
>> +
>> +	uc_pmu->identifier = readl(uc_pmu->base + HISI_UC_VERSION_REG);
>> +
>> +	return 0;
>> +}
>
>> +static struct platform_driver hisi_uc_pmu_driver = {
>> +	.driver = {
>> +		.name = "hisi_uc_pmu",
>> +		.acpi_match_table = hisi_uc_pmu_acpi_match,
>> +		/*
>> +		 * We have not worked out a safe bind/unbind process,
>> +		 * so this is not supported yet.
> If you can reference more info on this that would be great.
> Perhaps a thread talking about why?
forcefully unbinding during sampling will lead to a
kernel panic, because the perf upper-layer framework
call a NULL pointer in this situation.

Best regards,
Junhao.
>> +		 */
>> +		.suppress_bind_attrs = true,
>> +	},
>> +	.probe = hisi_uc_pmu_probe,
>> +};
> .
>


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-06-07 11:25 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-31 10:46 [PATCH v2 0/3] Add support for HiSilicon SoC uncore PMU Junhao He
2023-05-31 10:46 ` [PATCH v2 1/3] drivers/perf: hisi: Add support for HiSilicon H60PA and PAv3 PMU driver Junhao He
2023-05-31 15:45   ` Jonathan Cameron
2023-06-01  6:40   ` Yicong Yang
2023-05-31 10:46 ` [PATCH v2 2/3] drivers/perf: hisi: Add support for HiSilicon UC " Junhao He
2023-05-31 15:59   ` Jonathan Cameron
2023-06-01  6:53     ` Yicong Yang
2023-06-07 11:00     ` hejunhao
2023-06-01  6:41   ` Yicong Yang
2023-05-31 10:46 ` [PATCH v2 3/3] docs: perf: Add new description for HiSilicon UC PMU Junhao He
2023-05-31 16:00   ` Jonathan Cameron
2023-06-01  6:44   ` Yicong Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).