LCOV - code coverage report
Current view: top level - drivers/power/acpi - acpi_cpufreq.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 7 202 3.5 %
Date: 2026-07-01 18:02:41 Functions: 3 18 16.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 1 110 0.9 %

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

Generated by: LCOV version 1.14