Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2014 Intel Corporation
3 : : */
4 : :
5 : : #include <stdio.h>
6 : : #include <stdint.h>
7 : : #include <unistd.h>
8 : : #include <limits.h>
9 : : #include <string.h>
10 : : #include <inttypes.h>
11 : : #include <rte_cycles.h>
12 : : #include <rte_lcore.h>
13 : :
14 : : #include "test.h"
15 : :
16 : : #ifndef RTE_LIB_POWER
17 : :
18 : : static int
19 : : test_power_cpufreq(void)
20 : : {
21 : : printf("Power management library not supported, skipping test\n");
22 : : return TEST_SKIPPED;
23 : : }
24 : :
25 : : static int
26 : : test_power_caps(void)
27 : : {
28 : : printf("Power management library not supported, skipping test\n");
29 : : return TEST_SKIPPED;
30 : : }
31 : :
32 : : #else
33 : : #include <rte_power_cpufreq.h>
34 : :
35 : : #define TEST_POWER_LCORE_ID 2U
36 : : #define TEST_POWER_LCORE_INVALID ((unsigned)RTE_MAX_LCORE)
37 : : #define TEST_POWER_FREQS_NUM_MAX ((unsigned)RTE_MAX_LCORE_FREQS)
38 : :
39 : : /* macros used for rounding frequency to nearest 100000 */
40 : : #define TEST_FREQ_ROUNDING_DELTA 50000
41 : : #define TEST_ROUND_FREQ_TO_N_100000 100000
42 : :
43 : : #define TEST_POWER_SYSFILE_CPUINFO_FREQ \
44 : : "/sys/devices/system/cpu/cpu%u/cpufreq/cpuinfo_cur_freq"
45 : : #define TEST_POWER_SYSFILE_SCALING_FREQ \
46 : : "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_cur_freq"
47 : :
48 : : static uint32_t total_freq_num;
49 : : static uint32_t freqs[TEST_POWER_FREQS_NUM_MAX];
50 : : static uint32_t cpu_id;
51 : :
52 : : static int
53 : 0 : check_cur_freq(__rte_unused unsigned int lcore_id, uint32_t idx, bool turbo)
54 : : {
55 : : #define TEST_POWER_CONVERT_TO_DECIMAL 10
56 : : #define MAX_LOOP 100
57 : : FILE *f;
58 : : char fullpath[PATH_MAX];
59 : : char buf[BUFSIZ];
60 : : enum power_management_env env;
61 : : uint32_t cur_freq;
62 : : uint32_t freq_conv;
63 : : int ret = -1;
64 : : int i;
65 : :
66 [ # # ]: 0 : if (snprintf(fullpath, sizeof(fullpath),
67 : : TEST_POWER_SYSFILE_CPUINFO_FREQ, cpu_id) < 0) {
68 : : return 0;
69 : : }
70 : 0 : f = fopen(fullpath, "r");
71 [ # # ]: 0 : if (f == NULL) {
72 [ # # ]: 0 : if (snprintf(fullpath, sizeof(fullpath),
73 : : TEST_POWER_SYSFILE_SCALING_FREQ, cpu_id) < 0) {
74 : : return 0;
75 : : }
76 : 0 : f = fopen(fullpath, "r");
77 [ # # ]: 0 : if (f == NULL) {
78 : : return 0;
79 : : }
80 : : }
81 [ # # ]: 0 : for (i = 0; i < MAX_LOOP; i++) {
82 : 0 : fflush(f);
83 [ # # ]: 0 : if (fgets(buf, sizeof(buf), f) == NULL)
84 : 0 : goto fail_all;
85 : :
86 : 0 : cur_freq = strtoul(buf, NULL, TEST_POWER_CONVERT_TO_DECIMAL);
87 : : freq_conv = cur_freq;
88 : :
89 : 0 : env = rte_power_get_env();
90 [ # # ]: 0 : if (env == PM_ENV_CPPC_CPUFREQ || env == PM_ENV_PSTATE_CPUFREQ) {
91 : : /* convert the frequency to nearest 100000 value
92 : : * Ex: if cur_freq=1396789 then freq_conv=1400000
93 : : * Ex: if cur_freq=800030 then freq_conv=800000
94 : : */
95 : 0 : freq_conv = (cur_freq + TEST_FREQ_ROUNDING_DELTA)
96 : : / TEST_ROUND_FREQ_TO_N_100000;
97 : 0 : freq_conv = freq_conv * TEST_ROUND_FREQ_TO_N_100000;
98 [ # # ]: 0 : } else if (env == PM_ENV_AMD_PSTATE_CPUFREQ) {
99 [ # # ]: 0 : freq_conv = cur_freq > freqs[idx] ? (cur_freq - freqs[idx]) :
100 : : (freqs[idx] - cur_freq);
101 [ # # ]: 0 : if (freq_conv <= TEST_FREQ_ROUNDING_DELTA) {
102 : : /* workaround: current frequency may deviate from
103 : : * nominal freq. Allow deviation of up to 50Mhz.
104 : : */
105 : : printf("Current frequency deviated from nominal "
106 : : "frequency by %d Khz!\n", freq_conv);
107 : 0 : freq_conv = freqs[idx];
108 : : }
109 : : }
110 : :
111 [ # # ]: 0 : if (turbo)
112 [ # # ]: 0 : ret = (freqs[idx] <= freq_conv ? 0 : -1);
113 : : else
114 [ # # ]: 0 : ret = (freqs[idx] == freq_conv ? 0 : -1);
115 : :
116 : : if (ret == 0)
117 : : break;
118 : :
119 [ # # ]: 0 : if (fseek(f, 0, SEEK_SET) < 0) {
120 : : printf("Fail to set file position indicator to 0\n");
121 : 0 : goto fail_all;
122 : : }
123 : :
124 : : /* wait for the value to be updated */
125 : : rte_delay_ms(10);
126 : : }
127 : :
128 : 0 : fail_all:
129 : 0 : fclose(f);
130 : :
131 : 0 : return ret;
132 : : }
133 : :
134 : : /* Check rte_power_freqs() */
135 : : static int
136 : 0 : check_power_freqs(void)
137 : : {
138 : : uint32_t ret;
139 : :
140 : 0 : total_freq_num = 0;
141 : : memset(freqs, 0, sizeof(freqs));
142 : :
143 : : /* test with an invalid lcore id */
144 : 0 : ret = rte_power_freqs(TEST_POWER_LCORE_INVALID, freqs,
145 : : TEST_POWER_FREQS_NUM_MAX);
146 [ # # ]: 0 : if (ret > 0) {
147 : : printf("Unexpectedly get available freqs successfully on "
148 : : "lcore %u\n", TEST_POWER_LCORE_INVALID);
149 : 0 : return -1;
150 : : }
151 : :
152 : : /* test with NULL buffer to save available freqs */
153 : 0 : ret = rte_power_freqs(TEST_POWER_LCORE_ID, NULL,
154 : : TEST_POWER_FREQS_NUM_MAX);
155 [ # # ]: 0 : if (ret > 0) {
156 : : printf("Unexpectedly get available freqs successfully with "
157 : : "NULL buffer on lcore %u\n", TEST_POWER_LCORE_ID);
158 : 0 : return -1;
159 : : }
160 : :
161 : : /* test of getting zero number of freqs */
162 : 0 : ret = rte_power_freqs(TEST_POWER_LCORE_ID, freqs, 0);
163 [ # # ]: 0 : if (ret > 0) {
164 : : printf("Unexpectedly get available freqs successfully with "
165 : : "zero buffer size on lcore %u\n", TEST_POWER_LCORE_ID);
166 : 0 : return -1;
167 : : }
168 : :
169 : : /* test with all valid input parameters */
170 : 0 : ret = rte_power_freqs(TEST_POWER_LCORE_ID, freqs,
171 : : TEST_POWER_FREQS_NUM_MAX);
172 [ # # ]: 0 : if (ret == 0 || ret > TEST_POWER_FREQS_NUM_MAX) {
173 : : printf("Fail to get available freqs on lcore %u\n",
174 : : TEST_POWER_LCORE_ID);
175 : 0 : return -1;
176 : : }
177 : :
178 : : /* Save the total number of available freqs */
179 : 0 : total_freq_num = ret;
180 : :
181 : 0 : return 0;
182 : : }
183 : :
184 : : /* Check rte_power_get_freq() */
185 : : static int
186 : 0 : check_power_get_freq(void)
187 : : {
188 : : int ret;
189 : : uint32_t count;
190 : :
191 : : /* test with an invalid lcore id */
192 : 0 : count = rte_power_get_freq(TEST_POWER_LCORE_INVALID);
193 [ # # ]: 0 : if (count < TEST_POWER_FREQS_NUM_MAX) {
194 : : printf("Unexpectedly get freq index successfully on "
195 : : "lcore %u\n", TEST_POWER_LCORE_INVALID);
196 : 0 : return -1;
197 : : }
198 : :
199 : 0 : count = rte_power_get_freq(TEST_POWER_LCORE_ID);
200 [ # # ]: 0 : if (count >= TEST_POWER_FREQS_NUM_MAX) {
201 : : printf("Fail to get the freq index on lcore %u\n",
202 : : TEST_POWER_LCORE_ID);
203 : 0 : return -1;
204 : : }
205 : :
206 : : /* Check the current frequency */
207 : 0 : ret = check_cur_freq(TEST_POWER_LCORE_ID, count, false);
208 [ # # ]: 0 : if (ret < 0)
209 : 0 : return -1;
210 : :
211 : : return 0;
212 : : }
213 : :
214 : : /* Check rte_power_set_freq() */
215 : : static int
216 : 0 : check_power_set_freq(void)
217 : : {
218 : : int ret;
219 : :
220 : : /* test with an invalid lcore id */
221 : 0 : ret = rte_power_set_freq(TEST_POWER_LCORE_INVALID, 0);
222 [ # # ]: 0 : if (ret >= 0) {
223 : : printf("Unexpectedly set freq index successfully on "
224 : : "lcore %u\n", TEST_POWER_LCORE_INVALID);
225 : 0 : return -1;
226 : : }
227 : :
228 : : /* test with an invalid freq index */
229 : 0 : ret = rte_power_set_freq(TEST_POWER_LCORE_ID,
230 : : TEST_POWER_FREQS_NUM_MAX);
231 [ # # ]: 0 : if (ret >= 0) {
232 : : printf("Unexpectedly set an invalid freq index (%u)"
233 : : "successfully on lcore %u\n", TEST_POWER_FREQS_NUM_MAX,
234 : : TEST_POWER_LCORE_ID);
235 : 0 : return -1;
236 : : }
237 : :
238 : : /**
239 : : * test with an invalid freq index which is right one bigger than
240 : : * total number of freqs
241 : : */
242 : 0 : ret = rte_power_set_freq(TEST_POWER_LCORE_ID, total_freq_num);
243 [ # # ]: 0 : if (ret >= 0) {
244 : 0 : printf("Unexpectedly set an invalid freq index (%u)"
245 : : "successfully on lcore %u\n", total_freq_num,
246 : : TEST_POWER_LCORE_ID);
247 : 0 : return -1;
248 : : }
249 : 0 : ret = rte_power_set_freq(TEST_POWER_LCORE_ID, total_freq_num - 1);
250 [ # # ]: 0 : if (ret < 0) {
251 : : printf("Fail to set freq index on lcore %u\n",
252 : : TEST_POWER_LCORE_ID);
253 : 0 : return -1;
254 : : }
255 : :
256 : : /* Check the current frequency */
257 : 0 : ret = check_cur_freq(TEST_POWER_LCORE_ID, total_freq_num - 1, false);
258 [ # # ]: 0 : if (ret < 0)
259 : 0 : return -1;
260 : :
261 : : return 0;
262 : : }
263 : :
264 : : /* Check rte_power_freq_down() */
265 : : static int
266 : 0 : check_power_freq_down(void)
267 : : {
268 : : int ret;
269 : :
270 : 0 : rte_power_freq_enable_turbo(TEST_POWER_LCORE_ID);
271 : :
272 : : /* test with an invalid lcore id */
273 : 0 : ret = rte_power_freq_down(TEST_POWER_LCORE_INVALID);
274 [ # # ]: 0 : if (ret >= 0) {
275 : : printf("Unexpectedly scale down successfully the freq on "
276 : : "lcore %u\n", TEST_POWER_LCORE_INVALID);
277 : 0 : return -1;
278 : : }
279 : :
280 : : /* Scale down to min and then scale down one step */
281 : 0 : ret = rte_power_freq_min(TEST_POWER_LCORE_ID);
282 [ # # ]: 0 : if (ret < 0) {
283 : : printf("Fail to scale down the freq to min on lcore %u\n",
284 : : TEST_POWER_LCORE_ID);
285 : 0 : return -1;
286 : : }
287 : 0 : ret = rte_power_freq_down(TEST_POWER_LCORE_ID);
288 [ # # ]: 0 : if (ret < 0) {
289 : : printf("Fail to scale down the freq on lcore %u\n",
290 : : TEST_POWER_LCORE_ID);
291 : 0 : return -1;
292 : : }
293 : :
294 : : /* Check the current frequency */
295 : 0 : ret = check_cur_freq(TEST_POWER_LCORE_ID, total_freq_num - 1, false);
296 [ # # ]: 0 : if (ret < 0)
297 : : return -1;
298 : :
299 : : /* Scale up to max and then scale down one step */
300 : 0 : ret = rte_power_freq_max(TEST_POWER_LCORE_ID);
301 [ # # ]: 0 : if (ret < 0) {
302 : : printf("Fail to scale up the freq to max on lcore %u\n",
303 : : TEST_POWER_LCORE_ID);
304 : 0 : return -1;
305 : : }
306 : 0 : ret = rte_power_freq_down(TEST_POWER_LCORE_ID);
307 [ # # ]: 0 : if (ret < 0) {
308 : : printf("Fail to scale down the freq on lcore %u\n",
309 : : TEST_POWER_LCORE_ID);
310 : 0 : return -1;
311 : : }
312 : :
313 : : /* Check the current frequency */
314 : 0 : ret = check_cur_freq(TEST_POWER_LCORE_ID, 1, false);
315 [ # # ]: 0 : if (ret < 0)
316 : 0 : return -1;
317 : :
318 : : return 0;
319 : : }
320 : :
321 : : /* Check rte_power_freq_up() */
322 : : static int
323 : 0 : check_power_freq_up(void)
324 : : {
325 : : int ret;
326 : :
327 : : /* test with an invalid lcore id */
328 : 0 : ret = rte_power_freq_up(TEST_POWER_LCORE_INVALID);
329 [ # # ]: 0 : if (ret >= 0) {
330 : : printf("Unexpectedly scale up successfully the freq on %u\n",
331 : : TEST_POWER_LCORE_INVALID);
332 : 0 : return -1;
333 : : }
334 : :
335 : : /* Scale down to min and then scale up one step */
336 : 0 : ret = rte_power_freq_min(TEST_POWER_LCORE_ID);
337 [ # # ]: 0 : if (ret < 0) {
338 : : printf("Fail to scale down the freq to min on lcore %u\n",
339 : : TEST_POWER_LCORE_ID);
340 : 0 : return -1;
341 : : }
342 : 0 : ret = rte_power_freq_up(TEST_POWER_LCORE_ID);
343 [ # # ]: 0 : if (ret < 0) {
344 : : printf("Fail to scale up the freq on lcore %u\n",
345 : : TEST_POWER_LCORE_ID);
346 : 0 : return -1;
347 : : }
348 : :
349 : : /* Check the current frequency */
350 : 0 : ret = check_cur_freq(TEST_POWER_LCORE_ID, total_freq_num - 2, false);
351 [ # # ]: 0 : if (ret < 0)
352 : : return -1;
353 : :
354 : : /* Scale up to max and then scale up one step */
355 : 0 : ret = rte_power_freq_max(TEST_POWER_LCORE_ID);
356 [ # # ]: 0 : if (ret < 0) {
357 : : printf("Fail to scale up the freq to max on lcore %u\n",
358 : : TEST_POWER_LCORE_ID);
359 : 0 : return -1;
360 : : }
361 : 0 : ret = rte_power_freq_up(TEST_POWER_LCORE_ID);
362 [ # # ]: 0 : if (ret < 0) {
363 : : printf("Fail to scale up the freq on lcore %u\n",
364 : : TEST_POWER_LCORE_ID);
365 : 0 : return -1;
366 : : }
367 : :
368 : : /* Check the current frequency */
369 : 0 : ret = check_cur_freq(TEST_POWER_LCORE_ID, 0, true);
370 [ # # ]: 0 : if (ret < 0)
371 : 0 : return -1;
372 : :
373 : : return 0;
374 : : }
375 : :
376 : : /* Check rte_power_freq_max() */
377 : : static int
378 : 0 : check_power_freq_max(void)
379 : : {
380 : : int ret;
381 : :
382 : : /* test with an invalid lcore id */
383 : 0 : ret = rte_power_freq_max(TEST_POWER_LCORE_INVALID);
384 [ # # ]: 0 : if (ret >= 0) {
385 : : printf("Unexpectedly scale up successfully the freq to max on "
386 : : "lcore %u\n", TEST_POWER_LCORE_INVALID);
387 : 0 : return -1;
388 : : }
389 : 0 : ret = rte_power_freq_max(TEST_POWER_LCORE_ID);
390 [ # # ]: 0 : if (ret < 0) {
391 : : printf("Fail to scale up the freq to max on lcore %u\n",
392 : : TEST_POWER_LCORE_ID);
393 : 0 : return -1;
394 : : }
395 : :
396 : : /* Check the current frequency */
397 : 0 : ret = check_cur_freq(TEST_POWER_LCORE_ID, 0, true);
398 [ # # ]: 0 : if (ret < 0)
399 : 0 : return -1;
400 : :
401 : : return 0;
402 : : }
403 : :
404 : : /* Check rte_power_freq_min() */
405 : : static int
406 : 0 : check_power_freq_min(void)
407 : : {
408 : : int ret;
409 : :
410 : : /* test with an invalid lcore id */
411 : 0 : ret = rte_power_freq_min(TEST_POWER_LCORE_INVALID);
412 [ # # ]: 0 : if (ret >= 0) {
413 : : printf("Unexpectedly scale down successfully the freq to min "
414 : : "on lcore %u\n", TEST_POWER_LCORE_INVALID);
415 : 0 : return -1;
416 : : }
417 : 0 : ret = rte_power_freq_min(TEST_POWER_LCORE_ID);
418 [ # # ]: 0 : if (ret < 0) {
419 : : printf("Fail to scale down the freq to min on lcore %u\n",
420 : : TEST_POWER_LCORE_ID);
421 : 0 : return -1;
422 : : }
423 : :
424 : : /* Check the current frequency */
425 : 0 : ret = check_cur_freq(TEST_POWER_LCORE_ID, total_freq_num - 1, false);
426 [ # # ]: 0 : if (ret < 0)
427 : 0 : return -1;
428 : :
429 : : return 0;
430 : : }
431 : :
432 : : /* Check rte_power_turbo() */
433 : : static int
434 : 0 : check_power_turbo(void)
435 : : {
436 : : int ret;
437 : :
438 [ # # ]: 0 : if (rte_power_turbo_status(TEST_POWER_LCORE_ID) == 0) {
439 : : printf("Turbo not available on lcore %u, skipping test\n",
440 : : TEST_POWER_LCORE_ID);
441 : 0 : return 0;
442 : : }
443 : :
444 : : /* test with an invalid lcore id */
445 : 0 : ret = rte_power_freq_enable_turbo(TEST_POWER_LCORE_INVALID);
446 [ # # ]: 0 : if (ret >= 0) {
447 : : printf("Unexpectedly enable turbo successfully on lcore %u\n",
448 : : TEST_POWER_LCORE_INVALID);
449 : 0 : return -1;
450 : : }
451 : 0 : ret = rte_power_freq_enable_turbo(TEST_POWER_LCORE_ID);
452 [ # # ]: 0 : if (ret < 0) {
453 : : printf("Fail to enable turbo on lcore %u\n",
454 : : TEST_POWER_LCORE_ID);
455 : 0 : return -1;
456 : : }
457 : 0 : ret = rte_power_freq_max(TEST_POWER_LCORE_ID);
458 [ # # ]: 0 : if (ret < 0) {
459 : : printf("Fail to scale up the freq to max on lcore %u\n",
460 : : TEST_POWER_LCORE_ID);
461 : 0 : return -1;
462 : : }
463 : :
464 : : /* Check the current frequency */
465 : 0 : ret = check_cur_freq(TEST_POWER_LCORE_ID, 0, true);
466 [ # # ]: 0 : if (ret < 0)
467 : : return -1;
468 : :
469 : : /* test with an invalid lcore id */
470 : 0 : ret = rte_power_freq_disable_turbo(TEST_POWER_LCORE_INVALID);
471 [ # # ]: 0 : if (ret >= 0) {
472 : : printf("Unexpectedly disable turbo successfully on lcore %u\n",
473 : : TEST_POWER_LCORE_INVALID);
474 : 0 : return -1;
475 : : }
476 : 0 : ret = rte_power_freq_disable_turbo(TEST_POWER_LCORE_ID);
477 [ # # ]: 0 : if (ret < 0) {
478 : : printf("Fail to disable turbo on lcore %u\n",
479 : : TEST_POWER_LCORE_ID);
480 : 0 : return -1;
481 : : }
482 : 0 : ret = rte_power_freq_max(TEST_POWER_LCORE_ID);
483 [ # # ]: 0 : if (ret < 0) {
484 : : printf("Fail to scale up the freq to max on lcore %u\n",
485 : : TEST_POWER_LCORE_ID);
486 : 0 : return -1;
487 : : }
488 : :
489 : : /* Nominal frequency is not at a fixed index in the table. */
490 : 0 : ret = check_cur_freq(TEST_POWER_LCORE_ID,
491 : : rte_power_get_freq(TEST_POWER_LCORE_ID), false);
492 [ # # ]: 0 : if (ret < 0)
493 : 0 : return -1;
494 : :
495 : : return 0;
496 : : }
497 : :
498 : : static int
499 : 1 : test_power_cpufreq(void)
500 : : {
501 : : int ret = -1;
502 : : enum power_management_env env;
503 : : rte_cpuset_t lcore_cpus;
504 : :
505 : 1 : lcore_cpus = rte_lcore_cpuset(TEST_POWER_LCORE_ID);
506 [ - + ]: 1 : if (CPU_COUNT(&lcore_cpus) != 1) {
507 : 0 : printf("Power management doesn't support lcore %u mapping to %u CPUs\n",
508 : : TEST_POWER_LCORE_ID,
509 : : CPU_COUNT(&lcore_cpus));
510 : 0 : return TEST_SKIPPED;
511 : : }
512 [ + - ]: 3 : for (cpu_id = 0; cpu_id < CPU_SETSIZE; cpu_id++) {
513 [ + + ]: 3 : if (CPU_ISSET(cpu_id, &lcore_cpus))
514 : : break;
515 : : }
516 : :
517 : : /* Test initialisation of a valid lcore */
518 : 1 : ret = rte_power_init(TEST_POWER_LCORE_ID);
519 [ + - ]: 1 : if (ret < 0) {
520 : : printf("Cannot initialise power management for lcore %u, this "
521 : : "may occur if environment is not configured "
522 : : "correctly(APCI cpufreq) or operating in another valid "
523 : : "Power management environment\n",
524 : : TEST_POWER_LCORE_ID);
525 : 1 : rte_power_unset_env();
526 : 1 : return TEST_SKIPPED;
527 : : }
528 : :
529 : : /* Test environment configuration */
530 : 0 : env = rte_power_get_env();
531 [ # # ]: 0 : if ((env != PM_ENV_ACPI_CPUFREQ) && (env != PM_ENV_PSTATE_CPUFREQ) &&
532 [ # # ]: 0 : (env != PM_ENV_CPPC_CPUFREQ) &&
533 : : (env != PM_ENV_AMD_PSTATE_CPUFREQ)) {
534 : : printf("Unexpectedly got an environment other than ACPI/PSTATE\n");
535 : 0 : goto fail_all;
536 : : }
537 : :
538 : 0 : ret = rte_power_exit(TEST_POWER_LCORE_ID);
539 [ # # ]: 0 : if (ret < 0) {
540 : : printf("Cannot exit power management for lcore %u\n",
541 : : TEST_POWER_LCORE_ID);
542 : 0 : rte_power_unset_env();
543 : 0 : return -1;
544 : : }
545 : :
546 : : /* test of init power management for an invalid lcore */
547 : 0 : ret = rte_power_init(TEST_POWER_LCORE_INVALID);
548 [ # # ]: 0 : if (ret == 0) {
549 : : printf("Unexpectedly initialise power management successfully "
550 : : "for lcore %u\n", TEST_POWER_LCORE_INVALID);
551 : 0 : rte_power_unset_env();
552 : 0 : return -1;
553 : : }
554 : :
555 : : /* Test initialisation of a valid lcore */
556 : 0 : ret = rte_power_init(TEST_POWER_LCORE_ID);
557 [ # # ]: 0 : if (ret < 0) {
558 : : printf("Cannot initialise power management for lcore %u, this "
559 : : "may occur if environment is not configured "
560 : : "correctly(APCI cpufreq) or operating in another valid "
561 : : "Power management environment\n", TEST_POWER_LCORE_ID);
562 : 0 : rte_power_unset_env();
563 : 0 : return TEST_SKIPPED;
564 : : }
565 : :
566 : : /**
567 : : * test of initialising power management for the lcore which has
568 : : * been initialised
569 : : */
570 : 0 : ret = rte_power_init(TEST_POWER_LCORE_ID);
571 [ # # ]: 0 : if (ret == 0) {
572 : : printf("Unexpectedly init successfully power twice on "
573 : : "lcore %u\n", TEST_POWER_LCORE_ID);
574 : 0 : goto fail_all;
575 : : }
576 : :
577 : 0 : ret = check_power_freqs();
578 [ # # ]: 0 : if (ret < 0)
579 : 0 : goto fail_all;
580 : :
581 [ # # ]: 0 : if (total_freq_num < 2) {
582 : 0 : rte_power_exit(TEST_POWER_LCORE_ID);
583 : : printf("Frequency can not be changed due to CPU itself\n");
584 : 0 : rte_power_unset_env();
585 : 0 : return 0;
586 : : }
587 : :
588 : 0 : ret = check_power_get_freq();
589 [ # # ]: 0 : if (ret < 0)
590 : 0 : goto fail_all;
591 : :
592 : 0 : ret = check_power_set_freq();
593 [ # # ]: 0 : if (ret < 0)
594 : 0 : goto fail_all;
595 : :
596 : 0 : ret = check_power_freq_down();
597 [ # # ]: 0 : if (ret < 0)
598 : 0 : goto fail_all;
599 : :
600 : 0 : ret = check_power_freq_up();
601 [ # # ]: 0 : if (ret < 0)
602 : 0 : goto fail_all;
603 : :
604 : 0 : ret = check_power_freq_max();
605 [ # # ]: 0 : if (ret < 0)
606 : 0 : goto fail_all;
607 : :
608 : 0 : ret = check_power_freq_min();
609 [ # # ]: 0 : if (ret < 0)
610 : 0 : goto fail_all;
611 : :
612 : 0 : ret = check_power_turbo();
613 [ # # ]: 0 : if (ret < 0)
614 : 0 : goto fail_all;
615 : :
616 : 0 : ret = rte_power_exit(TEST_POWER_LCORE_ID);
617 [ # # ]: 0 : if (ret < 0) {
618 : : printf("Cannot exit power management for lcore %u\n",
619 : : TEST_POWER_LCORE_ID);
620 : 0 : rte_power_unset_env();
621 : 0 : return -1;
622 : : }
623 : :
624 : : /**
625 : : * test of exiting power management for the lcore which has been exited
626 : : */
627 : 0 : ret = rte_power_exit(TEST_POWER_LCORE_ID);
628 [ # # ]: 0 : if (ret == 0) {
629 : : printf("Unexpectedly exit successfully power management twice "
630 : : "on lcore %u\n", TEST_POWER_LCORE_ID);
631 : 0 : rte_power_unset_env();
632 : 0 : return -1;
633 : : }
634 : :
635 : : /* test of exit power management for an invalid lcore */
636 : 0 : ret = rte_power_exit(TEST_POWER_LCORE_INVALID);
637 [ # # ]: 0 : if (ret == 0) {
638 : : printf("Unexpectedly exit power management successfully for "
639 : : "lcore %u\n", TEST_POWER_LCORE_INVALID);
640 : 0 : rte_power_unset_env();
641 : 0 : return -1;
642 : : }
643 : 0 : rte_power_unset_env();
644 : 0 : return 0;
645 : :
646 : 0 : fail_all:
647 : 0 : rte_power_exit(TEST_POWER_LCORE_ID);
648 : 0 : rte_power_unset_env();
649 : 0 : return -1;
650 : : }
651 : :
652 : : static int
653 : 1 : test_power_caps(void)
654 : : {
655 : : struct rte_power_core_capabilities caps;
656 : : int ret;
657 : :
658 : 1 : ret = rte_power_init(TEST_POWER_LCORE_ID);
659 [ + - ]: 1 : if (ret < 0) {
660 : : printf("Cannot initialise power management for lcore %u, this "
661 : : "may occur if environment is not configured "
662 : : "correctly(APCI cpufreq) or operating in another valid "
663 : : "Power management environment\n", TEST_POWER_LCORE_ID);
664 : 1 : rte_power_unset_env();
665 : 1 : return TEST_SKIPPED;
666 : : }
667 : :
668 : 0 : ret = rte_power_get_capabilities(TEST_POWER_LCORE_ID, &caps);
669 [ # # ]: 0 : if (ret) {
670 : : printf("POWER: Error getting capabilities\n");
671 : 0 : return -1;
672 : : }
673 : :
674 : 0 : printf("POWER: Capabilities %"PRIx64"\n", caps.capabilities);
675 : :
676 : 0 : rte_power_unset_env();
677 : 0 : return 0;
678 : : }
679 : :
680 : : #endif
681 : :
682 : 305 : REGISTER_FAST_TEST(power_cpufreq_autotest, NOHUGE_SKIP, ASAN_OK, test_power_cpufreq);
683 : 305 : REGISTER_FAST_TEST(power_caps_autotest, NOHUGE_OK, ASAN_OK, test_power_caps);
|