Skip to content

Commit 357d1fc

Browse files
Shinji Nomotoshuahkh
authored andcommitted
cpupower: Allow control of boost feature on non-x86 based systems with boost support.
The cpufreq subsystem has a generic sysfs interface for controlling boost (/sys/devices/system/cpu/cpufreq/boost). The sysfs interface can be used to enable boost control from the cpupower command on non-x86 platforms as well. So, allow boost controlling on non-x86 system if boost sysfs file exists. The set subcommand enables/disables the boost feature using the following syntax: cpupower set --boost 1 cpupower set --boost 0 The --boost option is an alias for --turbo-boost. We provided the neutral option name because the name "turbo boost" is specific to Intel technology. The frequency-info subcommand displays the enabled/disabled state of the boost feature as follows: boost state support: Active: yes (or no) Link: https://lore.kernel.org/r/20250522061122.2149188-3-fj5851bi@fujitsu.com Signed-off-by: Shinji Nomoto <fj5851bi@fujitsu.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent b3eaf14 commit 357d1fc

File tree

5 files changed

+81
-33
lines changed

5 files changed

+81
-33
lines changed

tools/power/cpupower/man/cpupower-set.1

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,11 @@ Refer to the AMD P-State kernel documentation for further information.
8181
.RE
8282

8383
.PP
84-
\-\-turbo\-boost, \-t
84+
\-\-turbo\-boost, \-\-boost, \-t
8585
.RS 4
86-
This option is used to enable or disable the turbo boost feature on
87-
supported Intel and AMD processors.
86+
This option is used to enable or disable the boost feature on
87+
supported Intel and AMD processors, and other boost supported systems.
88+
(The --boost option is an alias for the --turbo-boost option)
8889

8990
This option takes as parameter either \fB1\fP to enable, or \fB0\fP to disable the feature.
9091

tools/power/cpupower/utils/cpufreq-info.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ static int get_boost_mode_x86(unsigned int cpu)
128128
/* ToDo: Make this more global */
129129
unsigned long pstates[MAX_HW_PSTATES] = {0,};
130130

131-
ret = cpufreq_has_boost_support(cpu, &support, &active, &b_states);
131+
ret = cpufreq_has_x86_boost_support(cpu, &support, &active, &b_states);
132132
if (ret) {
133133
printf(_("Error while evaluating Boost Capabilities"
134134
" on CPU %d -- are you root?\n"), cpu);
@@ -204,6 +204,18 @@ static int get_boost_mode_x86(unsigned int cpu)
204204
return 0;
205205
}
206206

207+
static int get_boost_mode_generic(unsigned int cpu)
208+
{
209+
bool active;
210+
211+
if (!cpufreq_has_generic_boost_support(&active)) {
212+
printf(_(" boost state support:\n"));
213+
printf(_(" Active: %s\n"), active ? _("yes") : _("no"));
214+
}
215+
216+
return 0;
217+
}
218+
207219
/* --boost / -b */
208220

209221
static int get_boost_mode(unsigned int cpu)
@@ -214,6 +226,8 @@ static int get_boost_mode(unsigned int cpu)
214226
cpupower_cpu_info.vendor == X86_VENDOR_HYGON ||
215227
cpupower_cpu_info.vendor == X86_VENDOR_INTEL)
216228
return get_boost_mode_x86(cpu);
229+
else
230+
get_boost_mode_generic(cpu);
217231

218232
freqs = cpufreq_get_boost_frequencies(cpu);
219233
if (freqs) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ static struct option set_opts[] = {
2121
{"epp", required_argument, NULL, 'e'},
2222
{"amd-pstate-mode", required_argument, NULL, 'm'},
2323
{"turbo-boost", required_argument, NULL, 't'},
24+
{"boost", required_argument, NULL, 't'},
2425
{ },
2526
};
2627

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ extern struct cpupower_cpu_info cpupower_cpu_info;
103103

104104
/* cpuid and cpuinfo helpers **************************/
105105

106+
int cpufreq_has_generic_boost_support(bool *active);
107+
int cpupower_set_turbo_boost(int turbo_boost);
108+
106109
/* X86 ONLY ****************************************/
107110
#if defined(__i386__) || defined(__x86_64__)
108111

@@ -118,7 +121,6 @@ extern unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu);
118121

119122
extern int cpupower_set_epp(unsigned int cpu, char *epp);
120123
extern int cpupower_set_amd_pstate_mode(char *mode);
121-
extern int cpupower_set_turbo_boost(int turbo_boost);
122124

123125
/* Read/Write msr ****************************/
124126

