Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/powerpc/pmu: Add selftest for group constraint for MMCRA Sampling Mode field

Testcase for reserved bits in Monitor Mode Control Register A (MMCRA)
Random Sampling Mode (SM) value. As per Instruction Set
Architecture (ISA), the values 0x5, 0x9, 0xD, 0x19, 0x1D, 0x1A, 0x1E are
reserved for sampling mode field. Test that having these reserved bit
values should cause event_open to fail. Input event code in testcases
uses these sampling bits along with 401e0 (PM_MRK_INST_CMPL).

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-22-atrajeev@linux.vnet.ibm.com

authored by

Athira Rajeev and committed by
Michael Ellerman
beebeecb dc431be3

+78 -1
+1 -1
tools/testing/selftests/powerpc/pmu/event_code_tests/Makefile
··· 2 2 CFLAGS += -m64 3 3 4 4 TEST_GEN_PROGS := group_constraint_pmc56_test group_pmc56_exclude_constraints_test group_constraint_pmc_count_test \ 5 - group_constraint_repeat_test group_constraint_radix_scope_qual_test 5 + group_constraint_repeat_test group_constraint_radix_scope_qual_test reserved_bits_mmcra_sample_elig_mode_test 6 6 7 7 top_srcdir = ../../../../../.. 8 8 include ../../../lib.mk
+77
tools/testing/selftests/powerpc/pmu/event_code_tests/reserved_bits_mmcra_sample_elig_mode_test.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Copyright 2022, Athira Rajeev, IBM Corp. 4 + */ 5 + 6 + #include <stdio.h> 7 + #include "../event.h" 8 + #include "../sampling_tests/misc.h" 9 + 10 + /* 11 + * Testcase for reserved bits in Monitor Mode Control 12 + * Register A (MMCRA) Random Sampling Mode (SM) value. 13 + * As per Instruction Set Architecture (ISA), the values 14 + * 0x5, 0x9, 0xD, 0x19, 0x1D, 0x1A, 0x1E are reserved 15 + * for sampling mode field. Test that having these reserved 16 + * bit values should cause event_open to fail. 17 + * Input event code uses these sampling bits along with 18 + * 401e0 (PM_MRK_INST_CMPL). 19 + */ 20 + 21 + static int reserved_bits_mmcra_sample_elig_mode(void) 22 + { 23 + struct event event; 24 + 25 + /* Check for platform support for the test */ 26 + SKIP_IF(platform_check_for_tests()); 27 + 28 + /* Skip for Generic compat PMU */ 29 + SKIP_IF(check_for_generic_compat_pmu()); 30 + 31 + /* 32 + * MMCRA Random Sampling Mode (SM) values: 0x5 33 + * 0x9, 0xD, 0x19, 0x1D, 0x1A, 0x1E is reserved. 34 + * Expected to fail when using these reserved values. 35 + */ 36 + event_init(&event, 0x50401e0); 37 + FAIL_IF(!event_open(&event)); 38 + 39 + event_init(&event, 0x90401e0); 40 + FAIL_IF(!event_open(&event)); 41 + 42 + event_init(&event, 0xD0401e0); 43 + FAIL_IF(!event_open(&event)); 44 + 45 + event_init(&event, 0x190401e0); 46 + FAIL_IF(!event_open(&event)); 47 + 48 + event_init(&event, 0x1D0401e0); 49 + FAIL_IF(!event_open(&event)); 50 + 51 + event_init(&event, 0x1A0401e0); 52 + FAIL_IF(!event_open(&event)); 53 + 54 + event_init(&event, 0x1E0401e0); 55 + FAIL_IF(!event_open(&event)); 56 + 57 + /* 58 + * MMCRA Random Sampling Mode (SM) value 0x10 59 + * is reserved in power10 and 0xC is reserved in 60 + * power9. 61 + */ 62 + if (PVR_VER(mfspr(SPRN_PVR)) == POWER10) { 63 + event_init(&event, 0x100401e0); 64 + FAIL_IF(!event_open(&event)); 65 + } else if (PVR_VER(mfspr(SPRN_PVR)) == POWER9) { 66 + event_init(&event, 0xC0401e0); 67 + FAIL_IF(!event_open(&event)); 68 + } 69 + 70 + return 0; 71 + } 72 + 73 + int main(void) 74 + { 75 + return test_harness(reserved_bits_mmcra_sample_elig_mode, 76 + "reserved_bits_mmcra_sample_elig_mode"); 77 + }