lkml.org 
[lkml]   [2023]   [Feb]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
Subject[PATCH v1 04/51] perf pmu-events: Change aggr_mode to be an enum
From
Rather than use a string to encode aggr_mode, use an enum value.

Signed-off-by: Ian Rogers <irogers@google.com>
---
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 78eef77d8a8d..c8d0dc775e5d 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 db8b92de113e..2b08d7c18f4b 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 cee8b83792f8..7225efc4e4df 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.39.2.637.g21b0678d19-goog
\
 
 \ /
  Last update: 2023-03-27 00:28    [W:0.307 / U:0.404 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site