Linux Perf Users
 help / color / mirror / Atom feed
* [PATCH] tools/perf/tests: Update event_groups test to use instructions as one of the sibling event for hw type
@ 2025-01-10  9:46 Athira Rajeev
  2025-01-20  6:30 ` Ravi Bangoria
  2025-01-20 18:26 ` Namhyung Kim
  0 siblings, 2 replies; 5+ messages in thread
From: Athira Rajeev @ 2025-01-10  9:46 UTC (permalink / raw)
  To: acme, jolsa, adrian.hunter, irogers, namhyung, ravi.bangoria
  Cc: linux-perf-users, linuxppc-dev, maddy, atrajeev, kjain, disgoel,
	hbathini, Tejas Manhas

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 <Tejas.Manhas1@ibm.com>
Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
---
 tools/perf/tests/event_groups.c | 31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/tools/perf/tests/event_groups.c b/tools/perf/tests/event_groups.c
index ccd9d8b2903f..c119ff114948 100644
--- a/tools/perf/tests/event_groups.c
+++ b/tools/perf/tests/event_groups.c
@@ -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
 
@@ -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);
@@ -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");
 			}
 		}
 	}
-- 
2.43.5


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] tools/perf/tests: Update event_groups test to use instructions as one of the sibling event for hw type
  2025-01-10  9:46 [PATCH] tools/perf/tests: Update event_groups test to use instructions as one of the sibling event for hw type Athira Rajeev
@ 2025-01-20  6:30 ` Ravi Bangoria
  2025-01-20  8:23   ` Athira Rajeev
  2025-01-20 18:26 ` Namhyung Kim
  1 sibling, 1 reply; 5+ messages in thread
From: Ravi Bangoria @ 2025-01-20  6:30 UTC (permalink / raw)
  To: Athira Rajeev
  Cc: acme, jolsa, adrian.hunter, irogers, namhyung, linux-perf-users,
	linuxppc-dev, maddy, kjain, disgoel, hbathini, Tejas Manhas,
	Ravi Bangoria

Hi Athira,

On 10-Jan-25 3:16 PM, Athira Rajeev wrote:
> 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.

For power9, cycles seems to map to PM_CYC event:

   GENERIC_EVENT_ATTR(cpu-cycles,                  PM_CYC);

However, I don't see PM_CYC in power9_event_alternatives[]. Is PM_RUN_CYC
and PM_CYC are same?

Thanks,
Ravi

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] tools/perf/tests: Update event_groups test to use instructions as one of the sibling event for hw type
  2025-01-20  6:30 ` Ravi Bangoria
@ 2025-01-20  8:23   ` Athira Rajeev
  2025-01-20  9:38     ` Ravi Bangoria
  0 siblings, 1 reply; 5+ messages in thread
From: Athira Rajeev @ 2025-01-20  8:23 UTC (permalink / raw)
  To: Ravi Bangoria
  Cc: acme, jolsa, adrian.hunter, irogers, namhyung, linux-perf-users,
	linuxppc-dev, maddy, kjain, disgoel, hbathini, Tejas Manhas



> On 20 Jan 2025, at 12:00 PM, Ravi Bangoria <ravi.bangoria@amd.com> wrote:
> 
> Hi Athira,
> 
> On 10-Jan-25 3:16 PM, Athira Rajeev wrote:
>> 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.
> 
> For power9, cycles seems to map to PM_CYC event:
> 
>   GENERIC_EVENT_ATTR(cpu-cycles,                  PM_CYC);
> 
> However, I don't see PM_CYC in power9_event_alternatives[]. Is PM_RUN_CYC
> and PM_CYC are same?

Hi Ravi

They are not the same. PM_CYC count irrespective of the run latch state (idle state)
whereas PM_RUN_CYC doesn’t do that.

This test runs fine in power9. The event code for PM_CYC is 
EVENT(PM_CYC,                                   0x0001e)

