1
0
Fork 0
mirror of synced 2025-03-06 20:59:54 +01:00
linux/tools/testing/selftests/powerpc/pmu/ebb/pmc56_overflow_test.c
Desnes A. Nunes do Rosario 3337bf41e0 selftests/powerpc: Purge extra count_pmc() calls of ebb selftests
An extra count on ebb_state.stats.pmc_count[PMC_INDEX(pmc)] is being per-
formed when count_pmc() is used to reset PMCs on a few selftests. 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 value on 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
>> [30]: register SPRN_PMC1  = 0x000000004000051e
PMC1 count (0x280000546) above upper limit 0x2800003e8 (+0x15e)
[FAIL] Test FAILED on line 52
failure: cycles
==========

Signed-off-by: Desnes A. Nunes do Rosario <desnesn@linux.ibm.com>
Tested-by: Sachin Sant <sachinp@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20200626164737.21943-1-desnesn@linux.ibm.com
2020-07-08 22:09:31 +10:00

93 lines
1.6 KiB
C

// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright 2014, Michael Ellerman, IBM Corp.
*/
#include <stdio.h>
#include <stdlib.h>
#include "ebb.h"
/*
* Test that PMC5 & 6 are frozen (ie. don't overflow) when they are not being
* used. Tests the MMCR0_FC56 logic in the kernel.
*/
static int pmc56_overflowed;
static void ebb_callee(void)
{
uint64_t val;
val = mfspr(SPRN_BESCR);
if (!(val & BESCR_PMEO)) {
ebb_state.stats.spurious++;
goto out;
}
ebb_state.stats.ebb_count++;
count_pmc(2, sample_period);
val = mfspr(SPRN_PMC5);
if (val >= COUNTER_OVERFLOW)
pmc56_overflowed++;
count_pmc(5, COUNTER_OVERFLOW);
val = mfspr(SPRN_PMC6);
if (val >= COUNTER_OVERFLOW)
pmc56_overflowed++;
count_pmc(6, COUNTER_OVERFLOW);
out:
reset_ebb();
}
int pmc56_overflow(void)
{
struct event event;
SKIP_IF(!ebb_is_supported());
/* Use PMC2 so we set PMCjCE, which enables PMC5/6 */
event_init(&event, 0x2001e);
event_leader_ebb_init(&event);
event.attr.exclude_kernel = 1;
event.attr.exclude_hv = 1;
event.attr.exclude_idle = 1;
FAIL_IF(event_open(&event));
setup_ebb_handler(ebb_callee);
ebb_global_enable();
FAIL_IF(ebb_event_enable(&event));
mtspr(SPRN_PMC2, pmc_sample_period(sample_period));
mtspr(SPRN_PMC5, 0);
mtspr(SPRN_PMC6, 0);
while (ebb_state.stats.ebb_count < 10)
FAIL_IF(core_busy_loop());
ebb_global_disable();
ebb_freeze_pmcs();
dump_ebb_state();
printf("PMC5/6 overflow %d\n", pmc56_overflowed);
event_close(&event);
FAIL_IF(ebb_state.stats.ebb_count == 0 || pmc56_overflowed != 0);
return 0;
}
int main(void)
{
return test_harness(pmc56_overflow, "pmc56_overflow");
}