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