Skip to content

Commit ddc137d

Browse files
author
CKI KWF Bot
committed
Merge: cpupower: Updates for boost feature on non-x86 based systems with boost support.
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-10/-/merge_requests/1506 Description: Updates for boost feature on non-x86 based systems with boost support. JIRA: https://issues.redhat.com/browse/RHEL-111892 Build Info: 68996751 Tested: Successful platform test results on Intel (intel-arrowlake-s-02) system. Signed-off-by: Steve Best <sbest@redhat.com> Approved-by: David Arcari <darcari@redhat.com> Approved-by: Tony Camuso <tcamuso@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: CKI GitLab Kmaint Pipeline Bot <26919896-cki-kmaint-pipeline-bot@users.noreply.gitlab.com>
2 parents 9ced933 + 312e08c commit ddc137d

File tree

5 files changed

+114
-32
lines changed

5 files changed

+114
-32
lines changed

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

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
cpupower\-set \- Set processor power related kernel or hardware configurations
44
.SH SYNOPSIS
55
.ft B
6-
.B cpupower set [ \-b VAL ]
6+
.B cpupower set [ \-b VAL | \-e POLICY | \-m MODE | \-t BOOL ]
77

88

99
.SH DESCRIPTION
@@ -19,7 +19,7 @@ described in the Options sections.
1919
Use \fBcpupower info \fP to read out current settings and whether they are
2020
supported on the system at all.
2121

22-
.SH Options
22+
.SH OPTIONS
2323
.PP
2424
\-\-perf-bias, \-b
2525
.RS 4
@@ -56,6 +56,41 @@ Use \fBcpupower -c all info -b\fP to verify.
5656
This options needs the msr kernel driver (CONFIG_X86_MSR) loaded.
5757
.RE
5858

59+
.PP
60+
\-\-epp, \-e
61+
.RS 4
62+
Sets the energy performance policy preference on supported Intel or AMD
63+
processors which use the Intel or AMD P-State cpufreq driver respectively.
64+
65+
Available policies can be found with
66+
\fBcat /sys/devices/system/cpu/cpufreq/policy0/energy_performance_available_preferences\fP :
67+
.RS 4
68+
default performance balance_performance balance_power power
69+
.RE
70+
71+
.RE
72+
73+
.PP
74+
\-\-amd\-pstate\-mode, \-m
75+
.RS 4
76+
Sets the AMD P-State mode for supported AMD processors.
77+
Available modes are "active", "guided" or "passive".
78+
79+
Refer to the AMD P-State kernel documentation for further information.
80+
81+
.RE
82+
83+
.PP
84+
\-\-turbo\-boost, \-\-boost, \-t
85+
.RS 4
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)
89+
90+
This option takes as parameter either \fB1\fP to enable, or \fB0\fP to disable the feature.
91+
92+
.RE
93+
5994
.SH "SEE ALSO"
6095
cpupower-info(1), cpupower-monitor(1), powertop(1)
6196
.PP

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)