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 bhrb disable field

The testcase uses "instructions" event to generate the
samples and fetch Monitor Mode Control Register A (MMCRA)
when overflow. Branch History Rolling Buffer(bhrb) disable bit
is part of MMCRA which need to be verified by perf interface.
Testcase checks if the bhrb disable bit of MMCRA register is
programmed correctly via perf interface for ISA v3.1 platform
Also make get_mmcra_ifm return type as u64.

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

authored by

Kajol Jain and committed by
Michael Ellerman
84cc4e66 014fb4a3

+69 -2
+2 -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 mmcra_bhrb_any_test mmcra_bhrb_cond_test 8 + mmcra_bhrb_ind_call_test mmcra_bhrb_any_test mmcra_bhrb_cond_test \ 9 + mmcra_bhrb_disable_test 9 10 10 11 top_srcdir = ../../../../../.. 11 12 include ../../../lib.mk
+1 -1
tools/testing/selftests/powerpc/pmu/sampling_tests/misc.h
··· 188 188 return ((mmcra >> 42) & 0x3); 189 189 } 190 190 191 - static inline int get_mmcra_bhrb_disable(u64 mmcra, int pmc) 191 + static inline u64 get_mmcra_bhrb_disable(u64 mmcra, int pmc) 192 192 { 193 193 if (pvr == POWER10) 194 194 return mmcra & BHRB_DISABLE;
+66
tools/testing/selftests/powerpc/pmu/sampling_tests/mmcra_bhrb_disable_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 + /* 19 + * A perf sampling test for mmcra 20 + * field: bhrb_disable. 21 + */ 22 + static int mmcra_bhrb_disable_test(void) 23 + { 24 + struct event event; 25 + u64 *intr_regs; 26 + 27 + /* 28 + * Check for platform support for the test. 29 + * This test is only aplicable on power10 30 + */ 31 + SKIP_IF(check_pvr_for_sampling_tests()); 32 + SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_3_1)); 33 + 34 + /* Init the event for the sampling test */ 35 + event_init_sampling(&event, EventCode); 36 + event.attr.sample_regs_intr = platform_extended_mask; 37 + event.attr.sample_type |= PERF_SAMPLE_BRANCH_STACK; 38 + event.attr.branch_sample_type = PERF_SAMPLE_BRANCH_ANY; 39 + event.attr.exclude_kernel = 1; 40 + 41 + FAIL_IF(event_open(&event)); 42 + event.mmap_buffer = event_sample_buf_mmap(event.fd, 1); 43 + 44 + FAIL_IF(event_enable(&event)); 45 + 46 + /* workload to make the event overflow */ 47 + thirty_two_instruction_loop(10000); 48 + 49 + FAIL_IF(event_disable(&event)); 50 + 51 + intr_regs = get_intr_regs(&event, event.mmap_buffer); 52 + 53 + /* Check for intr_regs */ 54 + FAIL_IF(!intr_regs); 55 + 56 + /* Verify that bhrb_disable bit is set in MMCRA */ 57 + FAIL_IF(get_mmcra_bhrb_disable(get_reg_value(intr_regs, "MMCRA"), 5)); 58 + 59 + event_close(&event); 60 + return 0; 61 + } 62 + 63 + int main(void) 64 + { 65 + return test_harness(mmcra_bhrb_disable_test, "mmcra_bhrb_disable_test"); 66 + }