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 p9_EventCode 0x13E35340401e0
19 #define p10_EventCode 0x35340401e0
20
21 extern void thirty_two_instruction_loop_with_ll_sc(u64 loops, u64 *ll_sc_target);
22
23 /* A perf sampling test to test mmcra fields */
mmcra_thresh_cmp(void)24 static int mmcra_thresh_cmp(void)
25 {
26 struct event event;
27 u64 *intr_regs;
28 u64 dummy;
29
30 /* Check for platform support for the test */
31 SKIP_IF(check_pvr_for_sampling_tests());
32
33 /* Skip for comapt mode */
34 SKIP_IF(check_for_compat_mode());
35
36 /* Init the event for the sampling test */
37 if (!have_hwcap2(PPC_FEATURE2_ARCH_3_1)) {
38 event_init_sampling(&event, p9_EventCode);
39 } else {
40 event_init_sampling(&event, p10_EventCode);
41 event.attr.config1 = 1000;
42 }
43
44 event.attr.sample_regs_intr = platform_extended_mask;
45 FAIL_IF(event_open(&event));
46 event.mmap_buffer = event_sample_buf_mmap(event.fd, 1);
47
48 FAIL_IF(event_enable(&event));
49
50 /* workload to make the event overflow */
51 thirty_two_instruction_loop_with_ll_sc(1000000, &dummy);
52
53 FAIL_IF(event_disable(&event));
54
55 /* Check for sample count */
56 FAIL_IF(!collect_samples(event.mmap_buffer));
57
58 intr_regs = get_intr_regs(&event, event.mmap_buffer);
59
60 /* Check for intr_regs */
61 FAIL_IF(!intr_regs);
62
63 /* Verify that thresh cmp match with the corresponding event code fields */
64 FAIL_IF(get_thresh_cmp_val(event) !=
65 get_mmcra_thd_cmp(get_reg_value(intr_regs, "MMCRA"), 4));
66
67 event_close(&event);
68 return 0;
69 }
70
main(void)71 int main(void)
72 {
73 FAIL_IF(test_harness(mmcra_thresh_cmp, "mmcra_thresh_cmp"));
74 }
75