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
20extern void thirty_two_instruction_loop_with_ll_sc(u64 loops, u64 *ll_sc_target);
21
22/* A perf sampling test to test mmcra fields */
23static 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(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 the 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 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(mmcra: get_reg_value(intr_regs, register_name: "MMCRA"), pmc: 4));
60 FAIL_IF(EV_CODE_EXTRACT(event.attr.config, thd_start) !=
61 get_mmcra_thd_start(mmcra: get_reg_value(intr_regs, register_name: "MMCRA"), pmc: 4));
62 FAIL_IF(EV_CODE_EXTRACT(event.attr.config, thd_stop) !=
63 get_mmcra_thd_stop(mmcra: get_reg_value(intr_regs, register_name: "MMCRA"), pmc: 4));
64 FAIL_IF(EV_CODE_EXTRACT(event.attr.config, marked) !=
65 get_mmcra_marked(mmcra: get_reg_value(intr_regs, register_name: "MMCRA"), pmc: 4));
66 FAIL_IF((EV_CODE_EXTRACT(event.attr.config, sample) >> 2) !=
67 get_mmcra_rand_samp_elig(mmcra: get_reg_value(intr_regs, register_name: "MMCRA"), pmc: 4));
68 FAIL_IF((EV_CODE_EXTRACT(event.attr.config, sample) & 0x3) !=
69 get_mmcra_sample_mode(mmcra: get_reg_value(intr_regs, register_name: "MMCRA"), pmc: 4));
70 FAIL_IF(EV_CODE_EXTRACT(event.attr.config, sm) !=
71 get_mmcra_sm(mmcra: get_reg_value(intr_regs, register_name: "MMCRA"), pmc: 4));
72
73 event_close(e: &event);
74 return 0;
75}
76
77int main(void)
78{
79 return test_harness(mmcra_thresh_marked_sample, "mmcra_thresh_marked_sample");
80}
81

source code of linux/tools/testing/selftests/powerpc/pmu/sampling_tests/mmcra_thresh_marked_sample_test.c