Skip to contentSkip to conversation

tools/perf: Fix ratio_to_prev event parsing test

PATCH Superseded [email protected] 2 participants 3 messages Mar 24 – Mar 25 perf events

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/perf: Fix ratio_to_prev event parsing test

From: Thomas Falcon <[email protected]>

test__ratio_to_prev() assumed the first event in a group is the leader, which is not the case when the event is expanded into two event groups on hybrid PMU's with auto counter reload support. This patch updates the test to iterate over the event group generated for each core PMU. Also update "wrong leader" test to check that the subordinate event has the correct leader instead of checking that it is not the group leader.

Fixes 56be0fe5f62c ("perf record: Add auto counter reload parse and regression tests")
---
 tools/perf/tests/parse-events.c | 45 +++++++++++++++++++--------------
 1 file changed, 26 insertions(+), 19 deletions(-)
tools/perf/tests/parse-events.c +26 -19
index 1d3cc224fbc2..cd48e6b2bb57 100644
@@ -1796,31 +1796,38 @@ static bool test__acr_valid(void)
 
 static int test__ratio_to_prev(struct evlist *evlist)
 {
-	struct evsel *evsel;
+	struct evsel *evsel, *leader;
 
 	TEST_ASSERT_VAL("wrong number of entries", 2 * perf_pmus__num_core_pmus() == evlist->core.nr_entries);
 
-	 evlist__for_each_entry(evlist, evsel) {
+	for (int i = 0; i < num_core_entries(evlist); i++) {
+		evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
 		if (!perf_pmu__has_format(evsel->pmu, "acr_mask"))
 			return TEST_OK;
 
-		if (evsel == evlist__first(evlist)) {
-			TEST_ASSERT_VAL("wrong config2", 0 == evsel->core.attr.config2);
-			TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
-			TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
-			TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
-			TEST_ASSERT_EVSEL("unexpected event",
-					evsel__match(evsel, HARDWARE, HW_CPU_CYCLES),
-					evsel);
-		} else {
-			TEST_ASSERT_VAL("wrong config2", 0 == evsel->core.attr.config2);
-			TEST_ASSERT_VAL("wrong leader", !evsel__is_group_leader(evsel));
-			TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 0);
-			TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
-			TEST_ASSERT_EVSEL("unexpected event",
-					evsel__match(evsel, HARDWARE, HW_INSTRUCTIONS),
-					evsel);
-		}
+		/* cycles */
+		TEST_ASSERT_VAL("wrong config2", 0 == evsel->core.attr.config2);
+		TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
+		TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
+		TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
+		TEST_ASSERT_EVSEL("unexpected event",
+				  evsel__match(evsel, HARDWARE, HW_CPU_CYCLES),
+				  evsel);
+		/*
+		 * The period value gets configured within evlist__config,
+		 * while this test executes only parse events method.
+		 */
+		TEST_ASSERT_VAL("wrong period", 0 == evsel->core.attr.sample_period);
+
+		 /* instructions/period=200000,ratio-to-prev=2.0/ */
+		evsel = evsel__next(evsel);
+		TEST_ASSERT_VAL("wrong config2", 0 == evsel->core.attr.config2);
+		TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
+		TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 0);
+		TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
+		TEST_ASSERT_EVSEL("unexpected event",
+				  evsel__match(evsel, HARDWARE, HW_INSTRUCTIONS),
+				  evsel);
 		/*
 		 * The period value gets configured within evlist__config,
 		 * while this test executes only parse events method.
Signature · 1 line
2.43.0
#1 lore raw
Quoted 21 lines · On 3/25/2026 6:25 AM, [email protected] wrote:

From: Thomas Falcon <[email protected]>

test__ratio_to_prev() assumed the first event in a group is the leader, which is not the case when the event is expanded into two event groups on hybrid PMU's with auto counter reload support. This patch updates the test to iterate over the event group generated for each core PMU. Also update "wrong leader" test to check that the subordinate event has the correct leader instead of checking that it is not the group leader.

Fixes 56be0fe5f62c ("perf record: Add auto counter reload parse and regression tests")
---
 tools/perf/tests/parse-events.c | 45 +++++++++++++++++++--------------
 1 file changed, 26 insertions(+), 19 deletions(-)
tools/perf/tests/parse-events.c +0 -0
index 1d3cc224fbc2..cd48e6b2bb57 100644
@@ -1796,31 +1796,38 @@ static bool test__acr_valid(void)
 

tools/perf/tests/parse-events.c static bool test__acr_valid(void) · line 1804

Quoted 10 lines
tools/perf/tests/parse-events.c +3 -2
 static int test__ratio_to_prev(struct evlist *evlist)
 {
-	struct evsel *evsel;
+	struct evsel *evsel, *leader;
 
 	TEST_ASSERT_VAL("wrong number of entries", 2 * perf_pmus__num_core_pmus() == evlist->core.nr_entries);
 
-	 evlist__for_each_entry(evlist, evsel) {
+	for (int i = 0; i < num_core_entries(evlist); i++) {
+		evsel = leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));

could we use the "leader" to replace "evsel" for all the "TEST_ASSERT_VAL" of cycles event? That make code look more clearer. Then the above sentence can be simplified to this,

```
leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));

```
Quoted 26 lines
tools/perf/tests/parse-events.c +6 -17
 		if (!perf_pmu__has_format(evsel->pmu, "acr_mask"))
 			return TEST_OK;
 
-		if (evsel == evlist__first(evlist)) {
-			TEST_ASSERT_VAL("wrong config2", 0 == evsel->core.attr.config2);
-			TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
-			TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
-			TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
-			TEST_ASSERT_EVSEL("unexpected event",
-					evsel__match(evsel, HARDWARE, HW_CPU_CYCLES),
-					evsel);
-		} else {
-			TEST_ASSERT_VAL("wrong config2", 0 == evsel->core.attr.config2);
-			TEST_ASSERT_VAL("wrong leader", !evsel__is_group_leader(evsel));
-			TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 0);
-			TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
-			TEST_ASSERT_EVSEL("unexpected event",
-					evsel__match(evsel, HARDWARE, HW_INSTRUCTIONS),
-					evsel);
-		}
+		/* cycles */
+		TEST_ASSERT_VAL("wrong config2", 0 == evsel->core.attr.config2);
+		TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
+		TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
+		TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0);
+		TEST_ASSERT_EVSEL("unexpected event",

tools/perf/tests/parse-events.c static bool test__acr_valid(void) · line 1823

Quoted 10 lines
tools/perf/tests/parse-events.c +10 -0
+				  evsel__match(evsel, HARDWARE, HW_CPU_CYCLES),
+				  evsel);
+		/*
+		 * The period value gets configured within evlist__config,
+		 * while this test executes only parse events method.
+		 */
+		TEST_ASSERT_VAL("wrong period", 0 == evsel->core.attr.sample_period);
+
+		 /* instructions/period=200000,ratio-to-prev=2.0/ */
+		evsel = evsel__next(evsel);

