drivers/perf: hisi: Add driver for HNS3 PMU
Subsystems (5)
cover drivers/perf: hisi: Add driver for HNS3 PMU
This patch-set adds driver for HNS3(HiSilicon network system version 3) PMU and doc to descript it.
Guangbin Huang (2):
drivers/perf: hisi: Add description for HNS3 PMU driver drivers/perf: hisi: add driver for HNS3 PMU
Documentation/admin-guide/perf/hns3-pmu.rst | 122 ++ MAINTAINERS | 6 + drivers/perf/hisilicon/Kconfig | 9 + drivers/perf/hisilicon/Makefile | 1 + drivers/perf/hisilicon/hns3_pmu.c | 1631 +++++++++++++++++++ include/linux/cpuhotplug.h | 1 + 6 files changed, 1770 insertions(+) create mode 100644 Documentation/admin-guide/perf/hns3-pmu.rst create mode 100644 drivers/perf/hisilicon/hns3_pmu.c
Signature · 7 lines
2.33.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH RESEND 1/2 drivers/perf: hisi: Add description for HNS3 PMU driver
HNS3 PMU End Point device is supported on HiSilicon HIP09 platform, so add document hns3-pmu.rst to provide guidance on how to use it.
--- Documentation/admin-guide/perf/hns3-pmu.rst | 122 ++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 Documentation/admin-guide/perf/hns3-pmu.rst
Documentation/admin-guide/perf/hns3-pmu.rst new file +122 -0
@@ -0,0 +1,122 @@ +====================================== +HNS3 Performance Monitoring Unit (PMU) +====================================== + +HNS3(HiSilicon network system 3) Performance Monitoring Unit (PMU) is an +End Point device to collect performance statistics of HiSilicon SoC NIC. +On Hip09, each SICL(Super I/O cluster) has one PMU device. + +HNS3 PMU supports collection of performance statistics such as bandwidth, +latency, packet rate and interrupt rate. + +Each HNS3 PMU supports 8 hardware events. + +HNS3 PMU driver +=============== + +The HNS3 PMU driver registers a perf PMU with the name of its device id.:: + + /sys/devices/hns3_pmu_<device_id> + +The device_id is read from hardware register, it contains information of +chip_id(bit 31:2) and SICL_ID(bit 1:0). One chip may have one or more SICL. + +PMU driver provides description of available events, filter modes, format, +identifier and cpumask in sysfs. + +The "events" directory describes the event code and subevent code of all +supported events shown in perf list. + +The "filtermode" directory describes the supported filter modes of each +event. + +The "format" directory describes all formats of the config (events) and +config1 (filter options) fields of the perf_event_attr structure. + +The "identifier" file shows version of PMU hardware device. + +Example usage of checking event code and subevent code:: + + $# cat /sys/devices/hns3_pmu_0/events/pps_ssu_rpu + config=0x0102 + +The upper 8 bits of config (here 0x01) are the event code. The lower 8 bits +of config (here 0x02) are the subevent code. + +Example usage of checking supported filter mode:: + + $# cat /sys/devices/hns3_pmu_0/filtermode/bw_igu_ssu + filter mode supported: global/port/port-tc/ + +Example usage of perf:: + + $# perf list + hns3_pmu_0/bw_igu_ssu/ [kernel PMU event] + ------------------------------------------ + + $# perf stat -a -e hns3_pmu_0/bw_igu_ssu,global=1/ -I 1000 + or + $# perf stat -a -e hns3_pmu_0/event=0,subevent=0,global=1/ -I 1000 + +The current driver does not support sampling, so "perf record" is unsupported. +Also attach to a task is unsupported for HNS3 PMU. + +Filter modes +-------------- + +1. global mode +PMU collect performance statistics for all HNS3 PCIe functions of IO DIE. +Set the "global" filter option to 1 will enable this mode. +Example usage of perf:: + + $# perf stat -a -e hns3_pmu_0/event=0,subevent=0,global=1/ -I 1000 + +2. port mode +PMU collect performance statistic of one whole physical port. The port id +is same as mac id. The "tc" filter option must be set to 0xF in this mode, +here tc stands for traffic class. + +Example usage of perf:: + + $# perf stat -a -e hns3_pmu_0/event=0,subevent=0,port=0,tc=0xF/ -I 1000 + +3. port-tc mode +PMU collect performance statistic of one tc of physical port. The port id +is same as mac id. The "tc" filter option must be set to 0 ~ 7 in this +mode. +Example usage of perf:: + + $# perf stat -a -e hns3_pmu_0/event=0,subevent=0,port=0,tc=0/ -I 1000 + +4. func mode +PMU collect performance statistic of one PF/VF. The function id is BDF of +PF/VF, its conversion formula:: + + func = (bus << 8) + (device << 3) + (function) + +for example: + BDF func + 35:00.0 0x3500 + 35:00.1 0x3501 + 35:01.0 0x3508 + +In this mode, the "queue" filter option must be set to 0xFFFF. +Example usage of perf:: + + $# perf stat -a -e hns3_pmu_0/event=0,subevent=0,bdf=0x3500,queue=0xFFFF/ -I 1000 + +5. func-queue mode +PMU collect performance statistic of one queue of PF/VF. The function id +is BDF of PF/VF, the "queue" filter option must be set to the exact queue +id of function. +Example usage of perf:: + + $# perf stat -a -e hns3_pmu_0/event=0,subevent=0,bdf=0x3500,queue=0/ -I 1000 + +6. func-intr mode +PMU collect performance statistic of one interrupt of PF/VF. The function +id is BDF of PF/VF, the "intr" filter option must be set to the exact +interrupt id of function. +Example usage of perf:: + + $# perf stat -a -e hns3_pmu_0/event=0,subevent=0,bdf=0x3500,intr=0/ -I 1000
Signature · 7 lines
2.33.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH RESEND 2/2 drivers/perf: hisi: add driver for HNS3 PMU
In reply to Guangbin HuangHNS3 PMU End Point device supports to collect performance statistics of bandwidth, latency, packet rate, interrupt rate in HiSilicon SoC NIC.
NIC of each IO DIE has one PMU device for it. Driver registers each PMU device to perf, and exports information of supported events, filter mode of each event, identifier and so on via sysfs.
Each PMU device has its own control, counter and interrupt registers, and supports up to 8 events by hardware.
Filter options contains:
event - select event subevent - select subevent port - select physical port of nic tc - select tc(must be used with port) func - select PF/VF queue - select queue of PF/VF(must be used with func) intr - select interrupt number(must be used with func) global - select all functions of IO DIE
--- MAINTAINERS | 6 + drivers/perf/hisilicon/Kconfig | 9 + drivers/perf/hisilicon/Makefile | 1 + drivers/perf/hisilicon/hns3_pmu.c | 1631 +++++++++++++++++++++++++++++ include/linux/cpuhotplug.h | 1 + 5 files changed, 1648 insertions(+) create mode 100644 drivers/perf/hisilicon/hns3_pmu.c
MAINTAINERS +6 -0
@@ -8614,6 +8614,12 @@ F: Documentation/admin-guide/perf/hisi-pcie-pmu.rst F: Documentation/admin-guide/perf/hisi-pmu.rst F: drivers/perf/hisilicon +HISILICON HNS3 PMU DRIVER +M: Guangbin Huang <[email protected]> +S: Supported +F: Documentation/admin-guide/perf/hns3-pmu.rst +F: drivers/perf/hisilicon/hns3_pmu.c + HISILICON QM AND ZIP Controller DRIVER M: Zhou Wang <[email protected]> L: [email protected]
drivers/perf/hisilicon/Kconfig +9 -0
@@ -14,3 +14,12 @@ config HISI_PCIE_PMU RCiEP devices. Adds the PCIe PMU into perf events system for monitoring latency, bandwidth etc. + +config HNS3_PMU + tristate "HNS3 PERF PMU" + depends on ARM64 && PCI + help + Provide support for HNS3 performance monitoring unit (PMU) IEP + devices. + Adds the HNS3 PMU into perf events system for monitoring latency, + bandwidth etc.
drivers/perf/hisilicon/Makefile +1 -0
@@ -4,3 +4,4 @@ obj-$(CONFIG_HISI_PMU) += hisi_uncore_pmu.o hisi_uncore_l3c_pmu.o \ hisi_uncore_pa_pmu.o obj-$(CONFIG_HISI_PCIE_PMU) += hisi_pcie_pmu.o +obj-$(CONFIG_HNS3_PMU) += hns3_pmu.o
drivers/perf/hisilicon/hns3_pmu.c new file +1631 -0
1,631 lines not on this page · raw message
include/linux/cpuhotplug.h +1 -0
@@ -226,6 +226,7 @@ enum cpuhp_state {CPUHP_AP_PERF_ARM_HISI_PA_ONLINE ,CPUHP_AP_PERF_ARM_HISI_SLLC_ONLINE ,CPUHP_AP_PERF_ARM_HISI_PCIE_PMU_ONLINE , +CPUHP_AP_PERF_ARM_HNS3_PMU_ONLINE ,CPUHP_AP_PERF_ARM_L2X0_ONLINE ,CPUHP_AP_PERF_ARM_QCOM_L2_ONLINE , CPUHP_AP_PERF_ARM_QCOM_L3_ONLINE,
Signature · 7 lines
2.33.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [RESEND PATCH 2/2] drivers/perf: hisi: add driver for HNS3 PMU
On 17/01/2022 01:52, Guangbin Huang wrote:
+linuxarm
Quoted 53 lines
HNS3 PMU End Point device supports to collect performance statistics of bandwidth, latency, packet rate, interrupt rate in HiSilicon SoC NIC.
NIC of each IO DIE has one PMU device for it. Driver registers each PMU device to perf, and exports information of supported events, filter mode of each event, identifier and so on via sysfs.
Each PMU device has its own control, counter and interrupt registers, and supports up to 8 events by hardware.
Filter options contains:
event - select event subevent - select subevent port - select physical port of nic tc - select tc(must be used with port) func - select PF/VF queue - select queue of PF/VF(must be used with func) intr - select interrupt number(must be used with func) global - select all functions of IO DIESigned-off-by Guangbin Huang <[email protected]>--- MAINTAINERS | 6 + drivers/perf/hisilicon/Kconfig | 9 + drivers/perf/hisilicon/Makefile | 1 + drivers/perf/hisilicon/hns3_pmu.c | 1631 +++++++++++++++++++++++++++++ include/linux/cpuhotplug.h | 1 + 5 files changed, 1648 insertions(+)create mode 100644
drivers/perf/hisilicon/hns3_pmu.cMAINTAINERS +6
-0@@ -8614,6 +8614,12 @@ F: Documentation/admin-guide/perf/hisi-pcie-pmu.rst F: Documentation/admin-guide/perf/hisi-pmu.rst F: drivers/perf/hisilicon +HISILICON HNS3 PMU DRIVER +M: Guangbin Huang <[email protected]> +S: Supported +F: Documentation/admin-guide/perf/hns3-pmu.rst +F: drivers/perf/hisilicon/hns3_pmu.c + HISILICON QM AND ZIP Controller DRIVER M: Zhou Wang <[email protected]> L: [email protected]drivers/perf/hisilicon/Kconfig +0
-0
drivers/perf/hisilicon/Kconfig config HISI_PCIE_PMU · line 20
Quoted 7 lines
drivers/perf/hisilicon/Kconfig +4
-0@@ -14,3 +14,12 @@ config HISI_PCIE_PMU RCiEP devices. Adds the PCIe PMU into perf events system for monitoring latency, bandwidth etc. + +config HNS3_PMU + tristate "HNS3 PERF PMU" + depends on ARM64 && PCI
Any reason not to add COMPILE_TEST, like:
depends on ARM64 || COMPILE_TEST depends on PCI
Quoted 25 lines
drivers/perf/hisilicon/Kconfig +5
-0+ help + Provide support for HNS3 performance monitoring unit (PMU) IEP + devices. + Adds the HNS3 PMU into perf events system for monitoring latency, + bandwidth etc.drivers/perf/hisilicon/Makefile +1
-0@@ -4,3 +4,4 @@ obj-$(CONFIG_HISI_PMU) += hisi_uncore_pmu.o hisi_uncore_l3c_pmu.o \ hisi_uncore_pa_pmu.o obj-$(CONFIG_HISI_PCIE_PMU) += hisi_pcie_pmu.o +obj-$(CONFIG_HNS3_PMU) += hns3_pmu.odrivers/perf/hisilicon/hns3_pmu.c new file +3
-0@@ -0,0 +1,1631 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* This driver adds support for HNS3 PMU iEP device.
Quoted 2 lines
Related perf events are
+ * bandwidth, latency, packet rate, interrupt rate etc.
I don't think that this is relevant here
Quoted 3 lines
+ *
+ * Copyright (C) 2021 HiSilicon Limited
+ */
2022, I suppose now...
drivers/perf/hisilicon/hns3_pmu.c line 371
Quoted 11 lines
drivers/perf/hisilicon/hns3_pmu.c new file +11
-0+}; + +#define HNS3_PMU_SET_HW_FILTER (_hwc, _mode) \ + ((_hwc)->addr_filters = (void *)&hns3_pmu_hw_filter_modes[(_mode)]) + +static ssize_t identifier_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct hns3_pmu *hns3_pmu; + + hns3_pmu =to_hns3_pmu (dev_get_drvdata (dev));
Can the declaration and assignment be on the same line?
Quoted 19 lines
drivers/perf/hisilicon/hns3_pmu.c new file +19
-0+ +return sysfs_emit (buf,"0x%x\n" , hns3_pmu->identifier); +} +static DEVICE_ATTR_RO (identifier); + +static ssize_t cpumask_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct hns3_pmu *hns3_pmu =to_hns3_pmu (dev_get_drvdata (dev)); + +return sysfs_emit (buf,"%d\n" , hns3_pmu->on_cpu); +} +static DEVICE_ATTR_RO (cpumask); + +static ssize_t bdf_min_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct hns3_pmu *hns3_pmu =to_hns3_pmu (dev_get_drvdata (dev)); +
drivers/perf/hisilicon/hns3_pmu.c line 400
Quoted 10 lines
drivers/perf/hisilicon/hns3_pmu.c new file +10
-0+return sysfs_emit (buf,"0x%4x\n" , hns3_pmu->bdf_min); +} +static DEVICE_ATTR_RO (bdf_min); + +static ssize_t bdf_max_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct hns3_pmu *hns3_pmu =to_hns3_pmu (dev_get_drvdata (dev)); + +return sysfs_emit (buf,"0x%4x\n" , hns3_pmu->bdf_max);
are these same files as in HISI PCI PMU driver?
Quoted 30 lines
drivers/perf/hisilicon/hns3_pmu.c new file +27
-0+} +static DEVICE_ATTR_RO (bdf_max); + +static struct attribute *hns3_pmu_events_attr[] = { +/* bandwidth events */ + +static struct attribute_group hns3_pmu_events_group = { + .name ="events" , + .attrs = hns3_pmu_events_attr, +}; + +static struct attribute_group hns3_pmu_filter_mode_group = { + .name ="filtermode" , +}; + +} + +static bool hns3_pmu_valid_bdf (struct hns3_pmu *hns3_pmu,u16 bdf) +{ +struct pci_dev *pdev; + +if (bdf < hns3_pmu->bdf_min || bdf > hns3_pmu->bdf_max) { +pci_err (hns3_pmu->pdev,"Invalid EP device: %#x!\n" , bdf); +return false; + } + + pdev = pci_get_domain_bus_and_slot(pci_domain_nr(hns3_pmu->pdev->bus),
drivers/perf/hisilicon/hns3_pmu.c
Quoted 10 lines
drivers/perf/hisilicon/hns3_pmu.c new file +10
-0+PCI_BUS_NUM (bdf), + GET_PCI_DEVFN(bdf)); +if (!pdev) { +pci_err (hns3_pmu->pdev,"Nonexistent EP device: %#x!\n" , bdf); +return false; + } + +pci_dev_put (pdev); +return true; +}
if any of this code is same as hisi pci pmu driver then please put in a common lib
Quoted 21 lines
drivers/perf/hisilicon/hns3_pmu.c new file +21
-0+ +static void hns3_pmu_set_qid_para (struct hns3_pmu *hns3_pmu,u32 idx,u16 bdf, +u16 queue) +{ +u32 val; + + val =GET_PCI_DEVFN (bdf); + val |= (u32 )queue <<HNS3_PMU_QID_PARA_QUEUE_S ; +hns3_pmu_writel (hns3_pmu,HNS3_PMU_REG_EVENT_QID_PARA , idx, val); +} + +static bool hns3_pmu_qid_req_start (struct hns3_pmu *hns3_pmu,u32 idx) +{ +bool queue_id_valid = false; +u32 reg_qid_ctrl, val; +int err; + +/* enable queue id request */ +hns3_pmu_writel (hns3_pmu,HNS3_PMU_REG_EVENT_QID_CTRL , idx, +HNS3_PMU_QID_CTRL_REQ_ENABLE ); +
...
Quoted 25 lines
drivers/perf/hisilicon/hns3_pmu.c new file +25
-0+} + +static bool hns3_pmu_validate_event_group (struct perf_event *event) +{ +struct perf_event *leader = event->group_leader; +struct perf_event *sibling; +int counters =1 ; + +if (!is_software_event (leader)) { +/* +* We must NOT create groups containing mixed PMUs, although +* software events are acceptable +*/ +if (leader->pmu != event->pmu) +return false; + +/* Increase counter for the leader */ +if (leader != event) + counters++; + } + +for_each_sibling_event (sibling, event->group_leader) { +if (is_software_event (sibling)) +continue ; +
drivers/perf/hisilicon/hns3_pmu.c line 951
Quoted 10 lines
drivers/perf/hisilicon/hns3_pmu.c new file +10
-0+if (sibling->pmu != event->pmu) +return false; + +/* Increase counter for each sibling */ + counters++; + } + +return counters <=HNS3_PMU_MAX_COUNTERS ; +} +
This is exact same effectively as hisi_validate_event_group(), apart from:
return counters <= HNS3_PMU_MAX_COUNTERS;
vs
return counters <= hisi_pmu->num_counters;
Can we factor all this out? Less code to review makes reviewing easier and quicker and less daunting ...
Quoted 100 lines
drivers/perf/hisilicon/hns3_pmu.c new file +100
-0+} + +/* +* The performance calculation formula of all types of event is +* performance = data / data_ext. +* The arguments data and data_ext have different meanings for different types +* of events as follow: +* event_type data data_ext +* bandwidth byte number cycles number +* packet rate packet number cycles number +* interrupt rate interrupt number cycles number +* latency cycles number packet number +*/ +static u64 hns3_pmu_get_performance (u8 event_type,u32 hw_clk_freq,u64 data, +u64 data_ext) +{ +u64 result; + +if (!hw_clk_freq || !data || !data_ext) +return 0 ; + +switch (event_type) { +case HNS3_PMU_EVENT_TYPE_BANDWIDTH : +/* process data to set unit of bandwidth as "KBits/s" */ + result = data /hns3_pmu_tick_to_ms (hw_clk_freq, data_ext); + result =BYTES_TO_BITS (result); +break ; + +case HNS3_PMU_EVENT_TYPE_PACKET_RATE : +case HNS3_PMU_EVENT_TYPE_INTR_RATE : +/* process data to set unit as "pps" */ + result = data *1000 / +hns3_pmu_tick_to_ms (hw_clk_freq, data_ext); +break ; + +case HNS3_PMU_EVENT_TYPE_LATENCY : +/* process data to set unit of latency as "ns" */ + result = data / data_ext; + result = result *1000000000 / hw_clk_freq; +break ; + +default : + result = data / data_ext; +break ; + } + +return result; +} + +static int hns3_pmu_event_init (struct perf_event *event) +{ +struct hns3_pmu *hns3_pmu =to_hns3_pmu (event->pmu); +struct hw_perf_event *hwc = &event->hw; +int idx; +int ret; + +if (event->attr.type != event->pmu->type) +return -ENOENT ; + +/* Sampling is not supported */ +if (is_sampling_event (event) || event->attach_state &PERF_ATTACH_TASK ) +return -EOPNOTSUPP ; + + event->cpu = hns3_pmu->on_cpu; + + idx =hns3_pmu_get_event_idx (hns3_pmu); +if (idx <0 ) { +pci_err (hns3_pmu->pdev,"Up to %u events are supported!\n" , +HNS3_PMU_MAX_COUNTERS ); +return -EBUSY ; + } + + hwc->idx = idx; + + ret =hns3_pmu_select_filter_mode (event, hns3_pmu); +if (ret) { +pci_err (hns3_pmu->pdev,"Invalid filter, ret = %d.\n" , ret); +return ret; + } + +if (!hns3_pmu_validate_event_group (event)) { +pci_err (hns3_pmu->pdev,"Invalid event group.\n" ); +return -EINVAL ; + } + +return 0 ; +} + +static void hns3_pmu_read (struct perf_event *event) +{ +struct hns3_pmu *hns3_pmu =to_hns3_pmu (event->pmu); +struct hw_perf_event *hwc = &event->hw; +struct hw_perf_event_extra *hwc_ext; +u64 new_cnt_ext, prev_cnt_ext; +u64 new_cnt, prev_cnt, delta; + + hwc_ext = &hwc->extra_reg; + do { + prev_cnt = local64_read(&hwc->prev_count); + prev_cnt_ext = hwc_ext->config;
drivers/perf/hisilicon/hns3_pmu.c line 1216
Quoted 10 lines
drivers/perf/hisilicon/hns3_pmu.c new file +10
-0+hns3_pmu_read_counter (event, &new_cnt, &new_cnt_ext); + }while (local64_cmpxchg (&hwc->prev_count, prev_cnt, new_cnt) != + prev_cnt); + + hwc_ext->config = new_cnt_ext; + + delta =hns3_pmu_get_performance (hns3_get_event (event), + hns3_pmu->hw_clk_freq, + new_cnt - prev_cnt, + new_cnt_ext - prev_cnt_ext);
This looks very much like what was originally had in the hisi PCI PMU driver:
https://lore.kernel.org/linux-arm-kernel/20210616134257.GA22905@willie-the-truck/
https://lore.kernel.org/linux-arm-kernel/20210617175704.GF24813@willie-the-truck/
Please consult with liuqi
If it is, I figure that we're going to need to expose the 2x values and do the calculation in userspace.
Quoted 13 lines
drivers/perf/hisilicon/hns3_pmu.c new file +13
-0+ +local64_add (delta, &event->count); +} + +static void hns3_pmu_start (struct perf_event *event,int flags) +{ +struct hns3_pmu *hns3_pmu =to_hns3_pmu (event->pmu); +struct hw_perf_event *hwc = &event->hw; + +if (WARN_ON_ONCE (!(hwc->state &PERF_HES_STOPPED ))) +return ; + +WARN_ON_ONCE (!(hwc->state &PERF_HES_UPTODATE ));
...
drivers/perf/hisilicon/hns3_pmu.c line 1333
Quoted 4 lines
drivers/perf/hisilicon/hns3_pmu.c new file +4
-0+ + val =readl (hns3_pmu->base +HNS3_PMU_REG_DEVICE_ID ); + device_id = val &0xffff ; + name =devm_kasprintf (&pdev->dev,GFP_KERNEL ,"hns3_pmu_%u" , device_id);
would adding sccl to the name help it make it more clear that this is per sccl, like hns3_pmu_sccl%u?
drivers/perf/hisilicon/hns3_pmu.c line 1335
Quoted 2 lines
drivers/perf/hisilicon/hns3_pmu.c new file +2
-0+if (!name) { +pci_err (pdev,"failed to allocate name for HNS3 PMU.\n" );
I don't think that you need this -ENOMEM messages
drivers/perf/hisilicon/hns3_pmu.c line 1341
Quoted 6 lines
drivers/perf/hisilicon/hns3_pmu.c new file +6
-0+ ret = -ENOMEM ; + goto err_alloc_dev_name; + } + + hns3_pmu->pdev = pdev; + hns3_pmu->on_cpu =HNS3_PMU_INVALID_CPU_ID ;
can you possibly just initially target the probe CPU?
Quoted 85 lines
drivers/perf/hisilicon/hns3_pmu.c new file +85
-0+ hns3_pmu->identifier =readl (hns3_pmu->base +HNS3_PMU_REG_VERSION ); + hns3_pmu->pmu = (struct pmu ) { + .name = name, + .module =THIS_MODULE , + .event_init = hns3_pmu_event_init, + .pmu_enable = hns3_pmu_enable, + .pmu_disable = hns3_pmu_disable, + .add = hns3_pmu_add, + .del = hns3_pmu_del, + .start = hns3_pmu_start, + .stop = hns3_pmu_stop, + .read = hns3_pmu_read, + .task_ctx_nr = perf_invalid_context, + .attr_groups = hns3_pmu_attr_groups, + .capabilities =PERF_PMU_CAP_NO_EXCLUDE , + }; + +return 0 ; + +err_alloc_dev_name: +iounmap (hns3_pmu->base); +err_ioremap_bar: +pci_release_regions (pdev); + +return ret; +} + +static irqreturn_t hns3_pmu_irq (int irq,void *data) +{ +struct hns3_pmu *hns3_pmu = data; +u32 intr_status, idx; + +for (idx =0 ; idx <HNS3_PMU_MAX_COUNTERS ; idx++) { + intr_status =hns3_pmu_readl (hns3_pmu, +HNS3_PMU_REG_EVENT_INTR_STATUS , + idx); + +/* +* As each counter will restart from 0 when it is overflowed, +* extra processing is no need, just clear interrupt status. +*/ +if (intr_status) +hns3_pmu_clear_intr_status (hns3_pmu, idx); + } + +return IRQ_HANDLED ; +} + +static int hns3_pmu_online_cpu (unsigned int cpu,struct hlist_node *node) +{ +struct hns3_pmu *hns3_pmu; + + hns3_pmu = hlist_entry_safe(node, struct hns3_pmu, node); +if (!hns3_pmu) +return -ENODEV ; + +if (hns3_pmu->on_cpu ==HNS3_PMU_INVALID_CPU_ID ) { + hns3_pmu->on_cpu = cpu; +irq_set_affinity_hint (hns3_pmu->irq,cpumask_of (cpu)); + } + +return 0 ; +} + +static int hns3_pmu_offline_cpu (unsigned int cpu,struct hlist_node *node) +{ +struct hns3_pmu *hns3_pmu; +unsigned int target; + + hns3_pmu = hlist_entry_safe(node, struct hns3_pmu, node); +if (!hns3_pmu) +return -ENODEV ; + +/* Nothing to do if this CPU doesn't own the PMU */ +if (hns3_pmu->on_cpu != cpu) +return 0 ; + +/* Choose a new CPU from all online cpus */ + target =cpumask_any_but (cpu_online_mask, cpu); +if (target >= nr_cpu_ids) +return 0 ; + +perf_pmu_migrate_context (&hns3_pmu->pmu, cpu, target); + hns3_pmu->on_cpu = target; +irq_set_affinity_hint (hns3_pmu->irq,cpumask_of (target));
drivers/perf/hisilicon/hns3_pmu.c line 1436
Quoted 10 lines
drivers/perf/hisilicon/hns3_pmu.c new file +10
-0+ +return 0 ; +} + +static int hns3_pmu_irq_register (struct pci_dev *pdev, +struct hns3_pmu *hns3_pmu) +{ +int irq, ret; + + ret =pci_alloc_irq_vectors (pdev,1 ,1 ,PCI_IRQ_MSI );
I don't think that a pcim exists here, so can use devm_add_action() to free them [maybe the name is wrong I mentioned]
drivers/perf/hisilicon/hns3_pmu.c line 1443
Quoted 7 lines
drivers/perf/hisilicon/hns3_pmu.c new file +7
-0+if (ret <0 ) { +pci_err (pdev,"failed to enable MSI vectors, ret = %d.\n" , ret); +return ret; + } + + irq =pci_irq_vector (pdev,0 ); + ret =request_irq (irq, hns3_pmu_irq,0 , hns3_pmu->pmu.name, hns3_pmu);
devm_request_irq()
Quoted 30 lines
drivers/perf/hisilicon/hns3_pmu.c new file +30
-0+if (ret) { +pci_err (pdev,"failed to register irq, ret = %d.\n" , ret); +pci_free_irq_vectors (pdev); +return ret; + } + + hns3_pmu->irq = irq; + +return 0 ; +} + +static void hns3_pmu_irq_unregister (struct pci_dev *pdev, +struct hns3_pmu *hns3_pmu) +{ +free_irq (hns3_pmu->irq, hns3_pmu); +pci_free_irq_vectors (pdev); +} + +static int hns3_pmu_init (struct pci_dev *pdev,struct hns3_pmu *hns3_pmu) +{ +int ret; + + ret =hns3_pmu_alloc_pmu (pdev, hns3_pmu); +if (ret) +return ret; + + ret =hns3_pmu_irq_register (pdev, hns3_pmu); +if (ret) + goto err_irq_register; +
drivers/perf/hisilicon/hns3_pmu.c line 1483
Quoted 10 lines
drivers/perf/hisilicon/hns3_pmu.c new file +10
-0+ ret =cpuhp_state_add_instance (CPUHP_AP_PERF_ARM_HNS3_PMU_ONLINE , + &hns3_pmu->node); +if (ret) { +pci_err (pdev,"failed to register hotplug, ret = %d.\n" , ret); + goto err_register_hotplug; + } + + ret =perf_pmu_register (&hns3_pmu->pmu, hns3_pmu->pmu.name,-1 ); +if (ret) { +pci_err (pdev,"failed to register HNS3 PMU, ret = %d.\n" , ret);
do you need to mention "HNS3 PMU", since pdev is passed
Quoted 12 lines
drivers/perf/hisilicon/hns3_pmu.c new file +12
-0+ goto err_register_pmu; + } + +return ret; + +err_register_pmu: +cpuhp_state_remove_instance (CPUHP_AP_PERF_ARM_HNS3_PMU_ONLINE , + &hns3_pmu->node); +irq_set_affinity_hint (hns3_pmu->irq,NULL ); + +err_register_hotplug: +hns3_pmu_irq_unregister (pdev, hns3_pmu);
drivers/perf/hisilicon/hns3_pmu.c line 1505
Quoted 10 lines
drivers/perf/hisilicon/hns3_pmu.c new file +10
-0+ +err_irq_register: +iounmap (hns3_pmu->base); + +return ret; +} + +static void hns3_pmu_uninit (struct pci_dev *pdev) +{ +struct hns3_pmu *hns3_pmu = (struct hns3_pmu *)pci_get_drvdata (pdev);
no need to cast a void ptr
Quoted 4 lines
drivers/perf/hisilicon/hns3_pmu.c new file +4
-0+ +perf_pmu_unregister (&hns3_pmu->pmu); +cpuhp_state_remove_instance (CPUHP_AP_PERF_ARM_HNS3_PMU_ONLINE , + &hns3_pmu->node);
drivers/perf/hisilicon/hns3_pmu.c line 1519
Quoted 10 lines
drivers/perf/hisilicon/hns3_pmu.c new file +10
-0+irq_set_affinity_hint (hns3_pmu->irq,NULL ); +hns3_pmu_irq_unregister (pdev, hns3_pmu); +iounmap (hns3_pmu->base); +} + +static int hns3_pmu_init_dev (struct pci_dev *pdev) +{ +int ret; + + ret =pci_enable_device (pdev);
isn't there pci-managed versions of this so that you don't need worry about undo'ing this manually?
Quoted 15 lines
drivers/perf/hisilicon/hns3_pmu.c new file +15
-0+if (ret) { +pci_err (pdev,"failed to enable pci device, ret = %d.\n" , ret); +return ret; + } + + ret =pci_request_mem_regions (pdev,"hns3_pmu" ); +if (ret <0 ) { +pci_err (pdev,"failed to request pci mem regions, ret = %d.\n" , + ret); +pci_disable_device (pdev); +return ret; + } + +pci_set_master (pdev); +
drivers/perf/hisilicon/hns3_pmu.c line 1544
Quoted 10 lines
drivers/perf/hisilicon/hns3_pmu.c new file +10
-0+return 0 ; +} + +static void hns3_pmu_uninit_dev (struct pci_dev *pdev) +{ +pci_clear_master (pdev); +pci_release_mem_regions (pdev); +pci_disable_device (pdev); +} +
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [RESEND PATCH 2/2] drivers/perf: hisi: add driver for HNS3 PMU
Quoted 4 lines · John Garry
On 17/01/2022 01:52, Guangbin Huang wrote:
+linuxarm
Ok, thanks.
Quoted 55 lines
Quoted 55 lines
HNS3 PMU End Point device supports to collect performance statistics of bandwidth, latency, packet rate, interrupt rate in HiSilicon SoC NIC.
NIC of each IO DIE has one PMU device for it. Driver registers each PMU device to perf, and exports information of supported events, filter mode of each event, identifier and so on via sysfs.
Each PMU device has its own control, counter and interrupt registers, and supports up to 8 events by hardware.
Filter options contains:
event - select event
subevent - select subevent
port - select physical port of nic
tc - select tc(must be used with port) func - select PF/VF
queue - select queue of PF/VF(must be used with func) intr - select interrupt number(must be used with func) global - select all functions of IO DIESigned-off-by Guangbin Huang <[email protected]>---
MAINTAINERS | 6 + drivers/perf/hisilicon/Kconfig | 9 + drivers/perf/hisilicon/Makefile | 1 +drivers/perf/hisilicon/hns3_pmu.c| 1631 +++++++++++++++++++++++++++++ include/linux/cpuhotplug.h | 1 +5 files changed, 1648 insertions(+)create mode 100644
drivers/perf/hisilicon/hns3_pmu.cMAINTAINERS +0
-0@@ -8614,6 +8614,12 @@ F: Documentation/admin-guide/perf/hisi-pcie-pmu.rstF:
Documentation/admin-guide/perf/hisi-pmu.rstF:drivers/perf/hisiliconMAINTAINERS +6
-0+HISILICON HNS3 PMU DRIVER +M: Guangbin Huang <[email protected]> +S: Supported +F: Documentation/admin-guide/perf/hns3-pmu.rst +F: drivers/perf/hisilicon/hns3_pmu.c +HISILICON QM AND ZIP Controller DRIVER
M: Zhou Wang <[email protected]>
L: [email protected]drivers/perf/hisilicon/Kconfig +0
-0@@ -14,3 +14,12 @@ config HISI_PCIE_PMURCiEP devices.
Adds the PCIe PMU into perf events system for monitoring latency, bandwidth etc.
Quoted 10 lines
drivers/perf/hisilicon/Kconfig config HISI_PCIE_PMU · line 20
Quoted 4 lines
drivers/perf/hisilicon/Kconfig +4
-0+ +config HNS3_PMU + tristate "HNS3 PERF PMU" + depends on ARM64 && PCIAny reason not to add
COMPILE_TEST, like:
depends on ARM64 ||COMPILE_TEST
depends on PCI
No, if need it, I will add next version.
Quoted 27 lines
Quoted 24 lines
+ help
+ Provide support for HNS3 performance monitoring unit (PMU) IEP + devices.
+ Adds the HNS3 PMU into perf events system for monitoring latency, + bandwidth etc.drivers/perf/hisilicon/Makefile +0
-0@@ -4,3 +4,4 @@ obj-$(CONFIG_HISI_PMU) += hisi_uncore_pmu.o hisi_uncore_l3c_pmu.o \hisi_uncore_pa_pmu.o
obj-$(CONFIG_HISI_PCIE_PMU) += hisi_pcie_pmu.odrivers/perf/hisilicon/Makefile +1
-0+obj-$(CONFIG_HNS3_PMU) += hns3_pmu.odrivers/perf/hisilicon/hns3_pmu.c new file +3
-0@@ -0,0 +1,1631 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* This driver adds support for HNS3 PMU iEP device. Quoted 2 lines
Related perf events are
+ * bandwidth, latency, packet rate, interrupt rate etc.
Quoted 8 lines
I don't think that this is relevant here
Quoted 3 lines
+ *
+ * Copyright (C) 2021 HiSilicon Limited
+ */2022, I suppose now...
Ok, thanks.
Quoted 5 lines
Quoted 5 lines
drivers/perf/hisilicon/hns3_pmu.c new file +5
-0+}; + +#define HNS3_PMU_SET_HW_FILTER (_hwc, _mode) \ + ((_hwc)->addr_filters = (void *)&hns3_pmu_hw_filter_modes[(_mode)]) +
Quoted 9 lines
drivers/perf/hisilicon/hns3_pmu.c line 371
Quoted 6 lines
drivers/perf/hisilicon/hns3_pmu.c new file +6
-0+static ssize_t identifier_show (struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct hns3_pmu *hns3_pmu; + + hns3_pmu = to_hns3_pmu(dev_get_drvdata(dev));Can the declaration and assignment be on the same line?
Yes.
Quoted 23 lines
Quoted 23 lines
drivers/perf/hisilicon/hns3_pmu.c new file +23
-0+ + return sysfs_emit(buf, "0x%x\n", hns3_pmu->identifier); +} +static DEVICE_ATTR_RO (identifier); + +static ssize_t cpumask_show (struct device *dev,struct device_attribute *attr, + char *buf) +{ + struct hns3_pmu *hns3_pmu = to_hns3_pmu(dev_get_drvdata(dev)); + + return sysfs_emit(buf, "%d\n", hns3_pmu->on_cpu); +} +static DEVICE_ATTR_RO (cpumask); + +static ssize_t bdf_min_show (struct device *dev,struct device_attribute *attr, + char *buf) +{ + struct hns3_pmu *hns3_pmu = to_hns3_pmu(dev_get_drvdata(dev)); + + return sysfs_emit(buf, "0x%4x\n", hns3_pmu->bdf_min); +} +static DEVICE_ATTR_RO (bdf_min); +
Quoted 9 lines
drivers/perf/hisilicon/hns3_pmu.c line 400
Quoted 6 lines
drivers/perf/hisilicon/hns3_pmu.c new file +6
-0+static ssize_t bdf_max_show (struct device *dev,struct device_attribute *attr, + char *buf) +{ + struct hns3_pmu *hns3_pmu = to_hns3_pmu(dev_get_drvdata(dev)); + + return sysfs_emit(buf, "0x%4x\n", hns3_pmu->bdf_max);are these same files as in HISI PCI PMU driver?
No,it is not.
Quoted 34 lines
Quoted 34 lines
drivers/perf/hisilicon/hns3_pmu.c new file +31
-0+} +static DEVICE_ATTR_RO (bdf_max); + +static struct attribute *hns3_pmu_events_attr[] = { + /* bandwidth events */ + +static struct attribute_group hns3_pmu_events_group = { + .name = "events", + .attrs = hns3_pmu_events_attr, +}; + +static struct attribute_group hns3_pmu_filter_mode_group = { + .name = "filtermode", +}; + +} + +static bool hns3_pmu_valid_bdf (struct hns3_pmu *hns3_pmu,u16 bdf) +{ + struct pci_dev *pdev; + + if (bdf < hns3_pmu->bdf_min || bdf > hns3_pmu->bdf_max) { + pci_err(hns3_pmu->pdev, "Invalid EP device: %#x!\n", bdf); + return false; + } + + pdev = pci_get_domain_bus_and_slot(pci_domain_nr(hns3_pmu->pdev->bus), + PCI_BUS_NUM(bdf), + GET_PCI_DEVFN(bdf)); + if (!pdev) { + pci_err(hns3_pmu->pdev, "Nonexistent EP device: %#x!\n", bdf);
Quoted 9 lines
drivers/perf/hisilicon/hns3_pmu.c line 712
Quoted 6 lines
+ return false;
+ }drivers/perf/hisilicon/hns3_pmu.c new file +4
-0+ + pci_dev_put(pdev); + return true; +}if any of this code is same as hisi pci pmu driver then please put in a common lib
Ok.
Quoted 62 lines
Quoted 21 lines
drivers/perf/hisilicon/hns3_pmu.c new file +21
-0+ +static void hns3_pmu_set_qid_para (struct hns3_pmu *hns3_pmu,u32 idx,u16 bdf, + u16 queue) +{ + u32 val; + + val = GET_PCI_DEVFN(bdf); + val |= (u32)queue << HNS3_PMU_QID_PARA_QUEUE_S; + hns3_pmu_writel(hns3_pmu, HNS3_PMU_REG_EVENT_QID_PARA, idx, val); +} + +static bool hns3_pmu_qid_req_start (struct hns3_pmu *hns3_pmu,u32 idx) +{ + bool queue_id_valid = false; + u32 reg_qid_ctrl, val; + int err; + + /* enable queue id request */ + hns3_pmu_writel(hns3_pmu, HNS3_PMU_REG_EVENT_QID_CTRL, idx, + HNS3_PMU_QID_CTRL_REQ_ENABLE); +...
Quoted 25 lines
drivers/perf/hisilicon/hns3_pmu.c new file +25
-0+} + +static bool hns3_pmu_validate_event_group (struct perf_event *event) +{ + struct perf_event *leader = event->group_leader; + struct perf_event *sibling; + int counters = 1; + + if (!is_software_event(leader)) { + /* + * We must NOT create groups containing mixed PMUs, although + * software events are acceptable + */ + if (leader->pmu != event->pmu) + return false; + + /* Increase counter for the leader */ + if (leader != event) + counters++; + } + + for_each_sibling_event(sibling, event->group_leader) { + if (is_software_event(sibling)) + continue; +drivers/perf/hisilicon/hns3_pmu.c line 951
Quoted 10 lines
drivers/perf/hisilicon/hns3_pmu.c new file +10
-0+ if (sibling->pmu != event->pmu) + return false; + + /* Increase counter for each sibling */ + counters++; + } + + return counters <= HNS3_PMU_MAX_COUNTERS; +} +This is exact same effectively as
hisi_validate_event_group(), apart from:
Quoted 9 lines
return counters <=
HNS3_PMU_MAX_COUNTERS;vs
return counters <=
hisi_pmu->num_counters;Can we factor all this out? Less code to review makes reviewing easier and quicker and less daunting ...
I don't think so, because each struct definition of hisi_xxx_pmu is different.
Quoted 113 lines
Quoted 100 lines
drivers/perf/hisilicon/hns3_pmu.c new file +100
-0+} + +/* +* The performance calculation formula of all types of event is +* performance = data / data_ext. +* The arguments data and data_ext have different meanings for different types +* of events as follow: +* event_type data data_ext +* bandwidth byte number cycles number +* packet rate packet number cycles number +* interrupt rate interrupt number cycles number +* latency cycles number packet number +*/ +static u64 hns3_pmu_get_performance (u8 event_type,u32 hw_clk_freq,u64 data, + u64 data_ext) +{ + u64 result; + + if (!hw_clk_freq || !data || !data_ext) + return 0; + + switch (event_type) { + case HNS3_PMU_EVENT_TYPE_BANDWIDTH: + /* process data to set unit of bandwidth as "KBits/s" */ + result = data / hns3_pmu_tick_to_ms(hw_clk_freq, data_ext); + result = BYTES_TO_BITS(result); + break; + + case HNS3_PMU_EVENT_TYPE_PACKET_RATE: + case HNS3_PMU_EVENT_TYPE_INTR_RATE: + /* process data to set unit as "pps" */ + result = data * 1000 / + hns3_pmu_tick_to_ms(hw_clk_freq, data_ext); + break; + + case HNS3_PMU_EVENT_TYPE_LATENCY: + /* process data to set unit of latency as "ns" */ + result = data / data_ext; + result = result * 1000000000 / hw_clk_freq; + break; + + default: + result = data / data_ext; + break; + } + + return result; +} + +static int hns3_pmu_event_init (struct perf_event *event) +{ + struct hns3_pmu *hns3_pmu = to_hns3_pmu(event->pmu); + struct hw_perf_event *hwc = &event->hw; + int idx; + int ret; + + if (event->attr.type != event->pmu->type) + return -ENOENT; + + /* Sampling is not supported */ + if (is_sampling_event(event) || event->attach_state & PERF_ATTACH_TASK) + return -EOPNOTSUPP; + + event->cpu = hns3_pmu->on_cpu; + + idx = hns3_pmu_get_event_idx(hns3_pmu); + if (idx < 0) { + pci_err(hns3_pmu->pdev, "Up to %u events are supported!\n", + HNS3_PMU_MAX_COUNTERS); + return -EBUSY; + } + + hwc->idx = idx; + + ret = hns3_pmu_select_filter_mode(event, hns3_pmu); + if (ret) { + pci_err(hns3_pmu->pdev, "Invalid filter, ret = %d.\n", ret); + return ret; + } + + if (!hns3_pmu_validate_event_group(event)) { + pci_err(hns3_pmu->pdev, "Invalid event group.\n"); + return -EINVAL; + } + + return 0; +} + +static void hns3_pmu_read (struct perf_event *event) +{ + struct hns3_pmu *hns3_pmu = to_hns3_pmu(event->pmu); + struct hw_perf_event *hwc = &event->hw; + struct hw_perf_event_extra *hwc_ext; + u64 new_cnt_ext, prev_cnt_ext; + u64 new_cnt, prev_cnt, delta; + + hwc_ext = &hwc->extra_reg; + do { + prev_cnt = local64_read(&hwc->prev_count); + prev_cnt_ext = hwc_ext->config;drivers/perf/hisilicon/hns3_pmu.c line 1216
Quoted 10 lines
drivers/perf/hisilicon/hns3_pmu.c new file +10
-0+ hns3_pmu_read_counter(event, &new_cnt, &new_cnt_ext); + } while (local64_cmpxchg(&hwc->prev_count, prev_cnt, new_cnt) != + prev_cnt); + + hwc_ext->config = new_cnt_ext; + + delta = hns3_pmu_get_performance(hns3_get_event(event), + hns3_pmu->hw_clk_freq, + new_cnt - prev_cnt, + new_cnt_ext - prev_cnt_ext);This looks very much like what was originally had in the hisi PCI PMU driver:
Quoted 8 lines
https://lore.kernel.org/linux-arm-kernel/20210616134257.GA22905@willie-the-truck/
https://lore.kernel.org/linux-arm-kernel/20210617175704.GF24813@willie-the-truck/
Please consult with liuqi
If it is, I figure that we're going to need to expose the 2x values and do the calculation in userspace.
Ok, I will separate counter and ext_counter into two events on next version.
Quoted 16 lines
Quoted 13 lines
drivers/perf/hisilicon/hns3_pmu.c new file +13
-0+ + local64_add(delta, &event->count); +} + +static void hns3_pmu_start (struct perf_event *event,int flags) +{ + struct hns3_pmu *hns3_pmu = to_hns3_pmu(event->pmu); + struct hw_perf_event *hwc = &event->hw; + + if (WARN_ON_ONCE(!(hwc->state & PERF_HES_STOPPED))) + return; + + WARN_ON_ONCE(!(hwc->state & PERF_HES_UPTODATE));...
Quoted 7 lines
Quoted 4 lines
+
+ val =readl(hns3_pmu->base + HNS3_PMU_REG_DEVICE_ID);
+device_id= val &0xffff;
+ name =devm_kasprintf(&pdev->dev, GFP_KERNEL, "hns3_pmu_%u", device_id);would adding sccl to the name help it make it more clear that this is per sccl, like hns3_pmu_sccl%u?
Ok, I will add sicl to the name.
Quoted 5 lines
Quoted 2 lines
+ if (!name) {
+pci_err(pdev, "failed to allocate name for HNS3 PMU.\n");I don't think that you need this
-ENOMEMmessages
Ok, I delete it.
Quoted 9 lines
Quoted 6 lines
+ ret =
-ENOMEM;
+ gotoerr_alloc_dev_name;
+ }
+
+hns3_pmu->pdev= pdev;
+hns3_pmu->on_cpu=HNS3_PMU_INVALID_CPU_ID;can you possibly just initially target the probe CPU?
OK.
Quoted 89 lines
Quoted 89 lines
+
hns3_pmu->identifier=readl(hns3_pmu->base + HNS3_PMU_REG_VERSION); +hns3_pmu->pmu= (struct pmu) {
+ .name = name,
+ .module =THIS_MODULE,
+ .event_init =hns3_pmu_event_init,
+ .pmu_enable =hns3_pmu_enable,
+ .pmu_disable =hns3_pmu_disable,
+ .add =hns3_pmu_add,
+ .del =hns3_pmu_del,
+ .start =hns3_pmu_start,
+ .stop =hns3_pmu_stop,
+ .read =hns3_pmu_read,
+ .task_ctx_nr =perf_invalid_context,
+ .attr_groups =hns3_pmu_attr_groups,
+ .capabilities =PERF_PMU_CAP_NO_EXCLUDE,
+ };drivers/perf/hisilicon/hns3_pmu.c new file +73
-0+ + return 0; + +err_alloc_dev_name: + iounmap(hns3_pmu->base); +err_ioremap_bar: + pci_release_regions(pdev); + + return ret; +} + +static irqreturn_t hns3_pmu_irq (int irq,void *data) +{ + struct hns3_pmu *hns3_pmu = data; + u32 intr_status, idx; + + for (idx = 0; idx < HNS3_PMU_MAX_COUNTERS; idx++) { + intr_status = hns3_pmu_readl(hns3_pmu, + HNS3_PMU_REG_EVENT_INTR_STATUS, + idx); + + /* + * As each counter will restart from 0 when it is overflowed, + * extra processing is no need, just clear interrupt status. + */ + if (intr_status) + hns3_pmu_clear_intr_status(hns3_pmu, idx); + } + + return IRQ_HANDLED; +} + +static int hns3_pmu_online_cpu (unsigned int cpu,struct hlist_node *node) +{ + struct hns3_pmu *hns3_pmu; + + hns3_pmu = hlist_entry_safe(node, struct hns3_pmu, node); + if (!hns3_pmu) + return -ENODEV; + + if (hns3_pmu->on_cpu == HNS3_PMU_INVALID_CPU_ID) { + hns3_pmu->on_cpu = cpu; + irq_set_affinity_hint(hns3_pmu->irq, cpumask_of(cpu)); + } + + return 0; +} + +static int hns3_pmu_offline_cpu (unsigned int cpu,struct hlist_node *node) +{ + struct hns3_pmu *hns3_pmu; + unsigned int target; + + hns3_pmu = hlist_entry_safe(node, struct hns3_pmu, node); + if (!hns3_pmu) + return -ENODEV; + + /* Nothing to do if this CPU doesn't own the PMU */ + if (hns3_pmu->on_cpu != cpu) + return 0; + + /* Choose a new CPU from all online cpus */ + target = cpumask_any_but(cpu_online_mask, cpu); + if (target >= nr_cpu_ids) + return 0; + + perf_pmu_migrate_context(&hns3_pmu->pmu, cpu, target); + hns3_pmu->on_cpu = target; + irq_set_affinity_hint(hns3_pmu->irq, cpumask_of(target)); + + return 0; +} +
Quoted 9 lines
drivers/perf/hisilicon/hns3_pmu.c line 1436
Quoted 6 lines
drivers/perf/hisilicon/hns3_pmu.c new file +6
-0+static int hns3_pmu_irq_register (struct pci_dev *pdev, + struct hns3_pmu *hns3_pmu) +{ + int irq, ret; + + ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_MSI);I don't think that a pcim exists here, so can use
devm_add_action()to free them [maybe the name is wrong I mentioned]
ok
Quoted 10 lines
Quoted 7 lines
+ if (ret < 0) {
+pci_err(pdev, "failed to enable MSI vectors, ret = %d.\n", ret); + return ret;
+ }
+
+ irq =pci_irq_vector(pdev, 0);
+ ret =request_irq(irq, hns3_pmu_irq, 0, hns3_pmu->pmu.name, hns3_pmu);
devm_request_irq()
ok
Quoted 34 lines
Quoted 34 lines
+ if (ret) {
+pci_err(pdev, "failed to register irq, ret = %d.\n", ret); +pci_free_irq_vectors(pdev);
+ return ret;
+ }drivers/perf/hisilicon/hns3_pmu.c new file +29
-0+ + hns3_pmu->irq = irq; + + return 0; +} + +static void hns3_pmu_irq_unregister (struct pci_dev *pdev, + struct hns3_pmu *hns3_pmu) +{ + free_irq(hns3_pmu->irq, hns3_pmu); + pci_free_irq_vectors(pdev); +} + +static int hns3_pmu_init (struct pci_dev *pdev,struct hns3_pmu *hns3_pmu) +{ + int ret; + + ret = hns3_pmu_alloc_pmu(pdev, hns3_pmu); + if (ret) + return ret; + + ret = hns3_pmu_irq_register(pdev, hns3_pmu); + if (ret) + goto err_irq_register; + + ret = cpuhp_state_add_instance(CPUHP_AP_PERF_ARM_HNS3_PMU_ONLINE, + &hns3_pmu->node); + if (ret) { + pci_err(pdev, "failed to register hotplug, ret = %d.\n", ret);
Quoted 9 lines
Quoted 6 lines
+ goto
err_register_hotplug;
+ }
+
+ ret =perf_pmu_register(&hns3_pmu->pmu, hns3_pmu->pmu.name, -1); + if (ret) {
+pci_err(pdev, "failed to register HNS3 PMU, ret = %d.\n", ret);do you need to mention "HNS3 PMU", since pdev is passed
Ok, I will modify to "perf PMU".
Quoted 16 lines
Quoted 16 lines
+ goto
err_register_pmu;
+ }drivers/perf/hisilicon/hns3_pmu.c new file +14
-0+ + return ret; + +err_register_pmu: + cpuhp_state_remove_instance(CPUHP_AP_PERF_ARM_HNS3_PMU_ONLINE, + &hns3_pmu->node); + irq_set_affinity_hint(hns3_pmu->irq, NULL); + +err_register_hotplug: + hns3_pmu_irq_unregister(pdev, hns3_pmu); + +err_irq_register: + iounmap(hns3_pmu->base); +
Quoted 9 lines
drivers/perf/hisilicon/hns3_pmu.c line 1505
Quoted 6 lines
+ return ret;
drivers/perf/hisilicon/hns3_pmu.c new file +5
-0+} + +static void hns3_pmu_uninit (struct pci_dev *pdev) +{ + struct hns3_pmu *hns3_pmu = (struct hns3_pmu *)pci_get_drvdata(pdev);no need to cast a void ptr
Ok.
Quoted 8 lines
Quoted 8 lines
drivers/perf/hisilicon/hns3_pmu.c new file +8
-0+ + perf_pmu_unregister(&hns3_pmu->pmu); + cpuhp_state_remove_instance(CPUHP_AP_PERF_ARM_HNS3_PMU_ONLINE, + &hns3_pmu->node); + irq_set_affinity_hint(hns3_pmu->irq, NULL); + hns3_pmu_irq_unregister(pdev, hns3_pmu); + iounmap(hns3_pmu->base); +}
Quoted 9 lines
drivers/perf/hisilicon/hns3_pmu.c line 1519
Quoted 6 lines
drivers/perf/hisilicon/hns3_pmu.c new file +6
-0+ +static int hns3_pmu_init_dev (struct pci_dev *pdev) +{ + int ret; + + ret = pci_enable_device(pdev);isn't there pci-managed versions of this so that you don't need worry about undo'ing this manually?
Ok, I modify it next version.
Quoted 18 lines
Quoted 18 lines
+ if (ret) {
+pci_err(pdev, "failed to enable pci device, ret = %d.\n", ret); + return ret;
+ }drivers/perf/hisilicon/hns3_pmu.c new file +14
-0+ + ret = pci_request_mem_regions(pdev, "hns3_pmu"); + if (ret < 0) { + pci_err(pdev, "failed to request pci mem regions, ret = %d.\n", + ret); + pci_disable_device(pdev); + return ret; + } + + pci_set_master(pdev); + + return 0; +} +
Quoted 8 lines
drivers/perf/hisilicon/hns3_pmu.c line 1544
Quoted 7 lines
drivers/perf/hisilicon/hns3_pmu.c new file +7
-0+static void hns3_pmu_uninit_dev (struct pci_dev *pdev) +{ + pci_clear_master(pdev); + pci_release_mem_regions(pdev); + pci_disable_device(pdev); +} +.
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel