tools/perf: Fix ratio_to_prev event parsing test
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.
---
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
@@ -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
Ian Rogers
reviewerQuoted 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.Signed-off-by Thomas Falcon <[email protected]>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@@ -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
-18return 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
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.Signed-off-by Thomas Falcon <[email protected]>Fixes 56be0fe5f62c ("perf record: Add auto counter reload parseand 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@@ -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__nextto get the instructions event, etc.
Hi Ian, thanks for catching that! I will send a new version soon.
Thanks,
Tom
Quoted 80 lines
Thanks,
IanQuoted 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 withinevlist__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 withinevlist__config,
* while this test executes only parse events method.
--
2.43.0
PATCH v3 1/1 tools/perf: Fix ratio_to_prev event parsing test
In reply to Ian Rogerstest__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.
---
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
@@ -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
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.Signed-off-by Thomas Falcon <[email protected]>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@@ -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
Ian Rogers
reviewerQuoted 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
Signed-off-by Thomas Falcon <[email protected]>Fixes 56be0fe5f62c ("perf record: Add auto counter reload parse and regression tests")Reviewed-by Ian Rogers <[email protected]>
Ping. Thanks,
Ian
Quoted 82 lines
Thanks!
IanQuoted 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@@ -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
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.Signed-off-by Thomas Falcon <[email protected]>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@@ -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.
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