From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: Yicong Yang <yangyicong@huawei.com>
Cc: <will@kernel.org>, <mark.rutland@arm.com>, <hejunhao3@huawei.com>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>, <yangyicong@hisilicon.com>,
<linuxarm@huawei.com>, <prime.zeng@hisilicon.com>,
<fanghao11@huawei.com>
Subject: Re: [PATCH 6/7] drivers/perf: hisi_pcie: Merge find_related_event() and get_event_idx()
Date: Thu, 8 Feb 2024 12:39:46 +0000 [thread overview]
Message-ID: <20240208123946.00006618@Huawei.com> (raw)
In-Reply-To: <20240204074527.47110-7-yangyicong@huawei.com>
On Sun, 4 Feb 2024 15:45:26 +0800
Yicong Yang <yangyicong@huawei.com> wrote:
> From: Junhao He <hejunhao3@huawei.com>
>
> The function xxx_find_related_event() scan all working events to find
> related events. During this process, we also can find the idle counters.
> If not found related events, return the first idle counter to simplify
> the code.
>
> Signed-off-by: Junhao He <hejunhao3@huawei.com>
> Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
A suggestion inline to avoid the magic HISI_PCIE_MAX_COUNTER value
being used outside of the function.
> ---
> drivers/perf/hisilicon/hisi_pcie_pmu.c | 55 ++++++++++----------------
> 1 file changed, 21 insertions(+), 34 deletions(-)
>
> diff --git a/drivers/perf/hisilicon/hisi_pcie_pmu.c b/drivers/perf/hisilicon/hisi_pcie_pmu.c
> index 1b45aeb82859..2edde66675e7 100644
> --- a/drivers/perf/hisilicon/hisi_pcie_pmu.c
> +++ b/drivers/perf/hisilicon/hisi_pcie_pmu.c
> @@ -397,16 +397,24 @@ static u64 hisi_pcie_pmu_read_counter(struct perf_event *event)
> return hisi_pcie_pmu_readq(pcie_pmu, event->hw.event_base, idx);
> }
>
> -static int hisi_pcie_pmu_find_related_event(struct hisi_pcie_pmu *pcie_pmu,
> - struct perf_event *event)
> +/*
> + * Check all work events, if a relevant event is found then we return it
> + * first, otherwise return the first idle counter (need to reset).
> + */
> +static int hisi_pcie_pmu_get_event_idx(struct hisi_pcie_pmu *pcie_pmu,
> + struct perf_event *event)
> {
> + int first_idle = HISI_PCIE_MAX_COUNTERS;
int first_idle = -EAGAIN;
> struct perf_event *sibling;
> int idx;
>
> for (idx = 0; idx < HISI_PCIE_MAX_COUNTERS; idx++) {
> sibling = pcie_pmu->hw_events[idx];
> - if (!sibling)
> + if (!sibling) {
> + if (first_idle == HISI_PCIE_MAX_COUNTERS)
if (first_idle == -EAGAIN)
> + first_idle = idx;
> continue;
> + }
>
> /* Related events must be used in group */
> if (hisi_pcie_pmu_cmp_event(sibling, event) &&
> @@ -414,19 +422,7 @@ static int hisi_pcie_pmu_find_related_event(struct hisi_pcie_pmu *pcie_pmu,
> return idx;
> }
>
> - return idx;
> -}
> -
> -static int hisi_pcie_pmu_get_event_idx(struct hisi_pcie_pmu *pcie_pmu)
> -{
> - int idx;
> -
> - for (idx = 0; idx < HISI_PCIE_MAX_COUNTERS; idx++) {
> - if (!pcie_pmu->hw_events[idx])
> - return idx;
> - }
> -
> - return -EINVAL;
> + return first_idle;
Then this will return -EAGAIN;
> }
>
> static void hisi_pcie_pmu_event_update(struct perf_event *event)
> @@ -552,27 +548,18 @@ static int hisi_pcie_pmu_add(struct perf_event *event, int flags)
>
> hwc->state = PERF_HES_STOPPED | PERF_HES_UPTODATE;
>
> - /* Check all working events to find a related event. */
> - idx = hisi_pcie_pmu_find_related_event(pcie_pmu, event);
> - if (idx < 0)
> - return idx;
> -
> - /* Current event shares an enabled counter with the related event */
> - if (idx < HISI_PCIE_MAX_COUNTERS) {
> - hwc->idx = idx;
> - goto start_count;
> - }
> -
> - idx = hisi_pcie_pmu_get_event_idx(pcie_pmu);
> - if (idx < 0)
> - return idx;
> + idx = hisi_pcie_pmu_get_event_idx(pcie_pmu, event);
> + if (idx == HISI_PCIE_MAX_COUNTERS)
> + return -EAGAIN;
Perhaps simpler to handle first_idle == HISI_PCIE_MAX_COUNTERS as
an error return in hisi_pcie_pmu_get_event_idx - see above.
if (idx < 0)
return idx;
>
> hwc->idx = idx;
> - pcie_pmu->hw_events[idx] = event;
> - /* Reset Counter to avoid previous statistic interference. */
> - hisi_pcie_pmu_reset_counter(pcie_pmu, idx);
>
> -start_count:
> + /* No enabled counter found with related event, reset it */
> + if (!pcie_pmu->hw_events[idx]) {
> + hisi_pcie_pmu_reset_counter(pcie_pmu, idx);
> + pcie_pmu->hw_events[idx] = event;
> + }
> +
> if (flags & PERF_EF_START)
> hisi_pcie_pmu_start(event, PERF_EF_RELOAD);
>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2024-02-08 12:40 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-04 7:45 [PATCH 0/7] Several updates for HiSilicon PCIe PMU driver Yicong Yang
2024-02-04 7:45 ` [PATCH 1/7] drivers/perf: hisi_pcie: Introduce hisi_pcie_pmu_get_filter() Yicong Yang
2024-02-08 12:06 ` Jonathan Cameron
2024-02-08 12:18 ` Jonathan Cameron
2024-02-21 9:39 ` Yicong Yang
2024-02-04 7:45 ` [PATCH 2/7] drivers/perf: hisi_pcie: Fix incorrect counting under metric mode Yicong Yang
2024-02-08 12:19 ` Jonathan Cameron
2024-02-04 7:45 ` [PATCH 3/7] drivers/perf: hisi_pcie: Add more events for counting TLP bandwidth Yicong Yang
2024-02-08 12:20 ` Jonathan Cameron
2024-02-21 9:40 ` Yicong Yang
2024-02-04 7:45 ` [PATCH 4/7] drivers/perf: hisi_pcie: Check the target filter properly Yicong Yang
2024-02-08 12:29 ` Jonathan Cameron
2024-02-21 9:46 ` Yicong Yang
2024-02-22 1:21 ` hejunhao
2024-02-22 1:29 ` hejunhao
2024-02-04 7:45 ` [PATCH 5/7] drivers/perf: hisi_pcie: Relax the check on related events Yicong Yang
2024-02-04 7:45 ` [PATCH 6/7] drivers/perf: hisi_pcie: Merge find_related_event() and get_event_idx() Yicong Yang
2024-02-08 12:39 ` Jonathan Cameron [this message]
2024-02-22 3:00 ` hejunhao
2024-02-04 7:45 ` [PATCH 7/7] docs: perf: Update usage for target filter of hisi-pcie-pmu 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=20240208123946.00006618@Huawei.com \
--to=jonathan.cameron@huawei.com \
--cc=fanghao11@huawei.com \
--cc=hejunhao3@huawei.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=mark.rutland@arm.com \
--cc=prime.zeng@hisilicon.com \
--cc=will@kernel.org \
--cc=yangyicong@hisilicon.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).