Skip to contentSkip to conversation

selftests/powerpc: A few fixes on powerpc selftests

PATCH RESEND In review Desnes A. Nunes do Rosario 2 participants 7 messages Apr 8, 2020 – Apr 23, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover selftests/powerpc: A few fixes on powerpc selftests

This patchseries addresses a few fixes on powerpc selftests (first and second patch are being resent).

The first fix has to do with the extra counts on PMCs resets, which not only are shown on the trace_logs, but can also invalidate the results of a few selftests. On the other hand, the second fix proper addresses the Per- formance Monitor Alert (PMAE) bit on MMCR0 when freezing counters are dis- abled on cycles_with_freeze_test selftest. Lastly, the third fix adds a memory barrier on count_pmc() to ensure read consistency of PMCs. This is necessary since these values are usually accounted on ebb_handlers to val- lidade tests results, such as the overflow values on pmc56_overflow_test.

Desnes A. Nunes do Rosario (2):
selftests/powerpc: Use write_pmc instead of count_pmc to reset PMCs on
ebb tests
selftests/powerpc: ensure PMC reads are set and ordered on count_pmc

Gustavo Romero (1):
selftests/powerpc: enable performance alerts when freezing counters on
cycles_with_freeze_test selftest

 .../powerpc/pmu/ebb/back_to_back_ebbs_test.c         |  2 +-
 .../testing/selftests/powerpc/pmu/ebb/cycles_test.c  |  2 +-
 .../powerpc/pmu/ebb/cycles_with_freeze_test.c        |  4 ++--
 .../powerpc/pmu/ebb/cycles_with_mmcr2_test.c         |  2 +-
 tools/testing/selftests/powerpc/pmu/ebb/ebb.c        |  6 +++++-
 .../powerpc/pmu/ebb/ebb_on_willing_child_test.c      |  2 +-
 .../selftests/powerpc/pmu/ebb/lost_exception_test.c  |  2 +-
 .../selftests/powerpc/pmu/ebb/multi_counter_test.c   | 12 ++++++------
 .../selftests/powerpc/pmu/ebb/multi_ebb_procs_test.c |  2 +-
 .../selftests/powerpc/pmu/ebb/pmae_handling_test.c   |  2 +-
 .../selftests/powerpc/pmu/ebb/pmc56_overflow_test.c  |  2 +-
 11 files changed, 21 insertions(+), 17 deletions(-)
Signature · 1 line
2.21.1
#1 lore raw

PATCH RESEND 1/3 selftests/powerpc: Use write_pmc instead of count_pmc to reset PMCs on ebb tests

By using count_pmc() to reset PMCs instead of write_pmc(), an extra count is performed on ebb_state.stats.pmc_count[PMC_INDEX(pmc)]. This extra pmc_count can occasionally invalidate results, such as the ones from cycles_test shown hereafter. The ebb_check_count() failed with an above the upper limit error due to the extra ebb_state.stats.pmc_count.

Furthermore, this extra count is also indicated by extra PMC1 trace_log on the output of the cycle test (as well as on pmc56_overflow_test):

==========
...
[21]: counter = 8
[22]: register SPRN_MMCR0 = 0x0000000080000080
[23]: register SPRN_PMC1 = 0x0000000080000004
[24]: counter = 9
[25]: register SPRN_MMCR0 = 0x0000000080000080
[26]: register SPRN_PMC1 = 0x0000000080000004
[27]: counter = 10
[28]: register SPRN_MMCR0 = 0x0000000080000080
[29]: register SPRN_PMC1 = 0x0000000080000004

Quoted 1 line
Quoted 1 line

[30]: register SPRN_PMC1 = 0x000000004000051e

PMC1 count (0x280000546) above upper limit 0x2800003e8 (+0x15e) [FAIL] Test FAILED on line 52
failure: cycles
==========

[desnesn: reflow of original comment]
---
 .../powerpc/pmu/ebb/back_to_back_ebbs_test.c         |  2 +-
 .../testing/selftests/powerpc/pmu/ebb/cycles_test.c  |  2 +-
 .../powerpc/pmu/ebb/cycles_with_freeze_test.c        |  2 +-
 .../powerpc/pmu/ebb/cycles_with_mmcr2_test.c         |  2 +-
 tools/testing/selftests/powerpc/pmu/ebb/ebb.c        |  2 +-
 .../powerpc/pmu/ebb/ebb_on_willing_child_test.c      |  2 +-
 .../selftests/powerpc/pmu/ebb/lost_exception_test.c  |  2 +-
 .../selftests/powerpc/pmu/ebb/multi_counter_test.c   | 12 ++++++------
 .../selftests/powerpc/pmu/ebb/multi_ebb_procs_test.c |  2 +-
 .../selftests/powerpc/pmu/ebb/pmae_handling_test.c   |  2 +-
 .../selftests/powerpc/pmu/ebb/pmc56_overflow_test.c  |  2 +-
 11 files changed, 16 insertions(+), 16 deletions(-)
tools/testing/selftests/powerpc/pmu/ebb/back_to_back_ebbs_test.c +1 -1
index a2d7b0e3dca9..f133ab425f10 100644
@@ -91,7 +91,7 @@ int back_to_back_ebbs(void)
 	ebb_global_disable();
 	ebb_freeze_pmcs();
 
-	count_pmc(1, sample_period);
+	write_pmc(1, pmc_sample_period(sample_period));
 
 	dump_ebb_state();
 
tools/testing/selftests/powerpc/pmu/ebb/cycles_test.c +1 -1
index bc893813483e..14a399a64729 100644
@@ -42,7 +42,7 @@ int cycles(void)
 	ebb_global_disable();
 	ebb_freeze_pmcs();
 
-	count_pmc(1, sample_period);
+	write_pmc(1, pmc_sample_period(sample_period));
 
 	dump_ebb_state();
 
tools/testing/selftests/powerpc/pmu/ebb/cycles_with_freeze_test.c +1 -1
index dcd351d20328..0f2089f6f82c 100644
@@ -99,7 +99,7 @@ int cycles_with_freeze(void)
 	ebb_global_disable();
 	ebb_freeze_pmcs();
 
-	count_pmc(1, sample_period);
+	write_pmc(1, pmc_sample_period(sample_period));
 
 	dump_ebb_state();
 
tools/testing/selftests/powerpc/pmu/ebb/cycles_with_mmcr2_test.c +1 -1
index 94c99c12c0f2..a8f3bee04cd8 100644
@@ -71,7 +71,7 @@ int cycles_with_mmcr2(void)
 	ebb_global_disable();
 	ebb_freeze_pmcs();
 
-	count_pmc(1, sample_period);
+	write_pmc(1, pmc_sample_period(sample_period));
 
 	dump_ebb_state();
 
tools/testing/selftests/powerpc/pmu/ebb/ebb.c +1 -1
index dfbc5c3ad52d..bf6f25dfcf7b 100644
@@ -396,7 +396,7 @@ int ebb_child(union pipe read_pipe, union pipe write_pipe)
 	ebb_global_disable();
 	ebb_freeze_pmcs();
 
-	count_pmc(1, sample_period);
+	write_pmc(1, pmc_sample_period(sample_period));
 
 	dump_ebb_state();
 
tools/testing/selftests/powerpc/pmu/ebb/ebb_on_willing_child_test.c +1 -1
index ca2f7d729155..513812cdcca1 100644
@@ -38,7 +38,7 @@ static int victim_child(union pipe read_pipe, union pipe write_pipe)
 	ebb_global_disable();
 	ebb_freeze_pmcs();
 
-	count_pmc(1, sample_period);
+	write_pmc(1, pmc_sample_period(sample_period));
 
 	dump_ebb_state();
 
tools/testing/selftests/powerpc/pmu/ebb/lost_exception_test.c +1 -1
index ac3e6e182614..5979606c41dc 100644
@@ -75,7 +75,7 @@ static int test_body(void)
 	ebb_freeze_pmcs();
 	ebb_global_disable();
 
-	count_pmc(4, sample_period);
+	write_pmc(4, pmc_sample_period(sample_period));
 	mtspr(SPRN_PMC4, 0xdead);
 
 	dump_summary_ebb_state();
tools/testing/selftests/powerpc/pmu/ebb/multi_counter_test.c +6 -6
index b8242e9d97d2..227827b665d5 100644
@@ -70,12 +70,12 @@ int multi_counter(void)
 	ebb_global_disable();
 	ebb_freeze_pmcs();
 
-	count_pmc(1, sample_period);
-	count_pmc(2, sample_period);
-	count_pmc(3, sample_period);
-	count_pmc(4, sample_period);
-	count_pmc(5, sample_period);
-	count_pmc(6, sample_period);
+	write_pmc(1, pmc_sample_period(sample_period));
+	write_pmc(2, pmc_sample_period(sample_period));
+	write_pmc(3, pmc_sample_period(sample_period));
+	write_pmc(4, pmc_sample_period(sample_period));
+	write_pmc(5, pmc_sample_period(sample_period));
+	write_pmc(6, pmc_sample_period(sample_period));
 
 	dump_ebb_state();
 
tools/testing/selftests/powerpc/pmu/ebb/multi_ebb_procs_test.c +1 -1
index a05c0e18ded6..ade70bed0499 100644
@@ -61,7 +61,7 @@ static int cycles_child(void)
 	ebb_global_disable();
 	ebb_freeze_pmcs();
 
-	count_pmc(1, sample_period);
+	write_pmc(1, pmc_sample_period(sample_period));
 
 	dump_summary_ebb_state();
 
tools/testing/selftests/powerpc/pmu/ebb/pmae_handling_test.c +1 -1
index 153ebc92234f..7b4bf4ed12cb 100644
@@ -82,7 +82,7 @@ static int test_body(void)
 	ebb_global_disable();
 	ebb_freeze_pmcs();
 
-	count_pmc(1, sample_period);
+	write_pmc(1, pmc_sample_period(sample_period));
 
 	dump_ebb_state();
 
tools/testing/selftests/powerpc/pmu/ebb/pmc56_overflow_test.c +1 -1
index eadad75ed7e6..bb55af71404d 100644
@@ -76,7 +76,7 @@ int pmc56_overflow(void)
 	ebb_global_disable();
 	ebb_freeze_pmcs();
 
-	count_pmc(2, sample_period);
+	write_pmc(2, pmc_sample_period(sample_period));
 
 	dump_ebb_state();
 
Signature · 1 line
2.21.1
#2 lore raw

Re: [PATCH, RESEND, 1/3] selftests/powerpc: Use write_pmc instead of count_pmc to reset PMCs on ebb tests

Quoted 23 lines · Desnes A. Nunes do Rosario

By using count_pmc() to reset PMCs instead of write_pmc(), an extra count
is performed on ebb_state.stats.pmc_count[PMC_INDEX(pmc)]. This extra pmc_count can occasionally invalidate results, such as the ones from cycles_test shown hereafter. The ebb_check_count() failed with an above
the upper limit error due to the extra ebb_state.stats.pmc_count.

Furthermore, this extra count is also indicated by extra PMC1 trace_log on
the output of the cycle test (as well as on pmc56_overflow_test):

==========
...
[21]: counter = 8
[22]: register SPRN_MMCR0 = 0x0000000080000080
[23]: register SPRN_PMC1 = 0x0000000080000004
[24]: counter = 9
[25]: register SPRN_MMCR0 = 0x0000000080000080
[26]: register SPRN_PMC1 = 0x0000000080000004
[27]: counter = 10
[28]: register SPRN_MMCR0 = 0x0000000080000080
[29]: register SPRN_PMC1 = 0x0000000080000004

Quoted 8 lines
Quoted 1 line
Quoted 1 line

[30]: register SPRN_PMC1 = 0x000000004000051e

PMC1 count (0x280000546) above upper limit 0x2800003e8 (+0x15e) [FAIL] Test FAILED on line 52
failure: cycles
==========

[desnesn: reflow of original comment]

Reviewed and Tested-by: Rashmica Gupta <[email protected]>

Quoted 198 lines
---
 .../powerpc/pmu/ebb/back_to_back_ebbs_test.c         |  2 +-
 .../testing/selftests/powerpc/pmu/ebb/cycles_test.c  |  2 +-
 .../powerpc/pmu/ebb/cycles_with_freeze_test.c        |  2 +-
 .../powerpc/pmu/ebb/cycles_with_mmcr2_test.c         |  2 +-
 tools/testing/selftests/powerpc/pmu/ebb/ebb.c        |  2 +-
 .../powerpc/pmu/ebb/ebb_on_willing_child_test.c      |  2 +-
 .../selftests/powerpc/pmu/ebb/lost_exception_test.c  |  2 +-
 .../selftests/powerpc/pmu/ebb/multi_counter_test.c   | 12 ++++++--
