Add support for HiSilicon SoC uncore PMU
Subsystems (3)
v3 cover Add support for HiSilicon SoC uncore PMU
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 v2:
- Modify the driver description according to Jonathan's comment.
Change since v1:
- Improve according to Yicong's suggestion
- Fixes build warning of "-Wmissing-prototypes"
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 | 578 ++++++++++++++++++++ 6 files changed, 732 insertions(+), 17 deletions(-) create mode 100644 drivers/perf/hisilicon/hisi_uncore_uc_pmu.c
Signature · 1 line
2.33.0
PATCH v3 1/3 drivers/perf: hisi: Add support for HiSilicon H60PA and PAv3 PMU driver
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.
--- drivers/perf/hisilicon/hisi_uncore_pa_pmu.c | 142 +++++++++++++++++--- drivers/perf/hisilicon/hisi_uncore_pmu.h | 9 ++ 2 files changed, 136 insertions(+), 15 deletions(-)
drivers/perf/hisilicon/hisi_uncore_pa_pmu.c +127 -15
@@ -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" ,
drivers/perf/hisilicon/hisi_uncore_pmu.h +9 -0
@@ -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;
Signature · 1 line
2.33.0
PATCH v3 2/3 drivers/perf: hisi: Add support for HiSilicon UC PMU driver
In reply to Junhao HeOn HiSilicon Hip09 platform, there is 4 UC (unified cache) module on each chip CCL (CPU Cluster). UC is a cache that provides coherence between NUMA and UMA domains. It is located between L2 and Memory System. And many PMU events are supported. Let's support the UC 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 at Documentation/admin-guide/perf/hisi-pmu.rst
* srcid_en & srcid: Allows users to filter statistical information based on specific CPU/ICL by srcid.srcid_en depending on rd_req_en enabled.
* uring_channel: Allows users to filter statistical information based on the specified tx request uring channel.uring_channel only supported events: [0x47 ~ 0x59].
--- 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 | 578 ++++++++++++++++++++ 4 files changed, 588 insertions(+), 2 deletions(-) create mode 100644 drivers/perf/hisilicon/hisi_uncore_uc_pmu.c
drivers/perf/hisilicon/Makefile +1 -1
@@ -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
drivers/perf/hisilicon/hisi_uncore_pmu.c +3 -1
@@ -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;
drivers/perf/hisilicon/hisi_uncore_pmu.h +6 -0
@@ -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 *);
drivers/perf/hisilicon/hisi_uncore_uc_pmu.c new file +578 -0
578 lines not on this page · raw message
Signature · 1 line
2.33.0
Re: [PATCH v3 2/3] drivers/perf: hisi: Add support for HiSilicon UC PMU driver
Quoted 1 line · On Thu, 8 Jun 2023 19:37:18 +0800 Junhao He <[email protected]> wrote:
On HiSilicon Hip09 platform, there is 4 UC (unified cache) module
are 4 UC (unified cache) modules
Quoted 3 lines
on each chip CCL (CPU Cluster). UC is a cache that provides coherence between NUMA and UMA domains. It is located between L2 and Memory System. And many PMU events are supported. Let's support
Many PMU events are supported.
Quoted 9 lines
the UC PMU driver using the HiSilicon uncore PMU framework.
*
rd_req_en:rd_req_enis the abbreviation of read request tracetag enable and allows user to count only read operations. Details are listed in the hisi-pmu document atDocumentation/admin-guide/perf/hisi-pmu.rst*
srcid_en& srcid: Allows users to filter statistical information based on specific CPU/ICL by srcid.srcid_endepending onrd_req_enenabled.
srcid_en depends on rd_req_en being enabled.
Quoted 7 lines
*
uring_channel: Allows users to filter statistical information based on the specified tx request uring channel.uring_channelonly supported events: [0x47~0x59].Signed-off-by Junhao He <[email protected]>Reviewed-by Yicong Yang <[email protected]>
The editorial stuff above is trivial and original text can be easily understood. So maintainers may not care. If you happen to be re rolling the patch then nice to clean it up.
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v3 2/3] drivers/perf: hisi: Add support for HiSilicon UC PMU driver
Hi, Jonathan
Quoted 6 lines · Jonathan Cameron
Quoted 1 line · On Thu, 8 Jun 2023 19:37:18 +0800 Junhao He <[email protected]> wrote:
On HiSilicon Hip09 platform, there is 4 UC (unified cache) module
are 4 UC (unified cache) modules
Ok, will fix it.
Thanks.
Quoted 4 lines
Quoted 3 lines
on each chip CCL (CPU Cluster). UC is a cache that provides coherence between NUMA and UMA domains. It is located between L2 and Memory System. And many PMU events are supported. Let's support
Many PMU events are supported.
Ok, will fix it.
Thanks.
Quoted 10 lines
Quoted 9 lines
the UC PMU driver using the HiSilicon uncore PMU framework.
*
rd_req_en:rd_req_enis the abbreviation of read request tracetag enable and allows user to count only read operations. Details are listed in the hisi-pmu document atDocumentation/admin-guide/perf/hisi-pmu.rst*
srcid_en& srcid: Allows users to filter statistical information based on specific CPU/ICL by srcid.srcid_endepending onrd_req_enenabled.
srcid_endepends onrd_req_enbeing enabled.
Ok, will fix it.
Thanks.
Quoted 4 lines
Quoted 4 lines
*
uring_channel: Allows users to filter statistical information based on the specified tx request uring channel.uring_channelonly supported events: [0x47~0x59].
Quoted 8 lines
Quoted 2 lines
Signed-off-by Junhao He <[email protected]>Reviewed-by Yicong Yang <[email protected]>The editorial stuff above is trivial and original text can be easily understood. So maintainers may not care. If you happen to be re rolling the patch then nice to clean it up.
Reviewed-by Jonathan Cameron <[email protected]>.
Sure, Will fix in next version.
Thanks.
PATCH v3 3/3 docs: perf: Add new description for HiSilicon UC PMU
In reply to Junhao HeA 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.
--- Documentation/admin-guide/perf/hisi-pmu.rst | 8 ++++++++ 1 file changed, 8 insertions(+)
Documentation/admin-guide/perf/hisi-pmu.rst +8 -0
@@ -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
Signature · 1 line
2.33.0