From: "Mi, Dapeng" <dapeng1.mi@linux.intel.com>
To: Zide Chen <zide.chen@intel.com>,
Namhyung Kim <namhyung@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Adrian Hunter <adrian.hunter@intel.com>,
Ingo Molnar <mingo@redhat.com>, Jiri Olsa <jolsa@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Ian Rogers <irogers@google.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
James Clark <james.clark@linaro.org>
Cc: Andi Kleen <ak@linux.intel.com>,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
thomas.falcon@intel.com, xudong.hao@intel.com
Subject: Re: [PATCH] perf topdown: Don't require config1==0 for a slots event
Date: Thu, 17 Sep 2026 08:29:59 +0800 [thread overview]
Message-ID: <97bd275d-d279-4000-b1e0-75a2022fa49e@linux.intel.com> (raw)
In-Reply-To: <20260916202740.257376-1-zide.chen@intel.com>
LGTM. Thanks.
Reviewed-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
On 9/17/2026 4:27 AM, Zide Chen wrote:
> arch_is_topdown_slots() requires config1 == 0, so it misidentified
> "cpu/slots,metrics_clear=1/" as not being the slots event, and an
> additional slots event gets inserted, which fails event scheduling
> since the group now needs two fixed counter 3.
>
> $ perf stat -e "{cpu/slots,metrics_clear=1/,cpu/topdown-retiring/}" -- sleep 1
> WARNING: events were regrouped to match PMUs
> <not counted> slots
> <not supported> cpu/slots,metrics_clear=1/
> <not counted> cpu/topdown-retiring/
>
> Drop the config1 == 0 check from arch_is_topdown_slots(). This is
> safe: config1 has no bearing on the event's identifying config value
> (TOPDOWN_SLOTS, 0x0400).
>
> The attr.type == PERF_TYPE_RAW check is what actually matters: only the
> core PMU is registered with PERF_TYPE_RAW, and on x86, 0x400 is
> guaranteed to be slots event on core CPU.
>
> arch_is_topdown_metrics() keeps its own config1 == 0 check, since
> genuine metrics events have no "metrics_clear" and config1 remains 0.
>
> Add a test verifying that an explicit "slots,metrics_clear=1" event in
> a group does not trigger an extra slots event injection.
>
> Fixes: 5b546de9cc17 ("perf topdown: Use attribute to see an event is a topdown metic or slots")
> Signed-off-by: Zide Chen <zide.chen@intel.com>
> ---
> tools/perf/arch/x86/tests/topdown.c | 28 ++++++++++++++++++++++++++++
> tools/perf/arch/x86/util/topdown.c | 3 +--
> 2 files changed, 29 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/arch/x86/tests/topdown.c b/tools/perf/arch/x86/tests/topdown.c
> index 2b6f47ce4932..b1ce9f83db00 100644
> --- a/tools/perf/arch/x86/tests/topdown.c
> +++ b/tools/perf/arch/x86/tests/topdown.c
> @@ -229,10 +229,38 @@ static int test__x86_topdown_slots_injection(struct test_suite *test __maybe_unu
> return TEST_OK;
> }
>
> +/*
> + * An explicit "slots,metrics_clear=1" event is still the slots event and
> + * must not cause an extra slots event to be injected into the group.
> + */
> +static int test__x86_topdown_metrics_clear(struct test_suite *test __maybe_unused,
> + int subtest __maybe_unused)
> +{
> + struct perf_pmu *pmu;
> + char event_str[128];
> + int ret;
> +
> + if (!topdown_sys_has_perf_metrics())
> + return TEST_OK;
> +
> + pmu = perf_pmus__find_by_type(PERF_TYPE_RAW);
> + if (!pmu || !perf_pmu__has_format(pmu, "metrics_clear"))
> + return TEST_OK;
> +
> + snprintf(event_str, sizeof(event_str),
> + "{%s/slots,metrics_clear=1/,%s/topdown-retiring/}",
> + pmu->name, pmu->name);
> + ret = test_sort(event_str, 2, 1);
> + TEST_ASSERT_EQUAL("explicit metrics_clear slots event isn't duplicated", ret, TEST_OK);
> +
> + return TEST_OK;
> +}
> +
> static struct test_case x86_topdown_tests[] = {
> TEST_CASE("topdown events", x86_topdown),
> TEST_CASE("topdown sorting", x86_topdown_sorting),
> TEST_CASE("topdown slots injection", x86_topdown_slots_injection),
> + TEST_CASE("topdown metrics_clear no extra slots", x86_topdown_metrics_clear),
> { .name = NULL, }
> };
>
> diff --git a/tools/perf/arch/x86/util/topdown.c b/tools/perf/arch/x86/util/topdown.c
> index bafd285119d7..64bc64e335a2 100644
> --- a/tools/perf/arch/x86/util/topdown.c
> +++ b/tools/perf/arch/x86/util/topdown.c
> @@ -37,8 +37,7 @@ bool topdown_sys_has_perf_metrics(void)
> bool arch_is_topdown_slots(const struct evsel *evsel)
> {
> return evsel->core.attr.type == PERF_TYPE_RAW &&
> - evsel->core.attr.config == TOPDOWN_SLOTS &&
> - evsel->core.attr.config1 == 0;
> + evsel->core.attr.config == TOPDOWN_SLOTS;
> }
>
> bool arch_is_topdown_metrics(const struct evsel *evsel)
prev parent reply other threads:[~2026-09-17 0:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-16 20:27 Zide Chen
2026-09-16 21:22 ` Ian Rogers
2026-09-17 0:29 ` Mi, Dapeng [this message]
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=97bd275d-d279-4000-b1e0-75a2022fa49e@linux.intel.com \
--to=dapeng1.mi@linux.intel.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=thomas.falcon@intel.com \
--cc=xudong.hao@intel.com \
--cc=zide.chen@intel.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
all inboxes | Powered by JetHome®