and here, the code needs to be changed to

```

evsel = evsel__next(leader);

```
Quoted 10 lines
tools/perf/tests/parse-events.c +7 -0
+		TEST_ASSERT_VAL("wrong config2", 0 == evsel->core.attr.config2);
+		TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
+		TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 0);
+		TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1);
+		TEST_ASSERT_EVSEL("unexpected event",
+				  evsel__match(evsel, HARDWARE, HW_INSTRUCTIONS),
+				  evsel);
 		/*
 		 * The period value gets configured within evlist__config,
 		 * while this test executes only parse events method.
#2 lore raw
Quoted 50 lines · Dapeng
Quoted 40 lines · On 3/25/2026 6:25 AM, [email protected] wrote:

From: Thomas Falcon <[email protected]>

test__ratio_to_prev() assumed the first event in a group is the leader,
which is not the case when the event is expanded into two event groups
on hybrid PMU's with auto counter reload support. This patch updates the
test to iterate over the event group generated for each core PMU. Also
update "wrong leader" test to check that the subordinate event has the
correct leader instead of checking that it is not the group leader.

Fixes 56be0fe5f62c ("perf record: Add auto counter reload parse

and regression tests")
---
 tools/perf/tests/parse-events.c | 45 +++++++++++++++++++----------
----

 1 file changed, 26 insertions(+), 19 deletions(-)
tools/perf/tests/parse-events.c +0 -0
index 1d3cc224fbc2..cd48e6b2bb57 100644
@@ -1796,31 +1796,38 @@ static bool test__acr_valid(void)


 static int test__ratio_to_prev(struct evlist *evlist) {

tools/perf/tests/parse-events.c +1 -1
-	struct evsel *evsel;
+	struct evsel *evsel, *leader;


  TEST_ASSERT_VAL("wrong number of entries", 2 * perf_pmus__num_core_pmus() == evlist->core.nr_entries);

tools/perf/tests/parse-events.c +2 -1
-	 evlist__for_each_entry(evlist, evsel) {
+	for (int i = 0; i < num_core_entries(evlist); i++) {
+		evsel = leader = (i == 0 ? evlist__first(evlist) :
Quoted 1 line

evsel__next(evsel));

could we use the "leader" to replace "evsel" for all the "TEST_ASSERT_VAL"
of cycles event? That make code look more clearer. Then the above sentence
can be simplified to this,

Quoted 5 lines
```
leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));

```

Hi Dapeng, the current patch follows a style similar to some of the other event parsing tests, though I don't see why it couldn't be simplified in this way. I will submit a v2 with the changes soon.

Thanks,
Tom

Quoted 83 lines
Quoted 55 lines

  if (!perf_pmu__has_format(evsel->pmu, "acr_mask")) return TEST_OK;

tools/perf/tests/parse-events.c +0 -2
-		if (evsel == evlist__first(evlist)) {
-			TEST_ASSERT_VAL("wrong config2", 0 ==

evsel->core.attr.config2);

tools/perf/tests/parse-events.c +0 -1
-			TEST_ASSERT_VAL("wrong leader",

evsel__is_group_leader(evsel));

tools/perf/tests/parse-events.c +0 -1
-			TEST_ASSERT_VAL("wrong core.nr_members",

evsel->core.nr_members == 2);

tools/perf/tests/parse-events.c +0 -1
-			TEST_ASSERT_VAL("wrong group_idx",

evsel__group_idx(evsel) == 0);

tools/perf/tests/parse-events.c +0 -2
-			TEST_ASSERT_EVSEL("unexpected event",
-					evsel__match(evsel,

HARDWARE, HW_CPU_CYCLES),

tools/perf/tests/parse-events.c +0 -3
-					evsel);
-		} else {
-			TEST_ASSERT_VAL("wrong config2", 0 ==

evsel->core.attr.config2);

tools/perf/tests/parse-events.c +0 -1
-			TEST_ASSERT_VAL("wrong leader",

!evsel__is_group_leader(evsel));

tools/perf/tests/parse-events.c +0 -1
-			TEST_ASSERT_VAL("wrong core.nr_members",

evsel->core.nr_members == 0);

tools/perf/tests/parse-events.c +0 -1
-			TEST_ASSERT_VAL("wrong group_idx",

evsel__group_idx(evsel) == 1);

tools/perf/tests/parse-events.c +0 -2
-			TEST_ASSERT_EVSEL("unexpected event",
-					evsel__match(evsel,

HARDWARE, HW_INSTRUCTIONS),

tools/perf/tests/parse-events.c +2 -2
-					evsel);
-		}
+		/* cycles */
+		TEST_ASSERT_VAL("wrong config2", 0 == evsel-
Quoted 1 line

core.attr.config2);

