Skip to content

Commit 3817b1d

Browse files
zhang-ruishuahkh
authored andcommitted
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-boost With 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 Signed-off-by: Zhang Rui <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent 50ad1a3 commit 3817b1d

3 files changed

Lines changed: 48 additions & 4 deletions

File tree

tools/power/cpupower/utils/cpupower-set.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ int cmd_set(int argc, char **argv)
124124
}
125125

126126
if (params.turbo_boost) {
127-
ret = cpupower_set_turbo_boost(turbo_boost);
127+
if (cpupower_cpu_info.vendor == X86_VENDOR_INTEL)
128+
ret = cpupower_set_intel_turbo_boost(turbo_boost);
129+
else
130+
ret = cpupower_set_generic_turbo_boost(turbo_boost);
131+
128132
if (ret)
129133
fprintf(stderr, "Error setting turbo-boost\n");
130134
}

tools/power/cpupower/utils/helpers/helpers.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ extern struct cpupower_cpu_info cpupower_cpu_info;
104104
/* cpuid and cpuinfo helpers **************************/
105105

106106
int cpufreq_has_generic_boost_support(bool *active);
107-
int cpupower_set_turbo_boost(int turbo_boost);
107+
int cpupower_set_generic_turbo_boost(int turbo_boost);
108108

109109
/* X86 ONLY ****************************************/
110110
#if defined(__i386__) || defined(__x86_64__)
@@ -143,6 +143,7 @@ extern int decode_pstates(unsigned int cpu, int boost_states,
143143

144144
int cpufreq_has_x86_boost_support(unsigned int cpu, int *support,
145145
int *active, int *states);
146+
int cpupower_set_intel_turbo_boost(int turbo_boost);
146147

147148
/* AMD P-State stuff **************************/
148149
bool cpupower_amd_pstate_enabled(void);
@@ -189,6 +190,8 @@ static inline int cpupower_set_amd_pstate_mode(char *mode)
189190
static inline int cpufreq_has_x86_boost_support(unsigned int cpu, int *support,
190191
int *active, int *states)
191192
{ return -1; }
193+
static inline int cpupower_set_intel_turbo_boost(int turbo_boost)
194+
{ return -1; }
192195

193196
static inline bool cpupower_amd_pstate_enabled(void)
194197
{ return false; }

tools/power/cpupower/utils/helpers/misc.c

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ int cpufreq_has_x86_boost_support(unsigned int cpu, int *support, int *active,
1919
{
2020
int ret;
2121
unsigned long long val;
22+
char linebuf[MAX_LINE_LEN];
23+
char path[SYSFS_PATH_MAX];
24+
char *endp;
2225

2326
*support = *active = *states = 0;
2427

@@ -42,8 +45,42 @@ int cpufreq_has_x86_boost_support(unsigned int cpu, int *support, int *active,
4245
}
4346
} else if (cpupower_cpu_info.caps & CPUPOWER_CAP_AMD_PSTATE) {
4447
amd_pstate_boost_init(cpu, support, active);
45-
} else if (cpupower_cpu_info.caps & CPUPOWER_CAP_INTEL_IDA)
48+
} else if (cpupower_cpu_info.caps & CPUPOWER_CAP_INTEL_IDA) {
4649
*support = *active = 1;
50+
51+
snprintf(path, sizeof(path), PATH_TO_CPU "intel_pstate/no_turbo");
52+
53+
if (!is_valid_path(path))
54+
return 0;
55+
56+
if (cpupower_read_sysfs(path, linebuf, MAX_LINE_LEN) == 0)
57+
return -1;
58+
59+
val = strtol(linebuf, &endp, 0);
60+
if (endp == linebuf || errno == ERANGE)
61+
return -1;
62+
63+
*active = !val;
64+
}
65+
return 0;
66+
}
67+
68+
int cpupower_set_intel_turbo_boost(int turbo_boost)
69+
{
70+
char path[SYSFS_PATH_MAX];
71+
char linebuf[2] = {};
72+
73+
snprintf(path, sizeof(path), PATH_TO_CPU "intel_pstate/no_turbo");
74+
75+
/* Fallback to generic solution when intel_pstate driver not running */
76+
if (!is_valid_path(path))
77+
return cpupower_set_generic_turbo_boost(turbo_boost);
78+
79+
snprintf(linebuf, sizeof(linebuf), "%d", !turbo_boost);
80+
81+
if (cpupower_write_sysfs(path, linebuf, 2) <= 0)
82+
return -1;
83+
4784
return 0;
4885
}
4986

@@ -274,7 +311,7 @@ void print_speed(unsigned long speed, int no_rounding)
274311
}
275312
}
276313

277-
int cpupower_set_turbo_boost(int turbo_boost)
314+
int cpupower_set_generic_turbo_boost(int turbo_boost)
278315
{
279316
char path[SYSFS_PATH_MAX];
280317
char linebuf[2] = {};

0 commit comments

Comments
 (0)