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 mmcr3_src fields

The testcase uses event code 0x1340000001c040 to verify the settings for
different src fields in Monitor Mode Control Register 3 (MMCR3). Checks
if these fields are translated correctly via perf interface to MMCR3 on
ISA v3.1 platform.

Signed-off-by: Kajol Jain <kjain@linux.ibm.com>
[mpe: Add error checking, drop GET_MMCR_FIELD, add to .gitignore]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20220127072012.662451-20-kjain@linux.ibm.com

authored by

Kajol Jain and committed by
Michael Ellerman
02f02feb 9ee241f1

+70 -1
+1
tools/testing/selftests/powerpc/pmu/sampling_tests/.gitignore
··· 7 7 mmcr1_comb_test 8 8 mmcr2_l2l3_test 9 9 mmcr2_fcs_fch_test 10 + mmcr3_src_test
+2 -1
tools/testing/selftests/powerpc/pmu/sampling_tests/Makefile
··· 3 3 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 - mmcr1_comb_test mmcr2_l2l3_test mmcr2_fcs_fch_test 6 + mmcr1_comb_test mmcr2_l2l3_test mmcr2_fcs_fch_test \ 7 + mmcr3_src_test 7 8 8 9 top_srcdir = ../../../../../.. 9 10 include ../../../lib.mk
+67
tools/testing/selftests/powerpc/pmu/sampling_tests/mmcr3_src_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_with_ll_sc(u64 loops, u64 *ll_sc_target); 14 + 15 + /* The data cache was reloaded from local core's L3 due to a demand load */ 16 + #define EventCode 0x1340000001c040 17 + 18 + /* 19 + * A perf sampling test for mmcr3 20 + * fields. 21 + */ 22 + static int mmcr3_src(void) 23 + { 24 + struct event event; 25 + u64 *intr_regs; 26 + u64 dummy; 27 + 28 + /* Check for platform support for the test */ 29 + SKIP_IF(check_pvr_for_sampling_tests()); 30 + SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_3_1)); 31 + 32 + /* Init the event for the sampling test */ 33 + event_init_sampling(&event, EventCode); 34 + event.attr.sample_regs_intr = platform_extended_mask; 35 + FAIL_IF(event_open(&event)); 36 + event.mmap_buffer = event_sample_buf_mmap(event.fd, 1); 37 + 38 + FAIL_IF(event_enable(&event)); 39 + 40 + /* workload to make event overflow */ 41 + thirty_two_instruction_loop_with_ll_sc(1000000, &dummy); 42 + 43 + FAIL_IF(event_disable(&event)); 44 + 45 + /* Check for sample count */ 46 + FAIL_IF(!collect_samples(event.mmap_buffer)); 47 + 48 + intr_regs = get_intr_regs(&event, event.mmap_buffer); 49 + 50 + /* Check for intr_regs */ 51 + FAIL_IF(!intr_regs); 52 + 53 + /* 54 + * Verify that src field of MMCR3 match with 55 + * corresponding event code field 56 + */ 57 + FAIL_IF(EV_CODE_EXTRACT(event.attr.config, mmcr3_src) != 58 + get_mmcr3_src(get_reg_value(intr_regs, "MMCR3"), 1)); 59 + 60 + event_close(&event); 61 + return 0; 62 + } 63 + 64 + int main(void) 65 + { 66 + return test_harness(mmcr3_src, "mmcr3_src"); 67 + }