summaryrefslogtreecommitdiff
path: root/tools/perf/pmu-events
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2023-02-19 12:28:06 +0300
committerArnaldo Carvalho de Melo <acme@redhat.com>2023-02-19 14:03:38 +0300
commitaa44724cb3179228bbfa509649ef021d14e4476f (patch)
tree91e895a794f4fdde2c0a25aa9f249901287619c5 /tools/perf/pmu-events
parent900536349d12516114eed9f5b47d30c362e68cdc (diff)
downloadlinux-aa44724cb3179228bbfa509649ef021d14e4476f.tar.xz
perf pmu-events: Don't '\0' terminate enum values
Encoding enums like '1\0' wastes a byte and could be '1' (no '\0' terminator) if the 0 case is '0', it also removes a branch for decompressing. Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Alexandre Torgue <alexandre.torgue@foss.st.com> Cc: Andrii Nakryiko <andrii@kernel.org> Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com> Cc: Caleb Biggers <caleb.biggers@intel.com> Cc: Eduard Zingerman <eddyz87@gmail.com> Cc: Florian Fischer <florian.fischer@muhq.space> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@arm.com> Cc: Jing Zhang <renyu.zj@linux.alibaba.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: John Garry <john.g.garry@oracle.com> Cc: Kajol Jain <kjain@linux.ibm.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Leo Yan <leo.yan@linaro.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Perry Taylor <perry.taylor@intel.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ravi Bangoria <ravi.bangoria@amd.com> Cc: Sandipan Das <sandipan.das@amd.com> Cc: Sean Christopherson <seanjc@google.com> Cc: Stephane Eranian <eranian@google.com> Cc: Suzuki Poulouse <suzuki.poulose@arm.com> Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com> Cc: linux-arm-kernel@lists.infradead.org Cc: linux-stm32@st-md-mailman.stormreply.com Link: https://lore.kernel.org/r/20230219092848.639226-10-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/pmu-events')
-rwxr-xr-xtools/perf/pmu-events/jevents.py26
1 files changed, 18 insertions, 8 deletions
diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py
index dc0c56dccb5e..e82dff3a1228 100755
--- a/tools/perf/pmu-events/jevents.py
+++ b/tools/perf/pmu-events/jevents.py
@@ -54,6 +54,8 @@ _json_metric_attributes = [
'metric_name', 'metric_group', 'metric_expr', 'desc',
'long_desc', 'unit', 'compat', 'aggr_mode', 'event_grouping'
]
+# Attributes that are bools or enum int values, encoded as '0', '1',...
+_json_enum_attributes = ['aggr_mode', 'deprecated', 'event_grouping', 'perpkg']
def removesuffix(s: str, suffix: str) -> str:
"""Remove the suffix from a string
@@ -360,7 +362,10 @@ class JsonEvent:
# Convert parsed metric expressions into a string. Slashes
# must be doubled in the file.
x = x.ToPerfJson().replace('\\', '\\\\')
- s += f'{x}\\000' if x else '\\000'
+ if attr in _json_enum_attributes:
+ s += x if x else '0'
+ else:
+ s += f'{x}\\000' if x else '\\000'
return s
def to_c_string(self, metric: bool) -> str:
@@ -690,16 +695,18 @@ static void decompress_event(int offset, struct pmu_event *pe)
{
\tconst char *p = &big_c_string[offset];
""")
- enum_attributes = ['aggr_mode', 'deprecated', 'event_grouping', 'perpkg']
for attr in _json_event_attributes:
_args.output_file.write(f'\n\tpe->{attr} = ')
- if attr in enum_attributes:
- _args.output_file.write("(*p == '\\0' ? 0 : *p - '0');\n")
+ if attr in _json_enum_attributes:
+ _args.output_file.write("*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++);')
+ if attr in _json_enum_attributes:
+ _args.output_file.write('\tp++;')
+ else:
+ _args.output_file.write('\twhile (*p++);')
_args.output_file.write("""}
static void decompress_metric(int offset, struct pmu_metric *pm)
@@ -708,13 +715,16 @@ static void decompress_metric(int offset, struct pmu_metric *pm)
""")
for attr in _json_metric_attributes:
_args.output_file.write(f'\n\tpm->{attr} = ')
- if attr in enum_attributes:
- _args.output_file.write("(*p == '\\0' ? 0 : *p - '0');\n")
+ if attr in _json_enum_attributes:
+ _args.output_file.write("*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++);')
+ if attr in _json_enum_attributes:
+ _args.output_file.write('\tp++;')
+ else:
+ _args.output_file.write('\twhile (*p++);')
_args.output_file.write("""}
int pmu_events_table_for_each_event(const struct pmu_events_table *table,