Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2022 Intel Corporation
3 : : */
4 : :
5 : : #include "test.h"
6 : :
7 : : #ifndef RTE_LIB_POWER
8 : :
9 : : static int
10 : : test_power_intel_uncore(void)
11 : : {
12 : : printf("Power management library not supported, skipping test\n");
13 : : return TEST_SKIPPED;
14 : : }
15 : :
16 : : #else
17 : : #include <rte_power_uncore.h>
18 : : #include <power_common.h>
19 : :
20 : : #define MAX_UNCORE_FREQS 32
21 : :
22 : : #define VALID_PKG 0
23 : : #define VALID_DIE 0
24 : : #define INVALID_PKG (rte_power_uncore_get_num_pkgs() + 1)
25 : : #define INVALID_DIE (rte_power_uncore_get_num_dies(VALID_PKG) + 1)
26 : : #define VALID_INDEX 1
27 : : #define INVALID_INDEX (MAX_UNCORE_FREQS + 1)
28 : :
29 : 0 : static int check_power_uncore_init(void)
30 : : {
31 : : int ret;
32 : :
33 : : /* Test initialisation of uncore configuration*/
34 : 0 : ret = rte_power_uncore_init(VALID_PKG, VALID_DIE);
35 [ # # ]: 0 : if (ret < 0) {
36 : : printf("Cannot initialise uncore power management for pkg %u die %u, this "
37 : : "may occur if environment is not configured "
38 : : "correctly(APCI cpufreq) or operating in another valid "
39 : : "Power management environment\n", VALID_PKG, VALID_DIE);
40 : 0 : return -1;
41 : : }
42 : :
43 : : /* Unsuccessful Test */
44 : 0 : ret = rte_power_uncore_init(INVALID_PKG, INVALID_DIE);
45 [ # # ]: 0 : if (ret == 0) {
46 : 0 : printf("Unexpectedly was able to initialise uncore power management "
47 : 0 : "for pkg %u die %u\n", INVALID_PKG, INVALID_DIE);
48 : 0 : return -1;
49 : : }
50 : :
51 : : return 0;
52 : : }
53 : :
54 : : static int
55 : 0 : check_power_get_uncore_freq(void)
56 : : {
57 : : int ret;
58 : :
59 : : /* Successfully get uncore freq */
60 : 0 : ret = rte_power_get_uncore_freq(VALID_PKG, VALID_DIE);
61 [ # # ]: 0 : if (ret < 0) {
62 : : printf("Failed to get uncore frequency for pkg %u die %u\n",
63 : : VALID_PKG, VALID_DIE);
64 : 0 : return -1;
65 : : }
66 : :
67 : : /* Unsuccessful Test */
68 : 0 : ret = rte_power_get_uncore_freq(INVALID_PKG, INVALID_DIE);
69 [ # # ]: 0 : if (ret >= 0) {
70 : 0 : printf("Unexpectedly got invalid uncore frequency for pkg %u die %u\n",
71 : 0 : INVALID_PKG, INVALID_DIE);
72 : 0 : return -1;
73 : : }
74 : :
75 : : return 0;
76 : : }
77 : :
78 : : static int
79 : 0 : check_power_set_uncore_freq(void)
80 : : {
81 : : int ret;
82 : :
83 : : /* Successfully set uncore freq */
84 : 0 : ret = rte_power_set_uncore_freq(VALID_PKG, VALID_DIE, VALID_INDEX);
85 [ # # ]: 0 : if (ret < 0) {
86 : : printf("Failed to set uncore frequency for pkg %u die %u index %u\n",
87 : : VALID_PKG, VALID_DIE, VALID_INDEX);
88 : 0 : return -1;
89 : : }
90 : :
91 : : /* Try to unsuccessfully set invalid uncore freq index */
92 : 0 : ret = rte_power_set_uncore_freq(VALID_PKG, VALID_DIE, INVALID_INDEX);
93 [ # # ]: 0 : if (ret == 0) {
94 : : printf("Unexpectedly set invalid uncore index for pkg %u die %u index %u\n",
95 : : VALID_PKG, VALID_DIE, INVALID_INDEX);
96 : 0 : return -1;
97 : : }
98 : :
99 : : /* Unsuccessful Test */
100 : 0 : ret = rte_power_set_uncore_freq(INVALID_PKG, INVALID_DIE, VALID_INDEX);
101 [ # # ]: 0 : if (ret == 0) {
102 : 0 : printf("Unexpectedly set invalid uncore frequency for pkg %u die %u index %u\n",
103 : 0 : INVALID_PKG, INVALID_DIE, VALID_INDEX);
104 : 0 : return -1;
105 : : }
106 : :
107 : : return 0;
108 : : }
109 : :
110 : : static int
111 : 0 : check_power_uncore_freq_max(void)
112 : : {
113 : : int ret;
114 : :
115 : : /* Successfully get max uncore freq */
116 : 0 : ret = rte_power_uncore_freq_max(VALID_PKG, VALID_DIE);
117 [ # # ]: 0 : if (ret < 0) {
118 : : printf("Failed to set max uncore frequency for pkg %u die %u\n",
119 : : VALID_PKG, VALID_DIE);
120 : 0 : return -1;
121 : : }
122 : :
123 : : /* Unsuccessful Test */
124 : 0 : ret = rte_power_uncore_freq_max(INVALID_PKG, INVALID_DIE);
125 [ # # ]: 0 : if (ret == 0) {
126 : 0 : printf("Unexpectedly set invalid max uncore frequency for pkg %u die %u\n",
127 : 0 : INVALID_PKG, INVALID_DIE);
128 : 0 : return -1;
129 : : }
130 : :
131 : : return 0;
132 : : }
133 : :
134 : : static int
135 : 0 : check_power_uncore_freq_min(void)
136 : : {
137 : : int ret;
138 : :
139 : : /* Successfully get min uncore freq */
140 : 0 : ret = rte_power_uncore_freq_min(VALID_PKG, VALID_DIE);
141 [ # # ]: 0 : if (ret < 0) {
142 : : printf("Failed to set min uncore frequency for pkg %u die %u\n",
143 : : VALID_PKG, VALID_DIE);
144 : 0 : return -1;
145 : : }
146 : :
147 : : /* Unsuccessful Test */
148 : 0 : ret = rte_power_uncore_freq_min(INVALID_PKG, INVALID_DIE);
149 [ # # ]: 0 : if (ret == 0) {
150 : 0 : printf("Unexpectedly set invalid min uncore frequency for pkg %u die %u\n",
151 : 0 : INVALID_PKG, INVALID_DIE);
152 : 0 : return -1;
153 : : }
154 : :
155 : : return 0;
156 : : }
157 : :
158 : : static int
159 : 0 : check_power_uncore_get_num_freqs(void)
160 : : {
161 : : int ret;
162 : :
163 : : /* Successfully get number of uncore freq */
164 : 0 : ret = rte_power_uncore_get_num_freqs(VALID_PKG, VALID_DIE);
165 [ # # ]: 0 : if (ret < 0) {
166 : : printf("Failed to get number of uncore frequencies for pkg %u die %u\n",
167 : : VALID_PKG, VALID_DIE);
168 : 0 : return -1;
169 : : }
170 : :
171 : : /* Unsuccessful Test */
172 : 0 : ret = rte_power_uncore_get_num_freqs(INVALID_PKG, INVALID_DIE);
173 [ # # ]: 0 : if (ret >= 0) {
174 : 0 : printf("Unexpectedly got number of invalid frequencies for pkg %u die %u\n",
175 : 0 : INVALID_PKG, INVALID_DIE);
176 : 0 : return -1;
177 : : }
178 : :
179 : : return 0;
180 : : }
181 : :
182 : : static int
183 : 0 : check_power_uncore_get_num_pkgs(void)
184 : : {
185 : : int ret;
186 : :
187 : : /* Successfully get number of uncore pkgs */
188 : 0 : ret = rte_power_uncore_get_num_pkgs();
189 [ # # ]: 0 : if (ret == 0) {
190 : : printf("Failed to get number of uncore pkgs\n");
191 : 0 : return -1;
192 : : }
193 : :
194 : : return 0;
195 : : }
196 : :
197 : : static int
198 : 0 : check_power_uncore_get_num_dies(void)
199 : : {
200 : : int ret;
201 : :
202 : : /* Successfully get number of uncore dies */
203 : 0 : ret = rte_power_uncore_get_num_dies(VALID_PKG);
204 [ # # ]: 0 : if (ret == 0) {
205 : : printf("Failed to get number of uncore dies for pkg %u\n",
206 : : VALID_PKG);
207 : 0 : return -1;
208 : : }
209 : :
210 : : /* Unsuccessful test */
211 : 0 : ret = rte_power_uncore_get_num_dies(INVALID_PKG);
212 [ # # ]: 0 : if (ret > 0) {
213 : 0 : printf("Unexpectedly got number of invalid dies for pkg %u\n",
214 : 0 : INVALID_PKG);
215 : 0 : return -1;
216 : : }
217 : :
218 : : return 0;
219 : : }
220 : :
221 : : static int
222 : 0 : check_power_uncore_exit(void)
223 : : {
224 : : int ret;
225 : :
226 : : /* Successfully exit uncore power management */
227 : 0 : ret = rte_power_uncore_exit(VALID_PKG, VALID_DIE);
228 [ # # ]: 0 : if (ret < 0) {
229 : : printf("Failed to exit uncore power management for pkg %u die %u\n",
230 : : VALID_PKG, VALID_DIE);
231 : : }
232 : :
233 : : /* Unsuccessful Test */
234 : 0 : ret = rte_power_uncore_exit(INVALID_PKG, INVALID_DIE);
235 [ # # ]: 0 : if (ret == 0) {
236 : 0 : printf("Unexpectedly was able to exit uncore power management for pkg %u die %u\n",
237 : 0 : INVALID_PKG, INVALID_DIE);
238 : 0 : return -1;
239 : : }
240 : :
241 : : return 0;
242 : : }
243 : :
244 : : static int
245 : 1 : test_power_intel_uncore(void)
246 : : {
247 : : int ret;
248 : :
249 : 1 : ret = rte_power_set_uncore_env(RTE_UNCORE_PM_ENV_INTEL_UNCORE);
250 [ - + ]: 1 : if (ret < 0)
251 : 0 : goto fail_all;
252 : :
253 : 1 : ret = rte_power_uncore_get_num_pkgs();
254 [ + - ]: 1 : if (ret == 0) {
255 : : printf("Uncore frequency management not supported/enabled on this kernel. "
256 : : "Please enable CONFIG_INTEL_UNCORE_FREQ_CONTROL if on Intel x86 with linux kernel"
257 : : " >= 5.6\n");
258 : 1 : return TEST_SKIPPED;
259 : : }
260 : :
261 : 0 : ret = check_power_uncore_init();
262 [ # # ]: 0 : if (ret < 0)
263 : 0 : goto fail_all;
264 : :
265 : 0 : ret = check_power_get_uncore_freq();
266 [ # # ]: 0 : if (ret < 0)
267 : 0 : goto fail_all;
268 : :
269 : 0 : ret = check_power_set_uncore_freq();
270 [ # # ]: 0 : if (ret < 0)
271 : 0 : goto fail_all;
272 : :
273 : 0 : ret = check_power_uncore_freq_max();
274 [ # # ]: 0 : if (ret < 0)
275 : 0 : goto fail_all;
276 : :
277 : 0 : ret = check_power_uncore_freq_min();
278 [ # # ]: 0 : if (ret < 0)
279 : 0 : goto fail_all;
280 : :
281 : 0 : ret = check_power_uncore_get_num_freqs();
282 [ # # ]: 0 : if (ret < 0)
283 : 0 : goto fail_all;
284 : :
285 : 0 : ret = check_power_uncore_get_num_pkgs();
286 [ # # ]: 0 : if (ret < 0)
287 : 0 : goto fail_all;
288 : :
289 : 0 : ret = check_power_uncore_get_num_dies();
290 [ # # ]: 0 : if (ret < 0)
291 : 0 : goto fail_all;
292 : :
293 : 0 : ret = check_power_uncore_exit();
294 [ # # ]: 0 : if (ret < 0)
295 : 0 : return -1;
296 : :
297 : : return 0;
298 : :
299 : 0 : fail_all:
300 : 0 : rte_power_uncore_exit(VALID_PKG, VALID_DIE);
301 : 0 : return -1;
302 : : }
303 : : #endif
304 : :
305 : 235 : REGISTER_FAST_TEST(power_intel_uncore_autotest, true, true, test_power_intel_uncore);
|