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

selftests/powerpc/pmu: Add interface test for mmcra_ifm field of indirect call type

The testcase uses "instructions" event to check if the
Instruction filtering mode(IFM) bits are programmed correctly
for indirect branch type. Testcase checks if IFM bits are
programmed correctly to Monitor Mode Control Register A (MMCRA)
via perf interface for ISA v3.1 platform.

Signed-off-by: Kajol Jain <kjain@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20220610134113.62991-6-atrajeev@linux.vnet.ibm.com

authored by

Kajol Jain and committed by
Michael Ellerman
c55dabc6 61d89900

+100 -2
+28
tools/testing/selftests/powerpc/pmu/branch_loops.S
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + /* 3 + * Copyright 2022, Kajol Jain, IBM Corp. 4 + */ 5 + 6 + #include <ppc-asm.h> 7 + 8 + .text 9 + 10 + #define ITER_SHIFT 31 11 + 12 + FUNC_START(indirect_branch_loop) 13 + li r3, 1 14 + sldi r3, r3, ITER_SHIFT 15 + 16 + 1: cmpdi r3, 0 17 + beqlr 18 + 19 + addi r3, r3, -1 20 + 21 + ld r4, 2f@got(%r2) 22 + mtctr r4 23 + bctr 24 + 25 + .balign 32 26 + 2: b 1b 27 + 28 + FUNC_END(indirect_branch_loop)
+3 -2
tools/testing/selftests/powerpc/pmu/sampling_tests/Makefile
··· 4 4 TEST_GEN_PROGS := mmcr0_exceptionbits_test mmcr0_cc56run_test mmcr0_pmccext_test \ 5 5 mmcr0_pmcjce_test mmcr0_fc56_pmc1ce_test mmcr0_fc56_pmc56_test \ 6 6 mmcr1_comb_test mmcr2_l2l3_test mmcr2_fcs_fch_test \ 7 - mmcr3_src_test mmcra_thresh_marked_sample_test mmcra_thresh_cmp_test 7 + mmcr3_src_test mmcra_thresh_marked_sample_test mmcra_thresh_cmp_test \ 8 + mmcra_bhrb_ind_call_test 8 9 9 10 top_srcdir = ../../../../../.. 10 11 include ../../../lib.mk 11 12 12 - $(TEST_GEN_PROGS): ../../harness.c ../../utils.c ../event.c ../lib.c misc.c misc.h ../loop.S 13 + $(TEST_GEN_PROGS): ../../harness.c ../../utils.c ../event.c ../lib.c misc.c misc.h ../loop.S ../branch_loops.S
+69
tools/testing/selftests/powerpc/pmu/sampling_tests/mmcra_bhrb_ind_call_test.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Copyright 2022, Kajol Jain, IBM Corp. 4 + */ 5 + 6 + #include <stdio.h> 7 + #include <stdlib.h> 8 + 9 + #include "../event.h" 10 + #include "misc.h" 11 + #include "utils.h" 12 + 13 + extern void indirect_branch_loop(void); 14 + 15 + /* Instructions */ 16 + #define EventCode 0x500fa 17 + 18 + /* ifm field for indirect branch mode */ 19 + #define IFM_IND_BRANCH 0x2 20 + 21 + /* 22 + * A perf sampling test for mmcra 23 + * field: ifm for bhrb ind_call. 24 + */ 25 + static int mmcra_bhrb_ind_call_test(void) 26 + { 27 + struct event event; 28 + u64 *intr_regs; 29 + 30 + /* 31 + * Check for platform support for the test. 32 + * This test is only aplicable on power10 33 + */ 34 + SKIP_IF(check_pvr_for_sampling_tests()); 35 + SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_3_1)); 36 + 37 + /* Init the event for the sampling test */ 38 + event_init_sampling(&event, EventCode); 39 + event.attr.sample_regs_intr = platform_extended_mask; 40 + event.attr.sample_type |= PERF_SAMPLE_BRANCH_STACK; 41 + event.attr.branch_sample_type = PERF_SAMPLE_BRANCH_IND_CALL; 42 + event.attr.exclude_kernel = 1; 43 + 44 + FAIL_IF(event_open(&event)); 45 + event.mmap_buffer = event_sample_buf_mmap(event.fd, 1); 46 + 47 + FAIL_IF(event_enable(&event)); 48 + 49 + /* workload to make the event overflow */ 50 + indirect_branch_loop(); 51 + 52 + FAIL_IF(event_disable(&event)); 53 + 54 + intr_regs = get_intr_regs(&event, event.mmap_buffer); 55 + 56 + /* Check for intr_regs */ 57 + FAIL_IF(!intr_regs); 58 + 59 + /* Verify that ifm bit is set properly in MMCRA */ 60 + FAIL_IF(get_mmcra_ifm(get_reg_value(intr_regs, "MMCRA"), 5) != IFM_IND_BRANCH); 61 + 62 + event_close(&event); 63 + return 0; 64 + } 65 + 66 + int main(void) 67 + { 68 + return test_harness(mmcra_bhrb_ind_call_test, "mmcra_bhrb_ind_call_test"); 69 + }