power: initial import

Signed-off-by: Intel
This commit is contained in:
Intel 2013-06-03 00:00:00 +00:00 committed by Thomas Monjalon
parent 5c510e13a9
commit d7937e2e3d
18 changed files with 3145 additions and 1 deletions

View File

@ -87,6 +87,7 @@ SRCS-$(CONFIG_RTE_APP_TEST) += test_cmdline_string.c
SRCS-$(CONFIG_RTE_APP_TEST) += test_cmdline_lib.c
SRCS-$(CONFIG_RTE_APP_TEST) += test_pmac_pm.c
SRCS-$(CONFIG_RTE_APP_TEST) += test_pmac_acl.c
SRCS-$(CONFIG_RTE_APP_TEST) += test_power.c
CFLAGS += -O3
CFLAGS += $(WERROR_FLAGS)

View File

@ -363,6 +363,19 @@ non_parallel_test_group_list = [
},
]
},
{
"Prefix" : "power",
"Memory" : all_sockets(512),
"Tests" :
[
{
"Name" : "Power autotest",
"Command" : "power_autotest",
"Func" : default_autotest,
"Report" : None,
},
]
},
{
"Prefix" : "lpm6",
"Memory" : "512",

View File

@ -171,6 +171,8 @@ static void cmd_autotest_parsed(void *parsed_result,
ret |= test_pmac_pm();
if (all || !strcmp(res->autotest, "acl_autotest"))
ret |= test_pmac_acl();
if (all || !strcmp(res->autotest, "power_autotest"))
ret |= test_power();
if (ret == 0)
printf("Test OK\n");
@ -200,7 +202,7 @@ cmdline_parse_token_string_t cmd_autotest_autotest =
"cmdline_autotest#func_reentrancy_autotest#"
"mempool_perf_autotest#hash_perf_autotest#"
"memcpy_perf_autotest#pm_autotest#"
"acl_autotest#"
"acl_autotest#power_autotest#"
"all_autotests");
cmdline_parse_inst_t cmd_autotest = {

View File

@ -86,6 +86,7 @@ int test_cmdline(void);
int test_func_reentrancy(void);
int test_pmac_pm(void);
int test_pmac_acl(void);
int test_power(void);
int test_pci_run;

487
app/test/test_power.c Normal file
View File

@ -0,0 +1,487 @@
/*-
* BSD LICENSE
*
* Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <limits.h>
#include <string.h>
#include <cmdline_parse.h>
#include "test.h"
#ifdef RTE_LIBRTE_POWER
#include <rte_power.h>
#define TEST_POWER_LCORE_ID 2U
#define TEST_POWER_LCORE_INVALID ((unsigned)RTE_MAX_LCORE)
#define TEST_POWER_FREQS_NUM_MAX ((unsigned)RTE_MAX_LCORE_FREQS)
#define TEST_POWER_SYSFILE_CUR_FREQ \
"/sys/devices/system/cpu/cpu%u/cpufreq/scaling_cur_freq"
static uint32_t total_freq_num;
static uint32_t freqs[TEST_POWER_FREQS_NUM_MAX];
static int
check_cur_freq(unsigned lcore_id, uint32_t idx)
{
#define TEST_POWER_CONVERT_TO_DECIMAL 10
FILE *f;
char fullpath[PATH_MAX];
char buf[BUFSIZ];
uint32_t cur_freq;
int ret = -1;
if (rte_snprintf(fullpath, sizeof(fullpath),
TEST_POWER_SYSFILE_CUR_FREQ, lcore_id) < 0) {
return 0;
}
f = fopen(fullpath, "r");
if (f == NULL) {
return 0;
}
if (fgets(buf, sizeof(buf), f) == NULL) {
goto fail_get_cur_freq;
}
cur_freq = strtoul(buf, NULL, TEST_POWER_CONVERT_TO_DECIMAL);
ret = (freqs[idx] == cur_freq ? 0 : -1);
fail_get_cur_freq:
fclose(f);
return ret;
}
/* Check rte_power_freqs() */
static int
check_power_freqs(void)
{
uint32_t ret;
total_freq_num = 0;
memset(freqs, 0, sizeof(freqs));
/* test with an invalid lcore id */
ret = rte_power_freqs(TEST_POWER_LCORE_INVALID, freqs,
TEST_POWER_FREQS_NUM_MAX);
if (ret > 0) {
printf("Unexpectedly get available freqs successfully on "
"lcore %u\n", TEST_POWER_LCORE_INVALID);
return -1;
}
/* test with NULL buffer to save available freqs */
ret = rte_power_freqs(TEST_POWER_LCORE_ID, NULL,
TEST_POWER_FREQS_NUM_MAX);
if (ret > 0) {
printf("Unexpectedly get available freqs successfully with "
"NULL buffer on lcore %u\n", TEST_POWER_LCORE_ID);
return -1;
}
/* test of getting zero number of freqs */
ret = rte_power_freqs(TEST_POWER_LCORE_ID, freqs, 0);
if (ret > 0) {
printf("Unexpectedly get available freqs successfully with "
"zero buffer size on lcore %u\n", TEST_POWER_LCORE_ID);
return -1;
}
/* test with all valid input parameters */
ret = rte_power_freqs(TEST_POWER_LCORE_ID, freqs,
TEST_POWER_FREQS_NUM_MAX);
if (ret == 0 || ret > TEST_POWER_FREQS_NUM_MAX) {
printf("Fail to get available freqs on lcore %u\n",
TEST_POWER_LCORE_ID);
return -1;
}
/* Save the total number of available freqs */
total_freq_num = ret;
return 0;
}
/* Check rte_power_get_freq() */
static int
check_power_get_freq(void)
{
int ret;
uint32_t count;
/* test with an invalid lcore id */
count = rte_power_get_freq(TEST_POWER_LCORE_INVALID);
if (count < TEST_POWER_FREQS_NUM_MAX) {
printf("Unexpectedly get freq index successfully on "
"lcore %u\n", TEST_POWER_LCORE_INVALID);
return -1;
}
count = rte_power_get_freq(TEST_POWER_LCORE_ID);
if (count >= TEST_POWER_FREQS_NUM_MAX) {
printf("Fail to get the freq index on lcore %u\n",
TEST_POWER_LCORE_ID);
return -1;
}
/* Check the current frequency */
ret = check_cur_freq(TEST_POWER_LCORE_ID, count);
if (ret < 0)
return -1;
return 0;
}
/* Check rte_power_set_freq() */
static int
check_power_set_freq(void)
{
int ret;
/* test with an invalid lcore id */
ret = rte_power_set_freq(TEST_POWER_LCORE_INVALID, 0);
if (ret >= 0) {
printf("Unexpectedly set freq index successfully on "
"lcore %u\n", TEST_POWER_LCORE_INVALID);
return -1;
}
/* test with an invalid freq index */
ret = rte_power_set_freq(TEST_POWER_LCORE_ID,
TEST_POWER_FREQS_NUM_MAX);
if (ret >= 0) {
printf("Unexpectedly set an invalid freq index (%u)"
"successfully on lcore %u\n", TEST_POWER_FREQS_NUM_MAX,
TEST_POWER_LCORE_ID);
return -1;
}
/**
* test with an invalid freq index which is right one bigger than
* total number of freqs
*/
ret = rte_power_set_freq(TEST_POWER_LCORE_ID, total_freq_num);
if (ret >= 0) {
printf("Unexpectedly set an invalid freq index (%u)"
"successfully on lcore %u\n", total_freq_num,
TEST_POWER_LCORE_ID);
return -1;
}
ret = rte_power_set_freq(TEST_POWER_LCORE_ID, 3);
if (ret < 0) {
printf("Fail to set freq index on lcore %u\n",
TEST_POWER_LCORE_ID);
return -1;
}
/* Check the current frequency */
ret = check_cur_freq(TEST_POWER_LCORE_ID, 3);
if (ret < 0)
return -1;
return 0;
}
/* Check rte_power_freq_down() */
static int
check_power_freq_down(void)
{
int ret;
/* test with an invalid lcore id */
ret = rte_power_freq_down(TEST_POWER_LCORE_INVALID);
if (ret >= 0) {
printf("Unexpectedly scale down successfully the freq on "
"lcore %u\n", TEST_POWER_LCORE_INVALID);
return -1;
}
/* Scale down to min and then scale down one step */
ret = rte_power_freq_min(TEST_POWER_LCORE_ID);
if (ret < 0) {
printf("Fail to scale down the freq to min on lcore %u\n",
TEST_POWER_LCORE_ID);
return -1;
}
ret = rte_power_freq_down(TEST_POWER_LCORE_ID);
if (ret < 0) {
printf("Fail to scale down the freq on lcore %u\n",
TEST_POWER_LCORE_ID);
return -1;
}
/* Check the current frequency */
ret = check_cur_freq(TEST_POWER_LCORE_ID, total_freq_num - 1);
if (ret < 0)
return -1;
/* Scale up to max and then scale down one step */
ret = rte_power_freq_max(TEST_POWER_LCORE_ID);
if (ret < 0) {
printf("Fail to scale up the freq to max on lcore %u\n",
TEST_POWER_LCORE_ID);
return -1;
}
ret = rte_power_freq_down(TEST_POWER_LCORE_ID);
if (ret < 0) {
printf ("Fail to scale down the freq on lcore %u\n",
TEST_POWER_LCORE_ID);
return -1;
}
/* Check the current frequency */
ret = check_cur_freq(TEST_POWER_LCORE_ID, 1);
if (ret < 0)
return -1;
return 0;
}
/* Check rte_power_freq_up() */
static int
check_power_freq_up(void)
{
int ret;
/* test with an invalid lcore id */
ret = rte_power_freq_up(TEST_POWER_LCORE_INVALID);
if (ret >= 0) {
printf("Unexpectedly scale up successfully the freq on %u\n",
TEST_POWER_LCORE_INVALID);
return -1;
}
/* Scale down to min and then scale up one step */
ret = rte_power_freq_min(TEST_POWER_LCORE_ID);
if (ret < 0) {
printf("Fail to scale down the freq to min on lcore %u\n",
TEST_POWER_LCORE_ID);
return -1;
}
ret = rte_power_freq_up(TEST_POWER_LCORE_ID);
if (ret < 0) {
printf("Fail to scale up the freq on lcore %u\n",
TEST_POWER_LCORE_ID);
return -1;
}
/* Check the current frequency */
ret = check_cur_freq(TEST_POWER_LCORE_ID, total_freq_num - 2);
if (ret < 0)
return -1;
/* Scale up to max and then scale up one step */
ret = rte_power_freq_max(TEST_POWER_LCORE_ID);
if (ret < 0) {
printf("Fail to scale up the freq to max on lcore %u\n",
TEST_POWER_LCORE_ID);
return -1;
}
ret = rte_power_freq_up(TEST_POWER_LCORE_ID);
if (ret < 0) {
printf("Fail to scale up the freq on lcore %u\n",
TEST_POWER_LCORE_ID);
return -1;
}
/* Check the current frequency */
ret = check_cur_freq(TEST_POWER_LCORE_ID, 0);
if (ret < 0)
return -1;
return 0;
}
/* Check rte_power_freq_max() */
static int
check_power_freq_max(void)
{
int ret;
/* test with an invalid lcore id */
ret = rte_power_freq_max(TEST_POWER_LCORE_INVALID);
if (ret >= 0) {
printf("Unexpectedly scale up successfully the freq to max on "
"lcore %u\n", TEST_POWER_LCORE_INVALID);
return -1;
}
ret = rte_power_freq_max(TEST_POWER_LCORE_ID);
if (ret < 0) {
printf("Fail to scale up the freq to max on lcore %u\n",
TEST_POWER_LCORE_ID);
return -1;
}
/* Check the current frequency */
ret = check_cur_freq(TEST_POWER_LCORE_ID, 0);
if (ret < 0)
return -1;
return 0;
}
/* Check rte_power_freq_min() */
static int
check_power_freq_min(void)
{
int ret;
/* test with an invalid lcore id */
ret = rte_power_freq_min(TEST_POWER_LCORE_INVALID);
if (ret >= 0) {
printf("Unexpectedly scale down successfully the freq to min "
"on lcore %u\n", TEST_POWER_LCORE_INVALID);
return -1;
}
ret = rte_power_freq_min(TEST_POWER_LCORE_ID);
if (ret < 0) {
printf("Fail to scale down the freq to min on lcore %u\n",
TEST_POWER_LCORE_ID);
return -1;
}
/* Check the current frequency */
ret = check_cur_freq(TEST_POWER_LCORE_ID, total_freq_num - 1);
if (ret < 0)
return -1;
return 0;
}
int
test_power(void)
{
int ret = -1;
/* test of init power management for an invalid lcore */
ret = rte_power_init(TEST_POWER_LCORE_INVALID);
if (ret == 0) {
printf("Unexpectedly initialise power management successfully "
"for lcore %u\n", TEST_POWER_LCORE_INVALID);
return -1;
}
ret = rte_power_init(TEST_POWER_LCORE_ID);
if (ret < 0) {
printf("Cannot initialise power management for lcore %u\n",
TEST_POWER_LCORE_ID);
return -1;
}
/**
* test of initialising power management for the lcore which has
* been initialised
*/
ret = rte_power_init(TEST_POWER_LCORE_ID);
if (ret == 0) {
printf("Unexpectedly init successfully power twice on "
"lcore %u\n", TEST_POWER_LCORE_ID);
return -1;
}
ret = check_power_freqs();
if (ret < 0)
goto fail_all;
ret = check_power_get_freq();
if (ret < 0)
goto fail_all;
ret = check_power_set_freq();
if (ret < 0)
goto fail_all;
ret = check_power_freq_down();
if (ret < 0)
goto fail_all;
ret = check_power_freq_up();
if (ret < 0)
goto fail_all;
ret = check_power_freq_max();
if (ret < 0)
goto fail_all;
ret = check_power_freq_min();
if (ret < 0)
goto fail_all;
ret = rte_power_exit(TEST_POWER_LCORE_ID);
if (ret < 0) {
printf("Cannot exit power management for lcore %u\n",
TEST_POWER_LCORE_ID);
return -1;
}
/**
* test of exiting power management for the lcore which has been exited
*/
ret = rte_power_exit(TEST_POWER_LCORE_ID);
if (ret == 0) {
printf("Unexpectedly exit successfully power management twice "
"on lcore %u\n", TEST_POWER_LCORE_ID);
return -1;
}
/* test of exit power management for an invalid lcore */
ret = rte_power_exit(TEST_POWER_LCORE_INVALID);
if (ret == 0) {
printf("Unpectedly exit power management successfully for "
"lcore %u\n", TEST_POWER_LCORE_INVALID);
return -1;
}
return 0;
fail_all:
rte_power_exit(TEST_POWER_LCORE_ID);
return -1;
}
#else /* RTE_LIBRTE_POWER */
int
test_power(void)
{
printf("The power library is not included in this build\n");
return 0;
}
#endif /* RTE_LIBRTE_POWER */

View File

@ -216,6 +216,13 @@ CONFIG_RTE_LIBRTE_HASH_DEBUG=n
CONFIG_RTE_LIBRTE_LPM=y
CONFIG_RTE_LIBRTE_LPM_DEBUG=n
#
# Compile librte_power
#
CONFIG_RTE_LIBRTE_POWER=y
CONFIG_RTE_LIBRTE_POWER_DEBUG=n
CONFIG_RTE_MAX_LCORE_FREQS=64
#
# Compile librte_net
#

View File

@ -217,6 +217,13 @@ CONFIG_RTE_LIBRTE_HASH_DEBUG=n
CONFIG_RTE_LIBRTE_LPM=y
CONFIG_RTE_LIBRTE_LPM_DEBUG=n
#
# Compile librte_power
#
CONFIG_RTE_LIBRTE_POWER=y
CONFIG_RTE_LIBRTE_POWER_DEBUG=n
CONFIG_RTE_MAX_LCORE_FREQS=64
#
# Compile librte_net
#

View File

@ -217,6 +217,13 @@ CONFIG_RTE_LIBRTE_HASH_DEBUG=n
CONFIG_RTE_LIBRTE_LPM=y
CONFIG_RTE_LIBRTE_LPM_DEBUG=n
#
# Compile librte_power
#
CONFIG_RTE_LIBRTE_POWER=y
CONFIG_RTE_LIBRTE_POWER_DEBUG=n
CONFIG_RTE_MAX_LCORE_FREQS=64
#
# Compile librte_net
#

View File

@ -217,6 +217,13 @@ CONFIG_RTE_LIBRTE_HASH_DEBUG=n
CONFIG_RTE_LIBRTE_LPM=y
CONFIG_RTE_LIBRTE_LPM_DEBUG=n
#
# Compile librte_power
#
CONFIG_RTE_LIBRTE_POWER=y
CONFIG_RTE_LIBRTE_POWER_DEBUG=n
CONFIG_RTE_MAX_LCORE_FREQS=64
#
# Compile librte_net
#

View File

@ -0,0 +1,57 @@
# BSD LICENSE
#
# Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Intel Corporation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
ifeq ($(RTE_SDK),)
$(error "Please define RTE_SDK environment variable")
endif
# Default target, can be overriden by command line or environment
RTE_TARGET ?= x86_64-default-linuxapp-gcc
include $(RTE_SDK)/mk/rte.vars.mk
# binary name
APP = l3fwd-power
# all source are stored in SRCS-y
SRCS-y := main.c
CFLAGS += -O3
CFLAGS += $(WERROR_FLAGS)
# workaround for a gcc bug with noreturn attribute
# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)
CFLAGS_main.o += -Wno-return-type
endif
include $(RTE_SDK)/mk/rte.extapp.mk

1714
examples/l3fwd-power/main.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,46 @@
/*-
* BSD LICENSE
*
* Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef _MAIN_H_
#define _MAIN_H_
#ifdef RTE_EXEC_ENV_BAREMETAL
#define MAIN _main
#else
#define MAIN main
#endif
int MAIN(int argc, char **argv);
#endif /* _MAIN_H_ */

View File

@ -46,6 +46,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_IXGBE_PMD) += librte_pmd_ixgbe
DIRS-$(CONFIG_RTE_LIBRTE_HASH) += librte_hash
DIRS-$(CONFIG_RTE_LIBRTE_LPM) += librte_lpm
DIRS-$(CONFIG_RTE_LIBRTE_NET) += librte_net
DIRS-$(CONFIG_RTE_LIBRTE_POWER) += librte_power
DIRS-$(CONFIG_RTE_LIBRTE_PMAC) += librte_pmac
ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y)

