Improve PTT filter interface
Subsystems (5)
v3 cover Improve PTT filter interface
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.
In order to support above function, this series also includes a patch 1/4 to factor out the allocation and release function of PTT filters.
Also includes an improvement. Patch 4 tends to set proper PMU capability to avoid collecting unnecessary data to save the storage.
Change since v2:
- Fix one possible issue for dereferencing a NULL pointer
Change since v1:
- Drop the patch for handling the cpumask since it seems to be redundant
- Refine of the codes per Jonathan
- Add Patch 1/4 for refactor the filters allocation and release
- Thanks the review of Jonathan.
Yicong Yang (4):
hwtracing: hisi_ptt: Factor out filter allocation and release
operation
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 | 426 ++++++++++++++++-- drivers/hwtracing/ptt/hisi_ptt.h | 53 +++ 4 files changed, 512 insertions(+), 29 deletions(-)
Signature · 1 line
2.24.0
PATCH v3 1/4 hwtracing: hisi_ptt: Factor out filter allocation and release operation
From: Yicong Yang <[email protected]>
Factor out the allocation and release of filters. This will make it easier to extend and manage the function of the filter.
--- drivers/hwtracing/ptt/hisi_ptt.c | 63 ++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 24 deletions(-)
drivers/hwtracing/ptt/hisi_ptt.c +39 -24
@@ -354,6 +354,39 @@ static int hisi_ptt_register_irq(struct hisi_ptt *hisi_ptt)return 0 ; } +static void hisi_ptt_del_free_filter (struct hisi_ptt *hisi_ptt, +struct hisi_ptt_filter_desc *filter) +{ +list_del (&filter->list); +kfree (filter); +} + +static struct hisi_ptt_filter_desc * +hisi_ptt_alloc_add_filter (struct hisi_ptt *hisi_ptt,struct pci_dev *pdev) +{ +struct hisi_ptt_filter_desc *filter; + + filter =kzalloc (sizeof (*filter),GFP_KERNEL ); +if (!filter) { +pci_err (hisi_ptt->pdev,"failed to add filter for %s\n" , +pci_name (pdev)); +return NULL ; + } + + filter->devid =PCI_DEVID (pdev->bus->number, pdev->devfn); + filter->is_port =pci_pcie_type (pdev) ==PCI_EXP_TYPE_ROOT_PORT ; +if (filter->is_port) { +list_add_tail (&filter->list, &hisi_ptt->port_filters); + +/* Update the available port mask */ + hisi_ptt->port_mask |=hisi_ptt_get_filter_val (filter->devid, true); + }else { +list_add_tail (&filter->list, &hisi_ptt->req_filters); + } + +return filter; +} +static int hisi_ptt_init_filters (struct pci_dev *pdev,void *data) {struct pci_dev *root_port =pcie_find_root_port (pdev);
@@ -374,23 +407,9 @@ static int hisi_ptt_init_filters(struct pci_dev *pdev, void *data)* should be partial initialized and users would know which filter fails * 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)); + filter =hisi_ptt_alloc_add_filter (hisi_ptt, pdev); +if (!filter)return -ENOMEM ; - } - - filter->devid =PCI_DEVID (pdev->bus->number, pdev->devfn); - -if (pci_pcie_type (pdev) ==PCI_EXP_TYPE_ROOT_PORT ) { - filter->is_port = true; -list_add_tail (&filter->list, &hisi_ptt->port_filters); - -/* Update the available port mask */ - hisi_ptt->port_mask |=hisi_ptt_get_filter_val (filter->devid, true); - }else { -list_add_tail (&filter->list, &hisi_ptt->req_filters); - }return 0 ; }
@@ -400,15 +419,11 @@ static void hisi_ptt_release_filters(void *data)struct hisi_ptt_filter_desc *filter, *tmp;struct hisi_ptt *hisi_ptt = data; -list_for_each_entry_safe (filter, tmp, &hisi_ptt->req_filters, list) { -list_del (&filter->list); -kfree (filter); - } +list_for_each_entry_safe (filter, tmp, &hisi_ptt->req_filters, list) +hisi_ptt_del_free_filter (hisi_ptt, filter); -list_for_each_entry_safe (filter, tmp, &hisi_ptt->port_filters, list) { -list_del (&filter->list); -kfree (filter); - } +list_for_each_entry_safe (filter, tmp, &hisi_ptt->port_filters, list) +hisi_ptt_del_free_filter (hisi_ptt, filter); }static int hisi_ptt_config_trace_buf (struct hisi_ptt *hisi_ptt)
Signature · 1 line
2.24.0
Re: [PATCH v3 1/4] hwtracing: hisi_ptt: Factor out filter allocation and release operation
Quoted 6 lines · On Tue, 23 May 2023 17:32:25 +0800 Yicong Yang <[email protected]> wrote:
From: Yicong Yang <[email protected]>
Factor out the allocation and release of filters. This will make it easier to extend and manage the function of the filter.
Signed-off-by Yicong Yang <[email protected]>
Straight forward refactor. LGTM
Quoted 94 lines
--- drivers/hwtracing/ptt/hisi_ptt.c | 63 ++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 24 deletions(-)drivers/hwtracing/ptt/hisi_ptt.c +39
-24@@ -354,6 +354,39 @@ static int hisi_ptt_register_irq(struct hisi_ptt *hisi_ptt)return 0 ; } +static void hisi_ptt_del_free_filter (struct hisi_ptt *hisi_ptt, +struct hisi_ptt_filter_desc *filter) +{ +list_del (&filter->list); +kfree (filter); +} + +static struct hisi_ptt_filter_desc * +hisi_ptt_alloc_add_filter (struct hisi_ptt *hisi_ptt,struct pci_dev *pdev) +{ +struct hisi_ptt_filter_desc *filter; + + filter =kzalloc (sizeof (*filter),GFP_KERNEL ); +if (!filter) { +pci_err (hisi_ptt->pdev,"failed to add filter for %s\n" , +pci_name (pdev)); +return NULL ; + } + + filter->devid =PCI_DEVID (pdev->bus->number, pdev->devfn); + filter->is_port =pci_pcie_type (pdev) ==PCI_EXP_TYPE_ROOT_PORT ; +if (filter->is_port) { +list_add_tail (&filter->list, &hisi_ptt->port_filters); + +/* Update the available port mask */ + hisi_ptt->port_mask |=hisi_ptt_get_filter_val (filter->devid, true); + }else { +list_add_tail (&filter->list, &hisi_ptt->req_filters); + } + +return filter; +} +static int hisi_ptt_init_filters (struct pci_dev *pdev,void *data) {struct pci_dev *root_port =pcie_find_root_port (pdev);@@ -374,23 +407,9 @@ static int hisi_ptt_init_filters(struct pci_dev *pdev, void *data)* should be partial initialized and users would know which filter fails * 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)); + filter =hisi_ptt_alloc_add_filter (hisi_ptt, pdev); +if (!filter)return -ENOMEM ; - } - - filter->devid =PCI_DEVID (pdev->bus->number, pdev->devfn); - -if (pci_pcie_type (pdev) ==PCI_EXP_TYPE_ROOT_PORT ) { - filter->is_port = true; -list_add_tail (&filter->list, &hisi_ptt->port_filters); - -/* Update the available port mask */ - hisi_ptt->port_mask |=hisi_ptt_get_filter_val (filter->devid, true); - }else { -list_add_tail (&filter->list, &hisi_ptt->req_filters); - }return 0 ; }@@ -400,15 +419,11 @@ static void hisi_ptt_release_filters(void *data)struct hisi_ptt_filter_desc *filter, *tmp;struct hisi_ptt *hisi_ptt = data; -list_for_each_entry_safe (filter, tmp, &hisi_ptt->req_filters, list) { -list_del (&filter->list); -kfree (filter); - } +list_for_each_entry_safe (filter, tmp, &hisi_ptt->req_filters, list) +hisi_ptt_del_free_filter (hisi_ptt, filter); -list_for_each_entry_safe (filter, tmp, &hisi_ptt->port_filters, list) { -list_del (&filter->list); -kfree (filter); - } +list_for_each_entry_safe (filter, tmp, &hisi_ptt->port_filters, list) +hisi_ptt_del_free_filter (hisi_ptt, filter); }static int hisi_ptt_config_trace_buf (struct hisi_ptt *hisi_ptt)
PATCH v3 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 | 165 +++++++++++++++++++++++++++++-- drivers/hwtracing/ptt/hisi_ptt.h | 39 ++++++++ 3 files changed, 201 insertions(+), 9 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 +159 -6
230 lines not on this page · raw message
drivers/hwtracing/ptt/hisi_ptt.h +39 -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 */
@@ -135,11 +143,24 @@ struct hisi_ptt_trace_ctrl {* struct hisi_ptt_filter_desc - Descriptor of the PTT trace 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 list_head list;bool is_port; +char *name; +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 { +bool is_port; +bool is_add;u16 devid; };
@@ -161,6 +182,7 @@ struct hisi_ptt_pmu_buf {* struct hisi_ptt - Per PTT device data * @trace_ctrl: the control information of PTT trace * @hotplug_node: node for register cpu hotplug event +* @hisi_ptt_nb: dynamic filter update notifier * @hisi_ptt_pmu: the pum device of trace * @iobase: base IO address of the device * @pdev: pci_dev of this PTT device
@@ -170,10 +192,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 +219,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 v3 2/4] hwtracing: hisi_ptt: Add support for dynamically updating the filter list
Quoted 10 lines · On Tue, 23 May 2023 17:32:26 +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]>
Hi Yangyicong,
A few comments inline
Jonathan
Quoted 11 lines
--- Documentation/trace/hisi-ptt.rst | 6 +- drivers/hwtracing/ptt/hisi_ptt.c | 165 +++++++++++++++++++++++++++++-- drivers/hwtracing/ptt/hisi_ptt.h | 39 ++++++++ 3 files changed, 201 insertions(+), 9 deletions(-)Documentation/trace/hisi-ptt.rst +0
-0
Documentation/trace/hisi-ptt.rst Endpoint function can be specified in one trace. Specifying both Root Port · line 156
Quoted 7 lines
Documentation/trace/hisi-ptt.rst +1
-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
updated,
Quoted 10 lines
Documentation/trace/hisi-ptt.rst +2
-0+get correct filter information when hotplug events happen, or when you manually +remove/rescan the devices. 2. Type -------drivers/hwtracing/ptt/hisi_ptt.c +0
-0@@ -357,24 +357,41 @@ static int hisi_ptt_register_irq(struct hisi_ptt *hisi_ptt)
...
Quoted 4 lines
static struct
hisi_ptt_filter_desc*drivers/hwtracing/ptt/hisi_ptt.c +1
-1-hisi_ptt_alloc_add_filter(struct hisi_ptt *hisi_ptt, struct pci_dev *pdev) +hisi_ptt_alloc_add_filter(struct hisi_ptt *hisi_ptt, u16 devid, bool is_port) {
drivers/hwtracing/ptt/hisi_ptt.c static int hisi_ptt_register_irq(struct hisi_ptt *hisi_ptt) · line 380
Quoted 10 lines
drivers/hwtracing/ptt/hisi_ptt.c +9
-0struct hisi_ptt_filter_desc *filter; +u8 devfn = devid &0xff ; +char *filter_name; + + filter_name =kasprintf (GFP_KERNEL ,"%04x:%02x:%02x.%d" ,pci_domain_nr (hisi_ptt->pdev->bus), +PCI_BUS_NUM (devid),PCI_SLOT (devfn),PCI_FUNC (devfn)); +if (!filter_name) { +pci_err (hisi_ptt->pdev,"failed to allocate name for filter %s\n" , + filter_name); +kfree (filter);
Don't think you've allocated filter yet.
Quoted 23 lines
drivers/hwtracing/ptt/hisi_ptt.c +7
-3+return NULL ; + } filter =kzalloc (sizeof (*filter),GFP_KERNEL );if (!filter) {pci_err (hisi_ptt->pdev,"failed to add filter for %s\n" , -pci_name (pdev)); + filter_name);return NULL ; } - filter->devid =PCI_DEVID (pdev->bus->number, pdev->devfn); - filter->is_port =pci_pcie_type (pdev) ==PCI_EXP_TYPE_ROOT_PORT ; + filter->name = filter_name; + filter->is_port = is_port; + filter->devid = devid; +if (filter->is_port) {list_add_tail (&filter->list, &hisi_ptt->port_filters);@@ -387,6 +404,102 @@ hisi_ptt_alloc_add_filter(struct hisi_ptt *hisi_ptt, struct pci_dev *pdev)return filter; }
...
drivers/hwtracing/ptt/hisi_ptt.c static int hisi_ptt_trace_valid_filter(struct hisi_ptt *hisi_ptt, u64 config) · line 759
Quoted 10 lines
drivers/hwtracing/ptt/hisi_ptt.c +3
-1@@ -633,14 +752,19 @@ static int hisi_ptt_trace_valid_filter(struct hisi_ptt *hisi_ptt, u64 config)* For Requester ID filters, walk the available filter list to see * whether we have one matched. */ +mutex_lock (&hisi_ptt->filter_lock);if (!hisi_ptt->trace_ctrl.is_port) {list_for_each_entry (filter, &hisi_ptt->req_filters, list) { -if (val ==hisi_ptt_get_filter_val (filter->devid, filter->is_port)) +if (val ==hisi_ptt_get_filter_val (filter->devid, filter->is_port)) { +mutex_unlock (&hisi_ptt->filter_lock);
Perhaps a single exit location makes more sense given we need to unlock in all paths? goto unlock; etc
Quoted 21 lines
drivers/hwtracing/ptt/hisi_ptt.c +3
-0return 0 ; + } } }else if (bitmap_subset (&val, &port_mask,BITS_PER_LONG )) { +mutex_unlock (&hisi_ptt->filter_lock);return 0 ; } +mutex_unlock (&hisi_ptt->filter_lock);return -EINVAL ; }@@ -916,6 +1040,31 @@ static int hisi_ptt_register_pmu(struct hisi_ptt *hisi_ptt) &hisi_ptt->hisi_ptt_pmu); }drivers/hwtracing/ptt/hisi_ptt.h +0
-0
...
drivers/hwtracing/ptt/hisi_ptt.h struct hisi_ptt_pmu_buf { · line 185
Quoted 5 lines
drivers/hwtracing/ptt/hisi_ptt.h +1
-0@@ -161,6 +182,7 @@ struct hisi_ptt_pmu_buf {* struct hisi_ptt - Per PTT device data * @trace_ctrl: the control information of PTT trace * @hotplug_node: node for register cpu hotplug event +* @hisi_ptt_nb: dynamic filter update notifier
Wrong location. Order should match the fields in the structure. So this belongs just above hotplug_node
Quoted 39 lines
drivers/hwtracing/ptt/hisi_ptt.h +17
-0* @hisi_ptt_pmu: the pum device of trace * @iobase: base IO address of the device * @pdev: pci_dev of this PTT device @@ -170,10 +192,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 +219,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 v3 2/4] hwtracing: hisi_ptt: Add support for dynamically updating the filter list
Quoted 12 lines · Jonathan Cameron
Quoted 9 lines · On Tue, 23 May 2023 17:32:26 +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 4 lines
Quoted 1 line
Signed-off-by Yicong Yang <[email protected]>Hi Yangyicong,
A few comments inline
Thanks for the comments! Will fix them up in next version.
Quoted 173 lines
Jonathan
Quoted 11 lines
--- Documentation/trace/hisi-ptt.rst | 6 +- drivers/hwtracing/ptt/hisi_ptt.c | 165 +++++++++++++++++++++++++++++-- drivers/hwtracing/ptt/hisi_ptt.h | 39 ++++++++ 3 files changed, 201 insertions(+), 9 deletions(-)Documentation/trace/hisi-ptt.rst +0
-0Documentation/trace/hisi-ptt.rst Endpoint function can be specified in one trace. Specifying both Root Port · line 156
Quoted 7 lines
Documentation/trace/hisi-ptt.rst +1
-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 alwaysupdated,
Quoted 10 lines
Documentation/trace/hisi-ptt.rst +2
-0+get correct filter information when hotplug events happen, or when you manually +remove/rescan the devices. 2. Type -------drivers/hwtracing/ptt/hisi_ptt.c +0
-0@@ -357,24 +357,41 @@ static int hisi_ptt_register_irq(struct hisi_ptt *hisi_ptt)...
Quoted 4 lines
static struct
hisi_ptt_filter_desc*drivers/hwtracing/ptt/hisi_ptt.c +1
-1-hisi_ptt_alloc_add_filter(struct hisi_ptt *hisi_ptt, struct pci_dev *pdev) +hisi_ptt_alloc_add_filter(struct hisi_ptt *hisi_ptt, u16 devid, bool is_port) {drivers/hwtracing/ptt/hisi_ptt.c static int hisi_ptt_register_irq(struct hisi_ptt *hisi_ptt) · line 380
Quoted 10 lines
drivers/hwtracing/ptt/hisi_ptt.c +9
-0struct hisi_ptt_filter_desc *filter; +u8 devfn = devid &0xff ; +char *filter_name; + + filter_name =kasprintf (GFP_KERNEL ,"%04x:%02x:%02x.%d" ,pci_domain_nr (hisi_ptt->pdev->bus), +PCI_BUS_NUM (devid),PCI_SLOT (devfn),PCI_FUNC (devfn)); +if (!filter_name) { +pci_err (hisi_ptt->pdev,"failed to allocate name for filter %s\n" , + filter_name); +kfree (filter);Don't think you've allocated filter yet.
Quoted 23 lines
drivers/hwtracing/ptt/hisi_ptt.c +7
-3+return NULL ; + } filter =kzalloc (sizeof (*filter),GFP_KERNEL );if (!filter) {pci_err (hisi_ptt->pdev,"failed to add filter for %s\n" , -pci_name (pdev)); + filter_name);return NULL ; } - filter->devid =PCI_DEVID (pdev->bus->number, pdev->devfn); - filter->is_port =pci_pcie_type (pdev) ==PCI_EXP_TYPE_ROOT_PORT ; + filter->name = filter_name; + filter->is_port = is_port; + filter->devid = devid; +if (filter->is_port) {list_add_tail (&filter->list, &hisi_ptt->port_filters);@@ -387,6 +404,102 @@ hisi_ptt_alloc_add_filter(struct hisi_ptt *hisi_ptt, struct pci_dev *pdev)return filter; }...
drivers/hwtracing/ptt/hisi_ptt.c static int hisi_ptt_trace_valid_filter(struct hisi_ptt *hisi_ptt, u64 config) · line 759
Quoted 10 lines
drivers/hwtracing/ptt/hisi_ptt.c +3
-1@@ -633,14 +752,19 @@ static int hisi_ptt_trace_valid_filter(struct hisi_ptt *hisi_ptt, u64 config)* For Requester ID filters, walk the available filter list to see * whether we have one matched. */ +mutex_lock (&hisi_ptt->filter_lock);if (!hisi_ptt->trace_ctrl.is_port) {list_for_each_entry (filter, &hisi_ptt->req_filters, list) { -if (val ==hisi_ptt_get_filter_val (filter->devid, filter->is_port)) +if (val ==hisi_ptt_get_filter_val (filter->devid, filter->is_port)) { +mutex_unlock (&hisi_ptt->filter_lock);Perhaps a single exit location makes more sense given we need to unlock in all paths? goto unlock; etc
Quoted 21 lines
drivers/hwtracing/ptt/hisi_ptt.c +3
-0return 0 ; + } } }else if (bitmap_subset (&val, &port_mask,BITS_PER_LONG )) { +mutex_unlock (&hisi_ptt->filter_lock);return 0 ; } +mutex_unlock (&hisi_ptt->filter_lock);return -EINVAL ; }@@ -916,6 +1040,31 @@ static int hisi_ptt_register_pmu(struct hisi_ptt *hisi_ptt) &hisi_ptt->hisi_ptt_pmu); }drivers/hwtracing/ptt/hisi_ptt.h +0
-0...
drivers/hwtracing/ptt/hisi_ptt.h struct hisi_ptt_pmu_buf { · line 185
Quoted 5 lines
drivers/hwtracing/ptt/hisi_ptt.h +1
-0@@ -161,6 +182,7 @@ struct hisi_ptt_pmu_buf {* struct hisi_ptt - Per PTT device data * @trace_ctrl: the control information of PTT trace * @hotplug_node: node for register cpu hotplug event +* @hisi_ptt_nb: dynamic filter update notifier Wrong location. Order should match the fields in the structure. So this belongs just above
hotplug_nodeQuoted 29 lines
drivers/hwtracing/ptt/hisi_ptt.h +10
-0* @hisi_ptt_pmu: the pum device of trace * @iobase: base IO address of the device * @pdev: pci_dev of this PTT device @@ -170,10 +192,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 +219,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 237
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 v3 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 | 206 ++++++++++++++++++ drivers/hwtracing/ptt/hisi_ptt.h | 14 ++ 4 files changed, 276 insertions(+)
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: May 2023 +KernelVersion: 6.5 +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: May 2023 +KernelVersion: 6.5 +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: May 2023 +KernelVersion: 6.5 +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: May 2023 +KernelVersion: 6.5 +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: May 2023 +KernelVersion: 6.5 +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: May 2023 +KernelVersion: 6.5 +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 +206 -0
240 lines not on this page · raw message
drivers/hwtracing/ptt/hisi_ptt.h +14 -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,14 +140,25 @@ 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;
@@ -193,6 +205,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
@@ -220,6 +233,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 v3 3/4] hwtracing: hisi_ptt: Export available filters through sysfs
Quoted 4 lines · On Tue, 23 May 2023 17:32:27 +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
PCI core (could be confused with CPU core)
Quoted 4 lines
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.
Could we in theory push this problem to userspace? If so perhaps call out advantages / disadvantages of doing so?
Quoted 8 lines
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]>
A few minor editorial type comments inline
Jonathan
Quoted 23 lines
--- .../ABI/testing/sysfs-devices-hisi_ptt | 50 +++++ Documentation/trace/hisi-ptt.rst | 6 + drivers/hwtracing/ptt/hisi_ptt.c | 206 ++++++++++++++++++ drivers/hwtracing/ptt/hisi_ptt.h | 14 ++ 4 files changed, 276 insertions(+)Documentation/ABI/testing/sysfs-devices-hisi_ptt +8
-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: May 2023 +KernelVersion: 6.5 +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>.
Documentation/ABI/testing/sysfs-devices-hisi_ptt Description: (RW) Control the allocated buffer watermark of outbound packets. · line 79
Quoted 10 lines
Documentation/ABI/testing/sysfs-devices-hisi_ptt +10
-0+ + 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: May 2023 +KernelVersion: 6.5 +Contact: Yicong Yang <[email protected]> +Description: (Read) Indicates whether this kind of filter can be multiselected + or not. 1 for multiselectable, 0 for not.
multiselect term isn't totally clear - so I'd say exactly what it means here.
Indicates if this kind of filter can be selected at the same time as others filters, or must be used on it's own.
Quoted 15 lines
Documentation/ABI/testing/sysfs-devices-hisi_ptt +15
-0+ +What: /sys/devices/hisi_ptt<sicl_id>_<core_id>/root_port_filters/<bdf> +Date: May 2023 +KernelVersion: 6.5 +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: May 2023 +KernelVersion: 6.5 +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>.
Documentation/ABI/testing/sysfs-devices-hisi_ptt Description: (RW) Control the allocated buffer watermark of outbound packets. · line 104
Quoted 10 lines
Documentation/ABI/testing/sysfs-devices-hisi_ptt +10
-0+ + 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: May 2023 +KernelVersion: 6.5 +Contact: Yicong Yang <[email protected]> +Description: (Read) Indicates whether this kind of filter can be multiselected + or not. 1 for multiselectable, 0 for not.
As above - explain multiselect using a different set of terms.
Quoted 132 lines
Documentation/ABI/testing/sysfs-devices-hisi_ptt +7
-0+ +What: /sys/devices/hisi_ptt<sicl_id>_<core_id>/requester_filters/<bdf> +Date: May 2023 +KernelVersion: 6.5 +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 ofdrivers/hwtracing/ptt/hisi_ptt.c +100
-0@@ -404,6 +404,142 @@ hisi_ptt_alloc_add_filter(struct hisi_ptt *hisi_ptt, u16 devid, bool is_port)return filter; } +static ssize_t hisi_ptt_filter_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct hisi_ptt_filter_desc *filter; +unsigned long filter_val; + + filter = container_of(attr, struct hisi_ptt_filter_desc, attr); + filter_val =hisi_ptt_get_filter_val (filter->devid, filter->is_port) | + (filter->is_port ?HISI_PTT_PMU_FILTER_IS_PORT :0 ); + +return sysfs_emit (buf,"0x%05lx\n" , filter_val); +} + +static int hisi_ptt_create_rp_filter_attr (struct hisi_ptt *hisi_ptt, +struct hisi_ptt_filter_desc *filter) +{ +struct kobject *kobj = &hisi_ptt->hisi_ptt_pmu.dev->kobj; + + filter->attr.attr.name = filter->name; + filter->attr.attr.mode =0400 ;/* DEVICE_ATTR_ADMIN_RO */ + filter->attr.show = hisi_ptt_filter_show; + +return sysfs_add_file_to_group (kobj, &filter->attr.attr, +HISI_PTT_RP_FILTERS_GRP_NAME ); +} + +static void hisi_ptt_remove_rp_filter_attr (struct hisi_ptt *hisi_ptt, +struct hisi_ptt_filter_desc *filter) +{ +struct kobject *kobj = &hisi_ptt->hisi_ptt_pmu.dev->kobj; + +sysfs_remove_file_from_group (kobj, &filter->attr.attr, +HISI_PTT_RP_FILTERS_GRP_NAME ); +} + +static int hisi_ptt_create_req_filter_attr (struct hisi_ptt *hisi_ptt, +struct hisi_ptt_filter_desc *filter) +{ +struct kobject *kobj = &hisi_ptt->hisi_ptt_pmu.dev->kobj; + + filter->attr.attr.name = filter->name; + filter->attr.attr.mode =0400 ;/* DEVICE_ATTR_ADMIN_RO */ + filter->attr.show = hisi_ptt_filter_show; + +return sysfs_add_file_to_group (kobj, &filter->attr.attr, +HISI_PTT_REQ_FILTERS_GRP_NAME ); +} + +static void hisi_ptt_remove_req_filter_attr (struct hisi_ptt *hisi_ptt, +struct hisi_ptt_filter_desc *filter) +{ +struct kobject *kobj = &hisi_ptt->hisi_ptt_pmu.dev->kobj; + +sysfs_remove_file_from_group (kobj, &filter->attr.attr, +HISI_PTT_REQ_FILTERS_GRP_NAME ); +} + +static int hisi_ptt_create_filter_attr (struct hisi_ptt *hisi_ptt, +struct hisi_ptt_filter_desc *filter) +{ +int ret; + +if (filter->is_port) + ret =hisi_ptt_create_rp_filter_attr (hisi_ptt, filter); +else + ret =hisi_ptt_create_req_filter_attr (hisi_ptt, filter); + +if (ret) +pci_err (hisi_ptt->pdev,"failed to create sysfs attribute for filter %s\n" , + filter->name); + +return ret; +} + +static void hisi_ptt_remove_filter_attr (struct hisi_ptt *hisi_ptt, +struct hisi_ptt_filter_desc *filter) +{ +if (filter->is_port) +hisi_ptt_remove_rp_filter_attr (hisi_ptt, filter); +else +hisi_ptt_remove_req_filter_attr (hisi_ptt, filter); +} + +static void hisi_ptt_remove_all_filter_attributes (void *data) +{ +struct hisi_ptt_filter_desc *filter; +struct hisi_ptt *hisi_ptt = data; + +mutex_lock (&hisi_ptt->filter_lock); + +list_for_each_entry (filter, &hisi_ptt->req_filters, list) +hisi_ptt_remove_filter_attr (hisi_ptt, filter); + +list_for_each_entry (filter, &hisi_ptt->port_filters, list) +hisi_ptt_remove_filter_attr (hisi_ptt, filter); + + hisi_ptt->sysfs_inited = false; +mutex_unlock (&hisi_ptt->filter_lock); +} +
drivers/hwtracing/ptt/hisi_ptt.c hisi_ptt_alloc_add_filter(struct hisi_ptt *hisi_ptt, u16 devid, bool is_port) · line 516
Quoted 10 lines
drivers/hwtracing/ptt/hisi_ptt.c +10
-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); + +/* +* Register the reset callback in the first stage. In reset we traverse +* the filters list to remove the sysfs attributes so itself alone can
"itself alone" is confusing. Maybe "the callback"
Quoted 26 lines
drivers/hwtracing/ptt/hisi_ptt.c +26
-0+* be called safely even without below filter attributes creation work. +*/ + ret =devm_add_action (&hisi_ptt->pdev->dev, + hisi_ptt_remove_all_filter_attributes, + hisi_ptt); +if (ret) + goto out; + +list_for_each_entry (filter, &hisi_ptt->port_filters, list) { + ret =hisi_ptt_create_filter_attr (hisi_ptt, filter); +if (ret) + goto out; + } + +list_for_each_entry (filter, &hisi_ptt->req_filters, list) { + ret =hisi_ptt_create_filter_attr (hisi_ptt, filter); +if (ret) + goto out; + } + + hisi_ptt->sysfs_inited = true; +out: +mutex_unlock (&hisi_ptt->filter_lock); +return ret; +} +
...
Re: [PATCH v3 3/4] hwtracing: hisi_ptt: Export available filters through sysfs
Quoted 10 lines · Jonathan Cameron
Quoted 4 lines · On Tue, 23 May 2023 17:32:27 +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
PCI core (could be confused with CPU core)
Quoted 8 lines
Quoted 4 lines
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.
Could we in theory push this problem to userspace? If so perhaps call out advantages / disadvantages of doing so?
I'm not quite sure how userspace can get this mapping information, currently in the driver we get part of the information from the firmware. Userspace alone cannot handle it, I think it need driver assistant anyway.
Quoted 8 lines
Quoted 8 lines
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 5 lines
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]>A few minor editorial type comments inline
Will fix them up.
Thanks.
Quoted 245 lines
Jonathan
Quoted 23 lines
--- .../ABI/testing/sysfs-devices-hisi_ptt | 50 +++++ Documentation/trace/hisi-ptt.rst | 6 + drivers/hwtracing/ptt/hisi_ptt.c | 206 ++++++++++++++++++ drivers/hwtracing/ptt/hisi_ptt.h | 14 ++ 4 files changed, 276 insertions(+)Documentation/ABI/testing/sysfs-devices-hisi_ptt +8
-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: May 2023 +KernelVersion: 6.5 +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>.Documentation/ABI/testing/sysfs-devices-hisi_ptt Description: (RW) Control the allocated buffer watermark of outbound packets. · line 79
Quoted 10 lines
Documentation/ABI/testing/sysfs-devices-hisi_ptt +10
-0+ + 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: May 2023 +KernelVersion: 6.5 +Contact: Yicong Yang <[email protected]> +Description: (Read) Indicates whether this kind of filter can be multiselected + or not. 1 for multiselectable, 0 for not.multiselect term isn't totally clear - so I'd say exactly what it means here.
Indicates if this kind of filter can be selected at the same time as others filters, or must be used on it's own.
Quoted 15 lines
Documentation/ABI/testing/sysfs-devices-hisi_ptt +15
-0+ +What: /sys/devices/hisi_ptt<sicl_id>_<core_id>/root_port_filters/<bdf> +Date: May 2023 +KernelVersion: 6.5 +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: May 2023 +KernelVersion: 6.5 +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>.Documentation/ABI/testing/sysfs-devices-hisi_ptt Description: (RW) Control the allocated buffer watermark of outbound packets. · line 104
Quoted 10 lines
Documentation/ABI/testing/sysfs-devices-hisi_ptt +10
-0+ + 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: May 2023 +KernelVersion: 6.5 +Contact: Yicong Yang <[email protected]> +Description: (Read) Indicates whether this kind of filter can be multiselected + or not. 1 for multiselectable, 0 for not.As above - explain multiselect using a different set of terms.
Quoted 132 lines
Documentation/ABI/testing/sysfs-devices-hisi_ptt +7
-0+ +What: /sys/devices/hisi_ptt<sicl_id>_<core_id>/requester_filters/<bdf> +Date: May 2023 +KernelVersion: 6.5 +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 ofdrivers/hwtracing/ptt/hisi_ptt.c +100
-0@@ -404,6 +404,142 @@ hisi_ptt_alloc_add_filter(struct hisi_ptt *hisi_ptt, u16 devid, bool is_port)return filter; } +static ssize_t hisi_ptt_filter_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct hisi_ptt_filter_desc *filter; +unsigned long filter_val; + + filter = container_of(attr, struct hisi_ptt_filter_desc, attr); + filter_val =hisi_ptt_get_filter_val (filter->devid, filter->is_port) | + (filter->is_port ?HISI_PTT_PMU_FILTER_IS_PORT :0 ); + +return sysfs_emit (buf,"0x%05lx\n" , filter_val); +} + +static int hisi_ptt_create_rp_filter_attr (struct hisi_ptt *hisi_ptt, +struct hisi_ptt_filter_desc *filter) +{ +struct kobject *kobj = &hisi_ptt->hisi_ptt_pmu.dev->kobj; + + filter->attr.attr.name = filter->name; + filter->attr.attr.mode =0400 ;/* DEVICE_ATTR_ADMIN_RO */ + filter->attr.show = hisi_ptt_filter_show; + +return sysfs_add_file_to_group (kobj, &filter->attr.attr, +HISI_PTT_RP_FILTERS_GRP_NAME ); +} + +static void hisi_ptt_remove_rp_filter_attr (struct hisi_ptt *hisi_ptt, +struct hisi_ptt_filter_desc *filter) +{ +struct kobject *kobj = &hisi_ptt->hisi_ptt_pmu.dev->kobj; + +sysfs_remove_file_from_group (kobj, &filter->attr.attr, +HISI_PTT_RP_FILTERS_GRP_NAME ); +} + +static int hisi_ptt_create_req_filter_attr (struct hisi_ptt *hisi_ptt, +struct hisi_ptt_filter_desc *filter) +{ +struct kobject *kobj = &hisi_ptt->hisi_ptt_pmu.dev->kobj; + + filter->attr.attr.name = filter->name; + filter->attr.attr.mode =0400 ;/* DEVICE_ATTR_ADMIN_RO */ + filter->attr.show = hisi_ptt_filter_show; + +return sysfs_add_file_to_group (kobj, &filter->attr.attr, +HISI_PTT_REQ_FILTERS_GRP_NAME ); +} + +static void hisi_ptt_remove_req_filter_attr (struct hisi_ptt *hisi_ptt, +struct hisi_ptt_filter_desc *filter) +{ +struct kobject *kobj = &hisi_ptt->hisi_ptt_pmu.dev->kobj; + +sysfs_remove_file_from_group (kobj, &filter->attr.attr, +HISI_PTT_REQ_FILTERS_GRP_NAME ); +} + +static int hisi_ptt_create_filter_attr (struct hisi_ptt *hisi_ptt, +struct hisi_ptt_filter_desc *filter) +{ +int ret; + +if (filter->is_port) + ret =hisi_ptt_create_rp_filter_attr (hisi_ptt, filter); +else + ret =hisi_ptt_create_req_filter_attr (hisi_ptt, filter); + +if (ret) +pci_err (hisi_ptt->pdev,"failed to create sysfs attribute for filter %s\n" , + filter->name); + +return ret; +} + +static void hisi_ptt_remove_filter_attr (struct hisi_ptt *hisi_ptt, +struct hisi_ptt_filter_desc *filter) +{ +if (filter->is_port) +hisi_ptt_remove_rp_filter_attr (hisi_ptt, filter); +else +hisi_ptt_remove_req_filter_attr (hisi_ptt, filter); +} + +static void hisi_ptt_remove_all_filter_attributes (void *data) +{ +struct hisi_ptt_filter_desc *filter; +struct hisi_ptt *hisi_ptt = data; + +mutex_lock (&hisi_ptt->filter_lock); + +list_for_each_entry (filter, &hisi_ptt->req_filters, list) +hisi_ptt_remove_filter_attr (hisi_ptt, filter); + +list_for_each_entry (filter, &hisi_ptt->port_filters, list) +hisi_ptt_remove_filter_attr (hisi_ptt, filter); + + hisi_ptt->sysfs_inited = false; +mutex_unlock (&hisi_ptt->filter_lock); +} +drivers/hwtracing/ptt/hisi_ptt.c hisi_ptt_alloc_add_filter(struct hisi_ptt *hisi_ptt, u16 devid, bool is_port) · line 516
Quoted 10 lines
drivers/hwtracing/ptt/hisi_ptt.c +10
-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); + +/* +* Register the reset callback in the first stage. In reset we traverse +* the filters list to remove the sysfs attributes so itself alone can "itself alone" is confusing. Maybe "the callback"
Quoted 16 lines
drivers/hwtracing/ptt/hisi_ptt.c +16
-0+* be called safely even without below filter attributes creation work. +*/ + ret =devm_add_action (&hisi_ptt->pdev->dev, + hisi_ptt_remove_all_filter_attributes, + hisi_ptt); +if (ret) + goto out; + +list_for_each_entry (filter, &hisi_ptt->port_filters, list) { + ret =hisi_ptt_create_filter_attr (hisi_ptt, filter); +if (ret) + goto out; + } + +list_for_each_entry (filter, &hisi_ptt->req_filters, list) { + ret =hisi_ptt_create_filter_attr (hisi_ptt, filter);drivers/hwtracing/ptt/hisi_ptt.c hisi_ptt_alloc_add_filter(struct hisi_ptt *hisi_ptt, u16 devid, bool is_port) · line 542
Quoted 10 lines
drivers/hwtracing/ptt/hisi_ptt.c +10
-0+if (ret) + goto out; + } + + hisi_ptt->sysfs_inited = true; +out: +mutex_unlock (&hisi_ptt->filter_lock); +return ret; +} +...
.
PATCH v3 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
@@ -1210,7 +1210,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 v3 4/4] hwtracing: hisi_ptt: Advertise PERF_PMU_CAP_NO_EXCLUDE for PTT PMU
Quoted 10 lines · On Tue, 23 May 2023 17:32:28 +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]>
Interesting - I didn't know about this flag.
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@@ -1210,7 +1210,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,