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 <fcntl.h>
7 : : #include <stdlib.h>
8 : :
9 : : #include <rte_memcpy.h>
10 : : #include <rte_stdatomic.h>
11 : : #include <rte_string_fns.h>
12 : :
13 : : #include "acpi_cpufreq.h"
14 : : #include "power_common.h"
15 : :
16 : : #define STR_SIZE 1024
17 : : #define POWER_CONVERT_TO_DECIMAL 10
18 : :
19 : : #define POWER_GOVERNOR_USERSPACE "userspace"
20 : : #define POWER_SYSFILE_AVAIL_FREQ \
21 : : "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_available_frequencies"
22 : : #define POWER_SYSFILE_SETSPEED \
23 : : "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_setspeed"
24 : : #define POWER_ACPI_DRIVER "acpi-cpufreq"
25 : :
26 : : /*
27 : : * MSR related
28 : : */
29 : : #define PLATFORM_INFO 0x0CE
30 : : #define TURBO_RATIO_LIMIT 0x1AD
31 : : #define IA32_PERF_CTL 0x199
32 : : #define CORE_TURBO_DISABLE_BIT ((uint64_t)1<<32)
33 : :
34 : : enum power_state {
35 : : POWER_IDLE = 0,
36 : : POWER_ONGOING,
37 : : POWER_USED,
38 : : POWER_UNKNOWN
39 : : };
40 : :
41 : : /**
42 : : * Power info per lcore.
43 : : */
44 : : struct __rte_cache_aligned acpi_power_info {
45 : : unsigned int lcore_id; /**< Logical core id */
46 : : uint32_t freqs[RTE_MAX_LCORE_FREQS]; /**< Frequency array */
47 : : uint32_t nb_freqs; /**< number of available freqs */
48 : : FILE *f; /**< FD of scaling_setspeed */
49 : : char governor_ori[32]; /**< Original governor name */
50 : : uint32_t curr_idx; /**< Freq index in freqs array */
51 : : RTE_ATOMIC(uint32_t) state; /**< Power in use state */
52 : : uint16_t turbo_available; /**< Turbo Boost available */
53 : : uint16_t turbo_enable; /**< Turbo Boost enable/disable */
54 : : };
55 : :
56 : : static struct acpi_power_info lcore_power_info[RTE_MAX_LCORE];
57 : :
58 : : /**
59 : : * It is to set specific freq for specific logical core, according to the index
60 : : * of supported frequencies.
61 : : */
62 : : static int
63 : 0 : set_freq_internal(struct acpi_power_info *pi, uint32_t idx)
64 : : {
65 [ # # # # ]: 0 : if (idx >= RTE_MAX_LCORE_FREQS || idx >= pi->nb_freqs) {
66 : 0 : POWER_LOG(ERR, "Invalid frequency index %u, which "
67 : : "should be less than %u", idx, pi->nb_freqs);
68 : 0 : return -1;
69 : : }
70 : :
71 : : /* Check if it is the same as current */
72 [ # # ]: 0 : if (idx == pi->curr_idx)
73 : : return 0;
74 : :
75 : : POWER_DEBUG_LOG("Frequency[%u] %u to be set for lcore %u",
76 : : idx, pi->freqs[idx], pi->lcore_id);
77 [ # # ]: 0 : if (fseek(pi->f, 0, SEEK_SET) < 0) {
78 : 0 : POWER_LOG(ERR, "Fail to set file position indicator to 0 "
79 : : "for setting frequency for lcore %u", pi->lcore_id);
80 : 0 : return -1;
81 : : }
82 [ # # ]: 0 : if (fprintf(pi->f, "%u", pi->freqs[idx]) < 0) {
83 : 0 : POWER_LOG(ERR, "Fail to write new frequency for "
84 : : "lcore %u", pi->lcore_id);
85 : 0 : return -1;
86 : : }
87 : 0 : fflush(pi->f);
88 : 0 : pi->curr_idx = idx;
89 : :
90 : 0 : return 1;
91 : : }
92 : :
93 : : /**
94 : : * It is to check the current scaling governor by reading sys file, and then
95 : : * set it into 'userspace' if it is not by writing the sys file. The original
96 : : * governor will be saved for rolling back.
97 : : */
98 : : static int
99 : : power_set_governor_userspace(struct acpi_power_info *pi)
100 : : {
101 : 0 : return power_set_governor(pi->lcore_id, POWER_GOVERNOR_USERSPACE,
102 : 0 : pi->governor_ori, sizeof(pi->governor_ori));
103 : : }
104 : :
105 : : /**
106 : : * It is to check the governor and then set the original governor back if
107 : : * needed by writing the sys file.
108 : : */
109 : : static int
110 : : power_set_governor_original(struct acpi_power_info *pi)
111 : : {
112 : 0 : return power_set_governor(pi->lcore_id, pi->governor_ori, NULL, 0);
113 : : }
114 : :
115 : : /**
116 : : * It is to get the available frequencies of the specific lcore by reading the
117 : : * sys file.
118 : : */
119 : : static int
120 : 0 : power_get_available_freqs(struct acpi_power_info *pi)
121 : : {
122 : : FILE *f;
123 : : int ret = -1, i, count;
124 : : char *p;
125 : : char buf[BUFSIZ];
126 : : char *freqs[RTE_MAX_LCORE_FREQS];
127 : :
128 : 0 : open_core_sysfs_file(&f, "r", POWER_SYSFILE_AVAIL_FREQ, pi->lcore_id);
129 [ # # ]: 0 : if (f == NULL) {
130 : 0 : POWER_LOG(ERR, "failed to open %s",
131 : : POWER_SYSFILE_AVAIL_FREQ);
132 : 0 : goto out;
133 : : }
134 : :
135 : 0 : ret = read_core_sysfs_s(f, buf, sizeof(buf));
136 [ # # ]: 0 : if ((ret) < 0) {
137 : 0 : POWER_LOG(ERR, "Failed to read %s",
138 : : POWER_SYSFILE_AVAIL_FREQ);
139 : 0 : goto out;
140 : : }
141 : :
142 : : /* Split string into at most RTE_MAX_LCORE_FREQS frequencies */
143 : 0 : count = rte_strsplit(buf, sizeof(buf), freqs,
144 : : RTE_MAX_LCORE_FREQS, ' ');
145 [ # # ]: 0 : if (count <= 0) {
146 : 0 : POWER_LOG(ERR, "No available frequency in "
147 : : POWER_SYSFILE_AVAIL_FREQ, pi->lcore_id);
148 : 0 : goto out;
149 : : }
150 [ # # ]: 0 : if (count >= RTE_MAX_LCORE_FREQS) {
151 : 0 : POWER_LOG(ERR, "Too many available frequencies : %d",
152 : : count);
153 : 0 : goto out;
154 : : }
155 : :
156 : : /* Store the available frequencies into power context */
157 [ # # ]: 0 : for (i = 0, pi->nb_freqs = 0; i < count; i++) {
158 : : POWER_DEBUG_LOG("Lcore %u frequency[%d]: %s", pi->lcore_id,
159 : : i, freqs[i]);
160 : 0 : pi->freqs[pi->nb_freqs++] = strtoul(freqs[i], &p,
161 : : POWER_CONVERT_TO_DECIMAL);
162 : : }
163 : :
164 [ # # ]: 0 : if ((pi->freqs[0]-1000) == pi->freqs[1]) {
165 : 0 : pi->turbo_available = 1;
166 : 0 : pi->turbo_enable = 1;
167 : : POWER_DEBUG_LOG("Lcore %u Can do Turbo Boost",
168 : : pi->lcore_id);
169 : : } else {
170 : 0 : pi->turbo_available = 0;
171 : 0 : pi->turbo_enable = 0;
172 : : POWER_DEBUG_LOG("Turbo Boost not available on Lcore %u",
173 : : pi->lcore_id);
174 : : }
175 : :
176 : : ret = 0;
177 : : POWER_DEBUG_LOG("%d frequency(s) of lcore %u are available",
178 : : count, pi->lcore_id);
179 : 0 : out:
180 [ # # ]: 0 : if (f != NULL)
181 : 0 : fclose(f);
182 : :
183 : 0 : return ret;
184 : : }
185 : :
186 : : /**
187 : : * It is to fopen the sys file for the future setting the lcore frequency.
188 : : */
189 : : static int
190 : 0 : power_init_for_setting_freq(struct acpi_power_info *pi)
191 : : {
192 : : FILE *f;
193 : : char buf[BUFSIZ];
194 : : uint32_t i, freq;
195 : : int ret;
196 : :
197 : 0 : open_core_sysfs_file(&f, "rw+", POWER_SYSFILE_SETSPEED, pi->lcore_id);
198 [ # # ]: 0 : if (f == NULL) {
199 : 0 : POWER_LOG(ERR, "Failed to open %s",
200 : : POWER_SYSFILE_SETSPEED);
201 : 0 : goto err;
202 : : }
203 : :
204 : 0 : ret = read_core_sysfs_s(f, buf, sizeof(buf));
205 [ # # ]: 0 : if ((ret) < 0) {
206 : 0 : POWER_LOG(ERR, "Failed to read %s",
207 : : POWER_SYSFILE_SETSPEED);
208 : 0 : goto err;
209 : : }
210 : :
211 : 0 : freq = strtoul(buf, NULL, POWER_CONVERT_TO_DECIMAL);
212 [ # # ]: 0 : for (i = 0; i < pi->nb_freqs; i++) {
213 [ # # ]: 0 : if (freq == pi->freqs[i]) {
214 : 0 : pi->curr_idx = i;
215 : 0 : pi->f = f;
216 : 0 : return 0;
217 : : }
218 : : }
219 : :
220 : 0 : err:
221 [ # # ]: 0 : if (f != NULL)
222 : 0 : fclose(f);
223 : :
224 : : return -1;
225 : : }
226 : :
227 : : int
228 : 1 : power_acpi_cpufreq_check_supported(void)
229 : : {
230 : 1 : return cpufreq_check_scaling_driver(POWER_ACPI_DRIVER);
231 : : }
232 : :
233 : : int
234 : 1 : power_acpi_cpufreq_init(unsigned int lcore_id)
235 : : {
236 : : struct acpi_power_info *pi;
237 : : uint32_t exp_state;
238 : :
239 [ + - ]: 1 : if (!power_acpi_cpufreq_check_supported()) {
240 : 1 : POWER_LOG(ERR, "%s driver is not supported",
241 : : POWER_ACPI_DRIVER);
242 : 1 : return -1;
243 : : }
244 : :
245 [ # # ]: 0 : if (lcore_id >= RTE_MAX_LCORE) {
246 : 0 : POWER_LOG(ERR, "Lcore id %u can not exceeds %u",
247 : : lcore_id, RTE_MAX_LCORE - 1U);
248 : 0 : return -1;
249 : : }
250 : :
251 : 0 : pi = &lcore_power_info[lcore_id];
252 : : exp_state = POWER_IDLE;
253 : : /* The power in use state works as a guard variable between
254 : : * the CPU frequency control initialization and exit process.
255 : : * The ACQUIRE memory ordering here pairs with the RELEASE
256 : : * ordering below as lock to make sure the frequency operations
257 : : * in the critical section are done under the correct state.
258 : : */
259 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&(pi->state), &exp_state,
260 : : POWER_ONGOING,
261 : : rte_memory_order_acquire, rte_memory_order_relaxed)) {
262 : 0 : POWER_LOG(INFO, "Power management of lcore %u is "
263 : : "in use", lcore_id);
264 : 0 : return -1;
265 : : }
266 : :
267 [ # # ]: 0 : if (power_get_lcore_mapped_cpu_id(lcore_id, &pi->lcore_id) < 0) {
268 : 0 : POWER_LOG(ERR, "Cannot get CPU ID mapped for lcore %u", lcore_id);
269 : 0 : return -1;
270 : : }
271 : :
272 : : /* Check and set the governor */
273 [ # # ]: 0 : if (power_set_governor_userspace(pi) < 0) {
274 : 0 : POWER_LOG(ERR, "Cannot set governor of lcore %u to "
275 : : "userspace", lcore_id);
276 : 0 : goto fail;
277 : : }
278 : :
279 : : /* Get the available frequencies */
280 [ # # ]: 0 : if (power_get_available_freqs(pi) < 0) {
281 : 0 : POWER_LOG(ERR, "Cannot get available frequencies of "
282 : : "lcore %u", lcore_id);
283 : 0 : goto fail;
284 : : }
285 : :
286 : : /* Init for setting lcore frequency */
287 [ # # ]: 0 : if (power_init_for_setting_freq(pi) < 0) {
288 : 0 : POWER_LOG(ERR, "Cannot init for setting frequency for "
289 : : "lcore %u", lcore_id);
290 : 0 : goto fail;
291 : : }
292 : :
293 : : /* Set freq to max by default */
294 [ # # ]: 0 : if (power_acpi_cpufreq_freq_max(lcore_id) < 0) {
295 : 0 : POWER_LOG(ERR, "Cannot set frequency of lcore %u "
296 : : "to max", lcore_id);
297 : 0 : goto fail;
298 : : }
299 : :
300 : 0 : POWER_LOG(INFO, "Initialized successfully for lcore %u "
301 : : "power management", lcore_id);
302 : : exp_state = POWER_ONGOING;
303 : 0 : rte_atomic_compare_exchange_strong_explicit(&(pi->state), &exp_state, POWER_USED,
304 : : rte_memory_order_release, rte_memory_order_relaxed);
305 : :
306 : 0 : return 0;
307 : :
308 : 0 : fail:
309 : : exp_state = POWER_ONGOING;
310 : 0 : rte_atomic_compare_exchange_strong_explicit(&(pi->state), &exp_state, POWER_UNKNOWN,
311 : : rte_memory_order_release, rte_memory_order_relaxed);
312 : :
313 : 0 : return -1;
314 : : }
315 : :
316 : : int
317 : 0 : power_acpi_cpufreq_exit(unsigned int lcore_id)
318 : : {
319 : : struct acpi_power_info *pi;
320 : : uint32_t exp_state;
321 : :
322 [ # # ]: 0 : if (lcore_id >= RTE_MAX_LCORE) {
323 : 0 : POWER_LOG(ERR, "Lcore id %u can not exceeds %u",
324 : : lcore_id, RTE_MAX_LCORE - 1U);
325 : 0 : return -1;
326 : : }
327 : : pi = &lcore_power_info[lcore_id];
328 : : exp_state = POWER_USED;
329 : : /* The power in use state works as a guard variable between
330 : : * the CPU frequency control initialization and exit process.
331 : : * The ACQUIRE memory ordering here pairs with the RELEASE
332 : : * ordering below as lock to make sure the frequency operations
333 : : * in the critical section are done under the correct state.
334 : : */
335 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&(pi->state), &exp_state,
336 : : POWER_ONGOING,
337 : : rte_memory_order_acquire, rte_memory_order_relaxed)) {
338 : 0 : POWER_LOG(INFO, "Power management of lcore %u is "
339 : : "not used", lcore_id);
340 : 0 : return -1;
341 : : }
342 : :
343 : : /* Close FD of setting freq */
344 : 0 : fclose(pi->f);
345 : 0 : pi->f = NULL;
346 : :
347 : : /* Set the governor back to the original */
348 [ # # ]: 0 : if (power_set_governor_original(pi) < 0) {
349 : 0 : POWER_LOG(ERR, "Cannot set the governor of %u back "
350 : : "to the original", lcore_id);
351 : 0 : goto fail;
352 : : }
353 : :
354 : 0 : POWER_LOG(INFO, "Power management of lcore %u has exited from "
355 : : "'userspace' mode and been set back to the "
356 : : "original", lcore_id);
357 : : exp_state = POWER_ONGOING;
358 : 0 : rte_atomic_compare_exchange_strong_explicit(&(pi->state), &exp_state, POWER_IDLE,
359 : : rte_memory_order_release, rte_memory_order_relaxed);
360 : :
361 : 0 : return 0;
362 : :
363 : : fail:
364 : : exp_state = POWER_ONGOING;
365 : 0 : rte_atomic_compare_exchange_strong_explicit(&(pi->state), &exp_state, POWER_UNKNOWN,
366 : : rte_memory_order_release, rte_memory_order_relaxed);
367 : :
368 : 0 : return -1;
369 : : }
370 : :
371 : : uint32_t
372 : 0 : power_acpi_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t num)
373 : : {
374 : : struct acpi_power_info *pi;
375 : :
376 [ # # ]: 0 : if (lcore_id >= RTE_MAX_LCORE) {
377 : 0 : POWER_LOG(ERR, "Invalid lcore ID");
378 : 0 : return 0;
379 : : }
380 : :
381 [ # # ]: 0 : if (freqs == NULL) {
382 : 0 : POWER_LOG(ERR, "NULL buffer supplied");
383 : 0 : return 0;
384 : : }
385 : :
386 : : pi = &lcore_power_info[lcore_id];
387 [ # # ]: 0 : if (num < pi->nb_freqs) {
388 : 0 : POWER_LOG(ERR, "Buffer size is not enough");
389 : 0 : return 0;
390 : : }
391 [ # # ]: 0 : rte_memcpy(freqs, pi->freqs, pi->nb_freqs * sizeof(uint32_t));
392 : :
393 : 0 : return pi->nb_freqs;
394 : : }
395 : :
396 : : uint32_t
397 : 0 : power_acpi_cpufreq_get_freq(unsigned int lcore_id)
398 : : {
399 [ # # ]: 0 : if (lcore_id >= RTE_MAX_LCORE) {
400 : 0 : POWER_LOG(ERR, "Invalid lcore ID");
401 : 0 : return RTE_POWER_INVALID_FREQ_INDEX;
402 : : }
403 : :
404 : 0 : return lcore_power_info[lcore_id].curr_idx;
405 : : }
406 : :
407 : : int
408 : 0 : power_acpi_cpufreq_set_freq(unsigned int lcore_id, uint32_t index)
409 : : {
410 [ # # ]: 0 : if (lcore_id >= RTE_MAX_LCORE) {
411 : 0 : POWER_LOG(ERR, "Invalid lcore ID");
412 : 0 : return -1;
413 : : }
414 : :
415 : 0 : return set_freq_internal(&(lcore_power_info[lcore_id]), index);
416 : : }
417 : :
418 : : int
419 : 0 : power_acpi_cpufreq_freq_down(unsigned int lcore_id)
420 : : {
421 : : struct acpi_power_info *pi;
422 : :
423 [ # # ]: 0 : if (lcore_id >= RTE_MAX_LCORE) {
424 : 0 : POWER_LOG(ERR, "Invalid lcore ID");
425 : 0 : return -1;
426 : : }
427 : :
428 : 0 : pi = &lcore_power_info[lcore_id];
429 [ # # ]: 0 : if (pi->curr_idx + 1 == pi->nb_freqs)
430 : : return 0;
431 : :
432 : : /* Frequencies in the array are from high to low. */
433 : 0 : return set_freq_internal(pi, pi->curr_idx + 1);
434 : : }
435 : :
436 : : int
437 : 0 : power_acpi_cpufreq_freq_up(unsigned int lcore_id)
438 : : {
439 : : struct acpi_power_info *pi;
440 : :
441 [ # # ]: 0 : if (lcore_id >= RTE_MAX_LCORE) {
442 : 0 : POWER_LOG(ERR, "Invalid lcore ID");
443 : 0 : return -1;
444 : : }
445 : :
446 : 0 : pi = &lcore_power_info[lcore_id];
447 [ # # # # ]: 0 : if (pi->curr_idx == 0 ||
448 [ # # # # ]: 0 : (pi->curr_idx == 1 && pi->turbo_available && !pi->turbo_enable))
449 : : return 0;
450 : :
451 : : /* Frequencies in the array are from high to low. */
452 : 0 : return set_freq_internal(pi, pi->curr_idx - 1);
453 : : }
454 : :
455 : : int
456 : 0 : power_acpi_cpufreq_freq_max(unsigned int lcore_id)
457 : : {
458 [ # # ]: 0 : if (lcore_id >= RTE_MAX_LCORE) {
459 : 0 : POWER_LOG(ERR, "Invalid lcore ID");
460 : 0 : return -1;
461 : : }
462 : :
463 : : /* Frequencies in the array are from high to low. */
464 [ # # ]: 0 : if (lcore_power_info[lcore_id].turbo_available) {
465 [ # # ]: 0 : if (lcore_power_info[lcore_id].turbo_enable)
466 : : /* Set to Turbo */
467 : 0 : return set_freq_internal(
468 : : &lcore_power_info[lcore_id], 0);
469 : : else
470 : : /* Set to max non-turbo */
471 : 0 : return set_freq_internal(
472 : : &lcore_power_info[lcore_id], 1);
473 : : } else
474 : 0 : return set_freq_internal(&lcore_power_info[lcore_id], 0);
475 : : }
476 : :
477 : : int
478 : 0 : power_acpi_cpufreq_freq_min(unsigned int lcore_id)
479 : : {
480 : : struct acpi_power_info *pi;
481 : :
482 [ # # ]: 0 : if (lcore_id >= RTE_MAX_LCORE) {
483 : 0 : POWER_LOG(ERR, "Invalid lcore ID");
484 : 0 : return -1;
485 : : }
486 : :
487 : 0 : pi = &lcore_power_info[lcore_id];
488 : :
489 : : /* Frequencies in the array are from high to low. */
490 : 0 : return set_freq_internal(pi, pi->nb_freqs - 1);
491 : : }
492 : :
493 : :
494 : : int
495 : 0 : power_acpi_turbo_status(unsigned int lcore_id)
496 : : {
497 : : struct acpi_power_info *pi;
498 : :
499 [ # # ]: 0 : if (lcore_id >= RTE_MAX_LCORE) {
500 : 0 : POWER_LOG(ERR, "Invalid lcore ID");
501 : 0 : return -1;
502 : : }
503 : :
504 : : pi = &lcore_power_info[lcore_id];
505 : :
506 : 0 : return pi->turbo_enable;
507 : : }
508 : :
509 : :
510 : : int
511 : 0 : power_acpi_enable_turbo(unsigned int lcore_id)
512 : : {
513 : : struct acpi_power_info *pi;
514 : :
515 [ # # ]: 0 : if (lcore_id >= RTE_MAX_LCORE) {
516 : 0 : POWER_LOG(ERR, "Invalid lcore ID");
517 : 0 : return -1;
518 : : }
519 : :
520 : : pi = &lcore_power_info[lcore_id];
521 : :
522 [ # # ]: 0 : if (pi->turbo_available)
523 : 0 : pi->turbo_enable = 1;
524 : : else {
525 : 0 : pi->turbo_enable = 0;
526 : 0 : POWER_LOG(ERR,
527 : : "Failed to enable turbo on lcore %u",
528 : : lcore_id);
529 : 0 : return -1;
530 : : }
531 : :
532 : : /* Max may have changed, so call to max function */
533 [ # # ]: 0 : if (power_acpi_cpufreq_freq_max(lcore_id) < 0) {
534 : 0 : POWER_LOG(ERR,
535 : : "Failed to set frequency of lcore %u to max",
536 : : lcore_id);
537 : 0 : return -1;
538 : : }
539 : :
540 : : return 0;
541 : : }
542 : :
543 : : int
544 : 0 : power_acpi_disable_turbo(unsigned int lcore_id)
545 : : {
546 : : struct acpi_power_info *pi;
547 : :
548 [ # # ]: 0 : if (lcore_id >= RTE_MAX_LCORE) {
549 : 0 : POWER_LOG(ERR, "Invalid lcore ID");
550 : 0 : return -1;
551 : : }
552 : :
553 : : pi = &lcore_power_info[lcore_id];
554 : :
555 : 0 : pi->turbo_enable = 0;
556 : :
557 [ # # # # ]: 0 : if ((pi->turbo_available) && (pi->curr_idx <= 1)) {
558 : : /* Try to set freq to max by default coming out of turbo */
559 [ # # ]: 0 : if (power_acpi_cpufreq_freq_max(lcore_id) < 0) {
560 : 0 : POWER_LOG(ERR,
561 : : "Failed to set frequency of lcore %u to max",
562 : : lcore_id);
563 : 0 : return -1;
564 : : }
565 : : }
566 : :
567 : : return 0;
568 : : }
569 : :
570 : 0 : int power_acpi_get_capabilities(unsigned int lcore_id,
571 : : struct rte_power_core_capabilities *caps)
572 : : {
573 : : struct acpi_power_info *pi;
574 : :
575 [ # # ]: 0 : if (lcore_id >= RTE_MAX_LCORE) {
576 : 0 : POWER_LOG(ERR, "Invalid lcore ID");
577 : 0 : return -1;
578 : : }
579 [ # # ]: 0 : if (caps == NULL) {
580 : 0 : POWER_LOG(ERR, "Invalid argument");
581 : 0 : return -1;
582 : : }
583 : :
584 : : pi = &lcore_power_info[lcore_id];
585 : 0 : caps->capabilities = 0;
586 : 0 : caps->turbo = !!(pi->turbo_available);
587 : :
588 : 0 : return 0;
589 : : }
590 : :
591 : : static struct rte_power_cpufreq_ops acpi_ops = {
592 : : .name = "acpi",
593 : : .init = power_acpi_cpufreq_init,
594 : : .exit = power_acpi_cpufreq_exit,
595 : : .check_env_support = power_acpi_cpufreq_check_supported,
596 : : .get_avail_freqs = power_acpi_cpufreq_freqs,
597 : : .get_freq = power_acpi_cpufreq_get_freq,
598 : : .set_freq = power_acpi_cpufreq_set_freq,
599 : : .freq_down = power_acpi_cpufreq_freq_down,
600 : : .freq_up = power_acpi_cpufreq_freq_up,
601 : : .freq_max = power_acpi_cpufreq_freq_max,
602 : : .freq_min = power_acpi_cpufreq_freq_min,
603 : : .turbo_status = power_acpi_turbo_status,
604 : : .enable_turbo = power_acpi_enable_turbo,
605 : : .disable_turbo = power_acpi_disable_turbo,
606 : : .get_caps = power_acpi_get_capabilities
607 : : };
608 : :
609 : 251 : RTE_POWER_REGISTER_CPUFREQ_OPS(acpi_ops);
|