linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: Yicong Yang <yangyicong@huawei.com>
Cc: <mathieu.poirier@linaro.org>, <suzuki.poulose@arm.com>,
	<corbet@lwn.net>, <linux-kernel@vger.kernel.org>,
	<linux-doc@vger.kernel.org>, <alexander.shishkin@linux.intel.com>,
	<helgaas@kernel.org>, <linux-pci@vger.kernel.org>,
	<prime.zeng@huawei.com>, <linuxarm@huawei.com>
Subject: Re: [PATCH 3/4] hwtracing: hisi_ptt: Export available filters through sysfs
Date: Tue, 28 Mar 2023 18:02:34 +0100	[thread overview]
Message-ID: <20230328180234.00003421@Huawei.com> (raw)
In-Reply-To: <20230315094316.26772-4-yangyicong@huawei.com>

On Wed, 15 Mar 2023 17:43:15 +0800
Yicong Yang <yangyicong@huawei.com> wrote:

> From: Yicong Yang <yangyicong@hisilicon.com>
> 
> 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.
> 
> Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>

Trivial comments only inline.

With those answered / tidied up.

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


> diff --git a/drivers/hwtracing/ptt/hisi_ptt.c b/drivers/hwtracing/ptt/hisi_ptt.c
> index 010cdbc3c172..a5cd87edb813 100644
> --- a/drivers/hwtracing/ptt/hisi_ptt.c
> +++ b/drivers/hwtracing/ptt/hisi_ptt.c


>
> +
> +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)
> +			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:

> +	mutex_unlock(&hisi_ptt->filter_lock);

	return ret;

No need for separate exit block when nothing to do but unlock.

> +	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;
> +
> +			/*
> +			 * 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.

> +			    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)
>  	}
>  
>  	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.

> +	return -ENOMEM;
>  }



  reply	other threads:[~2023-03-28 17:02 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-15  9:43 [PATCH 0/4] Improve PTT filter interface and some fixes Yicong Yang
2023-03-15  9:43 ` [PATCH 1/4] hwtracing: hisi_ptt: Make cpumask only present online CPUs Yicong Yang
2023-03-28 16:24   ` Jonathan Cameron
2023-03-30  3:53     ` Yicong Yang
2023-03-30  8:34       ` Jonathan Cameron
2023-03-15  9:43 ` [PATCH 2/4] hwtracing: hisi_ptt: Add support for dynamically updating the filter list Yicong Yang
2023-03-28 16:51   ` Jonathan Cameron
2023-03-29 12:52     ` Yicong Yang
2023-03-15  9:43 ` [PATCH 3/4] hwtracing: hisi_ptt: Export available filters through sysfs Yicong Yang
2023-03-28 17:02   ` Jonathan Cameron [this message]
2023-03-29 12:54     ` Yicong Yang
2023-03-15  9:43 ` [PATCH 4/4] hwtracing: hisi_ptt: Advertise PERF_PMU_CAP_NO_EXCLUDE for PTT PMU Yicong Yang
2023-03-28 16:53   ` Jonathan Cameron
2023-03-27 10:49 ` [PATCH 0/4] Improve PTT filter interface and some fixes Yicong Yang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230328180234.00003421@Huawei.com \
    --to=jonathan.cameron@huawei.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=corbet@lwn.net \
    --cc=helgaas@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=mathieu.poirier@linaro.org \
    --cc=prime.zeng@huawei.com \
    --cc=suzuki.poulose@arm.com \
    --cc=yangyicong@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).