From 1fa0c371c9824743fe373e624a55cb036bbb2de1 Mon Sep 17 00:00:00 2001 From: Ian Rogers Date: Sun, 19 Feb 2023 01:28:01 -0800 Subject: [PATCH] perf pmu-events: Change aggr_mode to be an enum Rather than use a string to encode aggr_mode, use an enum value. Signed-off-by: Ian Rogers Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Alexandre Torgue Cc: Andrii Nakryiko Cc: Athira Rajeev Cc: Caleb Biggers Cc: Eduard Zingerman Cc: Florian Fischer Cc: Ingo Molnar Cc: James Clark Cc: Jing Zhang Cc: Jiri Olsa Cc: John Garry Cc: Kajol Jain Cc: Kan Liang Cc: Leo Yan Cc: Mark Rutland Cc: Maxime Coquelin Cc: Namhyung Kim Cc: Perry Taylor Cc: Peter Zijlstra Cc: Ravi Bangoria Cc: Sandipan Das Cc: Sean Christopherson Cc: Stephane Eranian Cc: Suzuki Poulouse Cc: Xing Zhengjun Cc: linux-arm-kernel@lists.infradead.org Cc: linux-stm32@st-md-mailman.stormreply.com Link: https://lore.kernel.org/r/20230219092848.639226-5-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/arch/powerpc/util/header.c | 2 +- tools/perf/pmu-events/jevents.py | 17 +++++++++++------ tools/perf/pmu-events/pmu-events.h | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/tools/perf/arch/powerpc/util/header.c b/tools/perf/arch/powerpc/util/header.c index 78eef77..c8d0dc7 100644 --- a/tools/perf/arch/powerpc/util/header.c +++ b/tools/perf/arch/powerpc/util/header.c @@ -45,6 +45,6 @@ int arch_get_runtimeparam(const struct pmu_metric *pm) int count; char path[PATH_MAX] = "/devices/hv_24x7/interface/"; - atoi(pm->aggr_mode) == PerChip ? strcat(path, "sockets") : strcat(path, "coresperchip"); + strcat(path, pm->aggr_mode == PerChip ? "sockets" : "coresperchip"); return sysfs__read_int(path, &count) < 0 ? 1 : count; } diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index db8b92d..2b08d7c 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -678,10 +678,13 @@ static void decompress_event(int offset, struct pmu_event *pe) { \tconst char *p = &big_c_string[offset]; """) + enum_attributes = ['aggr_mode'] for attr in _json_event_attributes: - _args.output_file.write(f""" -\tpe->{attr} = (*p == '\\0' ? NULL : p); -""") + _args.output_file.write(f'\n\tpe->{attr} = ') + if attr in enum_attributes: + _args.output_file.write("(*p == '\\0' ? 0 : *p - '0');\n") + else: + _args.output_file.write("(*p == '\\0' ? NULL : p);\n") if attr == _json_event_attributes[-1]: continue _args.output_file.write('\twhile (*p++);') @@ -692,9 +695,11 @@ static void decompress_metric(int offset, struct pmu_metric *pm) \tconst char *p = &big_c_string[offset]; """) for attr in _json_metric_attributes: - _args.output_file.write(f""" -\tpm->{attr} = (*p == '\\0' ? NULL : p); -""") + _args.output_file.write(f'\n\tpm->{attr} = ') + if attr in enum_attributes: + _args.output_file.write("(*p == '\\0' ? 0 : *p - '0');\n") + else: + _args.output_file.write("(*p == '\\0' ? NULL : p);\n") if attr == _json_metric_attributes[-1]: continue _args.output_file.write('\twhile (*p++);') diff --git a/tools/perf/pmu-events/pmu-events.h b/tools/perf/pmu-events/pmu-events.h index cee8b83..7225efc 100644 --- a/tools/perf/pmu-events/pmu-events.h +++ b/tools/perf/pmu-events/pmu-events.h @@ -31,10 +31,10 @@ struct pmu_metric { const char *metric_expr; const char *unit; const char *compat; - const char *aggr_mode; const char *metric_constraint; const char *desc; const char *long_desc; + enum aggr_mode_class aggr_mode; }; struct pmu_events_table; -- 2.7.4