[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20260114-james-perf-config-bits-v5-4-0ef97aaf1ac0@linaro.org>
Date: Wed, 14 Jan 2026 15:57:16 +0000
From: James Clark <james.clark@...aro.org>
To: Peter Zijlstra <peterz@...radead.org>, Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Namhyung Kim <namhyung@...nel.org>, Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Jiri Olsa <jolsa@...nel.org>, Ian Rogers <irogers@...gle.com>,
Adrian Hunter <adrian.hunter@...el.com>,
Suzuki K Poulose <suzuki.poulose@....com>,
Mike Leach <mike.leach@...aro.org>, John Garry <john.g.garry@...cle.com>,
Will Deacon <will@...nel.org>, Leo Yan <leo.yan@...ux.dev>
Cc: linux-perf-users@...r.kernel.org, linux-kernel@...r.kernel.org,
coresight@...ts.linaro.org, linux-arm-kernel@...ts.infradead.org,
James Clark <james.clark@...aro.org>
Subject: [PATCH v5 04/14] perf evsel: Support sparse fields in
evsel__set_config_if_unset()
Sparse config fields are technically supported although currently
unused. field_prep() only works for contiguous bitfields so replace it
with pmu_format_value().
pmu_format_value() also takes a bitmap rather than a u64 so replace
'u64 bits' with format->bits.
Reviewed-by: Ian Rogers <irogers@...gle.com>
Signed-off-by: James Clark <james.clark@...aro.org>
---
tools/perf/util/evsel.c | 19 +++++++++++--------
tools/perf/util/pmu.c | 32 +++-----------------------------
tools/perf/util/pmu.h | 28 ++++++++++++++++++++++++++++
3 files changed, 42 insertions(+), 37 deletions(-)
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 21878e9bd029..9ef94632106b 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1322,25 +1322,28 @@ struct evsel_config_term *__evsel__get_config_term(struct evsel *evsel, enum evs
* the bit pattern. It is shifted into position by this function, so to set
* something to true, pass 1 for val rather than a pre shifted value.
*/
-#define field_prep(_mask, _val) (((_val) << (ffsll(_mask) - 1)) & (_mask))
void evsel__set_config_if_unset(struct evsel *evsel, const char *config_name,
u64 val)
{
- u64 user_bits = 0, bits;
+ u64 user_bits = 0;
struct evsel_config_term *term = evsel__get_config_term(evsel, CFG_CHG);
+ struct perf_pmu_format *format = pmu_find_format(&evsel->pmu->format,
+ config_name);
+ int fbit;
+
+ if (!format)
+ return;
if (term)
user_bits = term->val.cfg_chg;
- bits = perf_pmu__format_bits(evsel->pmu, config_name);
-
/* Do nothing if the user changed the value */
- if (bits & user_bits)
- return;
+ for_each_set_bit(fbit, format->bits, PERF_PMU_FORMAT_BITS)
+ if ((1ULL << fbit) & user_bits)
+ return;
/* Otherwise replace it */
- evsel->core.attr.config &= ~bits;
- evsel->core.attr.config |= field_prep(bits, val);
+ pmu_format_value(format->bits, val, &evsel->core.attr.config, /*zero=*/true);
}
void __weak arch_evsel__set_sample_weight(struct evsel *evsel)
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index e3a1f26213ec..7967d9159742 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -118,31 +118,6 @@ struct perf_pmu_alias {
bool info_loaded;
};
-/**
- * struct perf_pmu_format - Values from a format file read from
- * <sysfs>/devices/cpu/format/ held in struct perf_pmu.
- *
- * For example, the contents of <sysfs>/devices/cpu/format/event may be
- * "config:0-7" and will be represented here as name="event",
- * value=PERF_PMU_FORMAT_VALUE_CONFIG and bits 0 to 7 will be set.
- */
-struct perf_pmu_format {
- /** @list: Element on list within struct perf_pmu. */
- struct list_head list;
- /** @bits: Which config bits are set by this format value. */
- DECLARE_BITMAP(bits, PERF_PMU_FORMAT_BITS);
- /** @name: The modifier/file name. */
- char *name;
- /**
- * @value : Which config value the format relates to. Supported values
- * are from PERF_PMU_FORMAT_VALUE_CONFIG to
- * PERF_PMU_FORMAT_VALUE_CONFIG_END.
- */
- u16 value;
- /** @loaded: Has the contents been loaded/parsed. */
- bool loaded;
-};
-
static int pmu_aliases_parse(struct perf_pmu *pmu);
static struct perf_pmu_format *perf_pmu__new_format(struct list_head *list, char *name)
@@ -1362,8 +1337,8 @@ void perf_pmu__warn_invalid_formats(struct perf_pmu *pmu)
}
}
-static struct perf_pmu_format *
-pmu_find_format(const struct list_head *formats, const char *name)
+struct perf_pmu_format *pmu_find_format(const struct list_head *formats,
+ const char *name)
{
struct perf_pmu_format *format;
@@ -1404,8 +1379,7 @@ int perf_pmu__format_type(struct perf_pmu *pmu, const char *name)
* Sets value based on the format definition (format parameter)
* and unformatted value (value parameter).
*/
-static void pmu_format_value(unsigned long *format, __u64 value, __u64 *v,
- bool zero)
+void pmu_format_value(unsigned long *format, __u64 value, __u64 *v, bool zero)
{
unsigned long fbit, vbit;
diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
index 8f11bfe8ed6d..3a53e1882cf1 100644
--- a/tools/perf/util/pmu.h
+++ b/tools/perf/util/pmu.h
@@ -233,6 +233,31 @@ struct pmu_event_info {
bool deprecated;
};
+/**
+ * struct perf_pmu_format - Values from a format file read from
+ * <sysfs>/devices/cpu/format/ held in struct perf_pmu.
+ *
+ * For example, the contents of <sysfs>/devices/cpu/format/event may be
+ * "config:0-7" and will be represented here as name="event",
+ * value=PERF_PMU_FORMAT_VALUE_CONFIG and bits 0 to 7 will be set.
+ */
+struct perf_pmu_format {
+ /** @list: Element on list within struct perf_pmu. */
+ struct list_head list;
+ /** @bits: Which config bits are set by this format value. */
+ DECLARE_BITMAP(bits, PERF_PMU_FORMAT_BITS);
+ /** @name: The modifier/file name. */
+ char *name;
+ /**
+ * @value : Which config value the format relates to. Supported values
+ * are from PERF_PMU_FORMAT_VALUE_CONFIG to
+ * PERF_PMU_FORMAT_VALUE_CONFIG_END.
+ */
+ u16 value;
+ /** @loaded: Has the contents been loaded/parsed. */
+ bool loaded;
+};
+
typedef int (*pmu_event_callback)(void *state, struct pmu_event_info *info);
typedef int (*pmu_format_callback)(void *state, const char *name, int config,
const unsigned long *bits);
@@ -254,6 +279,9 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct parse_events_terms *head_
u64 *alternate_hw_config, struct parse_events_error *err);
int perf_pmu__find_event(struct perf_pmu *pmu, const char *event, void *state, pmu_event_callback cb);
+void pmu_format_value(unsigned long *format, __u64 value, __u64 *v, bool zero);
+struct perf_pmu_format *pmu_find_format(const struct list_head *formats,
+ const char *name);
void perf_pmu_format__set_value(void *format, int config, unsigned long *bits);
bool perf_pmu__has_format(const struct perf_pmu *pmu, const char *name);
int perf_pmu__for_each_format(struct perf_pmu *pmu, void *state, pmu_format_callback cb);
--
2.34.1
Powered by blists - more mailing lists