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(e: &event, EventCode); |
34 | event.attr.sample_regs_intr = platform_extended_mask; |
35 | FAIL_IF(event_open(e: &event)); |
36 | event.mmap_buffer = event_sample_buf_mmap(fd: event.fd, mmap_pages: 1); |
37 | |
38 | FAIL_IF(event_enable(e: &event)); |
39 | |
40 | /* workload to make event overflow */ |
41 | thirty_two_instruction_loop_with_ll_sc(loops: 1000000, ll_sc_target: &dummy); |
42 | |
43 | FAIL_IF(event_disable(e: &event)); |
44 | |
45 | /* Check for sample count */ |
46 | FAIL_IF(!collect_samples(sample_buff: event.mmap_buffer)); |
47 | |
48 | intr_regs = get_intr_regs(event: &event, sample_buff: 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(mmcr3: get_reg_value(intr_regs, register_name: "MMCR3" ), pmc: 1)); |
59 | |
60 | event_close(e: &event); |
61 | return 0; |
62 | } |
63 | |
64 | int main(void) |
65 | { |
66 | return test_harness(mmcr3_src, "mmcr3_src" ); |
67 | } |
68 | |