2017-12-19 15:49:03 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
* Copyright(c) 2010-2014 Intel Corporation
|
2014-11-25 16:18:08 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <limits.h>
|
|
|
|
|
2019-05-05 18:12:16 +00:00
|
|
|
#include <rte_memcpy.h>
|
|
|
|
#include <rte_memory.h>
|
|
|
|
#include <rte_string_fns.h>
|
2014-11-25 16:18:08 +00:00
|
|
|
|
2017-12-12 14:03:26 +00:00
|
|
|
#include "power_acpi_cpufreq.h"
|
2017-12-12 14:03:25 +00:00
|
|
|
#include "power_common.h"
|
2014-11-25 16:18:08 +00:00
|
|
|
|
|
|
|
#define STR_SIZE 1024
|
|
|
|
#define POWER_CONVERT_TO_DECIMAL 10
|
|
|
|
|
|
|
|
#define POWER_GOVERNOR_USERSPACE "userspace"
|
|
|
|
#define POWER_SYSFILE_AVAIL_FREQ \
|
|
|
|
"/sys/devices/system/cpu/cpu%u/cpufreq/scaling_available_frequencies"
|
|
|
|
#define POWER_SYSFILE_SETSPEED \
|
|
|
|
"/sys/devices/system/cpu/cpu%u/cpufreq/scaling_setspeed"
|
2020-06-19 10:53:54 +00:00
|
|
|
#define POWER_ACPI_DRIVER "acpi-cpufreq"
|
2014-11-25 16:18:08 +00:00
|
|
|
|
2017-09-13 10:44:16 +00:00
|
|
|
/*
|
|
|
|
* MSR related
|
|
|
|
*/
|
|
|
|
#define PLATFORM_INFO 0x0CE
|
|
|
|
#define TURBO_RATIO_LIMIT 0x1AD
|
|
|
|
#define IA32_PERF_CTL 0x199
|
|
|
|
#define CORE_TURBO_DISABLE_BIT ((uint64_t)1<<32)
|
|
|
|
|
2014-11-25 16:18:08 +00:00
|
|
|
enum power_state {
|
|
|
|
POWER_IDLE = 0,
|
|
|
|
POWER_ONGOING,
|
|
|
|
POWER_USED,
|
|
|
|
POWER_UNKNOWN
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Power info per lcore.
|
|
|
|
*/
|
2021-07-08 15:38:22 +00:00
|
|
|
struct acpi_power_info {
|
2017-12-12 14:03:24 +00:00
|
|
|
unsigned int lcore_id; /**< Logical core id */
|
2014-11-25 16:18:08 +00:00
|
|
|
uint32_t freqs[RTE_MAX_LCORE_FREQS]; /**< Frequency array */
|
|
|
|
uint32_t nb_freqs; /**< number of available freqs */
|
|
|
|
FILE *f; /**< FD of scaling_setspeed */
|
|
|
|
char governor_ori[32]; /**< Original governor name */
|
|
|
|
uint32_t curr_idx; /**< Freq index in freqs array */
|
2020-09-24 05:39:27 +00:00
|
|
|
uint32_t state; /**< Power in use state */
|
2017-09-13 10:44:16 +00:00
|
|
|
uint16_t turbo_available; /**< Turbo Boost available */
|
|
|
|
uint16_t turbo_enable; /**< Turbo Boost enable/disable */
|
2014-11-25 16:18:08 +00:00
|
|
|
} __rte_cache_aligned;
|
|
|
|
|
2021-07-08 15:38:22 +00:00
|
|
|
static struct acpi_power_info lcore_power_info[RTE_MAX_LCORE];
|
2014-11-25 16:18:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* It is to set specific freq for specific logical core, according to the index
|
|
|
|
* of supported frequencies.
|
|
|
|
*/
|
|
|
|
static int
|
2021-07-08 15:38:22 +00:00
|
|
|
set_freq_internal(struct acpi_power_info *pi, uint32_t idx)
|
2014-11-25 16:18:08 +00:00
|
|
|
{
|
|
|
|
if (idx >= RTE_MAX_LCORE_FREQS || idx >= pi->nb_freqs) {
|
|
|
|
RTE_LOG(ERR, POWER, "Invalid frequency index %u, which "
|
|
|
|
"should be less than %u\n", idx, pi->nb_freqs);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if it is the same as current */
|
|
|
|
if (idx == pi->curr_idx)
|
|
|
|
return 0;
|
|
|
|
|
2019-11-13 16:10:14 +00:00
|
|
|
POWER_DEBUG_TRACE("Frequency[%u] %u to be set for lcore %u\n",
|
2014-11-25 16:18:08 +00:00
|
|
|
idx, pi->freqs[idx], pi->lcore_id);
|
|
|
|
if (fseek(pi->f, 0, SEEK_SET) < 0) {
|
|
|
|
RTE_LOG(ERR, POWER, "Fail to set file position indicator to 0 "
|
|
|
|
"for setting frequency for lcore %u\n", pi->lcore_id);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (fprintf(pi->f, "%u", pi->freqs[idx]) < 0) {
|
|
|
|
RTE_LOG(ERR, POWER, "Fail to write new frequency for "
|
|
|
|
"lcore %u\n", pi->lcore_id);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
fflush(pi->f);
|
|
|
|
pi->curr_idx = idx;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* It is to check the current scaling governor by reading sys file, and then
|
|
|
|
* set it into 'userspace' if it is not by writing the sys file. The original
|
|
|
|
* governor will be saved for rolling back.
|
|
|
|
*/
|
|
|
|
static int
|
2021-07-08 15:38:22 +00:00
|
|
|
power_set_governor_userspace(struct acpi_power_info *pi)
|
2014-11-25 16:18:08 +00:00
|
|
|
{
|
2021-07-08 15:38:23 +00:00
|
|
|
return power_set_governor(pi->lcore_id, POWER_GOVERNOR_USERSPACE,
|
|
|
|
pi->governor_ori, sizeof(pi->governor_ori));
|
|
|
|
}
|
2014-11-25 16:18:08 +00:00
|
|
|
|
2021-07-08 15:38:23 +00:00
|
|
|
/**
|
|
|
|
* It is to check the governor and then set the original governor back if
|
|
|
|
* needed by writing the sys file.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
power_set_governor_original(struct acpi_power_info *pi)
|
|
|
|
{
|
|
|
|
return power_set_governor(pi->lcore_id, pi->governor_ori, NULL, 0);
|
2014-11-25 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* It is to get the available frequencies of the specific lcore by reading the
|
|
|
|
* sys file.
|
|
|
|
*/
|
|
|
|
static int
|
2021-07-08 15:38:22 +00:00
|
|
|
power_get_available_freqs(struct acpi_power_info *pi)
|
2014-11-25 16:18:08 +00:00
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
int ret = -1, i, count;
|
|
|
|
char *p;
|
|
|
|
char buf[BUFSIZ];
|
|
|
|
char *freqs[RTE_MAX_LCORE_FREQS];
|
|
|
|
|
2021-07-08 15:38:23 +00:00
|
|
|
open_core_sysfs_file(&f, "r", POWER_SYSFILE_AVAIL_FREQ, pi->lcore_id);
|
|
|
|
if (f == NULL) {
|
|
|
|
RTE_LOG(ERR, POWER, "failed to open %s\n",
|
|
|
|
POWER_SYSFILE_AVAIL_FREQ);
|
|
|
|
goto out;
|
|
|
|
}
|
2014-11-25 16:18:08 +00:00
|
|
|
|
2021-07-08 15:38:23 +00:00
|
|
|
ret = read_core_sysfs_s(f, buf, sizeof(buf));
|
|
|
|
if ((ret) < 0) {
|
|
|
|
RTE_LOG(ERR, POWER, "Failed to read %s\n",
|
|
|
|
POWER_SYSFILE_AVAIL_FREQ);
|
|
|
|
goto out;
|
|
|
|
}
|
2014-11-25 16:18:08 +00:00
|
|
|
|
|
|
|
/* Split string into at most RTE_MAX_LCORE_FREQS frequencies */
|
|
|
|
count = rte_strsplit(buf, sizeof(buf), freqs,
|
|
|
|
RTE_MAX_LCORE_FREQS, ' ');
|
|
|
|
if (count <= 0) {
|
|
|
|
RTE_LOG(ERR, POWER, "No available frequency in "
|
|
|
|
""POWER_SYSFILE_AVAIL_FREQ"\n", pi->lcore_id);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (count >= RTE_MAX_LCORE_FREQS) {
|
|
|
|
RTE_LOG(ERR, POWER, "Too many available frequencies : %d\n",
|
|
|
|
count);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Store the available frequncies into power context */
|
|
|
|
for (i = 0, pi->nb_freqs = 0; i < count; i++) {
|
|
|
|
POWER_DEBUG_TRACE("Lcore %u frequency[%d]: %s\n", pi->lcore_id,
|
|
|
|
i, freqs[i]);
|
|
|
|
pi->freqs[pi->nb_freqs++] = strtoul(freqs[i], &p,
|
|
|
|
POWER_CONVERT_TO_DECIMAL);
|
|
|
|
}
|
|
|
|
|
2017-09-13 10:44:16 +00:00
|
|
|
if ((pi->freqs[0]-1000) == pi->freqs[1]) {
|
|
|
|
pi->turbo_available = 1;
|
|
|
|
pi->turbo_enable = 1;
|
|
|
|
POWER_DEBUG_TRACE("Lcore %u Can do Turbo Boost\n",
|
|
|
|
pi->lcore_id);
|
|
|
|
} else {
|
|
|
|
pi->turbo_available = 0;
|
|
|
|
pi->turbo_enable = 0;
|
|
|
|
POWER_DEBUG_TRACE("Turbo Boost not available on Lcore %u\n",
|
|
|
|
pi->lcore_id);
|
|
|
|
}
|
|
|
|
|
2014-11-25 16:18:08 +00:00
|
|
|
ret = 0;
|
2017-11-10 08:24:23 +00:00
|
|
|
POWER_DEBUG_TRACE("%d frequency(s) of lcore %u are available\n",
|
2014-11-25 16:18:08 +00:00
|
|
|
count, pi->lcore_id);
|
|
|
|
out:
|
2021-07-08 15:38:23 +00:00
|
|
|
if (f != NULL)
|
|
|
|
fclose(f);
|
2014-11-25 16:18:08 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* It is to fopen the sys file for the future setting the lcore frequency.
|
|
|
|
*/
|
|
|
|
static int
|
2021-07-08 15:38:22 +00:00
|
|
|
power_init_for_setting_freq(struct acpi_power_info *pi)
|
2014-11-25 16:18:08 +00:00
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
char buf[BUFSIZ];
|
|
|
|
uint32_t i, freq;
|
2021-07-08 15:38:23 +00:00
|
|
|
int ret;
|
2014-11-25 16:18:08 +00:00
|
|
|
|
2021-07-08 15:38:23 +00:00
|
|
|
open_core_sysfs_file(&f, "rw+", POWER_SYSFILE_SETSPEED, pi->lcore_id);
|
|
|
|
if (f == NULL) {
|
|
|
|
RTE_LOG(ERR, POWER, "Failed to open %s\n",
|
|
|
|
POWER_SYSFILE_SETSPEED);
|
|
|
|
goto err;
|
|
|
|
}
|
2014-11-25 16:18:08 +00:00
|
|
|
|
2021-07-08 15:38:23 +00:00
|
|
|
ret = read_core_sysfs_s(f, buf, sizeof(buf));
|
|
|
|
if ((ret) < 0) {
|
|
|
|
RTE_LOG(ERR, POWER, "Failed to read %s\n",
|
|
|
|
POWER_SYSFILE_SETSPEED);
|
|
|
|
goto err;
|
|
|
|
}
|
2014-11-25 16:18:08 +00:00
|
|
|
|
|
|
|
freq = strtoul(buf, NULL, POWER_CONVERT_TO_DECIMAL);
|
|
|
|
for (i = 0; i < pi->nb_freqs; i++) {
|
|
|
|
if (freq == pi->freqs[i]) {
|
|
|
|
pi->curr_idx = i;
|
|
|
|
pi->f = f;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-08 15:38:23 +00:00
|
|
|
err:
|
|
|
|
if (f != NULL)
|
|
|
|
fclose(f);
|
2014-11-25 16:18:08 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-06-19 10:53:54 +00:00
|
|
|
int
|
|
|
|
power_acpi_cpufreq_check_supported(void)
|
|
|
|
{
|
|
|
|
return cpufreq_check_scaling_driver(POWER_ACPI_DRIVER);
|
|
|
|
}
|
|
|
|
|
2014-11-25 16:18:08 +00:00
|
|
|
int
|
2017-12-12 14:03:26 +00:00
|
|
|
power_acpi_cpufreq_init(unsigned int lcore_id)
|
2014-11-25 16:18:08 +00:00
|
|
|
{
|
2021-07-08 15:38:22 +00:00
|
|
|
struct acpi_power_info *pi;
|
2020-09-24 05:39:27 +00:00
|
|
|
uint32_t exp_state;
|
2014-11-25 16:18:08 +00:00
|
|
|
|
|
|
|
if (lcore_id >= RTE_MAX_LCORE) {
|
|
|
|
RTE_LOG(ERR, POWER, "Lcore id %u can not exceeds %u\n",
|
|
|
|
lcore_id, RTE_MAX_LCORE - 1U);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pi = &lcore_power_info[lcore_id];
|
2020-09-24 05:39:27 +00:00
|
|
|
exp_state = POWER_IDLE;
|
|
|
|
/* The power in use state works as a guard variable between
|
|
|
|
* the CPU frequency control initialization and exit process.
|
|
|
|
* The ACQUIRE memory ordering here pairs with the RELEASE
|
|
|
|
* ordering below as lock to make sure the frequency operations
|
|
|
|
* in the critical section are done under the correct state.
|
|
|
|
*/
|
|
|
|
if (!__atomic_compare_exchange_n(&(pi->state), &exp_state,
|
|
|
|
POWER_ONGOING, 0,
|
|
|
|
__ATOMIC_ACQUIRE, __ATOMIC_RELAXED)) {
|
2014-11-25 16:18:08 +00:00
|
|
|
RTE_LOG(INFO, POWER, "Power management of lcore %u is "
|
|
|
|
"in use\n", lcore_id);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pi->lcore_id = lcore_id;
|
|
|
|
/* Check and set the governor */
|
|
|
|
if (power_set_governor_userspace(pi) < 0) {
|
|
|
|
RTE_LOG(ERR, POWER, "Cannot set governor of lcore %u to "
|
|
|
|
"userspace\n", lcore_id);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the available frequencies */
|
|
|
|
if (power_get_available_freqs(pi) < 0) {
|
|
|
|
RTE_LOG(ERR, POWER, "Cannot get available frequencies of "
|
|
|
|
"lcore %u\n", lcore_id);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Init for setting lcore frequency */
|
|
|
|
if (power_init_for_setting_freq(pi) < 0) {
|
|
|
|
RTE_LOG(ERR, POWER, "Cannot init for setting frequency for "
|
|
|
|
"lcore %u\n", lcore_id);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set freq to max by default */
|
2017-12-12 14:03:26 +00:00
|
|
|
if (power_acpi_cpufreq_freq_max(lcore_id) < 0) {
|
2014-11-25 16:18:08 +00:00
|
|
|
RTE_LOG(ERR, POWER, "Cannot set frequency of lcore %u "
|
|
|
|
"to max\n", lcore_id);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
RTE_LOG(INFO, POWER, "Initialized successfully for lcore %u "
|
2017-11-10 08:24:23 +00:00
|
|
|
"power management\n", lcore_id);
|
2020-09-24 05:39:27 +00:00
|
|
|
exp_state = POWER_ONGOING;
|
|
|
|
__atomic_compare_exchange_n(&(pi->state), &exp_state, POWER_USED,
|
|
|
|
0, __ATOMIC_RELEASE, __ATOMIC_RELAXED);
|
2014-11-25 16:18:08 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
2020-09-24 05:39:27 +00:00
|
|
|
exp_state = POWER_ONGOING;
|
|
|
|
__atomic_compare_exchange_n(&(pi->state), &exp_state, POWER_UNKNOWN,
|
|
|
|
0, __ATOMIC_RELEASE, __ATOMIC_RELAXED);
|
2014-11-25 16:18:08 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2017-12-12 14:03:26 +00:00
|
|
|
power_acpi_cpufreq_exit(unsigned int lcore_id)
|
2014-11-25 16:18:08 +00:00
|
|
|
{
|
2021-07-08 15:38:22 +00:00
|
|
|
struct acpi_power_info *pi;
|
2020-09-24 05:39:27 +00:00
|
|
|
uint32_t exp_state;
|
2014-11-25 16:18:08 +00:00
|
|
|
|
|
|
|
if (lcore_id >= RTE_MAX_LCORE) {
|
|
|
|
RTE_LOG(ERR, POWER, "Lcore id %u can not exceeds %u\n",
|
|
|
|
lcore_id, RTE_MAX_LCORE - 1U);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
pi = &lcore_power_info[lcore_id];
|
2020-09-24 05:39:27 +00:00
|
|
|
exp_state = POWER_USED;
|
|
|
|
/* The power in use state works as a guard variable between
|
|
|
|
* the CPU frequency control initialization and exit process.
|
|
|
|
* The ACQUIRE memory ordering here pairs with the RELEASE
|
|
|
|
* ordering below as lock to make sure the frequency operations
|
|
|
|
* in the critical section are done under the correct state.
|
|
|
|
*/
|
|
|
|
if (!__atomic_compare_exchange_n(&(pi->state), &exp_state,
|
|
|
|
POWER_ONGOING, 0,
|
|
|
|
__ATOMIC_ACQUIRE, __ATOMIC_RELAXED)) {
|
2014-11-25 16:18:08 +00:00
|
|
|
RTE_LOG(INFO, POWER, "Power management of lcore %u is "
|
|
|
|
"not used\n", lcore_id);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Close FD of setting freq */
|
|
|
|
fclose(pi->f);
|
|
|
|
pi->f = NULL;
|
|
|
|
|
|
|
|
/* Set the governor back to the original */
|
|
|
|
if (power_set_governor_original(pi) < 0) {
|
|
|
|
RTE_LOG(ERR, POWER, "Cannot set the governor of %u back "
|
|
|
|
"to the original\n", lcore_id);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
RTE_LOG(INFO, POWER, "Power management of lcore %u has exited from "
|
|
|
|
"'userspace' mode and been set back to the "
|
|
|
|
"original\n", lcore_id);
|
2020-09-24 05:39:27 +00:00
|
|
|
exp_state = POWER_ONGOING;
|
|
|
|
__atomic_compare_exchange_n(&(pi->state), &exp_state, POWER_IDLE,
|
|
|
|
0, __ATOMIC_RELEASE, __ATOMIC_RELAXED);
|
2014-11-25 16:18:08 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
2020-09-24 05:39:27 +00:00
|
|
|
exp_state = POWER_ONGOING;
|
|
|
|
__atomic_compare_exchange_n(&(pi->state), &exp_state, POWER_UNKNOWN,
|
|
|
|
0, __ATOMIC_RELEASE, __ATOMIC_RELAXED);
|
2014-11-25 16:18:08 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
2017-12-12 14:03:26 +00:00
|
|
|
power_acpi_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t num)
|
2014-11-25 16:18:08 +00:00
|
|
|
{
|
2021-07-08 15:38:22 +00:00
|
|
|
struct acpi_power_info *pi;
|
2014-11-25 16:18:08 +00:00
|
|
|
|
2019-02-06 12:19:06 +00:00
|
|
|
if (lcore_id >= RTE_MAX_LCORE) {
|
|
|
|
RTE_LOG(ERR, POWER, "Invalid lcore ID\n");
|
2014-11-25 16:18:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-01-07 14:39:34 +00:00
|
|
|
if (freqs == NULL) {
|
|
|
|
RTE_LOG(ERR, POWER, "NULL buffer supplied\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-25 16:18:08 +00:00
|
|
|
pi = &lcore_power_info[lcore_id];
|
|
|
|
if (num < pi->nb_freqs) {
|
|
|
|
RTE_LOG(ERR, POWER, "Buffer size is not enough\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
rte_memcpy(freqs, pi->freqs, pi->nb_freqs * sizeof(uint32_t));
|
|
|
|
|
|
|
|
return pi->nb_freqs;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
2017-12-12 14:03:26 +00:00
|
|
|
power_acpi_cpufreq_get_freq(unsigned int lcore_id)
|
2014-11-25 16:18:08 +00:00
|
|
|
{
|
|
|
|
if (lcore_id >= RTE_MAX_LCORE) {
|
|
|
|
RTE_LOG(ERR, POWER, "Invalid lcore ID\n");
|
|
|
|
return RTE_POWER_INVALID_FREQ_INDEX;
|
|
|
|
}
|
|
|
|
|
|
|
|
return lcore_power_info[lcore_id].curr_idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2017-12-12 14:03:26 +00:00
|
|
|
power_acpi_cpufreq_set_freq(unsigned int lcore_id, uint32_t index)
|
2014-11-25 16:18:08 +00:00
|
|
|
{
|
|
|
|
if (lcore_id >= RTE_MAX_LCORE) {
|
|
|
|
RTE_LOG(ERR, POWER, "Invalid lcore ID\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return set_freq_internal(&(lcore_power_info[lcore_id]), index);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2017-12-12 14:03:26 +00:00
|
|
|
power_acpi_cpufreq_freq_down(unsigned int lcore_id)
|
2014-11-25 16:18:08 +00:00
|
|
|
{
|
2021-07-08 15:38:22 +00:00
|
|
|
struct acpi_power_info *pi;
|
2014-11-25 16:18:08 +00:00
|
|
|
|
|
|
|
if (lcore_id >= RTE_MAX_LCORE) {
|
|
|
|
RTE_LOG(ERR, POWER, "Invalid lcore ID\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pi = &lcore_power_info[lcore_id];
|
|
|
|
if (pi->curr_idx + 1 == pi->nb_freqs)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Frequencies in the array are from high to low. */
|
|
|
|
return set_freq_internal(pi, pi->curr_idx + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2017-12-12 14:03:26 +00:00
|
|
|
power_acpi_cpufreq_freq_up(unsigned int lcore_id)
|
2014-11-25 16:18:08 +00:00
|
|
|
{
|
2021-07-08 15:38:22 +00:00
|
|
|
struct acpi_power_info *pi;
|
2014-11-25 16:18:08 +00:00
|
|
|
|
|
|
|
if (lcore_id >= RTE_MAX_LCORE) {
|
|
|
|
RTE_LOG(ERR, POWER, "Invalid lcore ID\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pi = &lcore_power_info[lcore_id];
|
2019-11-14 14:10:36 +00:00
|
|
|
if (pi->curr_idx == 0 ||
|
|
|
|
(pi->curr_idx == 1 && pi->turbo_available && !pi->turbo_enable))
|
2014-11-25 16:18:08 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Frequencies in the array are from high to low. */
|
|
|
|
return set_freq_internal(pi, pi->curr_idx - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2017-12-12 14:03:26 +00:00
|
|
|
power_acpi_cpufreq_freq_max(unsigned int lcore_id)
|
2014-11-25 16:18:08 +00:00
|
|
|
{
|
|
|
|
if (lcore_id >= RTE_MAX_LCORE) {
|
|
|
|
RTE_LOG(ERR, POWER, "Invalid lcore ID\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Frequencies in the array are from high to low. */
|
2017-09-13 10:44:16 +00:00
|
|
|
if (lcore_power_info[lcore_id].turbo_available) {
|
|
|
|
if (lcore_power_info[lcore_id].turbo_enable)
|
|
|
|
/* Set to Turbo */
|
|
|
|
return set_freq_internal(
|
|
|
|
&lcore_power_info[lcore_id], 0);
|
|
|
|
else
|
|
|
|
/* Set to max non-turbo */
|
|
|
|
return set_freq_internal(
|
|
|
|
&lcore_power_info[lcore_id], 1);
|
|
|
|
} else
|
|
|
|
return set_freq_internal(&lcore_power_info[lcore_id], 0);
|
2014-11-25 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2017-12-12 14:03:26 +00:00
|
|
|
power_acpi_cpufreq_freq_min(unsigned int lcore_id)
|
2014-11-25 16:18:08 +00:00
|
|
|
{
|
2021-07-08 15:38:22 +00:00
|
|
|
struct acpi_power_info *pi;
|
2014-11-25 16:18:08 +00:00
|
|
|
|
|
|
|
if (lcore_id >= RTE_MAX_LCORE) {
|
|
|
|
RTE_LOG(ERR, POWER, "Invalid lcore ID\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pi = &lcore_power_info[lcore_id];
|
|
|
|
|
|
|
|
/* Frequencies in the array are from high to low. */
|
|
|
|
return set_freq_internal(pi, pi->nb_freqs - 1);
|
|
|
|
}
|
2017-09-13 10:44:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
int
|
2017-12-12 14:03:26 +00:00
|
|
|
power_acpi_turbo_status(unsigned int lcore_id)
|
2017-09-13 10:44:16 +00:00
|
|
|
{
|
2021-07-08 15:38:22 +00:00
|
|
|
struct acpi_power_info *pi;
|
2017-09-13 10:44:16 +00:00
|
|
|
|
|
|
|
if (lcore_id >= RTE_MAX_LCORE) {
|
|
|
|
RTE_LOG(ERR, POWER, "Invalid lcore ID\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pi = &lcore_power_info[lcore_id];
|
|
|
|
|
|
|
|
return pi->turbo_enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2017-12-12 14:03:26 +00:00
|
|
|
power_acpi_enable_turbo(unsigned int lcore_id)
|
2017-09-13 10:44:16 +00:00
|
|
|
{
|
2021-07-08 15:38:22 +00:00
|
|
|
struct acpi_power_info *pi;
|
2017-09-13 10:44:16 +00:00
|
|
|
|
|
|
|
if (lcore_id >= RTE_MAX_LCORE) {
|
|
|
|
RTE_LOG(ERR, POWER, "Invalid lcore ID\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pi = &lcore_power_info[lcore_id];
|
|
|
|
|
|
|
|
if (pi->turbo_available)
|
|
|
|
pi->turbo_enable = 1;
|
|
|
|
else {
|
|
|
|
pi->turbo_enable = 0;
|
|
|
|
RTE_LOG(ERR, POWER,
|
|
|
|
"Failed to enable turbo on lcore %u\n",
|
|
|
|
lcore_id);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Max may have changed, so call to max function */
|
2017-12-12 14:03:26 +00:00
|
|
|
if (power_acpi_cpufreq_freq_max(lcore_id) < 0) {
|
2017-09-13 10:44:16 +00:00
|
|
|
RTE_LOG(ERR, POWER,
|
|
|
|
"Failed to set frequency of lcore %u to max\n",
|
|
|
|
lcore_id);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2017-12-12 14:03:26 +00:00
|
|
|
power_acpi_disable_turbo(unsigned int lcore_id)
|
2017-09-13 10:44:16 +00:00
|
|
|
{
|
2021-07-08 15:38:22 +00:00
|
|
|
struct acpi_power_info *pi;
|
2017-09-13 10:44:16 +00:00
|
|
|
|
|
|
|
if (lcore_id >= RTE_MAX_LCORE) {
|
|
|
|
RTE_LOG(ERR, POWER, "Invalid lcore ID\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pi = &lcore_power_info[lcore_id];
|
|
|
|
|
|
|
|
pi->turbo_enable = 0;
|
|
|
|
|
|
|
|
if ((pi->turbo_available) && (pi->curr_idx <= 1)) {
|
|
|
|
/* Try to set freq to max by default coming out of turbo */
|
2017-12-12 14:03:26 +00:00
|
|
|
if (power_acpi_cpufreq_freq_max(lcore_id) < 0) {
|
2017-09-13 10:44:16 +00:00
|
|
|
RTE_LOG(ERR, POWER,
|
|
|
|
"Failed to set frequency of lcore %u to max\n",
|
|
|
|
lcore_id);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2018-06-11 10:03:21 +00:00
|
|
|
|
|
|
|
int power_acpi_get_capabilities(unsigned int lcore_id,
|
|
|
|
struct rte_power_core_capabilities *caps)
|
|
|
|
{
|
2021-07-08 15:38:22 +00:00
|
|
|
struct acpi_power_info *pi;
|
2018-06-11 10:03:21 +00:00
|
|
|
|
|
|
|
if (lcore_id >= RTE_MAX_LCORE) {
|
|
|
|
RTE_LOG(ERR, POWER, "Invalid lcore ID\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (caps == NULL) {
|
|
|
|
RTE_LOG(ERR, POWER, "Invalid argument\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pi = &lcore_power_info[lcore_id];
|
|
|
|
caps->capabilities = 0;
|
|
|
|
caps->turbo = !!(pi->turbo_available);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|