----
 .../selftests/powerpc/pmu/ebb/multi_ebb_procs_test.c |  2 +-
 .../selftests/powerpc/pmu/ebb/pmae_handling_test.c   |  2 +-
 .../selftests/powerpc/pmu/ebb/pmc56_overflow_test.c  |  2 +-
 11 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/tools/testing/selftests/powerpc/pmu/ebb/back_to_back_ebbs_test.c b/tools/testing/selftests/powerpc/pmu/ebb/back_to_back_ebbs_test.c index a2d7b0e3dca9..f133ab425f10 100644
---
a/tools/testing/selftests/powerpc/pmu/ebb/back_to_back_ebbs_test.c
+++
b/tools/testing/selftests/powerpc/pmu/ebb/back_to_back_ebbs_test.c

tools/testing/selftests/powerpc/pmu/ebb/back_to_back_ebbs_test.c +1 -1
@@ -91,7 +91,7 @@ int back_to_back_ebbs(void)
 	ebb_global_disable();
 	ebb_freeze_pmcs();
 
-	count_pmc(1, sample_period);
+	write_pmc(1, pmc_sample_period(sample_period));
 
 	dump_ebb_state();
 
tools/testing/selftests/powerpc/pmu/ebb/cycles_test.c +1 -1
index bc893813483e..14a399a64729 100644
@@ -42,7 +42,7 @@ int cycles(void)
 	ebb_global_disable();
 	ebb_freeze_pmcs();
 
-	count_pmc(1, sample_period);
+	write_pmc(1, pmc_sample_period(sample_period));
 
 	dump_ebb_state();
 

diff --git a/tools/testing/selftests/powerpc/pmu/ebb/cycles_with_freeze_test.c b/tools/testing/selftests/powerpc/pmu/ebb/cycles_with_freeze_test.c index dcd351d20328..0f2089f6f82c 100644
---
a/tools/testing/selftests/powerpc/pmu/ebb/cycles_with_freeze_test.c
+++
b/tools/testing/selftests/powerpc/pmu/ebb/cycles_with_freeze_test.c

tools/testing/selftests/powerpc/pmu/ebb/cycles_test.c +1 -1
@@ -99,7 +99,7 @@ int cycles_with_freeze(void)
 	ebb_global_disable();
 	ebb_freeze_pmcs();
 
-	count_pmc(1, sample_period);
+	write_pmc(1, pmc_sample_period(sample_period));
 
 	dump_ebb_state();
 

diff --git a/tools/testing/selftests/powerpc/pmu/ebb/cycles_with_mmcr2_test.c b/tools/testing/selftests/powerpc/pmu/ebb/cycles_with_mmcr2_test.c index 94c99c12c0f2..a8f3bee04cd8 100644
---
a/tools/testing/selftests/powerpc/pmu/ebb/cycles_with_mmcr2_test.c
+++
b/tools/testing/selftests/powerpc/pmu/ebb/cycles_with_mmcr2_test.c

tools/testing/selftests/powerpc/pmu/ebb/cycles_test.c +1 -1
@@ -71,7 +71,7 @@ int cycles_with_mmcr2(void)
 	ebb_global_disable();
 	ebb_freeze_pmcs();
 
-	count_pmc(1, sample_period);
+	write_pmc(1, pmc_sample_period(sample_period));
 
 	dump_ebb_state();
 
tools/testing/selftests/powerpc/pmu/ebb/ebb.c +1 -1
index dfbc5c3ad52d..bf6f25dfcf7b 100644
@@ -396,7 +396,7 @@ int ebb_child(union pipe read_pipe, union pipe
 write_pipe)
 	ebb_global_disable();
 	ebb_freeze_pmcs();
 
-	count_pmc(1, sample_period);
+	write_pmc(1, pmc_sample_period(sample_period));
 
 	dump_ebb_state();

diff --git a/tools/testing/selftests/powerpc/pmu/ebb/ebb_on_willing_child_test.c b/tools/testing/selftests/powerpc/pmu/ebb/ebb_on_willing_child_test.c index ca2f7d729155..513812cdcca1 100644
---
a/tools/testing/selftests/powerpc/pmu/ebb/ebb_on_willing_child_test.c
+++
b/tools/testing/selftests/powerpc/pmu/ebb/ebb_on_willing_child_test.c

tools/testing/selftests/powerpc/pmu/ebb/ebb.c +1 -1
@@ -38,7 +38,7 @@ static int victim_child(union pipe read_pipe, union
 pipe write_pipe)
 	ebb_global_disable();
 	ebb_freeze_pmcs();
 
