Skip to content

Commit 4fb7ca9

Browse files
Thomas Richtergregkh
Thomas Richter
authored andcommitted
perf test: Fix Hwmon PMU test endianess issue
[ Upstream commit 888751e ] perf test 11 hwmon fails on s390 with this error # ./perf test -Fv 11 --- start --- ---- end ---- 11.1: Basic parsing test : Ok --- start --- Testing 'temp_test_hwmon_event1' Using CPUID IBM,3931,704,A01,3.7,002f temp_test_hwmon_event1 -> hwmon_a_test_hwmon_pmu/temp_test_hwmon_event1/ FAILED tests/hwmon_pmu.c:189 Unexpected config for 'temp_test_hwmon_event1', 292470092988416 != 655361 ---- end ---- 11.2: Parsing without PMU name : FAILED! --- start --- Testing 'hwmon_a_test_hwmon_pmu/temp_test_hwmon_event1/' FAILED tests/hwmon_pmu.c:189 Unexpected config for 'hwmon_a_test_hwmon_pmu/temp_test_hwmon_event1/', 292470092988416 != 655361 ---- end ---- 11.3: Parsing with PMU name : FAILED! # The root cause is in member test_event::config which is initialized to 0xA0001 or 655361. During event parsing a long list event parsing functions are called and end up with this gdb call stack: #0 hwmon_pmu__config_term (hwm=0x168dfd0, attr=0x3ffffff5ee8, term=0x168db60, err=0x3ffffff81c8) at util/hwmon_pmu.c:623 #1 hwmon_pmu__config_terms (pmu=0x168dfd0, attr=0x3ffffff5ee8, terms=0x3ffffff5ea8, err=0x3ffffff81c8) at util/hwmon_pmu.c:662 #2 0x00000000012f870c in perf_pmu__config_terms (pmu=0x168dfd0, attr=0x3ffffff5ee8, terms=0x3ffffff5ea8, zero=false, apply_hardcoded=false, err=0x3ffffff81c8) at util/pmu.c:1519 #3 0x00000000012f88a4 in perf_pmu__config (pmu=0x168dfd0, attr=0x3ffffff5ee8, head_terms=0x3ffffff5ea8, apply_hardcoded=false, err=0x3ffffff81c8) at util/pmu.c:1545 #4 0x00000000012680c4 in parse_events_add_pmu (parse_state=0x3ffffff7fb8, list=0x168dc00, pmu=0x168dfd0, const_parsed_terms=0x3ffffff6090, auto_merge_stats=true, alternate_hw_config=10) at util/parse-events.c:1508 #5 0x00000000012684c6 in parse_events_multi_pmu_add (parse_state=0x3ffffff7fb8, event_name=0x168ec10 "temp_test_hwmon_event1", hw_config=10, const_parsed_terms=0x0, listp=0x3ffffff6230, loc_=0x3ffffff70e0) at util/parse-events.c:1592 torvalds#6 0x00000000012f0e4e in parse_events_parse (_parse_state=0x3ffffff7fb8, scanner=0x16878c0) at util/parse-events.y:293 torvalds#7 0x00000000012695a0 in parse_events__scanner (str=0x3ffffff81d8 "temp_test_hwmon_event1", input=0x0, parse_state=0x3ffffff7fb8) at util/parse-events.c:1867 torvalds#8 0x000000000126a1e8 in __parse_events (evlist=0x168b580, str=0x3ffffff81d8 "temp_test_hwmon_event1", pmu_filter=0x0, err=0x3ffffff81c8, fake_pmu=false, warn_if_reordered=true, fake_tp=false) at util/parse-events.c:2136 torvalds#9 0x00000000011e36aa in parse_events (evlist=0x168b580, str=0x3ffffff81d8 "temp_test_hwmon_event1", err=0x3ffffff81c8) at /root/linux/tools/perf/util/parse-events.h:41 torvalds#10 0x00000000011e3e64 in do_test (i=0, with_pmu=false, with_alias=false) at tests/hwmon_pmu.c:164 torvalds#11 0x00000000011e422c in test__hwmon_pmu (with_pmu=false) at tests/hwmon_pmu.c:219 torvalds#12 0x00000000011e431c in test__hwmon_pmu_without_pmu (test=0x1610368 <suite.hwmon_pmu>, subtest=1) at tests/hwmon_pmu.c:23 where the attr::config is set to value 292470092988416 or 0x10a0000000000 in line 625 of file ./util/hwmon_pmu.c: attr->config = key.type_and_num; However member key::type_and_num is defined as union and bit field: union hwmon_pmu_event_key { long type_and_num; struct { int num :16; enum hwmon_type type :8; }; }; s390 is big endian and Intel is little endian architecture. The events for the hwmon dummy pmu have num = 1 or num = 2 and type is set to HWMON_TYPE_TEMP (which is 10). On s390 this assignes member key::type_and_num the value of 0x10a0000000000 (which is 292470092988416) as shown in above trace output. Fix this and export the structure/union hwmon_pmu_event_key so the test shares the same implementation as the event parsing functions for union and bit fields. This should avoid endianess issues on all platforms. Output after: # ./perf test -F 11 11.1: Basic parsing test : Ok 11.2: Parsing without PMU name : Ok 11.3: Parsing with PMU name : Ok # Fixes: 531ee0f ("perf test: Add hwmon "PMU" test") Signed-off-by: Thomas Richter <tmricht@linux.ibm.com> Reviewed-by: Ian Rogers <irogers@google.com> Link: https://lore.kernel.org/r/20250131112400.568975-1-tmricht@linux.ibm.com Signed-off-by: Namhyung Kim <namhyung@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent fc49b1d commit 4fb7ca9

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

