Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf jevents: Drop or simplify small integer values

Prior to this patch '0' would be dropped as the config values default
to 0. Some json values are hex and the string '0' wouldn't match '0x0'
as zero. Add a more robust is_zero test to drop these event terms.

When encoding numbers as hex, if the number is between 0 and 9
inclusive then don't add a 0x prefix.

Update test expectations for these changes.

On x86 this reduces the event/metric C string by 58,411 bytes.

Signed-off-by: Ian Rogers <irogers@google.com>
Reviewed-by: Kan Liang <kan.liang@linux.intel.com>
Cc: Edward Baker <edward.baker@intel.com>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Veronika Molnarova <vmolnaro@redhat.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240131201429.792138-1-irogers@google.com

authored by

Ian Rogers and committed by
Namhyung Kim
b8db070f fd7b8e8f

+31 -14
+20 -3
tools/perf/pmu-events/jevents.py
··· 203 203 204 204 def llx(x: int) -> str: 205 205 """Convert an int to a string similar to a printf modifier of %#llx.""" 206 - return '0' if x == 0 else hex(x) 206 + return str(x) if x >= 0 and x < 10 else hex(x) 207 207 208 208 def fixdesc(s: str) -> str: 209 209 """Fix formatting issue for the desc string.""" ··· 294 294 } 295 295 return table[unit] if unit in table else f'uncore_{unit.lower()}' 296 296 297 + def is_zero(val: str) -> bool: 298 + try: 299 + if val.startswith('0x'): 300 + return int(val, 16) == 0 301 + else: 302 + return int(val) == 0 303 + except e: 304 + return False 305 + 306 + def canonicalize_value(val: str) -> str: 307 + try: 308 + if val.startswith('0x'): 309 + return llx(int(val, 16)) 310 + return str(int(val)) 311 + except e: 312 + return val 313 + 297 314 eventcode = 0 298 315 if 'EventCode' in jd: 299 316 eventcode = int(jd['EventCode'].split(',', 1)[0], 0) ··· 375 358 ('RdWrMask', 'rdwrmask='), 376 359 ] 377 360 for key, value in event_fields: 378 - if key in jd and jd[key] != '0': 379 - event += ',' + value + jd[key] 361 + if key in jd and not is_zero(jd[key]): 362 + event += f',{value}{canonicalize_value(jd[key])}' 380 363 if filter: 381 364 event += f',{filter}' 382 365 if msr:
+11 -11
tools/perf/tests/pmu-events.c
··· 70 70 .event = { 71 71 .pmu = "default_core", 72 72 .name = "segment_reg_loads.any", 73 - .event = "event=0x6,period=200000,umask=0x80", 73 + .event = "event=6,period=200000,umask=0x80", 74 74 .desc = "Number of segment register loads", 75 75 .topic = "other", 76 76 }, ··· 82 82 .event = { 83 83 .pmu = "default_core", 84 84 .name = "dispatch_blocked.any", 85 - .event = "event=0x9,period=200000,umask=0x20", 85 + .event = "event=9,period=200000,umask=0x20", 86 86 .desc = "Memory cluster signals to block micro-op dispatch for any reason", 87 87 .topic = "other", 88 88 }, ··· 94 94 .event = { 95 95 .pmu = "default_core", 96 96 .name = "eist_trans", 97 - .event = "event=0x3a,period=200000,umask=0x0", 97 + .event = "event=0x3a,period=200000", 98 98 .desc = "Number of Enhanced Intel SpeedStep(R) Technology (EIST) transitions", 99 99 .topic = "other", 100 100 }, 101 - .alias_str = "event=0x3a,period=0x30d40,umask=0", 101 + .alias_str = "event=0x3a,period=0x30d40", 102 102 .alias_long_desc = "Number of Enhanced Intel SpeedStep(R) Technology (EIST) transitions", 103 103 }; 104 104 ··· 128 128 static const struct perf_pmu_test_event uncore_hisi_ddrc_flux_wcmd = { 129 129 .event = { 130 130 .name = "uncore_hisi_ddrc.flux_wcmd", 131 - .event = "event=0x2", 131 + .event = "event=2", 132 132 .desc = "DDRC write commands", 133 133 .topic = "uncore", 134 134 .long_desc = "DDRC write commands", ··· 156 156 static const struct perf_pmu_test_event uncore_hyphen = { 157 157 .event = { 158 158 .name = "event-hyphen", 159 - .event = "event=0xe0,umask=0x00", 159 + .event = "event=0xe0", 160 160 .desc = "UNC_CBO_HYPHEN", 161 161 .topic = "uncore", 162 162 .long_desc = "UNC_CBO_HYPHEN", 163 163 .pmu = "uncore_cbox", 164 164 }, 165 - .alias_str = "event=0xe0,umask=0", 165 + .alias_str = "event=0xe0", 166 166 .alias_long_desc = "UNC_CBO_HYPHEN", 167 167 .matching_pmu = "uncore_cbox_0", 168 168 }; ··· 170 170 static const struct perf_pmu_test_event uncore_two_hyph = { 171 171 .event = { 172 172 .name = "event-two-hyph", 173 - .event = "event=0xc0,umask=0x00", 173 + .event = "event=0xc0", 174 174 .desc = "UNC_CBO_TWO_HYPH", 175 175 .topic = "uncore", 176 176 .long_desc = "UNC_CBO_TWO_HYPH", 177 177 .pmu = "uncore_cbox", 178 178 }, 179 - .alias_str = "event=0xc0,umask=0", 179 + .alias_str = "event=0xc0", 180 180 .alias_long_desc = "UNC_CBO_TWO_HYPH", 181 181 .matching_pmu = "uncore_cbox_0", 182 182 }; ··· 184 184 static const struct perf_pmu_test_event uncore_hisi_l3c_rd_hit_cpipe = { 185 185 .event = { 186 186 .name = "uncore_hisi_l3c.rd_hit_cpipe", 187 - .event = "event=0x7", 187 + .event = "event=7", 188 188 .desc = "Total read hits", 189 189 .topic = "uncore", 190 190 .long_desc = "Total read hits", ··· 265 265 static const struct perf_pmu_test_event sys_cmn_pmu_hnf_cache_miss = { 266 266 .event = { 267 267 .name = "sys_cmn_pmu.hnf_cache_miss", 268 - .event = "eventid=0x1,type=0x5", 268 + .event = "eventid=1,type=5", 269 269 .desc = "Counts total cache misses in first lookup result (high priority)", 270 270 .topic = "uncore", 271 271 .pmu = "uncore_sys_cmn_pmu",