-	count_pmc(1, sample_period);
+	write_pmc(1, pmc_sample_period(sample_period));
 
 	dump_ebb_state();

diff --git a/tools/testing/selftests/powerpc/pmu/ebb/lost_exception_test.c b/tools/testing/selftests/powerpc/pmu/ebb/lost_exception_test.c index ac3e6e182614..5979606c41dc 100644

tools/testing/selftests/powerpc/pmu/ebb/lost_exception_test.c +1 -1
@@ -75,7 +75,7 @@ static int test_body(void)
 	ebb_freeze_pmcs();
 	ebb_global_disable();
 
-	count_pmc(4, sample_period);
+	write_pmc(4, pmc_sample_period(sample_period));
 	mtspr(SPRN_PMC4, 0xdead);
 
 	dump_summary_ebb_state();

diff --git a/tools/testing/selftests/powerpc/pmu/ebb/multi_counter_test.c b/tools/testing/selftests/powerpc/pmu/ebb/multi_counter_test.c index b8242e9d97d2..227827b665d5 100644

tools/testing/selftests/powerpc/pmu/ebb/multi_counter_test.c +6 -6
@@ -70,12 +70,12 @@ int multi_counter(void)
 	ebb_global_disable();
 	ebb_freeze_pmcs();
 
-	count_pmc(1, sample_period);
-	count_pmc(2, sample_period);
-	count_pmc(3, sample_period);
-	count_pmc(4, sample_period);
-	count_pmc(5, sample_period);
-	count_pmc(6, sample_period);
+	write_pmc(1, pmc_sample_period(sample_period));
+	write_pmc(2, pmc_sample_period(sample_period));
+	write_pmc(3, pmc_sample_period(sample_period));
+	write_pmc(4, pmc_sample_period(sample_period));
+	write_pmc(5, pmc_sample_period(sample_period));
+	write_pmc(6, pmc_sample_period(sample_period));
 
 	dump_ebb_state();
 

diff --git a/tools/testing/selftests/powerpc/pmu/ebb/multi_ebb_procs_test.c b/tools/testing/selftests/powerpc/pmu/ebb/multi_ebb_procs_test.c index a05c0e18ded6..ade70bed0499 100644

tools/testing/selftests/powerpc/pmu/ebb/multi_ebb_procs_test.c +1 -1
@@ -61,7 +61,7 @@ static int cycles_child(void)
 	ebb_global_disable();
 	ebb_freeze_pmcs();
 
-	count_pmc(1, sample_period);
+	write_pmc(1, pmc_sample_period(sample_period));
 
 	dump_summary_ebb_state();
 

diff --git a/tools/testing/selftests/powerpc/pmu/ebb/pmae_handling_test.c b/tools/testing/selftests/powerpc/pmu/ebb/pmae_handling_test.c index 153ebc92234f..7b4bf4ed12cb 100644

tools/testing/selftests/powerpc/pmu/ebb/pmae_handling_test.c +1 -1
@@ -82,7 +82,7 @@ static int test_body(void)
 	ebb_global_disable();
 	ebb_freeze_pmcs();
 
-	count_pmc(1, sample_period);
+	write_pmc(1, pmc_sample_period(sample_period));
 
 	dump_ebb_state();
 

diff --git a/tools/testing/selftests/powerpc/pmu/ebb/pmc56_overflow_test.c b/tools/testing/selftests/powerpc/pmu/ebb/pmc56_overflow_test.c index eadad75ed7e6..bb55af71404d 100644

tools/testing/selftests/powerpc/pmu/ebb/pmc56_overflow_test.c +1 -1
@@ -76,7 +76,7 @@ int pmc56_overflow(void)
 	ebb_global_disable();
 	ebb_freeze_pmcs();
 
-	count_pmc(2, sample_period);
+	write_pmc(2, pmc_sample_period(sample_period));
 
 	dump_ebb_state();
 
#3 lore raw

PATCH RESEND 2/3 selftests/powerpc: enable performance alerts when freezing counters on cycles_with_freeze_test selftest

In reply to Desnes A. Nunes do Rosario

From: Gustavo Romero <[email protected]>

When disabling freezing counters by setting MMCR0 FC bit to 0, the MMCR0 PMAE bit must also be enabled if a Performance Monitor Alert (and the cor- responding Performance Monitor Interrupt) is still desired to be received when an enabled condition or event occurs.

