Skip to content

Commit

Permalink
perf test: Update event_groups test to use instructions
Browse files Browse the repository at this point in the history
In some of the powerpc platforms, event group testcase fails as below:

   # perf test -v 'Event groups'
   69: Event groups                                                    :
   --- start ---
   test child forked, pid 9765
   Using CPUID 0x00820200
   Using hv_24x7 for uncore pmu event
   0x0 0x0, 0x0 0x0, 0x0 0x0: Fail
   0x0 0x0, 0x0 0x0, 0x1 0x3: Pass

The testcase creates various combinations of hw, sw and uncore
PMU events and verify group creation succeeds or fails as expected.
This tests one of the limitation in perf where it doesn't allow
creating a group of events from different hw PMUs.

The testcase starts a leader event and opens two sibling events.
The combination the fails is three hardware events in a group.
"0x0 0x0, 0x0 0x0, 0x0 0x0: Fail"

Type zero and config zero which translates to PERF_TYPE_HARDWARE
and PERF_COUNT_HW_CPU_CYCLE. There is event constraint in powerpc
that events using same counter cannot be programmed in a group.
Here there is one alternative event for cycles, hence one leader
and only one sibling event can go in as a group.

if all three events (leader and two sibling events), are hardware
events, use instructions as one of the sibling event. Since
PERF_COUNT_HW_INSTRUCTIONS is a generic hardware event and present
in all architectures, use this as third event.

Reported-by: Tejas Manhas <[email protected]>
Signed-off-by: Athira Rajeev <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Namhyung Kim <[email protected]>
  • Loading branch information
athira-rajeev authored and namhyung committed Jan 18, 2025
1 parent 62892e7 commit 91b7747
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions tools/perf/tests/event_groups.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
#include "header.h"
#include "../perf-sys.h"

/* hw: cycles, sw: context-switch, uncore: [arch dependent] */
/* hw: cycles,instructions sw: context-switch, uncore: [arch dependent] */
static int types[] = {0, 1, -1};
static unsigned long configs[] = {0, 3, 0};
static unsigned long configs_hw[] = {1};

#define NR_UNCORE_PMUS 5

Expand Down Expand Up @@ -93,7 +94,18 @@ static int run_test(int i, int j, int k)
return erroneous ? 0 : -1;
}

sibling_fd2 = event_open(types[k], configs[k], group_fd);
/*
* if all three events (leader and two sibling events)
* are hardware events, use instructions as one of the
* sibling event. There is event constraint in powerpc that
* events using same counter cannot be programmed in a group.
* Since PERF_COUNT_HW_INSTRUCTIONS is a generic hardware
* event and present in all platforms, lets use that.
*/
if (!i && !j && !k)
sibling_fd2 = event_open(types[k], configs_hw[k], group_fd);
else
sibling_fd2 = event_open(types[k], configs[k], group_fd);
if (sibling_fd2 == -1) {
close(sibling_fd1);
close(group_fd);
Expand Down Expand Up @@ -124,9 +136,18 @@ static int test__event_groups(struct test_suite *text __maybe_unused, int subtes
if (r)
ret = TEST_FAIL;

pr_debug("0x%x 0x%lx, 0x%x 0x%lx, 0x%x 0x%lx: %s\n",
types[i], configs[i], types[j], configs[j],
types[k], configs[k], r ? "Fail" : "Pass");
/*
* For all three events as HW events, second sibling
* event is picked from configs_hw. So print accordingly
*/
if (!i && !j && !k)
pr_debug("0x%x 0x%lx, 0x%x 0x%lx, 0x%x 0x%lx: %s\n",
types[i], configs[i], types[j], configs[j],
types[k], configs_hw[k], r ? "Fail" : "Pass");
else
pr_debug("0x%x 0x%lx, 0x%x 0x%lx, 0x%x 0x%lx: %s\n",
types[i], configs[i], types[j], configs[j],
types[k], configs[k], r ? "Fail" : "Pass");
}
}
}
Expand Down

0 comments on commit 91b7747

Please sign in to comment.