[PATCH v14 1/7] perf/core: Add PMU_EVENT_ATTR_ID_STRING

Lucas De Marchi
2025-01-22T06:24:12Z

struct perf_pmu_events_attr has both id and event_str however zeroes
the id and only set event_str. Add another macro that allows to set both
so drivers can make use of them. The id is useful for determining the
visibility of the attributes without resorting to creating separate
groups passed via update_attr, while the event_str is still useful for
attributes like *.unit or *.scale.

Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
---
include/linux/perf_event.h | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index cb99ec8c9e96f..423f21b51cb0f 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -1923,13 +1923,16 @@ static struct perf_pmu_events_attr _var = { \
.id = _id, \
};

-#define PMU_EVENT_ATTR_STRING(_name, _var, _str) \
+#define PMU_EVENT_ATTR_ID_STRING(_name, _var, _id, _str) \
static struct perf_pmu_events_attr _var = { \
.attr = __ATTR(_name, 0444, perf_event_sysfs_show, NULL), \
- .id = 0, \
+ .id = _id, \
.event_str = _str, \
};

+#define PMU_EVENT_ATTR_STRING(_name, _var, _str) \
+ PMU_EVENT_ATTR_ID_STRING(_name, _var, 0, _str)
+
#define PMU_EVENT_ATTR_ID(_name, _show, _id) \
(&((struct perf_pmu_events_attr[]) { \
{ .attr = __ATTR(_name, 0444, _show, NULL), \
--
2.48.0