Diff for: tools/perf/tests/hwmon_pmu.c

+11-5
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,23 @@
1313
static const struct test_event {
1414
const char *name;
1515
const char *alias;
16-
long config;
16+
union hwmon_pmu_event_key key;
1717
} test_events[] = {
1818
{
1919
"temp_test_hwmon_event1",
2020
"temp1",
21-
0xA0001,
21+
.key = {
22+
.num = 1,
23+
.type = 10
24+
},
2225
},
2326
{
2427
"temp_test_hwmon_event2",
2528
"temp2",
26-
0xA0002,
29+
.key = {
30+
.num = 2,
31+
.type = 10
32+
},
2733
},
2834
};
2935

@@ -183,11 +189,11 @@ static int do_test(size_t i, bool with_pmu, bool with_alias)
183189
strcmp(evsel->pmu->name, "hwmon_a_test_hwmon_pmu"))
184190
continue;
185191

186-
if (evsel->core.attr.config != (u64)test_events[i].config) {
192+
if (evsel->core.attr.config != (u64)test_events[i].key.type_and_num) {
187193
pr_debug("FAILED %s:%d Unexpected config for '%s', %lld != %ld\n",
188194
__FILE__, __LINE__, str,
189195
evsel->core.attr.config,
190-
test_events[i].config);
196+
test_events[i].key.type_and_num);
191197
ret = TEST_FAIL;
192198
goto out;
193199
}

Diff for: tools/perf/util/hwmon_pmu.c

-14
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,6 @@ struct hwmon_pmu {
107107
int hwmon_dir_fd;
108108
};
109109

110-
/**
111-
* union hwmon_pmu_event_key: Key for hwmon_pmu->events as such each key
112-
* represents an event.
113-
*
114-
* Related hwmon files start <type><number> that this key represents.
115-
*/
116-
union hwmon_pmu_event_key {
117-
long type_and_num;
118-
struct {
119-
int num :16;
120-
enum hwmon_type type :8;
121-
};
122-
};
123-
124110
/**
125111
* struct hwmon_pmu_event_value: Value in hwmon_pmu->events.
126112
*

Diff for: tools/perf/util/hwmon_pmu.h

+16
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,22 @@ enum hwmon_item {
9191
HWMON_ITEM__MAX,
9292
};
9393

94+
/**
95+
* union hwmon_pmu_event_key: Key for hwmon_pmu->events as such each key
96+
* represents an event.
97+
* union is exposed for testing to ensure problems are avoided on big
98+
* endian machines.
99+
*
100+
* Related hwmon files start <type><number> that this key represents.
101+
*/
102+
union hwmon_pmu_event_key {
103+
long type_and_num;
104+
struct {
105+
int num :16;
106+
enum hwmon_type type :8;
107+
};
108+
};
109+
94110
bool perf_pmu__is_hwmon(const struct perf_pmu *pmu);
95111
bool evsel__is_hwmon(const struct evsel *evsel);
96112

0 commit comments

Comments
 (0)