tools/perf/tests/parse-events.c +1 -0
+		TEST_ASSERT_VAL("wrong leader",

evsel__is_group_leader(evsel));

tools/perf/tests/parse-events.c +1 -0
+		TEST_ASSERT_VAL("wrong core.nr_members", evsel-
Quoted 1 line

core.nr_members == 2);

tools/perf/tests/parse-events.c +1 -0
+		TEST_ASSERT_VAL("wrong group_idx",

evsel__group_idx(evsel) == 0);

tools/perf/tests/parse-events.c +2 -0
+		TEST_ASSERT_EVSEL("unexpected event",
+				  evsel__match(evsel, HARDWARE,

HW_CPU_CYCLES),

tools/perf/tests/parse-events.c +3 -0
+				  evsel);
+		/*
+		 * The period value gets configured within

evlist__config,

tools/perf/tests/parse-events.c +1 -0
+		 * while this test executes only parse events

method.

tools/perf/tests/parse-events.c +2 -0
+		 */
+		TEST_ASSERT_VAL("wrong period", 0 == evsel-
Quoted 1 line

core.attr.sample_period);

tools/perf/tests/parse-events.c +2 -0
+
+		 /* instructions/period=200000,ratio-to-prev=2.0/

*/

tools/perf/tests/parse-events.c static bool test__acr_valid(void) · line 1823

Quoted 1 line
tools/perf/tests/parse-events.c +1 -0
+		evsel = evsel__next(evsel);

and here, the code needs to be changed to

```

evsel = evsel__next(leader);

```
Quoted 17 lines
tools/perf/tests/parse-events.c +1 -0
+		TEST_ASSERT_VAL("wrong config2", 0 == evsel-
Quoted 1 line

core.attr.config2);

tools/perf/tests/parse-events.c +1 -0
+		TEST_ASSERT_VAL("wrong leader",

evsel__has_leader(evsel, leader));

tools/perf/tests/parse-events.c +1 -0
+		TEST_ASSERT_VAL("wrong core.nr_members", evsel-
Quoted 1 line

core.nr_members == 0);

tools/perf/tests/parse-events.c +1 -0
+		TEST_ASSERT_VAL("wrong group_idx",

evsel__group_idx(evsel) == 1);

tools/perf/tests/parse-events.c +2 -0
+		TEST_ASSERT_EVSEL("unexpected event",
+				  evsel__match(evsel, HARDWARE,

HW_INSTRUCTIONS),

tools/perf/tests/parse-events.c +1 -0
+				  evsel);

  /*
  * The period value gets configured within evlist__config,
  * while this test executes only parse events method.