Skip to content

Commit 66ad71b

Browse files
committed
Merge: Update cpupower to upstream 6.17
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/7416 JIRA: https://issues.redhat.com/browse/RHEL-118182 cpupower is a key tool and needs to be updated regularly. The following upstream commits were not applied to this update as they were either deemed unneccessary or inappropriate for RHEL9: fffadbd cpupower: Make lib versioning scheme more obvio 9c70b77 cpupower: add a systemd service to run cpupower 99d2fce cpupower: change binding's makefile to use -lcp 2a0eaa7 cpupower: do not write DESTDIR to cpupower.serv 4edef85 cpupower: do not call systemctl at install time e517436 cpupower: do not install files to /etc/default/ e044b8a cpupower: split unitdir from libdir in Makefile b74710e cpupower: Improve Python binding's Makefile Signed-off-by: David Arcari <darcari@redhat.com> Approved-by: Steve Best <sbest@redhat.com> Approved-by: Lenny Szubowicz <lszubowi@redhat.com> Approved-by: Tony Camuso <tcamuso@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Patrick Talbert <ptalbert@redhat.com>
2 parents c570ccc + 7ac8f63 commit 66ad71b

File tree

10 files changed

+164
-57
lines changed

10 files changed

+164
-57
lines changed

tools/power/cpupower/bench/parse.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ FILE *prepare_output(const char *dirname)
121121
struct config *prepare_default_config()
122122
{
123123
struct config *config = malloc(sizeof(struct config));
124+
if (!config) {
125+
perror("malloc");
126+
return NULL;
127+
}
124128

125129
dprintf("loading defaults\n");
126130

tools/power/cpupower/lib/cpupower.c

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <stdio.h>
1111
#include <errno.h>
1212
#include <stdlib.h>
13+
#include <string.h>
1314

1415
#include "cpupower.h"
1516
#include "cpupower_intern.h"
@@ -150,15 +151,25 @@ static int __compare(const void *t1, const void *t2)
150151
return 0;
151152
}
152153

154+
static int __compare_core_cpu_list(const void *t1, const void *t2)
155+
{
156+
struct cpuid_core_info *top1 = (struct cpuid_core_info *)t1;
157+
struct cpuid_core_info *top2 = (struct cpuid_core_info *)t2;
158+
159+
return strcmp(top1->core_cpu_list, top2->core_cpu_list);
160+
}
161+
153162
/*
154163
* Returns amount of cpus, negative on error, cpu_top must be
155164
* passed to cpu_topology_release to free resources
156165
*
157-
* Array is sorted after ->pkg, ->core, then ->cpu
166+
* Array is sorted after ->cpu_smt_list ->pkg, ->core
158167
*/
159168
int get_cpu_topology(struct cpupower_topology *cpu_top)
160169
{
161170
int cpu, last_pkg, cpus = sysconf(_SC_NPROCESSORS_CONF);
171+
char path[SYSFS_PATH_MAX];
172+
char *last_cpu_list;
162173

163174
cpu_top->core_info = malloc(sizeof(struct cpuid_core_info) * cpus);
164175
if (cpu_top->core_info == NULL)
@@ -183,6 +194,34 @@ int get_cpu_topology(struct cpupower_topology *cpu_top)
183194
cpu_top->core_info[cpu].core = -1;
184195
continue;
185196
}
197+
if (cpu_top->core_info[cpu].core == -1) {
198+
strncpy(cpu_top->core_info[cpu].core_cpu_list, "-1", CPULIST_BUFFER);
199+
continue;
200+
}
201+
snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/topology/%s",
202+
cpu, "core_cpus_list");
203+
if (cpupower_read_sysfs(
204+
path,
205+
cpu_top->core_info[cpu].core_cpu_list,
206+
CPULIST_BUFFER) < 1) {
207+
printf("Warning CPU%u has a 0 size core_cpus_list string", cpu);
208+
}
209+
}
210+
211+
/* Count the number of distinct cpu lists to get the physical core
212+
* count.
213+
*/
214+
qsort(cpu_top->core_info, cpus, sizeof(struct cpuid_core_info),
215+
__compare_core_cpu_list);
216+
217+
last_cpu_list = cpu_top->core_info[0].core_cpu_list;
218+
cpu_top->cores = 1;
219+
for (cpu = 1; cpu < cpus; cpu++) {
220+
if (strcmp(cpu_top->core_info[cpu].core_cpu_list, last_cpu_list) != 0 &&
221+
cpu_top->core_info[cpu].pkg != -1) {
222+
last_cpu_list = cpu_top->core_info[cpu].core_cpu_list;
223+
cpu_top->cores++;
224+
}
186225
}
187226

188227
qsort(cpu_top->core_info, cpus, sizeof(struct cpuid_core_info),
@@ -203,13 +242,6 @@ int get_cpu_topology(struct cpupower_topology *cpu_top)
203242
if (!(cpu_top->core_info[0].pkg == -1))
204243
cpu_top->pkgs++;
205244

206-
/* Intel's cores count is not consecutively numbered, there may
207-
* be a core_id of 3, but none of 2. Assume there always is 0
208-
* Get amount of cores by counting duplicates in a package
209-
for (cpu = 0; cpu_top->core_info[cpu].pkg = 0 && cpu < cpus; cpu++) {
210-
if (cpu_top->core_info[cpu].core == 0)
211-
cpu_top->cores++;
212-
*/
213245
return cpus;
214246
}
215247

tools/power/cpupower/lib/cpupower.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#ifndef __CPUPOWER_CPUPOWER_H__
33
#define __CPUPOWER_CPUPOWER_H__
44

5+
#define CPULIST_BUFFER 5
6+
57
struct cpupower_topology {
68
/* Amount of CPU cores, packages and threads per core in the system */
79
unsigned int cores;
@@ -16,6 +18,7 @@ struct cpuid_core_info {
1618
int pkg;
1719
int core;
1820
int cpu;
21+
char core_cpu_list[CPULIST_BUFFER];
1922

2023
/* flags */
2124
unsigned int is_online:1;

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: 3 additions & 2 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

@@ -62,8 +63,8 @@ int cmd_set(int argc, char **argv)
6263

6364
params.params = 0;
6465
/* parameter parsing */
65-
while ((ret = getopt_long(argc, argv, "b:e:m:",
66-
set_opts, NULL)) != -1) {
66+
while ((ret = getopt_long(argc, argv, "b:e:m:t:",
67+
set_opts, NULL)) != -1) {
6768
switch (ret) {
6869
case 'b':
6970
if (params.perf_bias)

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)