This is the case of the cycles_with_freeze_test selftest, since the test disables the MMCR0 PMAE due to the usage of PMU to trigger EBBs. This can make the test loop up to the point of being killed by the test harness timeout (2500 ms), since no other ebb event will happen because the MMCR0 PMAE bit is disabled, and thus, no more increments to ebb_count occur.

Fixes 3752e453f6bafd7 ("selftests/powerpc: Add tests of PMU EBBs")
[desnesn: Only set MMCR0_PMAE when disabling MMCR0_FC, reflow comment]
---
 .../testing/selftests/powerpc/pmu/ebb/cycles_with_freeze_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/powerpc/pmu/ebb/cycles_with_freeze_test.c +1 -1
index 0f2089f6f82c..d368199144fb 100644
@@ -81,7 +81,7 @@ int cycles_with_freeze(void)
 	{
 		counters_frozen = false;
 		mb();
-		mtspr(SPRN_MMCR0, mfspr(SPRN_MMCR0) & ~MMCR0_FC);
+		mtspr(SPRN_MMCR0, (mfspr(SPRN_MMCR0) & ~MMCR0_FC) | MMCR0_PMAE);
 
 		FAIL_IF(core_busy_loop());
 
Signature · 1 line
2.21.1
#4 lore raw

Re: [PATCH, RESEND, 2/3] selftests/powerpc: enable performance alerts when freezing counters on cycles_with_freeze_test selftest

Quoted 21 lines · Desnes A. Nunes do Rosario

From: Gustavo Romero <[email protected]>

When disabling freezing counters by setting MMCR0 FC bit to 0, the MMCR0
PMAE bit must also be enabled if a Performance Monitor Alert (and the cor-
responding Performance Monitor Interrupt) is still desired to be received
when an enabled condition or event occurs.

This is the case of the cycles_with_freeze_test selftest, since the test
disables the MMCR0 PMAE due to the usage of PMU to trigger EBBs. This can
make the test loop up to the point of being killed by the test harness
timeout (2500 ms), since no other ebb event will happen because the MMCR0
PMAE bit is disabled, and thus, no more increments to ebb_count occur.

Quoted 5 lines
Fixes 3752e453f6bafd7 ("selftests/powerpc: Add tests of PMU EBBs")

[desnesn: Only set MMCR0_PMAE when disabling MMCR0_FC, reflow comment]

Reviewed and Tested-by: Rashmica Gupta <[email protected]>

Quoted 23 lines
---
 .../testing/selftests/powerpc/pmu/ebb/cycles_with_freeze_test.c | 2
+-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/powerpc/pmu/ebb/cycles_with_freeze_test.c b/tools/testing/selftests/powerpc/pmu/ebb/cycles_with_freeze_test.c index 0f2089f6f82c..d368199144fb 100644
---
a/tools/testing/selftests/powerpc/pmu/ebb/cycles_with_freeze_test.c
+++
b/tools/testing/selftests/powerpc/pmu/ebb/cycles_with_freeze_test.c

tools/testing/selftests/powerpc/pmu/ebb/cycles_with_freeze_test.c +1 -1
@@ -81,7 +81,7 @@ int cycles_with_freeze(void)
 	{
 		counters_frozen = false;
 		mb();
-		mtspr(SPRN_MMCR0, mfspr(SPRN_MMCR0) & ~MMCR0_FC);
+		mtspr(SPRN_MMCR0, (mfspr(SPRN_MMCR0) & ~MMCR0_FC) |
 MMCR0_PMAE);
 
 		FAIL_IF(core_busy_loop());
#5 lore raw

PATCH 3/3 selftests/powerpc: ensure PMC reads are set and ordered on count_pmc

In reply to Desnes A. Nunes do Rosario

Function count_pmc() needs a memory barrier to ensure that PMC reads are fully consistent. The lack of it can occasionally fail pmc56_overflow test, since depending on the workload on the system, PMC5 & 6 can have past val- ues from the time the counters are frozen and turned back on. These past values will be accounted as overflows and make the test fail.

=========
test: pmc56_overflow
...
ebb_state:
...

Quoted 2 lines
Quoted 2 lines

pmc[5] count = 0xfd4cbc8c
pmc[6] count = 0xddd8b3b6

HW state:
MMCR0 0x0000000084000000 FC PMAE
MMCR2 0x0000000000000000
EBBHR 0x0000000010003f68
BESCR 0x8000000000000000 GE
...

PMC5  0x0000000000000000
PMC6  0x0000000000000000
SIAR  0x0000000010003398
...
  [3]: register SPRN_PMC2  = 0x0000000080000003
  [4]: register SPRN_PMC5  = 0x0000000000000000
  [5]: register SPRN_PMC6  = 0x0000000000000000
  [6]: register SPRN_PMC2  = 0x0000000080000003
>>[7]: register SPRN_PMC5  = 0x000000008f21266d
>>[8]: register SPRN_PMC6  = 0x000000000da80f8d
  [9]: register SPRN_PMC2  = 0x0000000080000003
Quoted 2 lines
Quoted 2 lines

[10]: register SPRN_PMC5 = 0x000000006e2b961f [11]: register SPRN_PMC6 = 0x00000000d030a429

  [12]: register SPRN_PMC2  = 0x0000000080000003
  [13]: register SPRN_PMC5  = 0x0000000000000000
  [14]: register SPRN_PMC6  = 0x0000000000000000

...
PMC5/6 overflow 2
[FAIL] Test FAILED on line 87
failure: pmc56_overflow
=========

---
 tools/testing/selftests/powerpc/pmu/ebb/ebb.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/testing/selftests/powerpc/pmu/ebb/ebb.c +4 -0
index bf6f25dfcf7b..6199f3cea0f9 100644
@@ -258,6 +258,10 @@ int count_pmc(int pmc, uint32_t sample_period)
 	start_value = pmc_sample_period(sample_period);
 
 	val = read_pmc(pmc);
+
+	/* Ensure pmc value is consistent between freezes */
+	mb();
+
 	if (val < start_value)
 		ebb_state.stats.negative++;
 	else
Signature · 1 line
2.21.1
Reviewed-by on v1 3/3
#6 lore raw

Re: [PATCH 3/3] selftests/powerpc: ensure PMC reads are set and ordered on count_pmc

Quoted 39 lines · Desnes A. Nunes do Rosario

Function count_pmc() needs a memory barrier to ensure that PMC reads are
fully consistent. The lack of it can occasionally fail pmc56_overflow test,
since depending on the workload on the system, PMC5 & 6 can have past val-
ues from the time the counters are frozen and turned back on. These past
values will be accounted as overflows and make the test fail.

=========
test: pmc56_overflow
...
ebb_state:
...

Quoted 2 lines
Quoted 2 lines

pmc[5] count = 0xfd4cbc8c
pmc[6] count = 0xddd8b3b6

HW state:
MMCR0 0x0000000084000000 FC PMAE
MMCR2 0x0000000000000000
EBBHR 0x0000000010003f68
BESCR 0x8000000000000000 GE
...

PMC5  0x0000000000000000
PMC6  0x0000000000000000
SIAR  0x0000000010003398
...
  [3]: register SPRN_PMC2  = 0x0000000080000003
  [4]: register SPRN_PMC5  = 0x0000000000000000
  [5]: register SPRN_PMC6  = 0x0000000000000000
  [6]: register SPRN_PMC2  = 0x0000000080000003
Quoted 2 lines
Quoted 2 lines

[7]: register SPRN_PMC5 = 0x000000008f21266d [8]: register SPRN_PMC6 = 0x000000000da80f8d

[9]: register SPRN_PMC2 = 0x0000000080000003

Quoted 2 lines
Quoted 2 lines

[10]: register SPRN_PMC5 = 0x000000006e2b961f [11]: register SPRN_PMC6 = 0x00000000d030a429

  [12]: register SPRN_PMC2  = 0x0000000080000003
  [13]: register SPRN_PMC5  = 0x0000000000000000
  [14]: register SPRN_PMC6  = 0x0000000000000000
Quoted 7 lines

...
PMC5/6 overflow 2
[FAIL] Test FAILED on line 87
failure: pmc56_overflow
=========

Quoted 20 lines
---
 tools/testing/selftests/powerpc/pmu/ebb/ebb.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/testing/selftests/powerpc/pmu/ebb/ebb.c +4 -0
index bf6f25dfcf7b..6199f3cea0f9 100644
@@ -258,6 +258,10 @@ int count_pmc(int pmc, uint32_t sample_period)
 	start_value = pmc_sample_period(sample_period);
 
 	val = read_pmc(pmc);
+
+	/* Ensure pmc value is consistent between freezes */
+	mb();
+
 	if (val < start_value)
 		ebb_state.stats.negative++;
 	else