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 /* All successful D-side store dispatches for this thread with PMC 2 */
14 #define EventCode_1 0x26080
15 /* All successful D-side store dispatches for this thread with PMC 4 */
16 #define EventCode_2 0x46080
17 /* All successful D-side store dispatches for this thread that were L2 Miss with PMC 3 */
18 #define EventCode_3 0x36880
19
20 /*
21 * Testcase for group constraint check of unit and pmc bits which is
22 * used to program corresponding unit and pmc field in Monitor Mode
23 * Control Register 1 (MMCR1)
24 * One of the event in the group should use PMC 4 incase units field
25 * value is within 6 to 9 otherwise event_open for the group will fail.
26 */
group_constraint_unit(void)27 static int group_constraint_unit(void)
28 {
29 struct event *e, events[3];
30
31 /*
32 * Check for platform support for the test.
33 * Constraint to use PMC4 with one of the event in group,
34 * when the unit is within 6 to 9 is only applicable on
35 * power9.
36 */
37 SKIP_IF(platform_check_for_tests());
38 SKIP_IF(have_hwcap2(PPC_FEATURE2_ARCH_3_1));
39
40 /* Init the events for the group contraint check for unit bits */
41 e = &events[0];
42 event_init(e, EventCode_1);
43
44 /* Expected to fail as PMC 4 is not used with unit field value 6 to 9 */
45 FAIL_IF(!event_open(&events[0]));
46
47 /* Init the events for the group contraint check for unit bits */
48 e = &events[1];
49 event_init(e, EventCode_2);
50
51 /* Expected to pass as PMC 4 is used with unit field value 6 to 9 */
52 FAIL_IF(event_open(&events[1]));
53
54 /* Init the event for the group contraint unit test */
55 e = &events[2];
56 event_init(e, EventCode_3);
57
58 /* Expected to fail as PMC4 is not being used */
59 FAIL_IF(!event_open_with_group(&events[2], events[0].fd));
60
61 /* Expected to succeed as event using PMC4 */
62 FAIL_IF(event_open_with_group(&events[2], events[1].fd));
63
64 event_close(&events[0]);
65 event_close(&events[1]);
66 event_close(&events[2]);
67
68 return 0;
69 }
70
main(void)71 int main(void)
72 {
73 return test_harness(group_constraint_unit, "group_constraint_unit");
74 }
75