Skip to content

Commit

Permalink
selftests/powerpc/pmu: Add selftest for PERF_TYPE_HARDWARE events val…
Browse files Browse the repository at this point in the history
…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
athira-rajeev authored and mpe committed Jun 28, 2022
1 parent 3f1a874 commit 8efeedf
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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");
}

0 comments on commit 8efeedf

Please sign in to comment.