]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf evsel: apply evsel__set_config_if_unset() to all config fields
authorJames Clark <james.clark@linaro.org>
Wed, 14 Jan 2026 15:57:18 +0000 (15:57 +0000)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 15 Jan 2026 02:15:06 +0000 (23:15 -0300)
Misleadingly, evsel__set_config_if_unset() only works with the config
field and not config1, config2, etc. This is fine at the moment because
all users of it happen to operate on bits that are in that config field.
Fix it before there are any new users of the function which operate on
bits in different config fields.

In theory it's also possible for a driver to move an existing bit to
another config field and this fixes that scenario too, although this
hasn't happened yet either.

Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: James Clark <james.clark@linaro.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Leo Yan <leo.yan@linux.dev>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/evsel.c

index 1a41a10d9ab2e9f71dec99d6ac645ef0518e8596..32517683351fe9805b1ac607acd7b73a349598a7 100644 (file)
@@ -1336,6 +1336,36 @@ void evsel__set_config_if_unset(struct evsel *evsel, const char *config_name,
        struct perf_pmu_format *format = pmu_find_format(&evsel->pmu->format,
                                                         config_name);
        int fbit;
+       __u64 *vp;
+
+       if (!format)
+               return;
+
+       switch (format->value) {
+       case PERF_PMU_FORMAT_VALUE_CONFIG:
+               term = evsel__get_config_term(evsel, USR_CHG_CONFIG);
+               vp = &evsel->core.attr.config;
+               break;
+       case PERF_PMU_FORMAT_VALUE_CONFIG1:
+               term = evsel__get_config_term(evsel, USR_CHG_CONFIG1);
+               vp = &evsel->core.attr.config1;
+               break;
+       case PERF_PMU_FORMAT_VALUE_CONFIG2:
+               term = evsel__get_config_term(evsel, USR_CHG_CONFIG2);
+               vp = &evsel->core.attr.config2;
+               break;
+       case PERF_PMU_FORMAT_VALUE_CONFIG3:
+               term = evsel__get_config_term(evsel, USR_CHG_CONFIG3);
+               vp = &evsel->core.attr.config3;
+               break;
+       case PERF_PMU_FORMAT_VALUE_CONFIG4:
+               term = evsel__get_config_term(evsel, USR_CHG_CONFIG4);
+               vp = &evsel->core.attr.config4;
+               break;
+       default:
+               pr_err("Unknown format value: %d\n", format->value);
+               return;
+       }
 
        if (!format)
                return;
@@ -1349,7 +1379,7 @@ void evsel__set_config_if_unset(struct evsel *evsel, const char *config_name,
                        return;
 
        /* Otherwise replace it */
-       pmu_format_value(format->bits, val, &evsel->core.attr.config, /*zero=*/true);
+       pmu_format_value(format->bits, val, vp, /*zero=*/true);
 }
 
 void __weak arch_evsel__set_sample_weight(struct evsel *evsel)