cpupower: Add intel_pstate turbo boost support for Intel platforms
PATCH 1/1 cpupower: Add intel_pstate turbo boost support for Intel platforms
On modern Intel platforms, the intel_pstate driver is commonly used and it provides turbo boost control via /sys/devices/system/cpu/intel_pstate/no_turbo.
However, cpupower doesn't handle this. it
1. shows turbo boost as "active" blindly for Intel platforms
2. controls turbo boost functionality via the generic /sys/devices/system/cpu/cpufreq/boost sysfs interface only.
Enhance the cpupower tool to ensure the "--boost" command works seamlessly on Intel platforms with intel_pstate driver running.
Without this patch,
$ echo 1 | sudo tee /sys/devices/system/cpu/intel_pstate/no_turbo
1
$ sudo cpupower frequency-info --boost
analyzing CPU 21:
boost state support:
Supported: yes
Active: yes
$ sudo cpupower set --boost 0
Error setting turbo-boost
$ sudo cpupower set --boost 1
Error setting turbo-boostWith this patch,
$ cat /sys/devices/system/cpu/intel_pstate/no_turbo
0
$ sudo cpupower set --boost 0
$ sudo cpupower frequency-info --boost
analyzing CPU 21:
boost state support:
Supported: yes
Active: no
$ cat /sys/devices/system/cpu/intel_pstate/no_turbo
1
$ sudo cpupower set --boost 1
$ sudo cpupower frequency-info --boost
analyzing CPU 28:
boost state support:
Supported: yes
Active: yes
$ cat /sys/devices/system/cpu/intel_pstate/no_turbo
0--- tools/power/cpupower/utils/cpupower-set.c | 6 ++- tools/power/cpupower/utils/helpers/helpers.h | 5 ++- tools/power/cpupower/utils/helpers/misc.c | 41 +++++++++++++++++++- 3 files changed, 48 insertions(+), 4 deletions(-)
tools/power/cpupower/utils/cpupower-set.c +5 -1
@@ -124,7 +124,11 @@ int cmd_set(int argc, char **argv) }if (params.turbo_boost) { - ret =cpupower_set_turbo_boost (turbo_boost); +if (cpupower_cpu_info.vendor ==X86_VENDOR_INTEL ) + ret =cpupower_set_intel_turbo_boost (turbo_boost); +else + ret =cpupower_set_generic_turbo_boost (turbo_boost); +if (ret)fprintf (stderr,"Error setting turbo-boost\n" ); }
tools/power/cpupower/utils/helpers/helpers.h +4 -1
@@ -104,7 +104,7 @@ extern struct cpupower_cpu_info cpupower_cpu_info;/* cpuid and cpuinfo helpers **************************/ int cpufreq_has_generic_boost_support (bool *active); -int cpupower_set_turbo_boost (int turbo_boost); +int cpupower_set_generic_turbo_boost (int turbo_boost);/* X86 ONLY ****************************************/ #if defined(__i386__) || defined(__x86_64__)
@@ -143,6 +143,7 @@ extern int decode_pstates(unsigned int cpu, int boost_states,int cpufreq_has_x86_boost_support (unsigned int cpu,int *support,int *active,int *states); +int cpupower_set_intel_turbo_boost (int turbo_boost);/* AMD P-State stuff **************************/ bool cpupower_amd_pstate_enabled (void );
@@ -189,6 +190,8 @@ static inline int cpupower_set_amd_pstate_mode(char *mode)static inline int cpufreq_has_x86_boost_support (unsigned int cpu,int *support,int *active,int *states) {return -1 ; } +static inline int cpupower_set_intel_turbo_boost (int turbo_boost) +{return -1 ; }static inline bool cpupower_amd_pstate_enabled (void ) {return false; }
tools/power/cpupower/utils/helpers/misc.c +39 -2
60 lines not on this page · raw message
Signature · 1 line
2.43.0
Quoted 5 lines · Zhang Rui
On modern Intel platforms, the
intel_pstatedriver is commonly used and
it provides turbo boost control via/sys/devices/system/cpu/intel_pstate/no_turbo.
Quoted 8 lines
However, cpupower doesn't handle this. it
1. shows turbo boost as "active" blindly for Intel platforms
2. controls turbo boost functionality via the generic/sys/devices/system/cpu/cpufreq/boostsysfs interface only.Enhance the cpupower tool to ensure the "--boost" command works seamlessly on Intel platforms with
intel_pstatedriver running.
Hi, Shuah,
can you please kindly check if this is a valid enhancement?
thanks,
rui
Quoted 176 lines
Without this patch,
$ echo 1 | sudo tee /sys/devices/system/cpu/intel_pstate/no_turbo 1 $ sudo cpupower frequency-info --boost analyzing CPU 21: boost state support: Supported: yes Active: yes $ sudo cpupower set --boost 0 Error setting turbo-boost $ sudo cpupower set --boost 1 Error setting turbo-boostWith this patch,
$ cat /sys/devices/system/cpu/intel_pstate/no_turbo 0 $ sudo cpupower set --boost 0 $ sudo cpupower frequency-info --boost analyzing CPU 21: boost state support: Supported: yes Active: no $ cat /sys/devices/system/cpu/intel_pstate/no_turbo 1 $ sudo cpupower set --boost 1 $ sudo cpupower frequency-info --boost analyzing CPU 28: boost state support: Supported: yes Active: yes $ cat /sys/devices/system/cpu/intel_pstate/no_turbo 0Signed-off-by Zhang Rui <[email protected]>---
tools/power/cpupower/utils/cpupower-set.c | 6 ++-tools/power/cpupower/utils/helpers/helpers.h| 5 ++- tools/power/cpupower/utils/helpers/misc.c | 41
+++++++++++++++++++-3 files changed, 48 insertions(+), 4 deletions(-)tools/power/cpupower/utils/cpupower-set.c +0
-0@@ -124,7 +124,11 @@ int cmd_set(int argc, char **argv) }
if (params.turbo_boost) {tools/power/cpupower/utils/cpupower-set.c +2
-1- ret =cpupower_set_turbo_boost (turbo_boost); +if (cpupower_cpu_info.vendor ==X86_VENDOR_INTEL ) + ret =
cpupower_set_intel_turbo_boost(turbo_boost);tools/power/cpupower/utils/cpupower-set.c +2
-0+else + ret =
cpupower_set_generic_turbo_boost(turbo_boost);
+
if (ret)
fprintf(stderr, "Error setting turbo- boost\n");
}tools/power/cpupower/utils/helpers/helpers.h +0
-0@@ -104,7 +104,7 @@ extern struct cpupower_cpu_info cpupower_cpu_info; /* cpuid and cpuinfo helpers **************************/
intcpufreq_has_generic_boost_support(bool *active);tools/power/cpupower/utils/helpers/helpers.h +1
-1-int cpupower_set_turbo_boost (int turbo_boost); +int cpupower_set_generic_turbo_boost (int turbo_boost);
/* X86 ONLY ****************************************/ #ifdefined(__i386__)||defined(__x86_64__)tools/power/cpupower/utils/helpers/helpers.h +0
-0@@ -143,6 +143,7 @@ extern int decode_pstates(unsigned int cpu, int boost_states,
intcpufreq_has_x86_boost_support(unsigned int cpu, int *support, int *active, int *states); +intcpupower_set_intel_turbo_boost(int turbo_boost);
/* AMD P-State stuff **************************/
boolcpupower_amd_pstate_enabled(void);tools/power/cpupower/utils/helpers/helpers.h +0
-0@@ -189,6 +190,8 @@ static inline int cpupower_set_amd_pstate_mode(char *mode) static inline int cpufreq_has_x86_boost_support(unsigned int cpu, int *support,int *active, int *states)
{ return -1; }tools/power/cpupower/utils/helpers/helpers.h +2
-0+static inline int cpupower_set_intel_turbo_boost (int turbo_boost) +{return -1 ; }
static inline boolcpupower_amd_pstate_enabled(void){ return false; }tools/power/cpupower/utils/helpers/misc.c +3
-0@@ -19,6 +19,9 @@ int cpufreq_has_x86_boost_support(unsigned int cpu, int *support, int *active, { int ret; unsigned long long val; +char linebuf[MAX_LINE_LEN ]; +char path[SYSFS_PATH_MAX ]; +char *endp;
*support = *active = *states = 0;tools/power/cpupower/utils/helpers/misc.c +3
-1@@ -42,8 +45,42 @@ int cpufreq_has_x86_boost_support(unsigned int cpu, int *support, int *active, } } else if (cpupower_cpu_info.caps & CPUPOWER_CAP_AMD_PSTATE) { amd_pstate_boost_init(cpu, support, active); - }else if (cpupower_cpu_info.caps &CPUPOWER_CAP_INTEL_IDA ) + }else if (cpupower_cpu_info.caps &CPUPOWER_CAP_INTEL_IDA ) { *support = *active = 1; + + snprintf(path, sizeof(path), PATH_TO_CPU"intel_pstate/no_turbo");
tools/power/cpupower/utils/helpers/misc.c +5
-0+ +if (!is_valid_path (path)) +return 0 ; + + if (cpupower_read_sysfs(path, linebuf, MAX_LINE_LEN)== 0)
tools/power/cpupower/utils/helpers/misc.c +17
-0+return -1 ; + + val =strtol (linebuf, &endp,0 ); +if (endp == linebuf || errno ==ERANGE ) +return -1 ; + + *active = !val; + } +return 0 ; +} + +int cpupower_set_intel_turbo_boost (int turbo_boost) +{ +char path[SYSFS_PATH_MAX ]; +char linebuf[2 ] = {}; + + snprintf(path, sizeof(path), PATH_TO_CPU"intel_pstate/no_turbo");
tools/power/cpupower/utils/helpers/misc.c +2
-0+ +/* Fallback to generic solution when intel_pstate driver not running */
tools/power/cpupower/utils/helpers/misc.c +2
-0+if (!is_valid_path (path)) +return
cpupower_set_generic_turbo_boost(turbo_boost);tools/power/cpupower/utils/helpers/misc.c +6
-0+ +snprintf (linebuf,sizeof (linebuf),"%d" , !turbo_boost); + +if (cpupower_write_sysfs (path, linebuf,2 ) <=0 ) +return -1 ; +return 0;
}tools/power/cpupower/utils/helpers/misc.c +0
-0@@ -274,7 +311,7 @@ void print_speed(unsigned long speed, int no_rounding) } }tools/power/cpupower/utils/helpers/misc.c +1
-1-int cpupower_set_turbo_boost (int turbo_boost) +int cpupower_set_generic_turbo_boost (int turbo_boost){
char path[SYSFS_PATH_MAX];
char linebuf[2] = {};