Here it is not specifically meant to be run a particular counter and even if no alternative event is defined, it can pick available counters and go in as a group. But there are cases like other PMU (which is used in absence of platform specific PMU) , where alternative event is specified to run a particular counter.
Example: arch/powerpc/perf/generic-compat-pmu.c 

        EVENT(PM_CYC_ALT,                       0x100f0)
	EVENT(PM_CYC,                           0x600f4)

In this case, we can have only two cycles events to go in a group. So with our testcase events, one leader and only one sibling event
can go in a group (checked other PMU’s to confirm two is possible). So added this fix to consider instructions as one of the sibling event.

Thanks
Athira

> 
> Thanks,
> Ravi



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] tools/perf/tests: Update event_groups test to use instructions as one of the sibling event for hw type
  2025-01-20  8:23   ` Athira Rajeev
@ 2025-01-20  9:38     ` Ravi Bangoria
  0 siblings, 0 replies; 5+ messages in thread
From: Ravi Bangoria @ 2025-01-20  9:38 UTC (permalink / raw)
  To: Athira Rajeev
  Cc: acme, jolsa, adrian.hunter, irogers, namhyung, linux-perf-users,
	linuxppc-dev, maddy, kjain, disgoel, hbathini, Tejas Manhas,
	Ravi Bangoria

>>> 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.
>>
>> For power9, cycles seems to map to PM_CYC event:
>>
>>   GENERIC_EVENT_ATTR(cpu-cycles,                  PM_CYC);
>>
>> However, I don't see PM_CYC in power9_event_alternatives[]. Is PM_RUN_CYC
>> and PM_CYC are same?
> 
> Hi Ravi
> 
> They are not the same. PM_CYC count irrespective of the run latch state (idle state)
> whereas PM_RUN_CYC doesn’t do that.
> 
> This test runs fine in power9. The event code for PM_CYC is 
> EVENT(PM_CYC,                                   0x0001e)
> 
> Here it is not specifically meant to be run a particular counter and even if no alternative event is defined, it can pick available counters and go in as a group.

Got it.

> But there are cases like other PMU (which is used in absence of platform specific PMU) , where alternative event is specified to run a particular counter.
> Example: arch/powerpc/perf/generic-compat-pmu.c 
> 
>         EVENT(PM_CYC_ALT,                       0x100f0)
> 	EVENT(PM_CYC,                           0x600f4)
> 
> In this case, we can have only two cycles events to go in a group. So with our testcase events, one leader and only one sibling event
> can go in a group (checked other PMU’s to confirm two is possible). So added this fix to consider instructions as one of the sibling event.
Thanks for the explanation.

Reviewed-by: Ravi Bangoria <ravi.bangoria@amd.com>

Thanks,
Ravi

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] tools/perf/tests: Update event_groups test to use instructions as one of the sibling event for hw type
  2025-01-10  9:46 [PATCH] tools/perf/tests: Update event_groups test to use instructions as one of the sibling event for hw type Athira Rajeev
  2025-01-20  6:30 ` Ravi Bangoria
@ 2025-01-20 18:26 ` Namhyung Kim
  1 sibling, 0 replies; 5+ messages in thread
From: Namhyung Kim @ 2025-01-20 18:26 UTC (permalink / raw)
  To: acme, jolsa, adrian.hunter, irogers, ravi.bangoria, Athira Rajeev
  Cc: linux-perf-users, linuxppc-dev, maddy, kjain, disgoel, hbathini,
	Tejas Manhas

On Fri, 10 Jan 2025 15:16:20 +0530, Athira Rajeev wrote:

> 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
> 
> [...]

Applied to perf-tools-next, thanks!

Best regards,
Namhyung


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-01-20 18:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-10  9:46 [PATCH] tools/perf/tests: Update event_groups test to use instructions as one of the sibling event for hw type Athira Rajeev
2025-01-20  6:30 ` Ravi Bangoria
2025-01-20  8:23   ` Athira Rajeev
2025-01-20  9:38     ` Ravi Bangoria
2025-01-20 18:26 ` Namhyung Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox