Skip to contentSkip to conversation

tools/perf: Fix ratio_to_prev event parsing test

PATCH Superseded Thomas Falcon 4 participants 8 messages Mar 26 – Apr 2 perf events

lore
Share & tools
lore
#0 lore raw

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

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")

---
v2: made changes suggested by Dapeng Mi
https://lore.kernel.org/all/[email protected]/

---
 tools/perf/tests/parse-events.c | 47 +++++++++++++++++++--------------
 1 file changed, 27 insertions(+), 20 deletions(-)
tools/perf/tests/parse-events.c +27 -20
index 1d3cc224fbc2..4487508c5658 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) {
-		if (!perf_pmu__has_format(evsel->pmu, "acr_mask"))
+	for (int i = 0; i < num_core_entries(evlist); i++) {
+		leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
+		if (!perf_pmu__has_format(leader->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 == leader->core.attr.config2);
+		TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(leader));
+		TEST_ASSERT_VAL("wrong core.nr_members", leader->core.nr_members == 2);
+		TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(leader) == 0);
+		TEST_ASSERT_EVSEL("unexpected event",
+				  evsel__match(leader, HARDWARE, HW_CPU_CYCLES),
+				  leader);
+		/*
+		 * The period value gets configured within evlist__config,
+		 * while this test executes only parse events method.
+		 */
+		TEST_ASSERT_VAL("wrong period", 0 == leader->core.attr.sample_period);
+
+		 /* instructions/period=200000,ratio-to-prev=2.0/ */
+		evsel = evsel__next(leader);
+		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
reviewer
#1 lore raw
Quoted 25 lines · Thomas Falcon

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")

---
v2: made changes suggested by Dapeng Mi
https://lore.kernel.org/all/[email protected]/

---
 tools/perf/tests/parse-events.c | 47 +++++++++++++++++++--------------
 1 file changed, 27 insertions(+), 20 deletions(-)
tools/perf/tests/parse-events.c +0 -0
index 1d3cc224fbc2..4487508c5658 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 static bool test__acr_valid(void) · line 1805

Quoted 10 lines
tools/perf/tests/parse-events.c +4 -3
-       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) {
-               if (!perf_pmu__has_format(evsel->pmu, "acr_mask"))
+       for (int i = 0; i < num_core_entries(evlist); i++) {
+               leader = (i == 0 ? evlist__first(evlist) : evsel__next(evsel));
+               if (!perf_pmu__has_format(leader->pmu, "acr_mask"))

If the p-core non-ACR supporting events are first, won't this mean the loop immediately terminates? I wonder the loop should be:

```
evlist__for_each_entry(evlist, evsel) {
               if (evsel != evsel__leader(evsel) ||
!perf_pmu__has_format(evsel->pmu, "acr_mask"))
                    continue; /* Not a group leader or the event is
for a non-ACR supporting PMU. */
```

then the regular tests on the config2, etc. Then evsel__next to get the instructions event, etc.

Thanks,
Ian

Quoted 48 lines
tools/perf/tests/parse-events.c +23 -18
                        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 == leader->core.attr.config2);
+               TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(leader));
+               TEST_ASSERT_VAL("wrong core.nr_members", leader->core.nr_members == 2);
+               TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(leader) == 0);
+               TEST_ASSERT_EVSEL("unexpected event",
+                                 evsel__match(leader, HARDWARE, HW_CPU_CYCLES),
+                                 leader);
+               /*
+                * The period value gets configured within evlist__config,
+                * while this test executes only parse events method.
+                */
+               TEST_ASSERT_VAL("wrong period", 0 == leader->core.attr.sample_period);
+
+                /* instructions/period=200000,ratio-to-prev=2.0/ */
+               evsel = evsel__next(leader);
+               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.43.0

#2 lore raw
Quoted 58 lines · Ian Rogers
Quoted 39 lines · Thomas Falcon

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")
---
v2: made changes suggested by Dapeng Mi
https://lore.kernel.org/all/[email protected]/
---
 tools/perf/tests/parse-events.c | 47 +++++++++++++++++++----------
----

 1 file changed, 27 insertions(+), 20 deletions(-)
tools/perf/tests/parse-events.c +1 -1
index 1d3cc224fbc2..4487508c5658 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);

Quoted 6 lines

-        evlist__for_each_entry(evlist, evsel) {
-               if (!perf_pmu__has_format(evsel->pmu, "acr_mask")) +       for (int i = 0; i < num_core_entries(evlist); i++) { +               leader = (i == 0 ? evlist__first(evlist) :
evsel__next(evsel));
+               if (!perf_pmu__has_format(leader->pmu, "acr_mask"))

If the p-core non-ACR supporting events are first, won't this mean the
loop immediately terminates? I wonder the loop should be:

```
evlist__for_each_entry(evlist, evsel) {
               if (evsel != evsel__leader(evsel) ||
!perf_pmu__has_format(evsel->pmu, "acr_mask"))
                    continue; /* Not a group leader or the event is
for a non-ACR supporting PMU. */
```
Quoted 2 lines

then the regular tests on the config2, etc. Then evsel__next to get the instructions event, etc.

Hi Ian, thanks for catching that! I will send a new version soon.

Thanks,
Tom

Quoted 80 lines

Thanks,
Ian

Quoted 74 lines

                        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 == leader-

Quoted 1 line

core.attr.config2);

+               TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(leader));
+               TEST_ASSERT_VAL("wrong core.nr_members", leader-

Quoted 1 line

core.nr_members == 2);

+               TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(leader) == 0);
+               TEST_ASSERT_EVSEL("unexpected event", +                                 evsel__match(leader, HARDWARE, HW_CPU_CYCLES),
+                                 leader);
+               /*
+                * The period value gets configured within evlist__config,
+                * while this test executes only parse events method.
+                */
+               TEST_ASSERT_VAL("wrong period", 0 == leader-

Quoted 1 line

core.attr.sample_period);

+
+                /* instructions/period=200000,ratio-to-prev=2.0/ */
+               evsel = evsel__next(leader);
+               TEST_ASSERT_VAL("wrong config2", 0 == evsel-

Quoted 1 line

core.attr.config2);

+               TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
+               TEST_ASSERT_VAL("wrong core.nr_members", evsel-

Quoted 1 line

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.43.0

#3 lore raw

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

In reply to Ian Rogers

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. Instead, 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. Finally, do not exit immediately if a PMU without auto counter reload support is found.

Fixes 56be0fe5f62c ("perf record: Add auto counter reload parse and regression tests")

---
v3: Fixed early loop termination if PMU without auto counter reload support is
encountered first, suggested by Ian Rogers
https://lore.kernel.org/all/CAP-5=fUFGevUhRROdybtDCXZgWgxYzfLrq_0f8r5_Yv_VfxP+A@mail.gmail.com/

v2: made changes suggested by Dapeng Mi
https://lore.kernel.org/all/[email protected]/
---

 tools/perf/tests/parse-events.c | 49 +++++++++++++++++++--------------
 1 file changed, 28 insertions(+), 21 deletions(-)
tools/perf/tests/parse-events.c +28 -21
index 1d3cc224f..05c3e899b 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) {
-		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);
+	evlist__for_each_entry(evlist, evsel) {
+		if (evsel != evsel__leader(evsel) ||
+		    !perf_pmu__has_format(evsel->pmu, "acr_mask")) {
+			continue;
 		}
+		leader = evsel;
+		/* cycles */
+		TEST_ASSERT_VAL("wrong config2", 0 == leader->core.attr.config2);
+		TEST_ASSERT_VAL("wrong core.nr_members", leader->core.nr_members == 2);
+		TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(leader) == 0);
+		TEST_ASSERT_EVSEL("unexpected event",
+				  evsel__match(leader, HARDWARE, HW_CPU_CYCLES),
+				  leader);
+		/*
+		 * The period value gets configured within evlist__config,
+		 * while this test executes only parse events method.
+		 */
+		TEST_ASSERT_VAL("wrong period", 0 == leader->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.51.0
reviewer Reviewed-by on v3 1/1
#4 lore raw
Quoted 11 lines · Thomas Falcon

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. Instead, 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. Finally, do not exit immediately if a PMU without auto counter reload support is found.

Fixes 56be0fe5f62c ("perf record: Add auto counter reload parse and regression tests")

Thanks!
Ian

Quoted 79 lines

---
v3: Fixed early loop termination if PMU without auto counter reload support is
encountered first, suggested by Ian Rogers
https://lore.kernel.org/all/CAP-5=fUFGevUhRROdybtDCXZgWgxYzfLrq_0f8r5_Yv_VfxP+A@mail.gmail.com/

v2: made changes suggested by Dapeng Mi
https://lore.kernel.org/all/[email protected]/
---

 tools/perf/tests/parse-events.c | 49 +++++++++++++++++++--------------
 1 file changed, 28 insertions(+), 21 deletions(-)
tools/perf/tests/parse-events.c +28 -22
index 1d3cc224f..05c3e899b 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) {
-               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);
+       evlist__for_each_entry(evlist, evsel) {
+               if (evsel != evsel__leader(evsel) ||
+                   !perf_pmu__has_format(evsel->pmu, "acr_mask")) {
+                       continue;
                }
+               leader = evsel;
+               /* cycles */
+               TEST_ASSERT_VAL("wrong config2", 0 == leader->core.attr.config2);
+               TEST_ASSERT_VAL("wrong core.nr_members", leader->core.nr_members == 2);
+               TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(leader) == 0);
+               TEST_ASSERT_EVSEL("unexpected event",
+                                 evsel__match(leader, HARDWARE, HW_CPU_CYCLES),
+                                 leader);
+               /*
+                * The period value gets configured within evlist__config,
+                * while this test executes only parse events method.
+                */
+               TEST_ASSERT_VAL("wrong period", 0 == leader->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.
--

2.51.0

reviewer
#5 lore raw
Quoted 11 lines · Ian Rogers
Quoted 9 lines · Thomas Falcon

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. Instead, 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. Finally, do not exit immediately if a PMU without auto counter reload support is found.

Quoted 4 lines
Quoted 2 lines
Fixes 56be0fe5f62c ("perf record: Add auto counter reload parse and regression tests")

Ping. Thanks,
Ian

Quoted 82 lines

Thanks!
Ian

Quoted 79 lines

---
v3: Fixed early loop termination if PMU without auto counter reload support is
encountered first, suggested by Ian Rogers
https://lore.kernel.org/all/CAP-5=fUFGevUhRROdybtDCXZgWgxYzfLrq_0f8r5_Yv_VfxP+A@mail.gmail.com/

v2: made changes suggested by Dapeng Mi
https://lore.kernel.org/all/[email protected]/
---

 tools/perf/tests/parse-events.c | 49 +++++++++++++++++++--------------
 1 file changed, 28 insertions(+), 21 deletions(-)
tools/perf/tests/parse-events.c +28 -22
index 1d3cc224f..05c3e899b 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) {
-               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);
+       evlist__for_each_entry(evlist, evsel) {
+               if (evsel != evsel__leader(evsel) ||
+                   !perf_pmu__has_format(evsel->pmu, "acr_mask")) {
+                       continue;
                }
+               leader = evsel;
+               /* cycles */
+               TEST_ASSERT_VAL("wrong config2", 0 == leader->core.attr.config2);
+               TEST_ASSERT_VAL("wrong core.nr_members", leader->core.nr_members == 2);
+               TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(leader) == 0);
+               TEST_ASSERT_EVSEL("unexpected event",
+                                 evsel__match(leader, HARDWARE, HW_CPU_CYCLES),
+                                 leader);
+               /*
+                * The period value gets configured within evlist__config,
+                * while this test executes only parse events method.
+                */
+               TEST_ASSERT_VAL("wrong period", 0 == leader->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.
--

2.51.0

Reviewed-by on v3 1/1
#6 lore raw
In reply to Thomas Falcon
Quoted 86 lines · Thomas Falcon

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. Instead, 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. Finally, do not exit immediately if a PMU without auto counter reload support is found.

Fixes 56be0fe5f62c ("perf record: Add auto counter reload parse and regression tests")

---
v3: Fixed early loop termination if PMU without auto counter reload support is
encountered first, suggested by Ian Rogers
https://lore.kernel.org/all/CAP-5=fUFGevUhRROdybtDCXZgWgxYzfLrq_0f8r5_Yv_VfxP+A@mail.gmail.com/

v2: made changes suggested by Dapeng Mi
https://lore.kernel.org/all/[email protected]/
---

 tools/perf/tests/parse-events.c | 49 +++++++++++++++++++--------------
 1 file changed, 28 insertions(+), 21 deletions(-)
tools/perf/tests/parse-events.c +28 -21
index 1d3cc224f..05c3e899b 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) {
-		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);
+	evlist__for_each_entry(evlist, evsel) {
+		if (evsel != evsel__leader(evsel) ||
+		    !perf_pmu__has_format(evsel->pmu, "acr_mask")) {
+			continue;
 		}
+		leader = evsel;
+		/* cycles */
+		TEST_ASSERT_VAL("wrong config2", 0 == leader->core.attr.config2);
+		TEST_ASSERT_VAL("wrong core.nr_members", leader->core.nr_members == 2);
+		TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(leader) == 0);
+		TEST_ASSERT_EVSEL("unexpected event",
+				  evsel__match(leader, HARDWARE, HW_CPU_CYCLES),
+				  leader);
+		/*
+		 * The period value gets configured within evlist__config,
+		 * while this test executes only parse events method.
+		 */
+		TEST_ASSERT_VAL("wrong period", 0 == leader->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.
maintainer Applied
#7 lore raw
In reply to Thomas Falcon
Quoted 9 lines · Thomas Falcon

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. Instead, 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. Finally, do not exit immediately if a PMU without auto counter reload support is found.

[...]

Applied to perf-tools-next, thanks!

Best regards,
Namhyung