View File

@ -72,6 +72,7 @@ extern struct rte_logs rte_logs;
#define RTE_LOGTYPE_LPM 0x00000080 /**< Log related to LPM. */
#define RTE_LOGTYPE_KNI 0X00000100 /**< Log related to KNI. */
#define RTE_LOGTYPE_PMAC 0x00000200 /**< Log related to PMAC. */
#define RTE_LOGTYPE_POWER 0x00000400 /**< Log related to power. */
/* these log types can be used in an application */
#define RTE_LOGTYPE_USER1 0x01000000 /**< User-defined log type 1. */

49
lib/librte_power/Makefile Normal file
View File

@ -0,0 +1,49 @@
# BSD LICENSE
#
# Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Intel Corporation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
include $(RTE_SDK)/mk/rte.vars.mk
# library name
LIB = librte_power.a
CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3 -fno-strict-aliasing
# all source are stored in SRCS-y
SRCS-$(CONFIG_RTE_LIBRTE_POWER) := rte_power.c
# install this header file
SYMLINK-$(CONFIG_RTE_LIBRTE_POWER)-include := rte_power.h
# this lib needs eal
DEPDIRS-$(CONFIG_RTE_LIBRTE_POWER) += lib/librte_eal
include $(RTE_SDK)/mk/rte.lib.mk

