Skip to content

Commit 91b156f

Browse files
committed
Merge tag 'linux-cpupower-6.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux
Merge cpupower utility update for 6.6-rc1 from Shuah Khan: "This cpupower update for Linux 6.6-rc1 consists of 2 fixes and enhancements to add support for amd-pstate active mode driver, amd_pstate mode change, EPP value change, turbo-boost support, and is_valid_path API." * tag 'linux-cpupower-6.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux: cpupower: Fix cpuidle_set to accept only numeric values for idle-set operation. cpupower: Add turbo-boost support in cpupower cpupower: Add support for amd_pstate mode change cpupower: Add EPP value change support cpupower: Add is_valid_path API cpupower: Recognise amd-pstate active mode driver cpupower: Bump soname version
2 parents 5d0c230 + 99481d2 commit 91b156f

File tree

7 files changed

+146
-13
lines changed

7 files changed

+146
-13
lines changed

tools/power/cpupower/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ DESTDIR ?=
5353

5454
VERSION:= $(shell ./utils/version-gen.sh)
5555
LIB_MAJ= 0.0.1
56-
LIB_MIN= 0
56+
LIB_MIN= 1
5757

5858
PACKAGE = cpupower
5959
PACKAGE_BUGREPORT = linux-pm@vger.kernel.org

tools/power/cpupower/lib/cpupower.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
#include "cpupower.h"
1515
#include "cpupower_intern.h"
1616

