Improve PTT filter interface and some fixes
Subsystems (5)
cover Improve PTT filter interface and some fixes
From: Yicong Yang <[email protected]>
This series tends to improve the PTT's filter interface in 2 aspects (Patch 2&3):
- Support dynamically filter updating to response to hotplug Previous the supported filter list is settled down once the driver probed and it maybe out-of-date if hotplug events happen later. User need to reload the driver to update list. Patch 1/2 enable the driver to update the list by registering a PCI bus notifier and the filter list will always be the latest.
- Export the available filters through sysfs
Previous user needs to calculate the filters and filter value using device's BDF number, which requires the user to know the hardware well. Patch 3/3 tends to export the available filter information through sysfs attributes, the filter value will be gotten by reading the file. This will be more user friendly.
Also includes a fix and an improve. Patch 1 tends to only export the online CPUs supported by the PTT, this will make perf work properly when there's offline CPUs within the node PTT locates. Patch 4 tends to set proper PMU capability to avoid collecting unnecessary data to save the storage.
Yicong Yang (4):
hwtracing: hisi_ptt: Make cpumask only present online CPUs
hwtracing: hisi_ptt: Add support for dynamically updating the filter
list
hwtracing: hisi_ptt: Export available filters through sysfs
hwtracing: hisi_ptt: Advertise PERF_PMU_CAP_NO_EXCLUDE for PTT PMU
.../ABI/testing/sysfs-devices-hisi_ptt | 50 +++ Documentation/trace/hisi-ptt.rst | 12 +- drivers/hwtracing/ptt/hisi_ptt.c | 396 +++++++++++++++++- drivers/hwtracing/ptt/hisi_ptt.h | 51 +++ 4 files changed, 498 insertions(+), 11 deletions(-)
Signature · 1 line
2.24.0
PATCH 1/4 hwtracing: hisi_ptt: Make cpumask only present online CPUs
From: Yicong Yang <[email protected]>
perf will try to start PTT trace on every CPU presented in cpumask sysfs attribute and it will fail to start on offline CPUs(see the comments in perf_event_open()). But the driver is using cpumask_of_node() to export the available cpumask which may include offline CPUs and may fail the perf unintendedly. Fix this by only export the online CPUs of the node.
--- drivers/hwtracing/ptt/hisi_ptt.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/hwtracing/ptt/hisi_ptt.c +11 -2
@@ -487,9 +487,18 @@ static ssize_t cpumask_show(struct device *dev, struct device_attribute *attr, char *buf) {struct hisi_ptt *hisi_ptt =to_hisi_ptt (dev_get_drvdata (dev)); -const cpumask_t *cpumask =cpumask_of_node (dev_to_node (&hisi_ptt->pdev->dev)); +cpumask_var_t mask; +ssize_t n; -return cpumap_print_to_pagebuf (true, buf, cpumask); +if (!alloc_cpumask_var (&mask,GFP_KERNEL )) +return 0 ; + +cpumask_and (mask,cpumask_of_node (dev_to_node (&hisi_ptt->pdev->dev)), + cpu_online_mask); + n =cpumap_print_to_pagebuf (true, buf, mask); +free_cpumask_var (mask); + +return n; }static DEVICE_ATTR_RO (cpumask);
Signature · 1 line
2.24.0
Re: [PATCH 1/4] hwtracing: hisi_ptt: Make cpumask only present online CPUs
Quoted 7 lines · On Wed, 15 Mar 2023 17:43:13 +0800 Yicong Yang <[email protected]> wrote:
From: Yicong Yang <[email protected]>
perf will try to start PTT trace on every CPU presented in cpumask sysfs attribute and it will fail to start on offline
CPUs(see the comments in perf_event_open()). But the driver is usingcpumask_of_node()to export the available cpumask which may include offline CPUs and may fail the perf unintendedly. Fix this by only export the online CPUs of the node.
There isn't clear documentation that I can find for cpumask_of_node() and chasing through on arm64 (which is what we care about for this driver) it's maintained via numa_add_cpu() numa_remove_cpu()
Those are called in arch/arm64/kernel/smp.c in locations that are closely coupled with set_cpu_online(cpu, XXX);
https://elixir.bootlin.com/linux/v6.3-rc4/source/arch/arm64/kernel/smp.c#L246
https://elixir.bootlin.com/linux/v6.3-rc4/source/arch/arm64/kernel/smp.c#L303
Now there are races when the two might not be in sync but in this case we are just exposing the result to userspace, so chances of a race after this sysfs attribute has been read seems much higher to me and I don't think we can do anything about that.
Is there another path that I'm missing where online and node masks are out of sync?
Jonathan
Quoted 33 lines
Fixes ff0de066b463 ("hwtracing: hisi_ptt: Add trace function support for HiSilicon PCIe Tune and Trace device")Signed-off-by Yicong Yang <[email protected]>--- drivers/hwtracing/ptt/hisi_ptt.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)drivers/hwtracing/ptt/hisi_ptt.c +11
-2@@ -487,9 +487,18 @@ static ssize_t cpumask_show(struct device *dev, struct device_attribute *attr, char *buf) {struct hisi_ptt *hisi_ptt =to_hisi_ptt (dev_get_drvdata (dev)); -const cpumask_t *cpumask =cpumask_of_node (dev_to_node (&hisi_ptt->pdev->dev)); +cpumask_var_t mask; +ssize_t n; -return cpumap_print_to_pagebuf (true, buf, cpumask); +if (!alloc_cpumask_var (&mask,GFP_KERNEL )) +return 0 ; + +cpumask_and (mask,cpumask_of_node (dev_to_node (&hisi_ptt->pdev->dev)), + cpu_online_mask); + n =cpumap_print_to_pagebuf (true, buf, mask); +free_cpumask_var (mask); + +return n; }static DEVICE_ATTR_RO (cpumask);
Re: [PATCH 1/4] hwtracing: hisi_ptt: Make cpumask only present online CPUs
Quoted 19 lines · Jonathan Cameron
Quoted 7 lines · On Wed, 15 Mar 2023 17:43:13 +0800 Yicong Yang <[email protected]> wrote:
From: Yicong Yang <[email protected]>
perf will try to start PTT trace on every CPU presented in cpumask sysfs attribute and it will fail to start on offline
CPUs(see the comments in perf_event_open()). But the driver is usingcpumask_of_node()to export the available cpumask which may include offline CPUs and may fail the perf unintendedly. Fix this by only export the online CPUs of the node.There isn't clear documentation that I can find for
cpumask_of_node()and chasing through on arm64 (which is what we care about for this driver) it's maintained vianuma_add_cpu()numa_remove_cpu()
Those are called inarch/arm64/kernel/smp.cin locations that are closely coupled withset_cpu_online(cpu, XXX);
https://elixir.bootlin.com/linux/v6.3-rc4/source/arch/arm64/kernel/smp.c#L246
https://elixir.bootlin.com/linux/v6.3-rc4/source/arch/arm64/kernel/smp.c#L303
Quoted 8 lines
Now there are races when the two might not be in sync but in this case we are just exposing the result to userspace, so chances of a race after this sysfs attribute has been read seems much higher to me and I don't think we can do anything about that.
Is there another path that I'm missing where online and node masks are out of sync?
maybe no. This patch maybe incorrect and I need more investigation, so let's me drop it from the series. Tested and everything seems fine now.
I found this problem and referred to commit 064f0e9302af ("mm: only display online cpus of the numa node") which might be the same problem. But seems unnecessary that cpumask_of_node()
already include online CPUs only.
Thanks.
Quoted 39 lines
Jonathan
Quoted 23 lines
Fixes ff0de066b463 ("hwtracing: hisi_ptt: Add trace function support for HiSilicon PCIe Tune and Trace device")Signed-off-by Yicong Yang <[email protected]>--- drivers/hwtracing/ptt/hisi_ptt.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)drivers/hwtracing/ptt/hisi_ptt.c +4
-2@@ -487,9 +487,18 @@ static ssize_t cpumask_show(struct device *dev, struct device_attribute *attr, char *buf) {struct hisi_ptt *hisi_ptt =to_hisi_ptt (dev_get_drvdata (dev)); -const cpumask_t *cpumask =cpumask_of_node (dev_to_node (&hisi_ptt->pdev->dev)); +cpumask_var_t mask; +ssize_t n; -return cpumap_print_to_pagebuf (true, buf, cpumask); +if (!alloc_cpumask_var (&mask,GFP_KERNEL )) +return 0 ;drivers/hwtracing/ptt/hisi_ptt.c static ssize_t cpumask_show(struct device *dev, struct device_attribute *attr, · line 504
Quoted 10 lines
drivers/hwtracing/ptt/hisi_ptt.c +7
-0+ +cpumask_and (mask,cpumask_of_node (dev_to_node (&hisi_ptt->pdev->dev)), + cpu_online_mask); + n =cpumap_print_to_pagebuf (true, buf, mask); +free_cpumask_var (mask); + +return n; }static DEVICE_ATTR_RO (cpumask);.
Re: [PATCH 1/4] hwtracing: hisi_ptt: Make cpumask only present online CPUs
Quoted 29 lines · On Thu, 30 Mar 2023 11:53:14 +0800 Yicong Yang <[email protected]> wrote:
Quoted 19 lines · Jonathan Cameron
Quoted 7 lines · On Wed, 15 Mar 2023 17:43:13 +0800 Yicong Yang <[email protected]> wrote:
From: Yicong Yang <[email protected]>
perf will try to start PTT trace on every CPU presented in cpumask sysfs attribute and it will fail to start on offline
CPUs(see the comments in perf_event_open()). But the driver is usingcpumask_of_node()to export the available cpumask which may include offline CPUs and may fail the perf unintendedly. Fix this by only export the online CPUs of the node.There isn't clear documentation that I can find for
cpumask_of_node()and chasing through on arm64 (which is what we care about for this driver) it's maintained vianuma_add_cpu()numa_remove_cpu()
Those are called inarch/arm64/kernel/smp.cin locations that are closely coupled withset_cpu_online(cpu, XXX);
https://elixir.bootlin.com/linux/v6.3-rc4/source/arch/arm64/kernel/smp.c#L246
https://elixir.bootlin.com/linux/v6.3-rc4/source/arch/arm64/kernel/smp.c#L303Quoted 8 lines
Now there are races when the two might not be in sync but in this case we are just exposing the result to userspace, so chances of a race after this sysfs attribute has been read seems much higher to me and I don't think we can do anything about that.
Is there another path that I'm missing where online and node masks are out of sync?
Quoted 6 lines
maybe no. This patch maybe incorrect and I need more investigation, so let's me drop it from the series. Tested and everything seems fine now.
I found this problem and referred to commit
064f0e9302af("mm: only display online cpus of the numa node") which might be the same problem. But seems unnecessary thatcpumask_of_node()
already include online CPUs only.
Seems it was fixed up for arm64 in7f954aa1a ("arm64: smp: remove cpu and numa topology information when hotplugging out CPMU")
If we could audit all the other architectures it would be great to document the properties of this cpmuask and possibly simplify the code in the path you highlight above (assuming no race conditions etc)
Jonathan
Quoted 42 lines
Thanks.
Quoted 39 lines
Jonathan
Quoted 23 lines
Fixes ff0de066b463 ("hwtracing: hisi_ptt: Add trace function support for HiSilicon PCIe Tune and Trace device")Signed-off-by Yicong Yang <[email protected]>--- drivers/hwtracing/ptt/hisi_ptt.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)drivers/hwtracing/ptt/hisi_ptt.c +4
-2@@ -487,9 +487,18 @@ static ssize_t cpumask_show(struct device *dev, struct device_attribute *attr, char *buf) {struct hisi_ptt *hisi_ptt =to_hisi_ptt (dev_get_drvdata (dev)); -const cpumask_t *cpumask =cpumask_of_node (dev_to_node (&hisi_ptt->pdev->dev)); +cpumask_var_t mask; +ssize_t n; -return cpumap_print_to_pagebuf (true, buf, cpumask); +if (!alloc_cpumask_var (&mask,GFP_KERNEL )) +return 0 ;drivers/hwtracing/ptt/hisi_ptt.c static ssize_t cpumask_show(struct device *dev, struct device_attribute *attr, · line 504
Quoted 10 lines
drivers/hwtracing/ptt/hisi_ptt.c +7
-0+ +cpumask_and (mask,cpumask_of_node (dev_to_node (&hisi_ptt->pdev->dev)), + cpu_online_mask); + n =cpumap_print_to_pagebuf (true, buf, mask); +free_cpumask_var (mask); + +return n; }static DEVICE_ATTR_RO (cpumask);.
PATCH 2/4 hwtracing: hisi_ptt: Add support for dynamically updating the filter list
In reply to Yicong YangFrom: Yicong Yang <[email protected]>
The PCIe devices supported by the PTT trace can be removed/rescanned by hotplug or through sysfs. Add support for dynamically updating the available filter list by registering a PCI bus notifier block. Then user can always get latest information about available tracing filters and driver can block the invalid filters of which related devices no longer exist in the system.
--- Documentation/trace/hisi-ptt.rst | 6 +- drivers/hwtracing/ptt/hisi_ptt.c | 152 ++++++++++++++++++++++++++++++- drivers/hwtracing/ptt/hisi_ptt.h | 35 +++++++ 3 files changed, 189 insertions(+), 4 deletions(-)
Documentation/trace/hisi-ptt.rst +3 -3
@@ -153,9 +153,9 @@ Endpoint function can be specified in one trace. Specifying both Root Port and function at the same time is not supported. Driver maintains a list of available filters and will check the invalid inputs. -Currently the available filters are detected in driver's probe. If the supported -devices are removed/added after probe, you may need to reload the driver to update -the filters. +The available filters will be dynamically updates, which means you will always +get correct filter information when hotplug events happen, or when you manually +remove/rescan the devices. 2. Type -------
drivers/hwtracing/ptt/hisi_ptt.c +151 -1
191 lines not on this page · raw message
drivers/hwtracing/ptt/hisi_ptt.h +35 -0
@@ -11,12 +11,15 @@#include <linux/bits.h> #include <linux/cpumask.h> +#include <linux/kfifo.h> #include <linux/list.h> #include <linux/mutex.h> +#include <linux/notifier.h> #include <linux/pci.h> #include <linux/perf_event.h> #include <linux/spinlock.h> #include <linux/types.h> +#include <linux/workqueue.h> #define DRV_NAME "hisi_ptt"
@@ -71,6 +74,11 @@#define HISI_PTT_WAIT_TRACE_TIMEOUT_US 100UL#define HISI_PTT_WAIT_POLL_INTERVAL_US 10UL +/* FIFO size for dynamically updating the PTT trace filter list. */ +#define HISI_PTT_FILTER_UPDATE_FIFO_SIZE 16 +/* Delay time for filter updating work */ +#define HISI_PTT_WORK_DELAY_MS 100UL +#define HISI_PCIE_CORE_PORT_ID (devfn) ((PCI_SLOT(devfn) & 0x7) << 1)/* Definition of the PMU configs */
@@ -143,6 +151,16 @@ struct hisi_ptt_filter_desc {u16 devid; }; +/** +* struct hisi_ptt_filter_update_info - Information for PTT filter updating +* @pdev: the PCI device to update in the filter list +* @is_add: adding to the filter or not +*/ +struct hisi_ptt_filter_update_info { +struct pci_dev *pdev; +bool is_add; +}; +/** * struct hisi_ptt_pmu_buf - Descriptor of the AUX buffer of PTT trace * @length: size of the AUX buffer
@@ -170,10 +188,15 @@ struct hisi_ptt_pmu_buf {* @lower_bdf: the lower BDF range of the PCI devices managed by this PTT device * @port_filters: the filter list of root ports * @req_filters: the filter list of requester ID +* @filter_lock: lock to protect the filters * @port_mask: port mask of the managed root ports +* @work: delayed work for filter updating +* @filter_update_lock: spinlock to protect the filter update fifo +* @filter_update_fifo: fifo of the filters waiting to update the filter list */ struct hisi_ptt {struct hisi_ptt_trace_ctrl trace_ctrl; +struct notifier_block hisi_ptt_nb;struct hlist_node hotplug_node;struct pmu hisi_ptt_pmu;void __iomem *iobase;
@@ -192,7 +215,19 @@ struct hisi_ptt {*/ struct list_head port_filters;struct list_head req_filters; +struct mutex filter_lock;u16 port_mask; + +/* +* We use a delayed work here to avoid indefinitely waiting for +* the hisi_ptt->mutex which protecting the filter list. The +* work will be delayed only if the mutex can not be held, +* otherwise no delay will be applied. +*/ +struct delayed_work work; +spinlock_t filter_update_lock; + DECLARE_KFIFO(filter_update_kfifo, struct hisi_ptt_filter_update_info, +HISI_PTT_FILTER_UPDATE_FIFO_SIZE ); };#define to_hisi_ptt (pmu) container_of(pmu, struct hisi_ptt, hisi_ptt_pmu)
Signature · 1 line
2.24.0
Re: [PATCH 2/4] hwtracing: hisi_ptt: Add support for dynamically updating the filter list
Quoted 11 lines · On Wed, 15 Mar 2023 17:43:14 +0800 Yicong Yang <[email protected]> wrote:
From: Yicong Yang <[email protected]>
The PCIe devices supported by the PTT trace can be removed/rescanned by hotplug or through sysfs. Add support for dynamically updating the available filter list by registering a PCI bus notifier block. Then user can always get latest information about available tracing filters and driver can block the invalid filters of which related devices no longer exist in the system.
Signed-off-by Yicong Yang <[email protected]>---
Just a few trivial comments on this.
With those tidied up
...
Quoted 6 lines
drivers/hwtracing/ptt/hisi_ptt.c +1
-0+/*
drivers/hwtracing/ptt/hisi_ptt.c static int hisi_ptt_register_irq(struct hisi_ptt *hisi_ptt) · line 448
Quoted 10 lines
drivers/hwtracing/ptt/hisi_ptt.c +10
-0+* A PCI bus notifier is used here for dynamically updating the filter +* list. +*/ +static int hisi_ptt_notifier_call (struct notifier_block *nb,unsigned long action, +void *data) +{ + struct hisi_ptt *hisi_ptt = container_of(nb, struct hisi_ptt, hisi_ptt_nb); +struct hisi_ptt_filter_update_info info; +struct device *dev = data; +struct pci_dev *pdev =to_pci_dev (dev);
This local variable doesn't add anything over
info.pdev = to_pci_dev(dev);
Quoted 32 lines
drivers/hwtracing/ptt/hisi_ptt.c +19
-0+ + info.pdev = pdev; + +switch (action) { +case BUS_NOTIFY_ADD_DEVICE : + info.is_add = true; +break ; +case BUS_NOTIFY_DEL_DEVICE : + info.is_add = false; +break ; +default : +return 0 ; + } + +hisi_ptt_update_fifo_in (hisi_ptt, &info); + +return 0 ; +} +drivers/hwtracing/ptt/hisi_ptt.h +0
-0@@ -11,12 +11,15 @@/** * struct hisi_ptt_pmu_buf - Descriptor of the AUX buffer of PTT trace * @length: size of the AUX buffer @@ -170,10 +188,15 @@ struct hisi_ptt_pmu_buf {* @lower_bdf: the lower BDF range of the PCI devices managed by this PTT device * @port_filters: the filter list of root ports
drivers/hwtracing/ptt/hisi_ptt.h struct hisi_ptt_pmu_buf { · line 199
Quoted 10 lines
drivers/hwtracing/ptt/hisi_ptt.h +5
-0* @req_filters: the filter list of requester ID +* @filter_lock: lock to protect the filters * @port_mask: port mask of the managed root ports +* @work: delayed work for filter updating +* @filter_update_lock: spinlock to protect the filter update fifo +* @filter_update_fifo: fifo of the filters waiting to update the filter list */ struct hisi_ptt {struct hisi_ptt_trace_ctrl trace_ctrl; +struct notifier_block hisi_ptt_nb;
Docs update for this one?
Quoted 23 lines
drivers/hwtracing/ptt/hisi_ptt.h +12
-0struct hlist_node hotplug_node;struct pmu hisi_ptt_pmu;void __iomem *iobase;@@ -192,7 +215,19 @@ struct hisi_ptt {*/ struct list_head port_filters;struct list_head req_filters; +struct mutex filter_lock;u16 port_mask; + +/* +* We use a delayed work here to avoid indefinitely waiting for +* the hisi_ptt->mutex which protecting the filter list. The +* work will be delayed only if the mutex can not be held, +* otherwise no delay will be applied. +*/ +struct delayed_work work; +spinlock_t filter_update_lock; + DECLARE_KFIFO(filter_update_kfifo, struct hisi_ptt_filter_update_info, +HISI_PTT_FILTER_UPDATE_FIFO_SIZE ); };#define to_hisi_ptt (pmu) container_of(pmu, struct hisi_ptt, hisi_ptt_pmu)
Re: [PATCH 2/4] hwtracing: hisi_ptt: Add support for dynamically updating the filter list
Quoted 12 lines · Jonathan Cameron
Quoted 9 lines · On Wed, 15 Mar 2023 17:43:14 +0800 Yicong Yang <[email protected]> wrote:
From: Yicong Yang <[email protected]>
The PCIe devices supported by the PTT trace can be removed/rescanned by hotplug or through sysfs. Add support for dynamically updating the available filter list by registering a PCI bus notifier block. Then user can always get latest information about available tracing filters and driver can block the invalid filters of which related devices no longer exist in the system.
Quoted 7 lines
Quoted 2 lines
Signed-off-by Yicong Yang <[email protected]>---
Just a few trivial comments on this.
With those tidied up
Reviewed-by Jonathan Cameron <[email protected]>
Thanks for the comment, will fix in next version.
Quoted 24 lines
...
Quoted 6 lines
drivers/hwtracing/ptt/hisi_ptt.c +1
-0+/* drivers/hwtracing/ptt/hisi_ptt.c static int hisi_ptt_register_irq(struct hisi_ptt *hisi_ptt) · line 448
Quoted 10 lines
drivers/hwtracing/ptt/hisi_ptt.c +10
-0+* A PCI bus notifier is used here for dynamically updating the filter +* list. +*/ +static int hisi_ptt_notifier_call (struct notifier_block *nb,unsigned long action, +void *data) +{ + struct hisi_ptt *hisi_ptt = container_of(nb, struct hisi_ptt, hisi_ptt_nb); +struct hisi_ptt_filter_update_info info; +struct device *dev = data; +struct pci_dev *pdev =to_pci_dev (dev);This local variable doesn't add anything over
Quoted 2 lines
info.pdev = to_pci_dev(dev);
ok, will drop it.
Quoted 38 lines
Quoted 38 lines
drivers/hwtracing/ptt/hisi_ptt.c +19
-0+ + info.pdev = pdev; + +switch (action) { +case BUS_NOTIFY_ADD_DEVICE : + info.is_add = true; +break ; +case BUS_NOTIFY_DEL_DEVICE : + info.is_add = false; +break ; +default : +return 0 ; + } + +hisi_ptt_update_fifo_in (hisi_ptt, &info); + +return 0 ; +} +drivers/hwtracing/ptt/hisi_ptt.h +2
-0@@ -11,12 +11,15 @@/** * struct hisi_ptt_pmu_buf - Descriptor of the AUX buffer of PTT trace * @length: size of the AUX buffer @@ -170,10 +188,15 @@ struct hisi_ptt_pmu_buf {* @lower_bdf: the lower BDF range of the PCI devices managed by this PTT device * @port_filters: the filter list of root ports * @req_filters: the filter list of requester ID +* @filter_lock: lock to protect the filters * @port_mask: port mask of the managed root ports +* @work: delayed work for filter updating
Quoted 9 lines
drivers/hwtracing/ptt/hisi_ptt.h struct hisi_ptt_pmu_buf { · line 199
Quoted 6 lines
drivers/hwtracing/ptt/hisi_ptt.h +3
-0+* @filter_update_lock: spinlock to protect the filter update fifo +* @filter_update_fifo: fifo of the filters waiting to update the filter list */ struct hisi_ptt {struct hisi_ptt_trace_ctrl trace_ctrl; +struct notifier_block hisi_ptt_nb;Docs update for this one?
sorry for missing this. will fix.
Thanks,
Yicong
Quoted 26 lines
Quoted 13 lines
drivers/hwtracing/ptt/hisi_ptt.h +5
-0struct hlist_node hotplug_node;struct pmu hisi_ptt_pmu;void __iomem *iobase;@@ -192,7 +215,19 @@ struct hisi_ptt {*/ struct list_head port_filters;struct list_head req_filters; +struct mutex filter_lock;u16 port_mask; + +/* +* We use a delayed work here to avoid indefinitely waiting for +* the hisi_ptt->mutex which protecting the filter list. The drivers/hwtracing/ptt/hisi_ptt.h struct hisi_ptt { · line 233
Quoted 10 lines
drivers/hwtracing/ptt/hisi_ptt.h +7
-0+* work will be delayed only if the mutex can not be held, +* otherwise no delay will be applied. +*/ +struct delayed_work work; +spinlock_t filter_update_lock; + DECLARE_KFIFO(filter_update_kfifo, struct hisi_ptt_filter_update_info, +HISI_PTT_FILTER_UPDATE_FIFO_SIZE ); };#define to_hisi_ptt (pmu) container_of(pmu, struct hisi_ptt, hisi_ptt_pmu).
PATCH 3/4 hwtracing: hisi_ptt: Export available filters through sysfs
In reply to Yicong YangFrom: Yicong Yang <[email protected]>
The PTT can only filter the traced TLP headers by the Root Ports or the Requester ID of the Endpoint, which are located on the same core of the PTT device. The filter value used is derived from the BDF number of the supported Root Port or the Endpoint. It's not friendly enough for the users since it requires the user to be familiar enough with the platform and calculate the filter value manually.
This patch export the available filters through sysfs. Each available filters is presented as an individual file with the name of the BDF number of the related PCIe device. The files are created under $(PTT PMU dir)/available_root_port_filters and
$(PTT PMU dir)/available_requester_filters respectively. The filter value can be known by reading the related file.
Then the users can easily know the available filters for trace and get the filter values without calculating.
--- .../ABI/testing/sysfs-devices-hisi_ptt | 50 ++++ Documentation/trace/hisi-ptt.rst | 6 + drivers/hwtracing/ptt/hisi_ptt.c | 229 +++++++++++++++++- drivers/hwtracing/ptt/hisi_ptt.h | 16 ++ 4 files changed, 297 insertions(+), 4 deletions(-)
Documentation/ABI/testing/sysfs-devices-hisi_ptt +50 -0
@@ -59,3 +59,53 @@ Description: (RW) Control the allocated buffer watermark of outbound packets. The available tune data is [0, 1, 2]. Writing a negative value will return an error, and out of range values will be converted to 2. The value indicates a probable level of the event. + +What: /sys/devices/hisi_ptt<sicl_id>_<core_id>/root_port_filters +Date: February 2023 +KernelVersion: 6.4 +Contact: Yicong Yang <[email protected]> +Description: This directory contains the files providing the PCIe Root Port filters + information used for PTT trace. Each file is named after the supported + Root Port device name <domain>:<bus>:<device>.<function>. + + See the description of the "filter" in Documentation/trace/hisi-ptt.rst + for more information. + +What: /sys/devices/hisi_ptt<sicl_id>_<core_id>/root_port_filters/multiselect +Date: February 2023 +KernelVersion: 6.4 +Contact: Yicong Yang <[email protected]> +Description: (Read) Indicates whether this kind of filter can be multiselected + or not. 1 for multiselectable, 0 for not. + +What: /sys/devices/hisi_ptt<sicl_id>_<core_id>/root_port_filters/<bdf> +Date: February 2023 +KernelVersion: 6.4 +Contact: Yicong Yang <[email protected]> +Description: (Read) Indicates the filter value of this Root Port filter, which + can be used to control the TLP headers to trace by the PTT trace. + +What: /sys/devices/hisi_ptt<sicl_id>_<core_id>/requester_filters +Date: February 2023 +KernelVersion: 6.4 +Contact: Yicong Yang <[email protected]> +Description: This directory contains the files providing the PCIe Requester filters + information used for PTT trace. Each file is named after the supported + Endpoint device name <domain>:<bus>:<device>.<function>. + + See the description of the "filter" in Documentation/trace/hisi-ptt.rst + for more information. + +What: /sys/devices/hisi_ptt<sicl_id>_<core_id>/requester_filters/multiselect +Date: February 2023 +KernelVersion: 6.4 +Contact: Yicong Yang <[email protected]> +Description: (Read) Indicates whether this kind of filter can be multiselected + or not. 1 for multiselectable, 0 for not. + +What: /sys/devices/hisi_ptt<sicl_id>_<core_id>/requester_filters/<bdf> +Date: February 2023 +KernelVersion: 6.4 +Contact: Yicong Yang <[email protected]> +Description: (Read) Indicates the filter value of this Requester filter, which + can be used to control the TLP headers to trace by the PTT trace.
Documentation/trace/hisi-ptt.rst +6 -0
@@ -148,6 +148,12 @@ For example, if the desired filter is Endpoint function 0000:01:00.1 the filter value will be 0x00101. If the desired filter is Root Port 0000:00:10.0 then then filter value is calculated as 0x80001. +The driver also presents every supported Root Port and Requester filter through +sysfs. Each filter will be an individual file with name of its related PCIe +device name (domain:bus:device.function). The files of Root Port filters are +under $(PTT PMU dir)/root_port_filters and files of Requester filters +are under $(PTT PMU dir)/requester_filters. + Note that multiple Root Ports can be specified at one time, but only one Endpoint function can be specified in one trace. Specifying both Root Port and function at the same time is not supported. Driver maintains a list of
drivers/hwtracing/ptt/hisi_ptt.c +225 -4
288 lines not on this page · raw message
drivers/hwtracing/ptt/hisi_ptt.h +16 -0
@@ -11,6 +11,7 @@#include <linux/bits.h> #include <linux/cpumask.h> +#include <linux/device.h> #include <linux/kfifo.h> #include <linux/list.h> #include <linux/mutex.h>
@@ -139,15 +140,28 @@ struct hisi_ptt_trace_ctrl { u32 type:4; }; +/* +* sysfs attribute group name for root port filters and requester filters: +* /sys/devices/hisi_ptt<sicl_id>_<core_id>/root_port_filters +* and +* /sys/devices/hisi_ptt<sicl_id>_<core_id>/requester_filters +*/ +#define HISI_PTT_RP_FILTERS_GRP_NAME "root_port_filters" +#define HISI_PTT_REQ_FILTERS_GRP_NAME "requester_filters" +/** * struct hisi_ptt_filter_desc - Descriptor of the PTT trace filter +* @attr: sysfs attribute of this filter * @list: entry of this descriptor in the filter list * @is_port: the PCI device of the filter is a Root Port or not +* @name: name of this filter, same as the name of the related PCI device * @devid: the PCI device's devid of the filter */ struct hisi_ptt_filter_desc { +struct device_attribute attr;struct list_head list;bool is_port; +char *name;u16 devid; };
@@ -189,6 +203,7 @@ struct hisi_ptt_pmu_buf {* @port_filters: the filter list of root ports * @req_filters: the filter list of requester ID * @filter_lock: lock to protect the filters +* @sysfs_inited: whether the filters' sysfs entries has been initialized * @port_mask: port mask of the managed root ports * @work: delayed work for filter updating * @filter_update_lock: spinlock to protect the filter update fifo
@@ -216,6 +231,7 @@ struct hisi_ptt {struct list_head port_filters;struct list_head req_filters;struct mutex filter_lock; +bool sysfs_inited;u16 port_mask;/*
Signature · 1 line
2.24.0
Re: [PATCH 3/4] hwtracing: hisi_ptt: Export available filters through sysfs
Quoted 16 lines · On Wed, 15 Mar 2023 17:43:15 +0800 Yicong Yang <[email protected]> wrote:
From: Yicong Yang <[email protected]>
The PTT can only filter the traced TLP headers by the Root Ports or the Requester ID of the Endpoint, which are located on the same core of the PTT device. The filter value used is derived from the BDF number of the supported Root Port or the Endpoint. It's not friendly enough for the users since it requires the user to be familiar enough with the platform and calculate the filter value manually.
This patch export the available filters through sysfs. Each available filters is presented as an individual file with the name of the BDF number of the related PCIe device. The files are created under $(PTT PMU dir)/available_root_port_filters and
$(PTT PMU dir)/available_requester_filters respectively. The filter value can be known by reading the related file.
Quoted 4 lines
Then the users can easily know the available filters for trace and get the filter values without calculating.
Signed-off-by Yicong Yang <[email protected]>
Trivial comments only inline.
With those answered / tidied up.
Quoted 24 lines
drivers/hwtracing/ptt/hisi_ptt.c +17
-0+ +static int hisi_ptt_init_filter_attributes (struct hisi_ptt *hisi_ptt) +{ +struct hisi_ptt_filter_desc *filter; +int ret; + +mutex_lock (&hisi_ptt->filter_lock); + +list_for_each_entry (filter, &hisi_ptt->port_filters, list) { + ret =hisi_ptt_create_filter_attr (hisi_ptt, filter); +if (ret) + goto err; + } + +list_for_each_entry (filter, &hisi_ptt->req_filters, list) { + ret =hisi_ptt_create_filter_attr (hisi_ptt, filter); +if (ret)
drivers/hwtracing/ptt/hisi_ptt.c static int hisi_ptt_register_irq(struct hisi_ptt *hisi_ptt) · line 482
Quoted 10 lines
drivers/hwtracing/ptt/hisi_ptt.c +10
-0+ goto err; + } + + ret =devm_add_action_or_reset (&hisi_ptt->pdev->dev, + hisi_ptt_remove_all_filter_attributes, + hisi_ptt); +if (ret) + goto err; + + hisi_ptt->sysfs_inited = true;
err:
drivers/hwtracing/ptt/hisi_ptt.c
Quoted 1 line
drivers/hwtracing/ptt/hisi_ptt.c +1
-0+mutex_unlock (&hisi_ptt->filter_lock);
return ret;
No need for separate exit block when nothing to do but unlock.
Quoted 20 lines
drivers/hwtracing/ptt/hisi_ptt.c +13
-0+return 0 ; +err: +mutex_unlock (&hisi_ptt->filter_lock); +return ret; +} +static void hisi_ptt_update_filters (struct work_struct *work) {struct delayed_work *delayed_work =to_delayed_work (work);@@ -384,8 +517,28 @@ static void hisi_ptt_update_filters(struct work_struct *work)continue ; } + filter->name =kstrdup (pci_name (info.pdev),GFP_KERNEL ); +if (!filter->name) { +pci_err (hisi_ptt->pdev,"failed to add filter %s\n" , +pci_name (info.pdev)); +kfree (filter); +continue ; + }
drivers/hwtracing/ptt/hisi_ptt.c static void hisi_ptt_update_filters(struct work_struct *work) · line 536
Quoted 10 lines
drivers/hwtracing/ptt/hisi_ptt.c +8
-0+ filter->devid = devid; filter->is_port = is_port; + +/* +* If filters' sysfs entries hasn't been initialized, then +* we're still at probe stage and leave it to handled by +* others. +*/ + if (hisi_ptt->sysfs_inited &&
Can we move this sysfs_inited check earlier? Seems silly to leave a simple check like that so late.
Quoted 38 lines
drivers/hwtracing/ptt/hisi_ptt.c +16
-4+ hisi_ptt_create_filter_attr(hisi_ptt, filter)) { +kfree (filter); +continue ; + } +list_add_tail (&filter->list, target_list);if (is_port)@@ -394,6 +547,11 @@ static void hisi_ptt_update_filters(struct work_struct *work)list_for_each_entry (filter, target_list, list)if (filter->devid == devid) {list_del (&filter->list); + +if (hisi_ptt->sysfs_inited) +hisi_ptt_remove_filter_attr (hisi_ptt, filter); + +kfree (filter->name);kfree (filter);break ; }@@ -486,10 +644,12 @@ static int hisi_ptt_init_filters(struct pci_dev *pdev, void *data)* through the log. Other functions of PTT device are still available. */ filter =kzalloc (sizeof (*filter),GFP_KERNEL ); -if (!filter) { -pci_err (hisi_ptt->pdev,"failed to add filter %s\n" ,pci_name (pdev)); -return -ENOMEM ; - } +if (!filter) + goto err_mem; + + filter->name =kstrdup (pci_name (pdev),GFP_KERNEL ); +if (!filter->name) + goto err_name; filter->devid =PCI_DEVID (pdev->bus->number, pdev->devfn);
drivers/hwtracing/ptt/hisi_ptt.c static int hisi_ptt_init_filters(struct pci_dev *pdev, void *data) · line 670
Quoted 7 lines
drivers/hwtracing/ptt/hisi_ptt.c +4
-0@@ -504,6 +664,11 @@ static int hisi_ptt_init_filters(struct pci_dev *pdev, void *data) }return 0 ; +err_name: +kfree (filter); +err_mem: +pci_err (hisi_ptt->pdev,"failed to add filter %s\n" ,pci_name (pdev));
I'd rather see a message for each of the error paths so we have some information on why. Original message wasn't great for this obviously and perhaps given they are both allocation errors it's not worth splitting them up.
Quoted 2 lines
drivers/hwtracing/ptt/hisi_ptt.c +1
-0+return -ENOMEM ; }
Re: [PATCH 3/4] hwtracing: hisi_ptt: Export available filters through sysfs
Quoted 68 lines · Jonathan Cameron
Quoted 16 lines · On Wed, 15 Mar 2023 17:43:15 +0800 Yicong Yang <[email protected]> wrote:
From: Yicong Yang <[email protected]>
The PTT can only filter the traced TLP headers by the Root Ports or the Requester ID of the Endpoint, which are located on the same core of the PTT device. The filter value used is derived from the BDF number of the supported Root Port or the Endpoint. It's not friendly enough for the users since it requires the user to be familiar enough with the platform and calculate the filter value manually.
This patch export the available filters through sysfs. Each available filters is presented as an individual file with the name of the BDF number of the related PCIe device. The files are created under $(PTT PMU dir)/available_root_port_filters and
$(PTT PMU dir)/available_requester_filters respectively. The filter value can be known by reading the related file.Quoted 4 lines
Then the users can easily know the available filters for trace and get the filter values without calculating.
Signed-off-by Yicong Yang <[email protected]>Trivial comments only inline.
With those answered / tidied up.
Reviewed-by Jonathan Cameron <[email protected]>Quoted 24 lines
drivers/hwtracing/ptt/hisi_ptt.c +17
-0+ +static int hisi_ptt_init_filter_attributes (struct hisi_ptt *hisi_ptt) +{ +struct hisi_ptt_filter_desc *filter; +int ret; + +mutex_lock (&hisi_ptt->filter_lock); + +list_for_each_entry (filter, &hisi_ptt->port_filters, list) { + ret =hisi_ptt_create_filter_attr (hisi_ptt, filter); +if (ret) + goto err; + } + +list_for_each_entry (filter, &hisi_ptt->req_filters, list) { + ret =hisi_ptt_create_filter_attr (hisi_ptt, filter); +if (ret)drivers/hwtracing/ptt/hisi_ptt.c static int hisi_ptt_register_irq(struct hisi_ptt *hisi_ptt) · line 482
Quoted 10 lines
drivers/hwtracing/ptt/hisi_ptt.c +10
-0+ goto err; + } + + ret =devm_add_action_or_reset (&hisi_ptt->pdev->dev, + hisi_ptt_remove_all_filter_attributes, + hisi_ptt); +if (ret) + goto err; + + hisi_ptt->sysfs_inited = true;err:
Quoted 6 lines
drivers/hwtracing/ptt/hisi_ptt.c
Quoted 1 line
drivers/hwtracing/ptt/hisi_ptt.c +1
-0+mutex_unlock (&hisi_ptt->filter_lock);return ret;No need for separate exit block when nothing to do but unlock.
ok. will refine here.
Quoted 25 lines
Quoted 25 lines
drivers/hwtracing/ptt/hisi_ptt.c +16
-0+return 0 ; +err: +mutex_unlock (&hisi_ptt->filter_lock); +return ret; +} +static void hisi_ptt_update_filters (struct work_struct *work) {struct delayed_work *delayed_work =to_delayed_work (work);@@ -384,8 +517,28 @@ static void hisi_ptt_update_filters(struct work_struct *work)continue ; } + filter->name =kstrdup (pci_name (info.pdev),GFP_KERNEL ); +if (!filter->name) { +pci_err (hisi_ptt->pdev,"failed to add filter %s\n" , +pci_name (info.pdev)); +kfree (filter); +continue ; + } + filter->devid = devid; filter->is_port = is_port; + +/*
Quoted 9 lines
drivers/hwtracing/ptt/hisi_ptt.c static void hisi_ptt_update_filters(struct work_struct *work) · line 536
Quoted 5 lines
drivers/hwtracing/ptt/hisi_ptt.c +5
-0+* If filters' sysfs entries hasn't been initialized, then +* we're still at probe stage and leave it to handled by +* others. +*/ + if (hisi_ptt->sysfs_inited &&Can we move this
sysfs_initedcheck earlier? Seems silly to leave a simple check like that so late.
maybe move it into the hisi_ptt_create_filter_attr()? will have a check. for here we still need to update filter list even if the hisi_ptt's sysfs is not initialized yet.
Quoted 40 lines
Quoted 40 lines
drivers/hwtracing/ptt/hisi_ptt.c +16
-4+ hisi_ptt_create_filter_attr(hisi_ptt, filter)) { +kfree (filter); +continue ; + } +list_add_tail (&filter->list, target_list);if (is_port)@@ -394,6 +547,11 @@ static void hisi_ptt_update_filters(struct work_struct *work)list_for_each_entry (filter, target_list, list)if (filter->devid == devid) {list_del (&filter->list); + +if (hisi_ptt->sysfs_inited) +hisi_ptt_remove_filter_attr (hisi_ptt, filter); + +kfree (filter->name);kfree (filter);break ; }@@ -486,10 +644,12 @@ static int hisi_ptt_init_filters(struct pci_dev *pdev, void *data)* through the log. Other functions of PTT device are still available. */ filter =kzalloc (sizeof (*filter),GFP_KERNEL ); -if (!filter) { -pci_err (hisi_ptt->pdev,"failed to add filter %s\n" ,pci_name (pdev)); -return -ENOMEM ; - } +if (!filter) + goto err_mem; + + filter->name =kstrdup (pci_name (pdev),GFP_KERNEL ); +if (!filter->name) + goto err_name; filter->devid =PCI_DEVID (pdev->bus->number, pdev->devfn);@@ -504,6 +664,11 @@ static int hisi_ptt_init_filters(struct pci_dev *pdev, void *data) }
Quoted 10 lines
drivers/hwtracing/ptt/hisi_ptt.c static int hisi_ptt_init_filters(struct pci_dev *pdev, void *data) · line 670
Quoted 5 lines
drivers/hwtracing/ptt/hisi_ptt.c +4
-0return 0 ; +err_name: +kfree (filter); +err_mem: +pci_err (hisi_ptt->pdev,"failed to add filter %s\n" ,pci_name (pdev));I'd rather see a message for each of the error paths so we have some information on why. Original message wasn't great for this obviously and perhaps given they are both allocation errors it's not worth splitting them up.
ok, will try to split it and make it more verbosely.
Thanks,
Yicong
Quoted 6 lines
drivers/hwtracing/ptt/hisi_ptt.c static int hisi_ptt_init_filters(struct pci_dev *pdev, void *data) · line 672
Quoted 2 lines
drivers/hwtracing/ptt/hisi_ptt.c +1
-0+return -ENOMEM ; }.
PATCH 4/4 hwtracing: hisi_ptt: Advertise PERF_PMU_CAP_NO_EXCLUDE for PTT PMU
In reply to Yicong YangFrom: Yicong Yang <[email protected]>
The PTT trace collects PCIe TLP headers from the PCIe link and don't have the ability to exclude certain context. It doesn't support itrace as well. So only advertise PERF_PMU_CAP_NO_EXCLUDE. This will greatly save the storage of final data. Tested tracing idle link for ~15s, without this patch we'll collect ~28.682MB data for context related information and with this patch it reduced to ~0.226MB.
--- drivers/hwtracing/ptt/hisi_ptt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwtracing/ptt/hisi_ptt.c +1 -1
@@ -1216,7 +1216,7 @@ static int hisi_ptt_register_pmu(struct hisi_ptt *hisi_ptt) hisi_ptt->hisi_ptt_pmu = (struct pmu ) { .module =THIS_MODULE , - .capabilities =PERF_PMU_CAP_EXCLUSIVE |PERF_PMU_CAP_ITRACE , + .capabilities =PERF_PMU_CAP_NO_EXCLUDE , .task_ctx_nr = perf_sw_context, .attr_groups = hisi_ptt_pmu_groups, .event_init = hisi_ptt_pmu_event_init,
Signature · 1 line
2.24.0
Re: [PATCH 4/4] hwtracing: hisi_ptt: Advertise PERF_PMU_CAP_NO_EXCLUDE for PTT PMU
Quoted 10 lines · On Wed, 15 Mar 2023 17:43:16 +0800 Yicong Yang <[email protected]> wrote:
From: Yicong Yang <[email protected]>
The PTT trace collects PCIe TLP headers from the PCIe link and don't have the ability to exclude certain context. It doesn't support itrace as well. So only advertise
PERF_PMU_CAP_NO_EXCLUDE. This will greatly save the storage of final data. Tested tracing idle link for ~15s, without this patch we'll collect ~28.682MB data for context related information and with this patch it reduced to ~0.226MB.Signed-off-by Yicong Yang <[email protected]>
Seems reasonable.
Quoted 17 lines
--- drivers/hwtracing/ptt/hisi_ptt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/hwtracing/ptt/hisi_ptt.c +1
-1@@ -1216,7 +1216,7 @@ static int hisi_ptt_register_pmu(struct hisi_ptt *hisi_ptt) hisi_ptt->hisi_ptt_pmu = (struct pmu ) { .module =THIS_MODULE , - .capabilities =PERF_PMU_CAP_EXCLUSIVE |PERF_PMU_CAP_ITRACE , + .capabilities =PERF_PMU_CAP_NO_EXCLUDE , .task_ctx_nr = perf_sw_context, .attr_groups = hisi_ptt_pmu_groups, .event_init = hisi_ptt_pmu_event_init,
A gentle ping...
Thanks.
Quoted 32 lines · Yicong Yang
From: Yicong Yang <[email protected]>
This series tends to improve the PTT's filter interface in 2 aspects (Patch 2&3):
- Support dynamically filter updating to response to hotplug Previous the supported filter list is settled down once the driver probed and it maybe out-of-date if hotplug events happen later. User need to reload the driver to update list. Patch 1/2 enable the driver to update the list by registering a PCI bus notifier and the filter list will always be the latest.
- Export the available filters through sysfs
Previous user needs to calculate the filters and filter value using device's BDF number, which requires the user to know the hardware well. Patch 3/3 tends to export the available filter information through sysfs attributes, the filter value will be gotten by reading the file. This will be more user friendly.Also includes a fix and an improve. Patch 1 tends to only export the online CPUs supported by the PTT, this will make perf work properly when there's offline CPUs within the node PTT locates. Patch 4 tends to set proper PMU capability to avoid collecting unnecessary data to save the storage.
Yicong Yang (4):
hwtracing:hisi_ptt: Make cpumask only present online CPUs
hwtracing:hisi_ptt: Add support for dynamically updating the filter
list
hwtracing:hisi_ptt: Export available filters through sysfs
hwtracing:hisi_ptt: AdvertisePERF_PMU_CAP_NO_EXCLUDEfor PTT PMU.../ABI/testing/sysfs-devices-hisi_ptt | 50 +++ Documentation/trace/hisi-ptt.rst | 12 +- drivers/hwtracing/ptt/hisi_ptt.c | 396 +++++++++++++++++- drivers/hwtracing/ptt/hisi_ptt.h | 51 +++ 4 files changed, 498 insertions(+), 11 deletions(-)