+++ /dev/null
-From 20adbb4dbda533ce0d3a88f89a73fba1a83ae3ba Mon Sep 17 00:00:00 2001
-From: Sasha Levin <sashal@kernel.org>
-Date: Wed, 26 Jun 2024 15:54:45 +0100
-Subject: perf pmu: Restore full PMU name wildcard support
-
-From: James Clark <james.clark@arm.com>
-
-[ Upstream commit 3e0bf9fde29844694ad9912aa290fbdb2c3fa767 ]
-
-Commit b2b9d3a3f021 ("perf pmu: Support wildcards on pmu name in dynamic
-pmu events") gives the following example for wildcarding a subset of
-PMUs:
-
- E.g., in a system with the following dynamic pmus:
-
- mypmu_0
- mypmu_1
- mypmu_2
- mypmu_4
-
- perf stat -e mypmu_[01]/<config>/
-
-Since commit f91fa2ae6360 ("perf pmu: Refactor perf_pmu__match()"), only
-"*" has been supported, removing the ability to subset PMUs, even though
-parse-events.l still supports ? and [] characters.
-
-Fix it by using fnmatch() when any glob character is detected and add a
-test which covers that and other scenarios of
-perf_pmu__match_ignoring_suffix().
-
-Fixes: f91fa2ae6360 ("perf pmu: Refactor perf_pmu__match()")
-Signed-off-by: James Clark <james.clark@arm.com>
-Reviewed-by: Ian Rogers <irogers@google.com>
-Cc: robin.murphy@arm.com
-Signed-off-by: Namhyung Kim <namhyung@kernel.org>
-Link: https://lore.kernel.org/r/20240626145448.896746-2-james.clark@arm.com
-Signed-off-by: Sasha Levin <sashal@kernel.org>
----
- tools/perf/tests/pmu.c | 78 ++++++++++++++++++++++++++++++++++++++++++
- tools/perf/util/pmu.c | 2 +-
- 2 files changed, 79 insertions(+), 1 deletion(-)
-
-diff --git a/tools/perf/tests/pmu.c b/tools/perf/tests/pmu.c
-index cc88b5920c3e2..fd07331b2d6e6 100644
---- a/tools/perf/tests/pmu.c
-+++ b/tools/perf/tests/pmu.c
-@@ -437,12 +437,90 @@ static int test__name_cmp(struct test_suite *test __maybe_unused, int subtest __
- return TEST_OK;
- }
-
-+/**
-+ * Test perf_pmu__match() that's used to search for a PMU given a name passed
-+ * on the command line. The name that's passed may also be a filename type glob
-+ * match.
-+ */
-+static int test__pmu_match(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
-+{
-+ struct perf_pmu test_pmu;
-+
-+ test_pmu.name = "pmuname";
-+ TEST_ASSERT_EQUAL("Exact match", perf_pmu__match(&test_pmu, "pmuname"), true);
-+ TEST_ASSERT_EQUAL("Longer token", perf_pmu__match(&test_pmu, "longertoken"), false);
-+ TEST_ASSERT_EQUAL("Shorter token", perf_pmu__match(&test_pmu, "pmu"), false);
-+
-+ test_pmu.name = "pmuname_10";
-+ TEST_ASSERT_EQUAL("Diff suffix_", perf_pmu__match(&test_pmu, "pmuname_2"), false);
-+ TEST_ASSERT_EQUAL("Sub suffix_", perf_pmu__match(&test_pmu, "pmuname_1"), true);
-+ TEST_ASSERT_EQUAL("Same suffix_", perf_pmu__match(&test_pmu, "pmuname_10"), true);
-+ TEST_ASSERT_EQUAL("No suffix_", perf_pmu__match(&test_pmu, "pmuname"), true);
-+ TEST_ASSERT_EQUAL("Underscore_", perf_pmu__match(&test_pmu, "pmuname_"), true);
-+ TEST_ASSERT_EQUAL("Substring_", perf_pmu__match(&test_pmu, "pmuna"), false);
-+
-+ test_pmu.name = "pmuname_ab23";
-+ TEST_ASSERT_EQUAL("Diff suffix hex_", perf_pmu__match(&test_pmu, "pmuname_2"), false);
-+ TEST_ASSERT_EQUAL("Sub suffix hex_", perf_pmu__match(&test_pmu, "pmuname_ab"), true);
-+ TEST_ASSERT_EQUAL("Same suffix hex_", perf_pmu__match(&test_pmu, "pmuname_ab23"), true);
-+ TEST_ASSERT_EQUAL("No suffix hex_", perf_pmu__match(&test_pmu, "pmuname"), true);
-+ TEST_ASSERT_EQUAL("Underscore hex_", perf_pmu__match(&test_pmu, "pmuname_"), true);
-+ TEST_ASSERT_EQUAL("Substring hex_", perf_pmu__match(&test_pmu, "pmuna"), false);
-+
-+ test_pmu.name = "pmuname10";
-+ TEST_ASSERT_EQUAL("Diff suffix", perf_pmu__match(&test_pmu, "pmuname2"), false);
-+ TEST_ASSERT_EQUAL("Sub suffix", perf_pmu__match(&test_pmu, "pmuname1"), true);
-+ TEST_ASSERT_EQUAL("Same suffix", perf_pmu__match(&test_pmu, "pmuname10"), true);
-+ TEST_ASSERT_EQUAL("No suffix", perf_pmu__match(&test_pmu, "pmuname"), true);
-+ TEST_ASSERT_EQUAL("Underscore", perf_pmu__match(&test_pmu, "pmuname_"), false);
-+ TEST_ASSERT_EQUAL("Substring", perf_pmu__match(&test_pmu, "pmuna"), false);
-+
-+ test_pmu.name = "pmunameab23";
-+ TEST_ASSERT_EQUAL("Diff suffix hex", perf_pmu__match(&test_pmu, "pmuname2"), false);
-+ TEST_ASSERT_EQUAL("Sub suffix hex", perf_pmu__match(&test_pmu, "pmunameab"), true);
-+ TEST_ASSERT_EQUAL("Same suffix hex", perf_pmu__match(&test_pmu, "pmunameab23"), true);
-+ TEST_ASSERT_EQUAL("No suffix hex", perf_pmu__match(&test_pmu, "pmuname"), true);
-+ TEST_ASSERT_EQUAL("Underscore hex", perf_pmu__match(&test_pmu, "pmuname_"), false);
-+ TEST_ASSERT_EQUAL("Substring hex", perf_pmu__match(&test_pmu, "pmuna"), false);
-+
-+ /*
-+ * 2 hex chars or less are not considered suffixes so it shouldn't be
-+ * possible to wildcard by skipping the suffix. Therefore there are more
-+ * false results here than above.
-+ */
-+ test_pmu.name = "pmuname_a3";
-+ TEST_ASSERT_EQUAL("Diff suffix 2 hex_", perf_pmu__match(&test_pmu, "pmuname_2"), false);
-+ /*
-+ * This one should be false, but because pmuname_a3 ends in 3 which is
-+ * decimal, it's not possible to determine if it's a short hex suffix or
-+ * a normal decimal suffix following text. And we want to match on any
-+ * length of decimal suffix. Run the test anyway and expect the wrong
-+ * result. And slightly fuzzy matching shouldn't do too much harm.
-+ */
-+ TEST_ASSERT_EQUAL("Sub suffix 2 hex_", perf_pmu__match(&test_pmu, "pmuname_a"), true);
-+ TEST_ASSERT_EQUAL("Same suffix 2 hex_", perf_pmu__match(&test_pmu, "pmuname_a3"), true);
-+ TEST_ASSERT_EQUAL("No suffix 2 hex_", perf_pmu__match(&test_pmu, "pmuname"), false);
-+ TEST_ASSERT_EQUAL("Underscore 2 hex_", perf_pmu__match(&test_pmu, "pmuname_"), false);
-+ TEST_ASSERT_EQUAL("Substring 2 hex_", perf_pmu__match(&test_pmu, "pmuna"), false);
-+
-+ test_pmu.name = "pmuname_5";
-+ TEST_ASSERT_EQUAL("Glob 1", perf_pmu__match(&test_pmu, "pmu*"), true);
-+ TEST_ASSERT_EQUAL("Glob 2", perf_pmu__match(&test_pmu, "nomatch*"), false);
-+ TEST_ASSERT_EQUAL("Seq 1", perf_pmu__match(&test_pmu, "pmuname_[12345]"), true);
-+ TEST_ASSERT_EQUAL("Seq 2", perf_pmu__match(&test_pmu, "pmuname_[67890]"), false);
-+ TEST_ASSERT_EQUAL("? 1", perf_pmu__match(&test_pmu, "pmuname_?"), true);
-+ TEST_ASSERT_EQUAL("? 2", perf_pmu__match(&test_pmu, "pmuname_1?"), false);
-+
-+ return TEST_OK;
-+}
-+
- static struct test_case tests__pmu[] = {
- TEST_CASE("Parsing with PMU format directory", pmu_format),
- TEST_CASE("Parsing with PMU event", pmu_events),
- TEST_CASE("PMU event names", pmu_event_names),
- TEST_CASE("PMU name combining", name_len),
- TEST_CASE("PMU name comparison", name_cmp),
-+ TEST_CASE("PMU cmdline match", pmu_match),
- { .name = NULL, }
- };
-
-diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
-index 888ce99122759..22291f48e4da1 100644
---- a/tools/perf/util/pmu.c
-+++ b/tools/perf/util/pmu.c
-@@ -2143,7 +2143,7 @@ void perf_pmu__warn_invalid_config(struct perf_pmu *pmu, __u64 config,
- bool perf_pmu__match(const struct perf_pmu *pmu, const char *tok)
- {
- const char *name = pmu->name;
-- bool need_fnmatch = strchr(tok, '*') != NULL;
-+ bool need_fnmatch = strisglob(tok);
-
- if (!strncmp(tok, "uncore_", 7))
- tok += 7;
---
-2.43.0
-
+++ /dev/null
-From 527f8bef2c7f975a7c00f843fcb76a7016c8b17f Mon Sep 17 00:00:00 2001
-From: Sasha Levin <sashal@kernel.org>
-Date: Tue, 14 May 2024 23:01:14 -0700
-Subject: perf tests: Add some pmu core functionality tests
-
-From: Ian Rogers <irogers@google.com>
-
-[ Upstream commit 678be1ca30cc939e0180c85b4cc9150b3d5ef0c8 ]
-
-Test behavior of PMU names and comparisons wrt suffixes using Intel
-uncore_cha, marvell mrvl_ddr_pmu and S390's cpum_cf as examples.
-
-Signed-off-by: Ian Rogers <irogers@google.com>
-Acked-by: Namhyung Kim <namhyung@kernel.org>
-Cc: Ravi Bangoria <ravi.bangoria@amd.com>
-Cc: James Clark <james.clark@arm.com>
-Cc: Robin Murphy <robin.murphy@arm.com>
-Cc: Stephane Eranian <eranian@google.com>
-Cc: Will Deacon <will@kernel.org>
-Cc: Thomas Richter <tmricht@linux.ibm.com>
-Cc: Bharat Bhushan <bbhushan2@marvell.com>
-Cc: Bhaskara Budiredla <bbudiredla@marvell.com>
-Cc: Tuan Phan <tuanphan@os.amperecomputing.com>
-Signed-off-by: Namhyung Kim <namhyung@kernel.org>
-Link: https://lore.kernel.org/r/20240515060114.3268149-3-irogers@google.com
-Stable-dep-of: 3e0bf9fde298 ("perf pmu: Restore full PMU name wildcard support")
-Signed-off-by: Sasha Levin <sashal@kernel.org>
----
- tools/perf/tests/pmu.c | 99 ++++++++++++++++++++++++++++++++++++++++++
- 1 file changed, 99 insertions(+)
-
-diff --git a/tools/perf/tests/pmu.c b/tools/perf/tests/pmu.c
-index 06cc0e46cb289..cc88b5920c3e2 100644
---- a/tools/perf/tests/pmu.c
-+++ b/tools/perf/tests/pmu.c
-@@ -3,6 +3,7 @@
- #include "evsel.h"
- #include "parse-events.h"
- #include "pmu.h"
-+#include "pmus.h"
- #include "tests.h"
- #include "debug.h"
- #include "fncache.h"
-@@ -340,10 +341,108 @@ static int test__pmu_event_names(struct test_suite *test __maybe_unused,
- return ret;
- }
-
-+static const char * const uncore_chas[] = {
-+ "uncore_cha_0",
-+ "uncore_cha_1",
-+ "uncore_cha_2",
-+ "uncore_cha_3",
-+ "uncore_cha_4",
-+ "uncore_cha_5",
-+ "uncore_cha_6",
-+ "uncore_cha_7",
-+ "uncore_cha_8",
-+ "uncore_cha_9",
-+ "uncore_cha_10",
-+ "uncore_cha_11",
-+ "uncore_cha_12",
-+ "uncore_cha_13",
-+ "uncore_cha_14",
-+ "uncore_cha_15",
-+ "uncore_cha_16",
-+ "uncore_cha_17",
-+ "uncore_cha_18",
-+ "uncore_cha_19",
-+ "uncore_cha_20",
-+ "uncore_cha_21",
-+ "uncore_cha_22",
-+ "uncore_cha_23",
-+ "uncore_cha_24",
-+ "uncore_cha_25",
-+ "uncore_cha_26",
-+ "uncore_cha_27",
-+ "uncore_cha_28",
-+ "uncore_cha_29",
-+ "uncore_cha_30",
-+ "uncore_cha_31",
-+};
-+
-+static const char * const mrvl_ddrs[] = {
-+ "mrvl_ddr_pmu_87e1b0000000",
-+ "mrvl_ddr_pmu_87e1b1000000",
-+ "mrvl_ddr_pmu_87e1b2000000",
-+ "mrvl_ddr_pmu_87e1b3000000",
-+ "mrvl_ddr_pmu_87e1b4000000",
-+ "mrvl_ddr_pmu_87e1b5000000",
-+ "mrvl_ddr_pmu_87e1b6000000",
-+ "mrvl_ddr_pmu_87e1b7000000",
-+ "mrvl_ddr_pmu_87e1b8000000",
-+ "mrvl_ddr_pmu_87e1b9000000",
-+ "mrvl_ddr_pmu_87e1ba000000",
-+ "mrvl_ddr_pmu_87e1bb000000",
-+ "mrvl_ddr_pmu_87e1bc000000",
-+ "mrvl_ddr_pmu_87e1bd000000",
-+ "mrvl_ddr_pmu_87e1be000000",
-+ "mrvl_ddr_pmu_87e1bf000000",
-+};
-+
-+static int test__name_len(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
-+{
-+ TEST_ASSERT_VAL("cpu", pmu_name_len_no_suffix("cpu") == strlen("cpu"));
-+ TEST_ASSERT_VAL("i915", pmu_name_len_no_suffix("i915") == strlen("i915"));
-+ TEST_ASSERT_VAL("cpum_cf", pmu_name_len_no_suffix("cpum_cf") == strlen("cpum_cf"));
-+ for (size_t i = 0; i < ARRAY_SIZE(uncore_chas); i++) {
-+ TEST_ASSERT_VAL("Strips uncore_cha suffix",
-+ pmu_name_len_no_suffix(uncore_chas[i]) ==
-+ strlen("uncore_cha"));
-+ }
-+ for (size_t i = 0; i < ARRAY_SIZE(mrvl_ddrs); i++) {
-+ TEST_ASSERT_VAL("Strips mrvl_ddr_pmu suffix",
-+ pmu_name_len_no_suffix(mrvl_ddrs[i]) ==
-+ strlen("mrvl_ddr_pmu"));
-+ }
-+ return TEST_OK;
-+}
-+
-+static int test__name_cmp(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
-+{
-+ TEST_ASSERT_EQUAL("cpu", pmu_name_cmp("cpu", "cpu"), 0);
-+ TEST_ASSERT_EQUAL("i915", pmu_name_cmp("i915", "i915"), 0);
-+ TEST_ASSERT_EQUAL("cpum_cf", pmu_name_cmp("cpum_cf", "cpum_cf"), 0);
-+ TEST_ASSERT_VAL("i915", pmu_name_cmp("cpu", "i915") < 0);
-+ TEST_ASSERT_VAL("i915", pmu_name_cmp("i915", "cpu") > 0);
-+ TEST_ASSERT_VAL("cpum_cf", pmu_name_cmp("cpum_cf", "cpum_ce") > 0);
-+ TEST_ASSERT_VAL("cpum_cf", pmu_name_cmp("cpum_cf", "cpum_d0") < 0);
-+ for (size_t i = 1; i < ARRAY_SIZE(uncore_chas); i++) {
-+ TEST_ASSERT_VAL("uncore_cha suffixes ordered lt",
-+ pmu_name_cmp(uncore_chas[i-1], uncore_chas[i]) < 0);
-+ TEST_ASSERT_VAL("uncore_cha suffixes ordered gt",
-+ pmu_name_cmp(uncore_chas[i], uncore_chas[i-1]) > 0);
-+ }
-+ for (size_t i = 1; i < ARRAY_SIZE(mrvl_ddrs); i++) {
-+ TEST_ASSERT_VAL("mrvl_ddr_pmu suffixes ordered lt",
-+ pmu_name_cmp(mrvl_ddrs[i-1], mrvl_ddrs[i]) < 0);
-+ TEST_ASSERT_VAL("mrvl_ddr_pmu suffixes ordered gt",
-+ pmu_name_cmp(mrvl_ddrs[i], mrvl_ddrs[i-1]) > 0);
-+ }
-+ return TEST_OK;
-+}
-+
- static struct test_case tests__pmu[] = {
- TEST_CASE("Parsing with PMU format directory", pmu_format),
- TEST_CASE("Parsing with PMU event", pmu_events),
- TEST_CASE("PMU event names", pmu_event_names),
-+ TEST_CASE("PMU name combining", name_len),
-+ TEST_CASE("PMU name comparison", name_cmp),
- { .name = NULL, }
- };
-
---
-2.43.0
-