View File

@ -0,0 +1,546 @@
/*-
* BSD LICENSE
*
* Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#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>
#include <rte_memcpy.h>
#include <rte_atomic.h>
#include "rte_power.h"
#ifdef RTE_LIBRTE_POWER_DEBUG
#define POWER_DEBUG_TRACE(fmt, args...) do { \
RTE_LOG(ERR, POWER, "%s: " fmt, __func__, ## args); \
} while (0)
#else
#define POWER_DEBUG_TRACE(fmt, args...)
#endif
#define FOPEN_OR_ERR_RET(f, retval) do { \
if ((f) == NULL) { \
RTE_LOG(ERR, POWER, "File not openned\n"); \
return (retval); \
} \
} while(0)
#define FOPS_OR_NULL_GOTO(ret, label) do { \
if ((ret) == NULL) { \
RTE_LOG(ERR, POWER, "fgets returns nothing\n"); \
goto label; \
} \
} while(0)
#define FOPS_OR_ERR_GOTO(ret, label) do { \
if ((ret) < 0) { \
RTE_LOG(ERR, POWER, "File operations failed\n"); \
goto label; \
} \
} while(0)
#define STR_SIZE 1024
#define POWER_CONVERT_TO_DECIMAL 10
#define POWER_GOVERNOR_USERSPACE "userspace"
#define POWER_SYSFILE_GOVERNOR \
"/sys/devices/system/cpu/cpu%u/cpufreq/scaling_governor"
#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"
enum power_state {
POWER_IDLE = 0,
POWER_ONGOING,
POWER_USED,
POWER_UNKNOWN
};
/**
* Power info per lcore.
*/
struct rte_power_info {
unsigned lcore_id; /**< Logical core id */
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 */
volatile uint32_t state; /**< Power in use state */
} __rte_cache_aligned;
static struct rte_power_info lcore_power_info[RTE_MAX_LCORE];
/**
* It is to set specific freq for specific logical core, according to the index
* of supported frequencies.
*/
static int
set_freq_internal(struct rte_power_info *pi, uint32_t idx)
{
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;
POWER_DEBUG_TRACE("Freqency[%u] %u to be set for lcore %u\n",
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
power_set_governor_userspace(struct rte_power_info *pi)
{
FILE *f;
int ret = -1;
char buf[BUFSIZ];
char fullpath[PATH_MAX];
char *s;
int val;
rte_snprintf(fullpath, sizeof(fullpath), POWER_SYSFILE_GOVERNOR,
pi->lcore_id);
f = fopen(fullpath, "rw+");
FOPEN_OR_ERR_RET(f, ret);
s = fgets(buf, sizeof(buf), f);
FOPS_OR_NULL_GOTO(s, out);
/* Check if current governor is userspace */
if (strncmp(buf, POWER_GOVERNOR_USERSPACE,
sizeof(POWER_GOVERNOR_USERSPACE)) == 0) {
ret = 0;
POWER_DEBUG_TRACE("Power management governor of lcore %u is "
"already userspace\n", pi->lcore_id);
goto out;
}
/* Save the original governor */
rte_snprintf(pi->governor_ori, sizeof(pi->governor_ori), "%s", buf);
/* Write 'userspace' to the governor */
val = fseek(f, 0, SEEK_SET);
FOPS_OR_ERR_GOTO(val, out);
val = fputs(POWER_GOVERNOR_USERSPACE, f);
FOPS_OR_ERR_GOTO(val, out);
ret = 0;
RTE_LOG(INFO, POWER, "Power management governor of lcore %u has been "
"set to user space successfully\n", pi->lcore_id);
out:
fclose(f);
return ret;
}
/**
* It is to get the available frequencies of the specific lcore by reading the
* sys file.
*/
static int
power_get_available_freqs(struct rte_power_info *pi)
{
FILE *f;
int ret = -1, i, count;
char *p;
char buf[BUFSIZ];
char fullpath[PATH_MAX];
char *freqs[RTE_MAX_LCORE_FREQS];
char *s;
rte_snprintf(fullpath, sizeof(fullpath), POWER_SYSFILE_AVAIL_FREQ,
pi->lcore_id);
f = fopen(fullpath, "r");
FOPEN_OR_ERR_RET(f, ret);
s = fgets(buf, sizeof(buf), f);
FOPS_OR_NULL_GOTO(s, out);
/* Strip the line break if there is */
p = strchr(buf, '\n');
if (p != NULL)
*p = 0;
/* 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);
}
ret = 0;
POWER_DEBUG_TRACE("%d frequencie(s) of lcore %u are available\n",
count, pi->lcore_id);
out:
fclose(f);
return ret;
}
/**
* It is to fopen the sys file for the future setting the lcore frequency.
*/
static int
power_init_for_setting_freq(struct rte_power_info *pi)
{
FILE *f;
char fullpath[PATH_MAX];
char buf[BUFSIZ];
uint32_t i, freq;
char *s;
rte_snprintf(fullpath, sizeof(fullpath), POWER_SYSFILE_SETSPEED,
pi->lcore_id);
f = fopen(fullpath, "rw+");
FOPEN_OR_ERR_RET(f, -1);
s = fgets(buf, sizeof(buf), f);
FOPS_OR_NULL_GOTO(s, out);
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;
}
}
out:
fclose(f);
return -1;
}
int
rte_power_init(unsigned lcore_id)
{
struct rte_power_info *pi;
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];
if (rte_atomic32_cmpset(&(pi->state), POWER_IDLE, POWER_ONGOING)
== 0) {
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 */
if (rte_power_freq_max(lcore_id) < 0) {
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 "
"power manamgement\n", lcore_id);
rte_atomic32_cmpset(&(pi->state), POWER_ONGOING, POWER_USED);
return 0;
fail:
rte_atomic32_cmpset(&(pi->state), POWER_ONGOING, POWER_UNKNOWN);
return -1;
}
/**
* It is to check the governor and then set the original governor back if
* needed by writing the the sys file.
*/
static int
power_set_governor_original(struct rte_power_info *pi)
{
FILE *f;
int ret = -1;
char buf[BUFSIZ];
char fullpath[PATH_MAX];
char *s;
int val;
rte_snprintf(fullpath, sizeof(fullpath), POWER_SYSFILE_GOVERNOR,
pi->lcore_id);
f = fopen(fullpath, "rw+");
FOPEN_OR_ERR_RET(f, ret);
s = fgets(buf, sizeof(buf), f);
FOPS_OR_NULL_GOTO(s, out);
/* Check if the governor to be set is the same as current */
if (strncmp(buf, pi->governor_ori, sizeof(pi->governor_ori)) == 0) {
ret = 0;
POWER_DEBUG_TRACE("Power management governor of lcore %u "
"has already been set to %s\n",
pi->lcore_id, pi->governor_ori);
goto out;
}
/* Write back the original governor */
val = fseek(f, 0, SEEK_SET);
FOPS_OR_ERR_GOTO(val, out);
val = fputs(pi->governor_ori, f);
FOPS_OR_ERR_GOTO(val, out);
ret = 0;
RTE_LOG(INFO, POWER, "Power manamgement governor of lcore %u "
"has been set back to %s successfully\n",
pi->lcore_id, pi->governor_ori);
out:
fclose(f);
return ret;
}
int
rte_power_exit(unsigned lcore_id)
{
struct rte_power_info *pi;
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];
if (rte_atomic32_cmpset(&(pi->state), POWER_USED, POWER_ONGOING)
== 0) {
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);
rte_atomic32_cmpset(&(pi->state), POWER_ONGOING, POWER_IDLE);
return 0;
fail:
rte_atomic32_cmpset(&(pi->state), POWER_ONGOING, POWER_UNKNOWN);
return -1;
}
uint32_t
rte_power_freqs(unsigned lcore_id, uint32_t *freqs, uint32_t num)
{
struct rte_power_info *pi;
if (lcore_id >= RTE_MAX_LCORE || !freqs) {
RTE_LOG(ERR, POWER, "Invalid input parameter\n");
return 0;
}
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
rte_power_get_freq(unsigned lcore_id)
{
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
rte_power_set_freq(unsigned lcore_id, uint32_t index)
{
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
rte_power_freq_down(unsigned lcore_id)
{
struct rte_power_info *pi;
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
rte_power_freq_up(unsigned lcore_id)
{
struct rte_power_info *pi;
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 == 0)
return 0;
/* Frequencies in the array are from high to low. */
return set_freq_internal(pi, pi->curr_idx - 1);
}
int
rte_power_freq_max(unsigned lcore_id)
{
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. */
return set_freq_internal(&lcore_power_info[lcore_id], 0);
}
int
rte_power_freq_min(unsigned lcore_id)
{
struct rte_power_info *pi;
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);
}

View File

@ -0,0 +1,194 @@
/*-
* BSD LICENSE
*
* Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef _RTE_POWER_H
#define _RTE_POWER_H
/**
* @file
* RTE Power Management
*/
#include <rte_common.h>
#include <rte_byteorder.h>
#include <rte_log.h>
#include <rte_string_fns.h>
#ifdef __cplusplus
extern "C" {
#endif
#define RTE_POWER_INVALID_FREQ_INDEX (~0)
/**
* Initialize power management for a specific lcore. It will check and set the
* governor to userspace for the lcore, get the available frequencies, and
* prepare to set new lcore frequency.
*
* @param lcore_id
* lcore id.
*
* @return
* - 0 on success.
* - Negative on error.
*/
int rte_power_init(unsigned lcore_id);
/**
* Exit power management on a specific lcore. It will set the governor to which
* is before initialized.
*
* @param lcore_id
* lcore id.
*
* @return
* - 0 on success.
* - Negative on error.
*/
int rte_power_exit(unsigned lcore_id);
/**
* Get the available frequencies of a specific lcore. The return value will be
* the minimal one of the total number of available frequencies and the number
* of buffer. The index of available frequencies used in other interfaces
* should be in the range of 0 to this return value.
* It should be protected outside of this function for threadsafe.
*
* @param lcore_id
* lcore id.
* @param freqs
* The buffer array to save the frequencies.
* @param num
* The number of frequencies to get.
*
* @return
* The number of available frequencies.
*/
uint32_t rte_power_freqs(unsigned lcore_id, uint32_t *freqs, uint32_t num);
/**
* Return the current index of available frequencies of a specific lcore. It
* will return 'RTE_POWER_INVALID_FREQ_INDEX = (~0)' if error.
* It should be protected outside of this function for threadsafe.
*
* @param lcore_id
* lcore id.
*
* @return
* The current index of available frequencies.
*/
uint32_t rte_power_get_freq(unsigned lcore_id);
/**
* Set the new frequency for a specific lcore by indicating the index of
* available frequencies.
* It should be protected outside of this function for threadsafe.
*
* @param lcore_id
* lcore id.
* @param index
* The index of available frequencies.
*
* @return
* - 1 on success with frequency changed.
* - 0 on success without frequency chnaged.
* - Negative on error.
*/
int rte_power_set_freq(unsigned lcore_id, uint32_t index);
/**
* Scale up the frequency of a specific lcore according to the available
* frequencies.
* It should be protected outside of this function for threadsafe.
*
* @param lcore_id
* lcore id.
*
* @return
* - 1 on success with frequency changed.
* - 0 on success without frequency chnaged.
* - Negative on error.
*/
int rte_power_freq_up(unsigned lcore_id);
/**
* Scale down the frequency of a specific lcore according to the available
* frequencies.
* It should be protected outside of this function for threadsafe.
*
* @param lcore_id
* lcore id.
*
* @return
* - 1 on success with frequency changed.
* - 0 on success without frequency chnaged.
* - Negative on error.
*/
int rte_power_freq_down(unsigned lcore_id);
/**
* Scale up the frequency of a specific lcore to the highest according to the
* available frequencies.
* It should be protected outside of this function for threadsafe.
*
* @param lcore_id
* lcore id.
*
* @return
* - 1 on success with frequency changed.
* - 0 on success without frequency chnaged.
* - Negative on error.
*/
int rte_power_freq_max(unsigned lcore_id);
/**
* Scale down the frequency of a specific lcore to the lowest according to the
* available frequencies.
* It should be protected outside of this function for threadsafe.
*
* @param lcore_id
* lcore id.
*
* @return
* - 1 on success with frequency changed.
* - 0 on success without frequency chnaged.
* - Negative on error.
*/
int rte_power_freq_min(unsigned lcore_id);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -93,6 +93,10 @@ ifeq ($(CONFIG_RTE_LIBRTE_LPM),y)
LDLIBS += -lrte_lpm
endif
ifeq ($(CONFIG_RTE_LIBRTE_POWER),y)
LDLIBS += -lrte_power
endif
ifeq ($(CONFIG_RTE_LIBRTE_PMAC),y)
LDLIBS += -lrte_pmac
endif