17+
int is_valid_path(const char *path)
18+
{
19+
if (access(path, F_OK) == -1)
20+
return 0;
21+
return 1;
22+
}
23+
1724
unsigned int cpupower_read_sysfs(const char *path, char *buf, size_t buflen)
1825
{
1926
ssize_t numread;

tools/power/cpupower/lib/cpupower_intern.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77

88
#define SYSFS_PATH_MAX 255
99

10+
int is_valid_path(const char *path);
1011
unsigned int cpupower_read_sysfs(const char *path, char *buf, size_t buflen);
1112
unsigned int cpupower_write_sysfs(const char *path, char *buf, size_t buflen);

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,20 @@ int cmd_idle_set(int argc, char **argv)
4141
cont = 0;
4242
break;
4343
case 'd':
44-
if (param) {
45-
param = -1;
46-
cont = 0;
47-
break;
48-
}
49-
param = ret;
50-
idlestate = atoi(optarg);
51-
break;
5244
case 'e':
5345
if (param) {
5446
param = -1;
5547
cont = 0;
5648
break;
5749
}
5850
param = ret;
59-
idlestate = atoi(optarg);
51+
strtol(optarg, &endptr, 10);
52+
if (*endptr != '\0') {
53+
printf(_("Bad value: %s, Integer expected\n"), optarg);
54+
exit(EXIT_FAILURE);
55+
} else {
56+
idlestate = atoi(optarg);
57+
}
6058
break;
6159
case 'D':
6260
if (param) {

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

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
static struct option set_opts[] = {
2020
{"perf-bias", required_argument, NULL, 'b'},
21+
{"epp", required_argument, NULL, 'e'},
22+
{"amd-pstate-mode", required_argument, NULL, 'm'},
23+
{"turbo-boost", required_argument, NULL, 't'},
2124
{ },
2225
};
2326

@@ -37,11 +40,15 @@ int cmd_set(int argc, char **argv)
3740
union {
3841
struct {
3942
int perf_bias:1;
43+
int epp:1;
44+
int mode:1;
45+
int turbo_boost:1;
4046
};
4147
int params;
4248
} params;
43-
int perf_bias = 0;
49+
int perf_bias = 0, turbo_boost = 1;
4450
int ret = 0;
51+
char epp[30], mode[20];
4552

4653
ret = uname(&uts);
4754
if (!ret && (!strcmp(uts.machine, "ppc64le") ||
@@ -55,7 +62,7 @@ int cmd_set(int argc, char **argv)
5562

5663
params.params = 0;
5764
/* parameter parsing */
58-
while ((ret = getopt_long(argc, argv, "b:",
65+
while ((ret = getopt_long(argc, argv, "b:e:m:",
5966
set_opts, NULL)) != -1) {
6067
switch (ret) {
6168
case 'b':
@@ -69,6 +76,38 @@ int cmd_set(int argc, char **argv)
6976
}
7077
params.perf_bias = 1;
7178
break;
79+
case 'e':
80+
if (params.epp)
81+
print_wrong_arg_exit();
82+
if (sscanf(optarg, "%29s", epp) != 1) {
83+
print_wrong_arg_exit();
84+
return -EINVAL;
85+
}
86+
params.epp = 1;
87+
break;
88+
case 'm':
89+
if (cpupower_cpu_info.vendor != X86_VENDOR_AMD)
90+
print_wrong_arg_exit();
91+
if (params.mode)
92+
print_wrong_arg_exit();
93+
if (sscanf(optarg, "%19s", mode) != 1) {
94+
print_wrong_arg_exit();
95+
return -EINVAL;
96+
}
97+
params.mode = 1;
98+
break;
99+
case 't':
100+
if (params.turbo_boost)
101+
print_wrong_arg_exit();
102+
turbo_boost = atoi(optarg);
103+
if (turbo_boost < 0 || turbo_boost > 1) {
104+
printf("--turbo-boost param out of range [0-1]\n");
105+
print_wrong_arg_exit();
106+
}
107+
params.turbo_boost = 1;
108+
break;
109+
110+
72111
default:
73112
print_wrong_arg_exit();
74113
}
@@ -77,6 +116,18 @@ int cmd_set(int argc, char **argv)
77116
if (!params.params)
78117
print_wrong_arg_exit();
79118

119+
if (params.mode) {
120+
ret = cpupower_set_amd_pstate_mode(mode);
121+
if (ret)
122+
fprintf(stderr, "Error setting mode\n");
123+
}
124+
125+
if (params.turbo_boost) {
126+
ret = cpupower_set_turbo_boost(turbo_boost);
127+
if (ret)
128+
fprintf(stderr, "Error setting turbo-boost\n");
129+
}
130+
80131
/* Default is: set all CPUs */
81132
if (bitmask_isallclear(cpus_chosen))
82133
bitmask_setall(cpus_chosen);
@@ -102,6 +153,16 @@ int cmd_set(int argc, char **argv)
102153
break;
103154
}
104155
}
156+
157+
if (params.epp) {
158+
ret = cpupower_set_epp(cpu, epp);
159+
if (ret) {
160+
fprintf(stderr,
161+
"Error setting epp value on CPU %d\n", cpu);
162+
break;
163+
}
164+
}
165+
105166
}
106167
return ret;
107168
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ extern int cpupower_intel_set_perf_bias(unsigned int cpu, unsigned int val);
116116
extern int cpupower_intel_get_perf_bias(unsigned int cpu);
117117
extern unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu);
118118

119+
extern int cpupower_set_epp(unsigned int cpu, char *epp);
120+
extern int cpupower_set_amd_pstate_mode(char *mode);
121+
extern int cpupower_set_turbo_boost(int turbo_boost);
122+
119123
/* Read/Write msr ****************************/
120124

121125
/* PCI stuff ****************************/
@@ -173,6 +177,13 @@ static inline int cpupower_intel_get_perf_bias(unsigned int cpu)
173177
static inline unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu)
174178
{ return 0; };
175179

180+
static inline int cpupower_set_epp(unsigned int cpu, char *epp)
181+
{ return -1; };
182+
static inline int cpupower_set_amd_pstate_mode(char *mode)
183+
{ return -1; };
184+
static inline int cpupower_set_turbo_boost(int turbo_boost)
185+
{ return -1; };
186+
176187
/* Read/Write msr ****************************/
177188

178189
static inline int cpufreq_has_boost_support(unsigned int cpu, int *support,

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

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,61 @@ int cpupower_intel_set_perf_bias(unsigned int cpu, unsigned int val)
8787
return 0;
8888
}
8989

90+
int cpupower_set_epp(unsigned int cpu, char *epp)
91+
{
92+
char path[SYSFS_PATH_MAX];
93+
char linebuf[30] = {};
94+
95+
snprintf(path, sizeof(path),
96+
PATH_TO_CPU "cpu%u/cpufreq/energy_performance_preference", cpu);
97+
98+
if (!is_valid_path(path))
99+
return -1;
100+
101+
snprintf(linebuf, sizeof(linebuf), "%s", epp);
102+
103+
if (cpupower_write_sysfs(path, linebuf, 30) <= 0)
104+
return -1;
105+
106+
return 0;
107+
}
108+
109+
int cpupower_set_amd_pstate_mode(char *mode)
110+
{
111+
char path[SYSFS_PATH_MAX];
112+
char linebuf[20] = {};
113+
114+
snprintf(path, sizeof(path), PATH_TO_CPU "amd_pstate/status");
115+
116+
if (!is_valid_path(path))
117+
return -1;
118+
119+
snprintf(linebuf, sizeof(linebuf), "%s\n", mode);
120+
121+
if (cpupower_write_sysfs(path, linebuf, 20) <= 0)
122+
return -1;
123+
124+
return 0;
125+
}
126+
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+
90145
bool cpupower_amd_pstate_enabled(void)
91146
{
92147
char *driver = cpufreq_get_driver(0);
@@ -95,7 +150,7 @@ bool cpupower_amd_pstate_enabled(void)
95150
if (!driver)
96151
return ret;
97152

98-
if (!strcmp(driver, "amd-pstate"))
153+
if (!strncmp(driver, "amd", 3))
99154
ret = true;
100155

101156
cpufreq_put_driver(driver);

0 commit comments

Comments
 (0)