Skip to content

Commit f2ab555

Browse files
wkarnyshuahkh
authored andcommitted
cpupower: Add EPP value change support
amd_pstate and intel_pstate active mode drivers support energy performance preference feature. Through this user can convey it's energy/performance preference to platform. Add this value change capability to cpupower. To change the EPP value use below command: cpupower set --epp performance Reviewed-by: Mario Limonciello <mario.limonciello@amd.com> Signed-off-by: Wyes Karny <wyes.karny@amd.com> Tested-by: Perry Yuan <Perry.Yuan@amd.com> Acked-by: Huang Rui <ray.huang@amd.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent 1ce5ab7 commit f2ab555

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
static struct option set_opts[] = {
2020
{"perf-bias", required_argument, NULL, 'b'},
21+
{"epp", required_argument, NULL, 'e'},
2122
{ },
2223
};
2324

@@ -37,11 +38,13 @@ int cmd_set(int argc, char **argv)
3738
union {
3839
struct {
3940
int perf_bias:1;
41+
int epp:1;
4042
};
4143
int params;
4244
} params;
4345
int perf_bias = 0;
4446
int ret = 0;
47+
char epp[30];
4548

4649
ret = uname(&uts);
4750
if (!ret && (!strcmp(uts.machine, "ppc64le") ||
@@ -55,7 +58,7 @@ int cmd_set(int argc, char **argv)
5558

5659
params.params = 0;
5760
/* parameter parsing */
58-
while ((ret = getopt_long(argc, argv, "b:",
61+
while ((ret = getopt_long(argc, argv, "b:e:",
5962
set_opts, NULL)) != -1) {
6063
switch (ret) {
6164
case 'b':
@@ -69,6 +72,15 @@ int cmd_set(int argc, char **argv)
6972
}
7073
params.perf_bias = 1;
7174
break;
75+
case 'e':
76+
if (params.epp)
77+
print_wrong_arg_exit();
78+
if (sscanf(optarg, "%29s", epp) != 1) {
79+
print_wrong_arg_exit();
80+
return -EINVAL;
81+
}
82+
params.epp = 1;
83+
break;
7284
default:
7385
print_wrong_arg_exit();
7486
}
@@ -102,6 +114,15 @@ int cmd_set(int argc, char **argv)
102114
break;
103115
}
104116
}
117+
118+
if (params.epp) {
119+
ret = cpupower_set_epp(cpu, epp);
120+
if (ret) {
121+
fprintf(stderr,
122+
"Error setting epp value on CPU %d\n", cpu);
123+
break;
124+
}
125+
}
105126
}
106127
return ret;
107128
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ 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+
119121
/* Read/Write msr ****************************/
120122

121123
/* PCI stuff ****************************/
@@ -173,6 +175,9 @@ static inline int cpupower_intel_get_perf_bias(unsigned int cpu)
173175
static inline unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu)
174176
{ return 0; };
175177

178+
static inline int cpupower_set_epp(unsigned int cpu, char *epp)
179+
{ return -1; };
180+
176181
/* Read/Write msr ****************************/
177182

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

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,25 @@ 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+
90109
bool cpupower_amd_pstate_enabled(void)
91110
{
92111
char *driver = cpufreq_get_driver(0);

0 commit comments

Comments
 (0)