From: Namhyung Kim <namhyung@kernel.org>
To: Ian Rogers <irogers@google.com>
Cc: 9erthalion6@gmail.com, acme@kernel.org, adrian.hunter@intel.com,
alexander.shishkin@linux.intel.com, collin.funk1@gmail.com,
german.gomez@arm.com, james.clark@linaro.org, jolsa@kernel.org,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
mingo@redhat.com, peterz@infradead.org, zide.chen@intel.com
Subject: Re: [PATCH v3 1/2] perf tests: Add test for uncore event sorting
Date: Wed, 1 Apr 2026 14:48:24 -0700 [thread overview]
Message-ID: <ac2SqEbH_-0BBNc0@google.com> (raw)
In-Reply-To: <20260331185419.4085479-2-irogers@google.com>
On Tue, Mar 31, 2026 at 11:54:18AM -0700, Ian Rogers wrote:
> Add a test for uncore event sorting matching multiple PMUs. Uncore
> PMUs may have a common prefix, like the PMUs uncore_imc_free_running_0
> and uncore_imc_free_running_1 have a prefix of
> uncore_imc_free_running. Parsing an event group like
> "{data_read,data_write}" for those PMUs should result with two groups
> "{uncore_imc_free_running_0/data_read/,uncore_imc_free_running_0/data_write/},
> {uncore_imc_free_running_1/data_read/,uncore_imc_free_running_1/data_write/}"
> which means the evsels need resorting as when initially parsed the
> evsels are ordered with mixed PMUs:
> "{uncore_imc_free_running_0/data_read/,uncore_imc_free_running_1/data_read/,
> uncore_imc_free_running_0/data_write/,uncore_imc_free_running_1/data_write/}".
I got this:
--- start ---
test child forked, pid 1168839
Using CPUID AuthenticAMD-23-31-0
Parsing: {amd_iommu/amd_iommu_0/ign_rd_wr_mmio_1ff8h//,amd_iommu/amd_iommu_0/cmd_processed_inv//}
parse_events failed
---- end(-1) ----
6: Uncore event sorting : FAILED!
Thanks,
Namhyung
>
> Signed-off-by: Ian Rogers <irogers@google.com>
> Tested-by: Zide Chen <zide.chen@intel.com>
> ---
> tools/perf/tests/Build | 1 +
> tools/perf/tests/builtin-test.c | 1 +
> tools/perf/tests/tests.h | 1 +
> tools/perf/tests/uncore-event-sorting.c | 122 ++++++++++++++++++++++++
> 4 files changed, 125 insertions(+)
> create mode 100644 tools/perf/tests/uncore-event-sorting.c
>
> diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
> index c2a67ce45941..66944a4f4968 100644
> --- a/tools/perf/tests/Build
> +++ b/tools/perf/tests/Build
> @@ -3,6 +3,7 @@
> perf-test-y += builtin-test.o
> perf-test-y += tests-scripts.o
> perf-test-y += parse-events.o
> +perf-test-y += uncore-event-sorting.o
> perf-test-y += dso-data.o
> perf-test-y += vmlinux-kallsyms.o
> perf-test-y += openat-syscall.o
> diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
> index 06507066213b..f2c135891477 100644
> --- a/tools/perf/tests/builtin-test.c
> +++ b/tools/perf/tests/builtin-test.c
> @@ -71,6 +71,7 @@ static struct test_suite *generic_tests[] = {
> &suite__basic_mmap,
> &suite__mem,
> &suite__parse_events,
> + &suite__uncore_event_sorting,
> &suite__expr,
> &suite__PERF_RECORD,
> &suite__pmu,
> diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
> index f5f1238d1f7f..ee00518bf36f 100644
> --- a/tools/perf/tests/tests.h
> +++ b/tools/perf/tests/tests.h
> @@ -177,6 +177,7 @@ DECLARE_SUITE(sigtrap);
> DECLARE_SUITE(event_groups);
> DECLARE_SUITE(symbols);
> DECLARE_SUITE(util);
> +DECLARE_SUITE(uncore_event_sorting);
> DECLARE_SUITE(subcmd_help);
> DECLARE_SUITE(kallsyms_split);
>
> diff --git a/tools/perf/tests/uncore-event-sorting.c b/tools/perf/tests/uncore-event-sorting.c
> new file mode 100644
> index 000000000000..7e61e46283d5
> --- /dev/null
> +++ b/tools/perf/tests/uncore-event-sorting.c
> @@ -0,0 +1,122 @@
> +// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
> +#include "tests.h"
> +#include "debug.h"
> +#include "parse-events.h"
> +#include "pmu.h"
> +#include "pmus.h"
> +#include "evlist.h"
> +#include <string.h>
> +
> +struct match_state {
> + char *event1;
> + char *event2;
> +};
> +
> +static int event_cb(void *state, struct pmu_event_info *info)
> +{
> + struct match_state *m = state;
> +
> + if (!m->event1) {
> + m->event1 = strdup(info->name);
> + } else if (!m->event2) {
> + if (strcmp(m->event1, info->name)) {
> + m->event2 = strdup(info->name);
> + return 1;
> + }
> + }
> + return 0;
> +}
> +
> +static int test__uncore_event_sorting(struct test_suite *test __maybe_unused,
> + int subtest __maybe_unused)
> +{
> + struct evlist *evlist;
> + struct parse_events_error err;
> + struct evsel *evsel;
> + struct perf_pmu *pmu = NULL;
> + char *pmu_prefix = NULL;
> + struct match_state m = { NULL, NULL };
> + char buf[1024];
> + int ret;
> +
> + while ((pmu = perf_pmus__scan(pmu)) != NULL) {
> + size_t len;
> + struct perf_pmu *sibling;
> +
> + if (pmu->is_core)
> + continue;
> +
> + len = pmu_name_len_no_suffix(pmu->name);
> + if (len == strlen(pmu->name))
> + continue;
> +
> + sibling = pmu;
> + while ((sibling = perf_pmus__scan(sibling)) != NULL) {
> + if (sibling->is_core)
> + continue;
> + if (pmu_name_len_no_suffix(sibling->name) == len &&
> + !strncmp(pmu->name, sibling->name, len))
> + break;
> + }
> +
> + if (!sibling)
> + continue;
> +
> + m.event1 = m.event2 = NULL;
> + perf_pmu__for_each_event(pmu, false, &m, event_cb);
> +
> + if (m.event1 && m.event2) {
> + pmu_prefix = strndup(pmu->name, len);
> + break;
> + }
> + free(m.event1);
> + }
> +
> + if (!pmu_prefix) {
> + pr_debug("No suitable uncore PMU found\n");
> + return TEST_SKIP;
> + }
> +
> + evlist = evlist__new();
> + if (!evlist)
> + return TEST_FAIL;
> +
> + snprintf(buf, sizeof(buf), "{%s/%s/,%s/%s/}",
> + pmu_prefix, m.event1, pmu_prefix, m.event2);
> + pr_debug("Parsing: %s\n", buf);
> +
> + parse_events_error__init(&err);
> + ret = parse_events(evlist, buf, &err);
> + if (ret) {
> + pr_debug("parse_events failed\n");
> + ret = TEST_FAIL;
> + goto out_err;
> + }
> +
> + TEST_ASSERT_VAL("Number of events is > 0", evlist->core.nr_entries > 0);
> + TEST_ASSERT_EQUAL("Number of events is a multiple of 2", evlist->core.nr_entries % 2, 0);
> +
> + evlist__for_each_entry(evlist, evsel) {
> + struct evsel *next;
> +
> + if (!evsel__is_group_leader(evsel))
> + continue;
> +
> + next = evsel__next(evsel);
> + TEST_ASSERT_EQUAL("Group size is 2", evsel->core.nr_members, 2);
> + TEST_ASSERT_VAL("PMU match", evsel->pmu == next->pmu);
> + TEST_ASSERT_VAL("First event name", strstr(evsel__name(evsel), m.event1) != NULL);
> + TEST_ASSERT_VAL("Second event name", strstr(evsel__name(next), m.event2) != NULL);
> + }
> + ret = TEST_OK;
> +
> +out_err:
> + evlist__delete(evlist);
> + parse_events_error__exit(&err);
> + free(pmu_prefix);
> + free(m.event1);
> + free(m.event2);
> + return ret;
> +}
> +
> +DEFINE_SUITE("Uncore event sorting", uncore_event_sorting);
> --
> 2.53.0.1118.gaef5881109-goog
>
next prev parent reply other threads:[~2026-04-01 21:48 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-25 18:30 [PATCH v1 0/2] perf tests: Add tests for uncore and perf metric event sorting Ian Rogers
2026-03-25 18:30 ` [PATCH v1 1/2] perf tests: Add test for uncore " Ian Rogers
2026-03-27 23:36 ` Chen, Zide
2026-03-31 3:06 ` Namhyung Kim
2026-03-25 18:30 ` [PATCH v1 2/2] perf arch x86 tests: Add test for topdown " Ian Rogers
2026-03-30 21:53 ` Chen, Zide
2026-03-31 3:08 ` Namhyung Kim
2026-03-31 16:52 ` [PATCH v2 0/2] perf tests: Add tests for uncore and perf metric " Ian Rogers
2026-03-31 16:52 ` [PATCH v2 1/2] perf tests: Add test for uncore " Ian Rogers
2026-03-31 16:52 ` [PATCH v2 2/2] perf arch x86 tests: Add test for topdown " Ian Rogers
2026-03-31 18:54 ` [PATCH v3 0/2] Add tests for uncore and perf metric " Ian Rogers
2026-03-31 18:54 ` [PATCH v3 1/2] perf tests: Add test for uncore " Ian Rogers
2026-04-01 21:48 ` Namhyung Kim [this message]
2026-03-31 18:54 ` [PATCH v3 2/2] perf arch x86 tests: Add test for topdown " Ian Rogers
2026-04-01 3:33 ` Namhyung Kim
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=ac2SqEbH_-0BBNc0@google.com \
--to=namhyung@kernel.org \
--cc=9erthalion6@gmail.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=collin.funk1@gmail.com \
--cc=german.gomez@arm.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=mingo@redhat.com \
--cc=peterz@infradead.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.