From: Ian Rogers <irogers@google.com>
To: irogers@google.com, acme@kernel.org, namhyung@kernel.org
Cc: 9erthalion6@gmail.com, 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: [PATCH v7 1/2] perf tests: Add test for uncore event sorting
Date: Sun, 17 May 2026 21:31:39 -0700 [thread overview]
Message-ID: <20260518043140.2522141-2-irogers@google.com> (raw)
In-Reply-To: <20260518043140.2522141-1-irogers@google.com>
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/}".
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 | 178 ++++++++++++++++++++++++
4 files changed, 181 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..594fe7ff7bf6
--- /dev/null
+++ b/tools/perf/tests/uncore-event-sorting.c
@@ -0,0 +1,178 @@
+// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
+#include <string.h>
+
+#include "debug.h"
+#include "evlist.h"
+#include "parse-events.h"
+#include "pmu.h"
+#include "pmus.h"
+#include "tests.h"
+
+struct match_state {
+ char *event1;
+ char *event2;
+};
+
+static char *clean_event_name(struct pmu_event_info *info)
+{
+ const char *name = info->name;
+ const char *pmu_name = info->pmu->name;
+ size_t pmu_len = strlen(pmu_name);
+ char *res;
+ size_t len;
+
+ if (!strncmp(name, pmu_name, pmu_len) && name[pmu_len] == '/')
+ name += pmu_len + 1;
+
+ res = strdup(name);
+ if (!res)
+ return NULL;
+
+ len = strlen(res);
+ if (len > 0 && res[len - 1] == '/')
+ res[len - 1] = '\0';
+
+ return res;
+}
+
+static int event_cb(void *state, struct pmu_event_info *info)
+{
+ struct match_state *m = state;
+ char *clean_name;
+
+ if (m->event1 && m->event2)
+ return 1;
+
+ clean_name = clean_event_name(info);
+ if (!clean_name)
+ return 0;
+
+ if (!m->event1) {
+ m->event1 = clean_name;
+ } else if (!m->event2) {
+ if (strcmp(m->event1, clean_name)) {
+ m->event2 = clean_name;
+ return 1;
+ }
+ free(clean_name);
+ } else {
+ free(clean_name);
+ }
+ return 0;
+}
+
+#define CHECK_COND(cond, text) \
+do { \
+ if (!(cond)) { \
+ pr_debug("FAILED %s:%d %s\n", __FILE__, __LINE__, text); \
+ ret = TEST_FAIL; \
+ goto out_err; \
+ } \
+} while (0)
+
+#define CHECK_EQUAL(val, expected, text) \
+do { \
+ if ((val) != (expected)) { \
+ pr_debug("FAILED %s:%d %s (%d != %d)\n", \
+ __FILE__, __LINE__, text, (val), (expected)); \
+ ret = TEST_FAIL; \
+ goto out_err; \
+ } \
+} while (0)
+
+static int test__uncore_event_sorting(struct test_suite *test __maybe_unused,
+ int subtest __maybe_unused)
+{
+ struct evlist *evlist = NULL;
+ 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;
+
+ parse_events_error__init(&err);
+
+ 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;
+ }
+ zfree(&m.event1);
+ }
+
+ if (!pmu_prefix) {
+ pr_debug("No suitable uncore PMU found\n");
+ ret = TEST_SKIP;
+ goto out_err;
+ }
+
+ evlist = evlist__new();
+ if (!evlist) {
+ ret = TEST_FAIL;
+ goto out_err;
+ }
+
+ snprintf(buf, sizeof(buf), "{%s/%s/,%s/%s/}", pmu_prefix, m.event1, pmu_prefix, m.event2);
+ pr_debug("Parsing: %s\n", buf);
+
+ ret = parse_events(evlist, buf, &err);
+ if (ret) {
+ pr_debug("parse_events failed\n");
+ ret = TEST_FAIL;
+ goto out_err;
+ }
+
+ CHECK_COND(evlist->core.nr_entries >= 4, "Number of events is >= 4");
+ CHECK_EQUAL(evlist->core.nr_entries % 2, 0, "Number of events is a multiple of 2");
+
+ evlist__for_each_entry(evlist, evsel) {
+ struct evsel *next;
+
+ if (!evsel__is_group_leader(evsel))
+ continue;
+
+ next = evsel__next(evsel);
+ CHECK_EQUAL(evsel->core.nr_members, 2, "Group size is 2");
+ CHECK_COND(evsel->pmu == next->pmu, "PMU match");
+ CHECK_COND(strstr(evsel__name(evsel), m.event1) != NULL, "First event name");
+ CHECK_COND(strstr(evsel__name(next), m.event2) != NULL, "Second event name");
+ }
+ ret = TEST_OK;
+
+out_err:
+ evlist__delete(evlist);
+ parse_events_error__exit(&err);
+ zfree(&pmu_prefix);
+ zfree(&m.event1);
+ zfree(&m.event2);
+ return ret;
+}
+
+DEFINE_SUITE("Uncore event sorting", uncore_event_sorting);
--
2.54.0.563.g4f69b47b94-goog
next prev parent reply other threads:[~2026-05-18 4:31 UTC|newest]
Thread overview: 39+ 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
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
2026-05-17 23:28 ` [PATCH v4 0/2] perf tests: Add uncore and x86 topdown event sorting tests Ian Rogers
2026-05-17 23:28 ` [PATCH v4 1/2] perf tests: Add test for uncore event sorting Ian Rogers
2026-05-17 23:49 ` sashiko-bot
2026-05-17 23:28 ` [PATCH v4 2/2] perf arch x86 tests: Add test for topdown " Ian Rogers
2026-05-18 0:05 ` sashiko-bot
2026-05-18 0:37 ` [PATCH v5 0/2] perf tests: Add uncore and x86 topdown event sorting tests Ian Rogers
2026-05-18 0:37 ` [PATCH v5 1/2] perf tests: Add test for uncore event sorting Ian Rogers
2026-05-18 1:06 ` sashiko-bot
2026-05-18 0:37 ` [PATCH v5 2/2] perf arch x86 tests: Add test for topdown " Ian Rogers
2026-05-18 1:20 ` sashiko-bot
2026-05-18 2:32 ` [PATCH v6 0/2] perf tests: Add uncore and x86 topdown event sorting tests Ian Rogers
2026-05-18 2:32 ` [PATCH v6 1/2] perf tests: Add test for uncore event sorting Ian Rogers
2026-05-18 2:53 ` sashiko-bot
2026-05-18 2:32 ` [PATCH v6 2/2] perf arch x86 tests: Add test for topdown " Ian Rogers
2026-05-18 3:08 ` sashiko-bot
2026-05-18 4:31 ` [PATCH v7 0/2] perf tests: Add uncore and x86 topdown event sorting tests Ian Rogers
2026-05-18 4:31 ` Ian Rogers [this message]
2026-05-18 4:48 ` [PATCH v7 1/2] perf tests: Add test for uncore event sorting sashiko-bot
2026-05-18 4:31 ` [PATCH v7 2/2] perf arch x86 tests: Add test for topdown " Ian Rogers
2026-05-18 6:29 ` [PATCH v8 0/2] perf tests: Add uncore and x86 topdown event sorting tests Ian Rogers
2026-05-18 6:29 ` [PATCH v8 1/2] perf tests: Add test for uncore event sorting Ian Rogers
2026-05-18 6:29 ` [PATCH v8 2/2] perf arch x86 tests: Add test for topdown " Ian Rogers
2026-05-20 15:31 ` [PATCH v8 0/2] perf tests: Add uncore and x86 topdown event sorting tests Ian Rogers
2026-05-20 20:28 ` 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=20260518043140.2522141-2-irogers@google.com \
--to=irogers@google.com \
--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=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=namhyung@kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox