xref: /linux/tools/testing/selftests/powerpc/pmu/sampling_tests/mmcr3_src_test.c (revision cbdb1f163af2bb90d01be1f0263df1d8d5c9d9d3)
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 }
68