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 "utils.h"
11#include "../sampling_tests/misc.h"
12
13/*
14 * Primary PMU events used here is PM_MRK_INST_CMPL (0x401e0) and
15 * PM_THRESH_MET (0x101ec)
16 * Threshold event selection used is issue to complete for cycles
17 * Sampling criteria is Load or Store only sampling
18 */
19#define p9_EventCode_1 0x13e35340401e0
20#define p9_EventCode_2 0x17d34340101ec
21#define p9_EventCode_3 0x13e35340101ec
22#define p10_EventCode_1 0x35340401e0
23#define p10_EventCode_2 0x35340101ec
24
25/*
26 * Testcase for group constraint check of thresh_cmp bits which is
27 * used to program thresh compare field in Monitor Mode Control Register A
28 * (MMCRA: 9-18 bits for power9 and MMCRA: 8-18 bits for power10).
29 * All events in the group should match thresh compare bits otherwise
30 * event_open for the group will fail.
31 */
32static int group_constraint_thresh_cmp(void)
33{
34 struct event event, leader;
35
36 /* Check for platform support for the test */
37 SKIP_IF(platform_check_for_tests());
38
39 if (have_hwcap2(PPC_FEATURE2_ARCH_3_1)) {
40 /* Init the events for the group contraint check for thresh_cmp bits */
41 event_init(e: &leader, p10_EventCode_1);
42
43 /* Add the thresh_cmp value for leader in config1 */
44 leader.attr.config1 = 1000;
45 FAIL_IF(event_open(e: &leader));
46
47 event_init(e: &event, p10_EventCode_2);
48
49 /* Add the different thresh_cmp value from the leader event in config1 */
50 event.attr.config1 = 2000;
51
52 /* Expected to fail as sibling and leader event request different thresh_cmp bits */
53 FAIL_IF(!event_open_with_group(e: &event, group_fd: leader.fd));
54
55 event_close(e: &event);
56
57 /* Init the event for the group contraint thresh compare test */
58 event_init(e: &event, p10_EventCode_2);
59
60 /* Add the same thresh_cmp value for leader and sibling event in config1 */
61 event.attr.config1 = 1000;
62
63 /* Expected to succeed as sibling and leader event request same thresh_cmp bits */
64 FAIL_IF(event_open_with_group(e: &event, group_fd: leader.fd));
65
66 event_close(e: &leader);
67 event_close(e: &event);
68 } else {
69 /* Init the events for the group contraint check for thresh_cmp bits */
70 event_init(e: &leader, p9_EventCode_1);
71 FAIL_IF(event_open(e: &leader));
72
73 event_init(e: &event, p9_EventCode_2);
74
75 /* Expected to fail as sibling and leader event request different thresh_cmp bits */
76 FAIL_IF(!event_open_with_group(e: &event, group_fd: leader.fd));
77
78 event_close(e: &event);
79
80 /* Init the event for the group contraint thresh compare test */
81 event_init(e: &event, p9_EventCode_3);
82
83 /* Expected to succeed as sibling and leader event request same thresh_cmp bits */
84 FAIL_IF(event_open_with_group(e: &event, group_fd: leader.fd));
85
86 event_close(e: &leader);
87 event_close(e: &event);
88 }
89
90 return 0;
91}
92
93int main(void)
94{
95 return test_harness(group_constraint_thresh_cmp, "group_constraint_thresh_cmp");
96}
97

source code of linux/tools/testing/selftests/powerpc/pmu/event_code_tests/group_constraint_thresh_cmp_test.c