1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Copyright 2022, Athira Rajeev, 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/* All successful D-side store dispatches for this thread that were L2 Miss */
14#define EventCode 0x46880
15
16extern void thirty_two_instruction_loop_with_ll_sc(u64 loops, u64 *ll_sc_target);
17
18/*
19 * A perf sampling test for mmcr1
20 * fields : comb.
21 */
22static int mmcr1_comb(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
31 /* Init the event for the sampling test */
32 event_init_sampling(e: &event, EventCode);
33 event.attr.sample_regs_intr = platform_extended_mask;
34 FAIL_IF(event_open(e: &event));
35 event.mmap_buffer = event_sample_buf_mmap(fd: event.fd, mmap_pages: 1);
36
37 FAIL_IF(event_enable(e: &event));
38
39 /* workload to make the event overflow */
40 thirty_two_instruction_loop_with_ll_sc(loops: 10000000, ll_sc_target: &dummy);
41
42 FAIL_IF(event_disable(e: &event));
43
44 /* Check for sample count */
45 FAIL_IF(!collect_samples(sample_buff: event.mmap_buffer));
46
47 intr_regs = get_intr_regs(event: &event, sample_buff: event.mmap_buffer);
48
49 /* Check for intr_regs */
50 FAIL_IF(!intr_regs);
51
52 /*
53 * Verify that comb field match with
54 * corresponding event code fields
55 */
56 FAIL_IF(EV_CODE_EXTRACT(event.attr.config, comb) !=
57 get_mmcr1_comb(mmcr1: get_reg_value(intr_regs, register_name: "MMCR1"), pmc: 4));
58
59 event_close(e: &event);
60 return 0;
61}
62
63int main(void)
64{
65 return test_harness(mmcr1_comb, "mmcr1_comb");
66}
67

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