selftests/powerpc/pmu: Add selftest for PERF_TYPE_HARDWARE events valid check

Testcase to ensure that using invalid event in generic event for
PERF_TYPE_HARDWARE will fail. Invalid generic events in power10 are:
- PERF_COUNT_HW_BUS_CYCLES
- PERF_COUNT_HW_STALLED_CYCLES_FRONTEND
- PERF_COUNT_HW_STALLED_CYCLES_BACKEND
- PERF_COUNT_HW_REF_CPU_CYCLES

Invalid generic events in power9 are:
- PERF_COUNT_HW_BUS_CYCLES
- PERF_COUNT_HW_REF_CPU_CYCLES

Testcase does event open for valid and invalid generic events to ensure
event open works for all valid events and fails for invalid events.

Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20220610134113.62991-29-atrajeev@linux.vnet.ibm.com
This commit is contained in:
Athira Rajeev 2022-06-10 19:11:06 +05:30 committed by Michael Ellerman
parent 3f1a87425f
commit 8efeedf5aa
2 changed files with 131 additions and 1 deletions

View File

@ -4,7 +4,7 @@ CFLAGS += -m64
TEST_GEN_PROGS := group_constraint_pmc56_test group_pmc56_exclude_constraints_test group_constraint_pmc_count_test \
group_constraint_repeat_test group_constraint_radix_scope_qual_test reserved_bits_mmcra_sample_elig_mode_test \
group_constraint_mmcra_sample_test invalid_event_code_test reserved_bits_mmcra_thresh_ctl_test \
blacklisted_events_test event_alternatives_tests_p9 event_alternatives_tests_p10
blacklisted_events_test event_alternatives_tests_p9 event_alternatives_tests_p10 generic_events_valid_test
top_srcdir = ../../../../../..
include ../../../lib.mk

View File

@ -0,0 +1,130 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright 2022, Athira Rajeev, IBM Corp.
*/
#include <stdio.h>
#include <sys/prctl.h>
#include <limits.h>
#include "../event.h"
#include "../sampling_tests/misc.h"
/*
* Testcase to ensure that using invalid event in generic
* event for PERF_TYPE_HARDWARE should fail
*/
static int generic_events_valid_test(void)
{
struct event event;
/* Check for platform support for the test */
SKIP_IF(platform_check_for_tests());
/* generic events is different in compat_mode */
SKIP_IF(check_for_generic_compat_pmu());
/*
* Invalid generic events in power10:
* - PERF_COUNT_HW_BUS_CYCLES
* - PERF_COUNT_HW_STALLED_CYCLES_FRONTEND
* - PERF_COUNT_HW_STALLED_CYCLES_BACKEND
* - PERF_COUNT_HW_REF_CPU_CYCLES
*/
if (PVR_VER(mfspr(SPRN_PVR)) == POWER10) {
event_init_opts(&event, PERF_COUNT_HW_CPU_CYCLES, PERF_TYPE_HARDWARE, "event");
FAIL_IF(event_open(&event));
event_close(&event);
event_init_opts(&event, PERF_COUNT_HW_INSTRUCTIONS,
PERF_TYPE_HARDWARE, "event");
FAIL_IF(event_open(&event));
event_close(&event);
event_init_opts(&event, PERF_COUNT_HW_CACHE_REFERENCES,
PERF_TYPE_HARDWARE, "event");
FAIL_IF(event_open(&event));
event_close(&event);
event_init_opts(&event, PERF_COUNT_HW_CACHE_MISSES, PERF_TYPE_HARDWARE, "event");
FAIL_IF(event_open(&event));
event_close(&event);
event_init_opts(&event, PERF_COUNT_HW_BRANCH_INSTRUCTIONS,
PERF_TYPE_HARDWARE, "event");
FAIL_IF(event_open(&event));
event_close(&event);
event_init_opts(&event, PERF_COUNT_HW_BRANCH_MISSES, PERF_TYPE_HARDWARE, "event");
FAIL_IF(event_open(&event));
event_close(&event);
event_init_opts(&event, PERF_COUNT_HW_BUS_CYCLES, PERF_TYPE_HARDWARE, "event");
FAIL_IF(!event_open(&event));
event_init_opts(&event, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND,
PERF_TYPE_HARDWARE, "event");
FAIL_IF(!event_open(&event));
event_init_opts(&event, PERF_COUNT_HW_STALLED_CYCLES_BACKEND,
PERF_TYPE_HARDWARE, "event");
FAIL_IF(!event_open(&event));
event_init_opts(&event, PERF_COUNT_HW_REF_CPU_CYCLES, PERF_TYPE_HARDWARE, "event");
FAIL_IF(!event_open(&event));
} else if (PVR_VER(mfspr(SPRN_PVR)) == POWER9) {
/*
* Invalid generic events in power9:
* - PERF_COUNT_HW_BUS_CYCLES
* - PERF_COUNT_HW_REF_CPU_CYCLES
*/
event_init_opts(&event, PERF_COUNT_HW_CPU_CYCLES, PERF_TYPE_HARDWARE, "event");
FAIL_IF(event_open(&event));
event_close(&event);
event_init_opts(&event, PERF_COUNT_HW_INSTRUCTIONS, PERF_TYPE_HARDWARE, "event");
FAIL_IF(event_open(&event));
event_close(&event);
event_init_opts(&event, PERF_COUNT_HW_CACHE_REFERENCES,
PERF_TYPE_HARDWARE, "event");
FAIL_IF(event_open(&event));
event_close(&event);
event_init_opts(&event, PERF_COUNT_HW_CACHE_MISSES, PERF_TYPE_HARDWARE, "event");
FAIL_IF(event_open(&event));
event_close(&event);
event_init_opts(&event, PERF_COUNT_HW_BRANCH_INSTRUCTIONS,
PERF_TYPE_HARDWARE, "event");
FAIL_IF(event_open(&event));
event_close(&event);
event_init_opts(&event, PERF_COUNT_HW_BRANCH_MISSES, PERF_TYPE_HARDWARE, "event");
FAIL_IF(event_open(&event));
event_close(&event);
event_init_opts(&event, PERF_COUNT_HW_BUS_CYCLES, PERF_TYPE_HARDWARE, "event");
FAIL_IF(!event_open(&event));
event_init_opts(&event, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND,
PERF_TYPE_HARDWARE, "event");
FAIL_IF(event_open(&event));
event_close(&event);
event_init_opts(&event, PERF_COUNT_HW_STALLED_CYCLES_BACKEND,
PERF_TYPE_HARDWARE, "event");
FAIL_IF(event_open(&event));
event_close(&event);
event_init_opts(&event, PERF_COUNT_HW_REF_CPU_CYCLES, PERF_TYPE_HARDWARE, "event");
FAIL_IF(!event_open(&event));
}
return 0;
}
int main(void)
{
return test_harness(generic_events_valid_test, "generic_events_valid_test");
}