@@ -139,8 +141,8 @@ extern int decode_pstates(unsigned int cpu, int boost_states,
139141

140142
/* AMD HW pstate decoding **************************/
141143

142-
extern int cpufreq_has_boost_support(unsigned int cpu, int *support,
143-
int *active, int * states);
144+
int cpufreq_has_x86_boost_support(unsigned int cpu, int *support,
145+
int *active, int *states);
144146

145147
/* AMD P-State stuff **************************/
146148
bool cpupower_amd_pstate_enabled(void);
@@ -181,13 +183,11 @@ static inline int cpupower_set_epp(unsigned int cpu, char *epp)
181183
{ return -1; };
182184
static inline int cpupower_set_amd_pstate_mode(char *mode)
183185
{ return -1; };
184-
static inline int cpupower_set_turbo_boost(int turbo_boost)
185-
{ return -1; };
186186

187187
/* Read/Write msr ****************************/
188188

189-
static inline int cpufreq_has_boost_support(unsigned int cpu, int *support,
190-
int *active, int * states)
189+
static inline int cpufreq_has_x86_boost_support(unsigned int cpu, int *support,
190+
int *active, int *states)
191191
{ return -1; }
192192

193193
static inline bool cpupower_amd_pstate_enabled(void)

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

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88
#include "helpers/helpers.h"
99
#include "helpers/sysfs.h"
1010
#include "cpufreq.h"
11+
#include "cpupower_intern.h"
1112

1213
#if defined(__i386__) || defined(__x86_64__)
1314

14-
#include "cpupower_intern.h"
15-
1615
#define MSR_AMD_HWCR 0xc0010015
1716

18-
int cpufreq_has_boost_support(unsigned int cpu, int *support, int *active,
19-
int *states)
17+
int cpufreq_has_x86_boost_support(unsigned int cpu, int *support, int *active,
18+
int *states)
2019
{
2120
int ret;
2221
unsigned long long val;
@@ -124,24 +123,6 @@ int cpupower_set_amd_pstate_mode(char *mode)
124123
return 0;
125124
}
126125

127-
int cpupower_set_turbo_boost(int turbo_boost)
128-
{
129-
char path[SYSFS_PATH_MAX];
130-
char linebuf[2] = {};
131-
132-
snprintf(path, sizeof(path), PATH_TO_CPU "cpufreq/boost");
133-
134-
if (!is_valid_path(path))
135-
return -1;
136-
137-
snprintf(linebuf, sizeof(linebuf), "%d", turbo_boost);
138-
139-
if (cpupower_write_sysfs(path, linebuf, 2) <= 0)
140-
return -1;
141-
142-
return 0;
143-
}
144-
145126
bool cpupower_amd_pstate_enabled(void)
146127
{
147128
char *driver = cpufreq_get_driver(0);
@@ -160,6 +141,39 @@ bool cpupower_amd_pstate_enabled(void)
160141

161142
#endif /* #if defined(__i386__) || defined(__x86_64__) */
162143

144+
int cpufreq_has_generic_boost_support(bool *active)
145+
{
146+
char path[SYSFS_PATH_MAX];
147+
char linebuf[2] = {};
148+
unsigned long val;
149+
char *endp;
150+
151+
snprintf(path, sizeof(path), PATH_TO_CPU "cpufreq/boost");
152+
153+
if (!is_valid_path(path))
154+
return -EACCES;
155+
156+
if (cpupower_read_sysfs(path, linebuf, 2) <= 0)
157+
return -EINVAL;
158+
159+
val = strtoul(linebuf, &endp, 0);
160+
if (endp == linebuf || errno == ERANGE)
161+
return -EINVAL;
162+
163+
switch (val) {
164+
case 0:
165+
*active = false;
166+
break;
167+
case 1:
168+
*active = true;
169+
break;
170+
default:
171+
return -EINVAL;
172+
}
173+
174+
return 0;
175+
}
176+
163177
/* get_cpustate
164178
*
165179
* Gather the information of all online CPUs into bitmask struct
@@ -259,3 +273,21 @@ void print_speed(unsigned long speed, int no_rounding)
259273
}
260274
}
261275
}
276+
277+
int cpupower_set_turbo_boost(int turbo_boost)
278+
{
279+
char path[SYSFS_PATH_MAX];
280+
char linebuf[2] = {};
281+
282+
snprintf(path, sizeof(path), PATH_TO_CPU "cpufreq/boost");
283+
284+
if (!is_valid_path(path))
285+
return -1;
286+
287+
snprintf(linebuf, sizeof(linebuf), "%d", turbo_boost);
288+
289+
if (cpupower_write_sysfs(path, linebuf, 2) <= 0)
290+
return -1;
291+
292+
return 0;
293+
}

0 commit comments

Comments
 (0)