forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
selftests/powerpc/pmu: Add selftest for PERF_TYPE_HARDWARE events val…
…id 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 <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
- Loading branch information
1 parent
3f1a874
commit 8efeedf
Showing
2 changed files
with
131 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
tools/testing/selftests/powerpc/pmu/event_code_tests/generic_events_valid_test.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} |