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 for any branch type

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

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

authored by

Kajol Jain and committed by
Michael Ellerman
faa64ddc c55dabc6

+66 -1
+1 -1
tools/testing/selftests/powerpc/pmu/sampling_tests/Makefile
··· 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 7 mmcr3_src_test mmcra_thresh_marked_sample_test mmcra_thresh_cmp_test \ 8 - mmcra_bhrb_ind_call_test 8 + mmcra_bhrb_ind_call_test mmcra_bhrb_any_test 9 9 10 10 top_srcdir = ../../../../../.. 11 11 include ../../../lib.mk
+65
tools/testing/selftests/powerpc/pmu/sampling_tests/mmcra_bhrb_any_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 thirty_two_instruction_loop(int loops); 14 + 15 + /* Instructions */ 16 + #define EventCode 0x500fa 17 + 18 + /* ifm field for any branch mode */ 19 + #define IFM_ANY_BRANCH 0x0 20 + 21 + /* 22 + * A perf sampling test for mmcra 23 + * field: ifm for bhrb any call. 24 + */ 25 + static int mmcra_bhrb_any_test(void) 26 + { 27 + struct event event; 28 + u64 *intr_regs; 29 + 30 + /* Check for platform support for the test */ 31 + SKIP_IF(check_pvr_for_sampling_tests()); 32 + 33 + /* Init the event for the sampling test */ 34 + event_init_sampling(&event, EventCode); 35 + event.attr.sample_regs_intr = platform_extended_mask; 36 + event.attr.sample_type |= PERF_SAMPLE_BRANCH_STACK; 37 + event.attr.branch_sample_type = PERF_SAMPLE_BRANCH_ANY; 38 + event.attr.exclude_kernel = 1; 39 + 40 + FAIL_IF(event_open(&event)); 41 + event.mmap_buffer = event_sample_buf_mmap(event.fd, 1); 42 + 43 + FAIL_IF(event_enable(&event)); 44 + 45 + /* workload to make the event overflow */ 46 + thirty_two_instruction_loop(10000); 47 + 48 + FAIL_IF(event_disable(&event)); 49 + 50 + intr_regs = get_intr_regs(&event, event.mmap_buffer); 51 + 52 + /* Check for intr_regs */ 53 + FAIL_IF(!intr_regs); 54 + 55 + /* Verify that ifm bit is set properly in MMCRA */ 56 + FAIL_IF(get_mmcra_ifm(get_reg_value(intr_regs, "MMCRA"), 5) != IFM_ANY_BRANCH); 57 + 58 + event_close(&event); 59 + return 0; 60 + } 61 + 62 + int main(void) 63 + { 64 + return test_harness(mmcra_bhrb_any_test, "mmcra_bhrb_any_test"); 65 + }