Commit b8db070f authored by Ian Rogers's avatar Ian Rogers Committed by Namhyung Kim

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: default avatarIan Rogers <irogers@google.com>
Reviewed-by: default avatarKan 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: default avatarNamhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240131201429.792138-1-irogers@google.com
parent fd7b8e8f
...@@ -203,7 +203,7 @@ class JsonEvent: ...@@ -203,7 +203,7 @@ class JsonEvent:
def llx(x: int) -> str: def llx(x: int) -> str:
"""Convert an int to a string similar to a printf modifier of %#llx.""" """Convert an int to a string similar to a printf modifier of %#llx."""
return '0' if x == 0 else hex(x) return str(x) if x >= 0 and x < 10 else hex(x)
def fixdesc(s: str) -> str: def fixdesc(s: str) -> str:
"""Fix formatting issue for the desc string.""" """Fix formatting issue for the desc string."""
...@@ -294,6 +294,23 @@ class JsonEvent: ...@@ -294,6 +294,23 @@ class JsonEvent:
} }
return table[unit] if unit in table else f'uncore_{unit.lower()}' return table[unit] if unit in table else f'uncore_{unit.lower()}'
def is_zero(val: str) -> bool:
try:
if val.startswith('0x'):
return int(val, 16) == 0
else:
return int(val) == 0
except e:
return False
def canonicalize_value(val: str) -> str:
try:
if val.startswith('0x'):
return llx(int(val, 16))
return str(int(val))
except e:
return val
eventcode = 0 eventcode = 0
if 'EventCode' in jd: if 'EventCode' in jd:
eventcode = int(jd['EventCode'].split(',', 1)[0], 0) eventcode = int(jd['EventCode'].split(',', 1)[0], 0)
...@@ -358,8 +375,8 @@ class JsonEvent: ...@@ -358,8 +375,8 @@ class JsonEvent:
('RdWrMask', 'rdwrmask='), ('RdWrMask', 'rdwrmask='),
] ]
for key, value in event_fields: for key, value in event_fields:
if key in jd and jd[key] != '0': if key in jd and not is_zero(jd[key]):
event += ',' + value + jd[key] event += f',{value}{canonicalize_value(jd[key])}'
if filter: if filter:
event += f',{filter}' event += f',{filter}'
if msr: if msr:
......
...@@ -70,7 +70,7 @@ static const struct perf_pmu_test_event segment_reg_loads_any = { ...@@ -70,7 +70,7 @@ static const struct perf_pmu_test_event segment_reg_loads_any = {
.event = { .event = {
.pmu = "default_core", .pmu = "default_core",
.name = "segment_reg_loads.any", .name = "segment_reg_loads.any",
.event = "event=0x6,period=200000,umask=0x80", .event = "event=6,period=200000,umask=0x80",
.desc = "Number of segment register loads", .desc = "Number of segment register loads",
.topic = "other", .topic = "other",
}, },
...@@ -82,7 +82,7 @@ static const struct perf_pmu_test_event dispatch_blocked_any = { ...@@ -82,7 +82,7 @@ static const struct perf_pmu_test_event dispatch_blocked_any = {
.event = { .event = {
.pmu = "default_core", .pmu = "default_core",
.name = "dispatch_blocked.any", .name = "dispatch_blocked.any",
.event = "event=0x9,period=200000,umask=0x20", .event = "event=9,period=200000,umask=0x20",
.desc = "Memory cluster signals to block micro-op dispatch for any reason", .desc = "Memory cluster signals to block micro-op dispatch for any reason",
.topic = "other", .topic = "other",
}, },
...@@ -94,11 +94,11 @@ static const struct perf_pmu_test_event eist_trans = { ...@@ -94,11 +94,11 @@ static const struct perf_pmu_test_event eist_trans = {
.event = { .event = {
.pmu = "default_core", .pmu = "default_core",
.name = "eist_trans", .name = "eist_trans",
.event = "event=0x3a,period=200000,umask=0x0", .event = "event=0x3a,period=200000",
.desc = "Number of Enhanced Intel SpeedStep(R) Technology (EIST) transitions", .desc = "Number of Enhanced Intel SpeedStep(R) Technology (EIST) transitions",
.topic = "other", .topic = "other",
}, },
.alias_str = "event=0x3a,period=0x30d40,umask=0", .alias_str = "event=0x3a,period=0x30d40",
.alias_long_desc = "Number of Enhanced Intel SpeedStep(R) Technology (EIST) transitions", .alias_long_desc = "Number of Enhanced Intel SpeedStep(R) Technology (EIST) transitions",
}; };
...@@ -128,7 +128,7 @@ static const struct perf_pmu_test_event *core_events[] = { ...@@ -128,7 +128,7 @@ static const struct perf_pmu_test_event *core_events[] = {
static const struct perf_pmu_test_event uncore_hisi_ddrc_flux_wcmd = { static const struct perf_pmu_test_event uncore_hisi_ddrc_flux_wcmd = {
.event = { .event = {
.name = "uncore_hisi_ddrc.flux_wcmd", .name = "uncore_hisi_ddrc.flux_wcmd",
.event = "event=0x2", .event = "event=2",
.desc = "DDRC write commands", .desc = "DDRC write commands",
.topic = "uncore", .topic = "uncore",
.long_desc = "DDRC write commands", .long_desc = "DDRC write commands",
...@@ -156,13 +156,13 @@ static const struct perf_pmu_test_event unc_cbo_xsnp_response_miss_eviction = { ...@@ -156,13 +156,13 @@ static const struct perf_pmu_test_event unc_cbo_xsnp_response_miss_eviction = {
static const struct perf_pmu_test_event uncore_hyphen = { static const struct perf_pmu_test_event uncore_hyphen = {
.event = { .event = {
.name = "event-hyphen", .name = "event-hyphen",
.event = "event=0xe0,umask=0x00", .event = "event=0xe0",
.desc = "UNC_CBO_HYPHEN", .desc = "UNC_CBO_HYPHEN",
.topic = "uncore", .topic = "uncore",
.long_desc = "UNC_CBO_HYPHEN", .long_desc = "UNC_CBO_HYPHEN",
.pmu = "uncore_cbox", .pmu = "uncore_cbox",
}, },
.alias_str = "event=0xe0,umask=0", .alias_str = "event=0xe0",
.alias_long_desc = "UNC_CBO_HYPHEN", .alias_long_desc = "UNC_CBO_HYPHEN",
.matching_pmu = "uncore_cbox_0", .matching_pmu = "uncore_cbox_0",
}; };
...@@ -170,13 +170,13 @@ static const struct perf_pmu_test_event uncore_hyphen = { ...@@ -170,13 +170,13 @@ static const struct perf_pmu_test_event uncore_hyphen = {
static const struct perf_pmu_test_event uncore_two_hyph = { static const struct perf_pmu_test_event uncore_two_hyph = {
.event = { .event = {
.name = "event-two-hyph", .name = "event-two-hyph",
.event = "event=0xc0,umask=0x00", .event = "event=0xc0",
.desc = "UNC_CBO_TWO_HYPH", .desc = "UNC_CBO_TWO_HYPH",
.topic = "uncore", .topic = "uncore",
.long_desc = "UNC_CBO_TWO_HYPH", .long_desc = "UNC_CBO_TWO_HYPH",
.pmu = "uncore_cbox", .pmu = "uncore_cbox",
}, },
.alias_str = "event=0xc0,umask=0", .alias_str = "event=0xc0",
.alias_long_desc = "UNC_CBO_TWO_HYPH", .alias_long_desc = "UNC_CBO_TWO_HYPH",
.matching_pmu = "uncore_cbox_0", .matching_pmu = "uncore_cbox_0",
}; };
...@@ -184,7 +184,7 @@ static const struct perf_pmu_test_event uncore_two_hyph = { ...@@ -184,7 +184,7 @@ static const struct perf_pmu_test_event uncore_two_hyph = {
static const struct perf_pmu_test_event uncore_hisi_l3c_rd_hit_cpipe = { static const struct perf_pmu_test_event uncore_hisi_l3c_rd_hit_cpipe = {
.event = { .event = {
.name = "uncore_hisi_l3c.rd_hit_cpipe", .name = "uncore_hisi_l3c.rd_hit_cpipe",
.event = "event=0x7", .event = "event=7",
.desc = "Total read hits", .desc = "Total read hits",
.topic = "uncore", .topic = "uncore",
.long_desc = "Total read hits", .long_desc = "Total read hits",
...@@ -265,7 +265,7 @@ static const struct perf_pmu_test_event sys_ccn_pmu_read_cycles = { ...@@ -265,7 +265,7 @@ static const struct perf_pmu_test_event sys_ccn_pmu_read_cycles = {
static const struct perf_pmu_test_event sys_cmn_pmu_hnf_cache_miss = { static const struct perf_pmu_test_event sys_cmn_pmu_hnf_cache_miss = {
.event = { .event = {
.name = "sys_cmn_pmu.hnf_cache_miss", .name = "sys_cmn_pmu.hnf_cache_miss",
.event = "eventid=0x1,type=0x5", .event = "eventid=1,type=5",
.desc = "Counts total cache misses in first lookup result (high priority)", .desc = "Counts total cache misses in first lookup result (high priority)",
.topic = "uncore", .topic = "uncore",
.pmu = "uncore_sys_cmn_pmu", .pmu = "uncore_sys_cmn_pmu",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment