1 | // SPDX-License-Identifier: GPL-2.0-only |
2 | /* |
3 | * Copyright 2022, Athira Rajeev, IBM Corp. |
4 | */ |
5 | |
6 | #include <stdio.h> |
7 | #include <sys/prctl.h> |
8 | #include <limits.h> |
9 | #include "../event.h" |
10 | #include "../sampling_tests/misc.h" |
11 | |
12 | #define PM_DTLB_MISS_16G 0x1c058 |
13 | #define PM_DERAT_MISS_2M 0x1c05a |
14 | #define PM_DTLB_MISS_2M 0x1c05c |
15 | #define PM_MRK_DTLB_MISS_1G 0x1d15c |
16 | #define PM_DTLB_MISS_4K 0x2c056 |
17 | #define PM_DERAT_MISS_1G 0x2c05a |
18 | #define PM_MRK_DERAT_MISS_2M 0x2d152 |
19 | #define PM_MRK_DTLB_MISS_4K 0x2d156 |
20 | #define PM_MRK_DTLB_MISS_16G 0x2d15e |
21 | #define PM_DTLB_MISS_64K 0x3c056 |
22 | #define PM_MRK_DERAT_MISS_1G 0x3d152 |
23 | #define PM_MRK_DTLB_MISS_64K 0x3d156 |
24 | #define PM_DISP_HELD_SYNC_HOLD 0x4003c |
25 | #define PM_DTLB_MISS_16M 0x4c056 |
26 | #define PM_DTLB_MISS_1G 0x4c05a |
27 | #define PM_MRK_DTLB_MISS_16M 0x4c15e |
28 | #define PM_MRK_ST_DONE_L2 0x10134 |
29 | #define PM_RADIX_PWC_L1_HIT 0x1f056 |
30 | #define PM_FLOP_CMPL 0x100f4 |
31 | #define PM_MRK_NTF_FIN 0x20112 |
32 | #define PM_RADIX_PWC_L2_HIT 0x2d024 |
33 | #define PM_IFETCH_THROTTLE 0x3405e |
34 | #define PM_MRK_L2_TM_ST_ABORT_SISTER 0x3e15c |
35 | #define PM_RADIX_PWC_L3_HIT 0x3f056 |
36 | #define PM_RUN_CYC_SMT2_MODE 0x3006c |
37 | #define PM_TM_TX_PASS_RUN_INST 0x4e014 |
38 | |
39 | #define PVR_POWER9_CUMULUS 0x00002000 |
40 | |
41 | int blacklist_events_dd21[] = { |
42 | PM_MRK_ST_DONE_L2, |
43 | PM_RADIX_PWC_L1_HIT, |
44 | PM_FLOP_CMPL, |
45 | PM_MRK_NTF_FIN, |
46 | PM_RADIX_PWC_L2_HIT, |
47 | PM_IFETCH_THROTTLE, |
48 | PM_MRK_L2_TM_ST_ABORT_SISTER, |
49 | PM_RADIX_PWC_L3_HIT, |
50 | PM_RUN_CYC_SMT2_MODE, |
51 | PM_TM_TX_PASS_RUN_INST, |
52 | PM_DISP_HELD_SYNC_HOLD, |
53 | }; |
54 | |
55 | int blacklist_events_dd22[] = { |
56 | PM_DTLB_MISS_16G, |
57 | PM_DERAT_MISS_2M, |
58 | PM_DTLB_MISS_2M, |
59 | PM_MRK_DTLB_MISS_1G, |
60 | PM_DTLB_MISS_4K, |
61 | PM_DERAT_MISS_1G, |
62 | PM_MRK_DERAT_MISS_2M, |
63 | PM_MRK_DTLB_MISS_4K, |
64 | PM_MRK_DTLB_MISS_16G, |
65 | PM_DTLB_MISS_64K, |
66 | PM_MRK_DERAT_MISS_1G, |
67 | PM_MRK_DTLB_MISS_64K, |
68 | PM_DISP_HELD_SYNC_HOLD, |
69 | PM_DTLB_MISS_16M, |
70 | PM_DTLB_MISS_1G, |
71 | PM_MRK_DTLB_MISS_16M, |
72 | }; |
73 | |
74 | int pvr_min; |
75 | |
76 | /* |
77 | * check for power9 support for 2.1 and |
78 | * 2.2 model where blacklist is applicable. |
79 | */ |
80 | int check_for_power9_version(void) |
81 | { |
82 | pvr_min = PVR_MIN(mfspr(SPRN_PVR)); |
83 | |
84 | SKIP_IF(PVR_VER(pvr) != POWER9); |
85 | SKIP_IF(!(pvr & PVR_POWER9_CUMULUS)); |
86 | |
87 | SKIP_IF(!(3 - pvr_min)); |
88 | |
89 | return 0; |
90 | } |
91 | |
92 | /* |
93 | * Testcase to ensure that using blacklisted bits in |
94 | * event code should cause event_open to fail in power9 |
95 | */ |
96 | |
97 | static int blacklisted_events(void) |
98 | { |
99 | struct event event; |
100 | int i = 0; |
101 | |
102 | /* Check for platform support for the test */ |
103 | SKIP_IF(platform_check_for_tests()); |
104 | |
105 | /* |
106 | * check for power9 support for 2.1 and |
107 | * 2.2 model where blacklist is applicable. |
108 | */ |
109 | SKIP_IF(check_for_power9_version()); |
110 | |
111 | /* Skip for Generic compat mode */ |
112 | SKIP_IF(check_for_generic_compat_pmu()); |
113 | |
114 | if (pvr_min == 1) { |
115 | for (i = 0; i < ARRAY_SIZE(blacklist_events_dd21); i++) { |
116 | event_init(e: &event, config: blacklist_events_dd21[i]); |
117 | FAIL_IF(!event_open(e: &event)); |
118 | } |
119 | } else if (pvr_min == 2) { |
120 | for (i = 0; i < ARRAY_SIZE(blacklist_events_dd22); i++) { |
121 | event_init(e: &event, config: blacklist_events_dd22[i]); |
122 | FAIL_IF(!event_open(e: &event)); |
123 | } |
124 | } |
125 | |
126 | return 0; |
127 | } |
128 | |
129 | int main(void) |
130 | { |
131 | return test_harness(blacklisted_events, "blacklisted_events" ); |
132 | } |
133 | |