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

The testcase uses event code 0x35340401e0 to verify the settings for
different fields in Monitor Mode Control Register A (MMCRA). The fields
include thresh_start, thresh_stop thresh_select, sdar mode, sample and
marked bit. Checks if these fields are translated correctly via perf
interface to MMCRA.

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-21-kjain@linux.ibm.com

authored by

Kajol Jain and committed by
Michael Ellerman
29cf373c 02f02feb

+82 -1
+1
tools/testing/selftests/powerpc/pmu/sampling_tests/.gitignore
··· 8 8 mmcr2_l2l3_test 9 9 mmcr2_fcs_fch_test 10 10 mmcr3_src_test 11 + mmcra_thresh_marked_sample_test
+1 -1
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 7 + mmcr3_src_test mmcra_thresh_marked_sample_test 8 8 9 9 top_srcdir = ../../../../../.. 10 10 include ../../../lib.mk
+80
tools/testing/selftests/powerpc/pmu/sampling_tests/mmcra_thresh_marked_sample_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 + /* 14 + * Primary PMU event used here is PM_MRK_INST_CMPL (0x401e0) 15 + * Threshold event selection used is issue to complete for cycles 16 + * Sampling criteria is Load only sampling 17 + */ 18 + #define EventCode 0x35340401e0 19 + 20 + extern void thirty_two_instruction_loop_with_ll_sc(u64 loops, u64 *ll_sc_target); 21 + 22 + /* A perf sampling test to test mmcra fields */ 23 + static int mmcra_thresh_marked_sample(void) 24 + { 25 + struct event event; 26 + u64 *intr_regs; 27 + u64 dummy; 28 + 29 + /* Check for platform support for the test */ 30 + SKIP_IF(check_pvr_for_sampling_tests()); 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 the 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 thresh sel/start/stop, marked, random sample 55 + * eligibility, sdar mode and sample mode fields match with 56 + * the corresponding event code fields 57 + */ 58 + FAIL_IF(EV_CODE_EXTRACT(event.attr.config, thd_sel) != 59 + get_mmcra_thd_sel(get_reg_value(intr_regs, "MMCRA"), 4)); 60 + FAIL_IF(EV_CODE_EXTRACT(event.attr.config, thd_start) != 61 + get_mmcra_thd_start(get_reg_value(intr_regs, "MMCRA"), 4)); 62 + FAIL_IF(EV_CODE_EXTRACT(event.attr.config, thd_stop) != 63 + get_mmcra_thd_stop(get_reg_value(intr_regs, "MMCRA"), 4)); 64 + FAIL_IF(EV_CODE_EXTRACT(event.attr.config, marked) != 65 + get_mmcra_marked(get_reg_value(intr_regs, "MMCRA"), 4)); 66 + FAIL_IF(EV_CODE_EXTRACT(event.attr.config, sample >> 2) != 67 + get_mmcra_rand_samp_elig(get_reg_value(intr_regs, "MMCRA"), 4)); 68 + FAIL_IF(EV_CODE_EXTRACT(event.attr.config, sample & 0x3) != 69 + get_mmcra_sample_mode(get_reg_value(intr_regs, "MMCRA"), 4)); 70 + FAIL_IF(EV_CODE_EXTRACT(event.attr.config, sm) != 71 + get_mmcra_sm(get_reg_value(intr_regs, "MMCRA"), 4)); 72 + 73 + event_close(&event); 74 + return 0; 75 + } 76 + 77 + int main(void) 78 + { 79 + return test_harness(mmcra_thresh_marked_sample, "mmcra_thresh_marked_sample"); 80 + }