From: James Clark Date: Fri, 10 Apr 2026 11:05:12 +0000 (+0100) Subject: perf arm-spe: Don't warn about the discard bit if it doesn't exist X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=83eff458a690e650b68cd6467aae8959755c5388;p=thirdparty%2Fkernel%2Flinux.git perf arm-spe: Don't warn about the discard bit if it doesn't exist Opening an SPE event shows a warning that doesn't concern the user: $ perf record -e arm_spe Unknown/empty format name: discard Perf only wants to know if the discard bit is set for configuring the event, not in response to anything the user has done. Fix it by adding another helper that returns if a config bit exists without warning. We should probably keep the warning in evsel__get_config_val() to avoid having every caller having to do it, and most format bits should never be missing. Add a test for the new helper. Rename the parent test function to be more generic rather than adding a new one as it requires a lot of boilerplate. Reviewed-by: Ian Rogers Reviewed-by: Leo Yan Signed-off-by: James Clark Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Ingo Molnar Cc: Jiri Olsa Cc: John Garry Cc: Leo Yan Cc: Mark Rutland Cc: Mike Leach Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Will Deacon Signed-off-by: Arnaldo Carvalho de Melo --- diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c index f00d72d087fcc..91bb28cad79a5 100644 --- a/tools/perf/arch/arm64/util/arm-spe.c +++ b/tools/perf/arch/arm64/util/arm-spe.c @@ -428,7 +428,8 @@ static int arm_spe_recording_options(struct auxtrace_record *itr, evlist__for_each_entry_safe(evlist, tmp, evsel) { if (evsel__is_aux_event(evsel)) { arm_spe_setup_evsel(evsel, cpus); - if (!evsel__get_config_val(evsel, "discard", &discard_bit)) + if (evsel__config_exists(evsel, "discard") && + !evsel__get_config_val(evsel, "discard", &discard_bit)) discard = !!discard_bit; } } diff --git a/tools/perf/tests/pmu.c b/tools/perf/tests/pmu.c index 0ebf2d7b2cb41..d7be9d1c6f52b 100644 --- a/tools/perf/tests/pmu.c +++ b/tools/perf/tests/pmu.c @@ -201,7 +201,8 @@ err_out: return ret; } -static int test__pmu_usr_chgs(struct test_suite *test __maybe_unused, int subtest __maybe_unused) +static int test__pmu_config_helpers(struct test_suite *test __maybe_unused, + int subtest __maybe_unused) { const char *event = "perf-pmu-test/config=15,config1=4,krava02=170," "krava03=1,krava11=27,krava12=1/"; @@ -236,6 +237,12 @@ static int test__pmu_usr_chgs(struct test_suite *test __maybe_unused, int subtes } evsel = evlist__first(evlist); + /* Test evsel__config_exists() */ + TEST_ASSERT_EQUAL("krava01 should exist", + evsel__config_exists(evsel, "krava01"), true); + TEST_ASSERT_EQUAL("krava99 should not exist", + evsel__config_exists(evsel, "krava99"), false); + /* * Set via config=15, krava01 bits 0-1 * Set via config1=4, krava11 bit 1 @@ -629,7 +636,7 @@ static struct test_case tests__pmu[] = { TEST_CASE("PMU name combining", name_len), TEST_CASE("PMU name comparison", name_cmp), TEST_CASE("PMU cmdline match", pmu_match), - TEST_CASE("PMU user config changes", pmu_usr_chgs), + TEST_CASE("PMU config helpers", pmu_config_helpers), { .name = NULL, } }; diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index ac92f9e0e5b4c..34c03f47a9133 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1399,6 +1399,12 @@ void evsel__set_config_if_unset(struct evsel *evsel, const char *config_name, perf_pmu__format_pack(format->bits, val, vp, /*zero=*/true); } +bool evsel__config_exists(const struct evsel *evsel, const char *config_name) +{ + struct perf_pmu_format *format = pmu_find_format(&evsel->pmu->format, config_name); + + return format && !bitmap_empty(format->bits, PERF_PMU_FORMAT_BITS); +} int evsel__get_config_val(const struct evsel *evsel, const char *config_name, u64 *val) diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 3b12d99f0aa9f..8178858d168a6 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -589,6 +589,7 @@ void evsel__uniquify_counter(struct evsel *counter); ((((src) >> (pos)) & ((1ull << (size)) - 1)) << (63 - ((pos) + (size) - 1))) u64 evsel__bitfield_swap_branch_flags(u64 value); +bool evsel__config_exists(const struct evsel *evsel, const char *config_name); int evsel__get_config_val(const struct evsel *evsel, const char *config_name, u64 *val); void evsel__set_config_if_unset(struct evsel *evsel, const char *config_name,