Skip to content

Commit eb426fc

Browse files
wkarnyshuahkh
authored andcommitted
cpupower: Add turbo-boost support in cpupower
If boost sysfs (/sys/devices/system/cpu/cpufreq/boost) file is present turbo-boost is feature is supported in the hardware. By default this feature should be enabled. But to disable/enable it write to the sysfs file. Use the same to control this feature via cpupower. To enable: cpupower set --turbo-boost 1 To disable: cpupower set --turbo-boost 0 Acked-by: Huang Rui <ray.huang@amd.com> Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com> 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> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent df8776b commit eb426fc

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ static struct option set_opts[] = {
2020
{"perf-bias", required_argument, NULL, 'b'},
2121
{"epp", required_argument, NULL, 'e'},
2222
{"amd-pstate-mode", required_argument, NULL, 'm'},
23+
{"turbo-boost", required_argument, NULL, 't'},
2324
{ },
2425
};
2526

@@ -41,10 +42,11 @@ int cmd_set(int argc, char **argv)
4142
int perf_bias:1;
4243
int epp:1;
4344
int mode:1;
45+
int turbo_boost:1;
4446
};
4547
int params;
4648
} params;
47-
int perf_bias = 0;
49+
int perf_bias = 0, turbo_boost = 1;
4850
int ret = 0;
4951
char epp[30], mode[20];
5052

@@ -94,6 +96,18 @@ int cmd_set(int argc, char **argv)
9496
}
9597
params.mode = 1;
9698
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+
97111
default:
98112
print_wrong_arg_exit();
99113
}
@@ -108,6 +122,12 @@ int cmd_set(int argc, char **argv)
108122
fprintf(stderr, "Error setting mode\n");
109123
}
110124

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+
111131
/* Default is: set all CPUs */
112132
if (bitmask_isallclear(cpus_chosen))
113133
bitmask_setall(cpus_chosen);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ extern unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu);
118118

119119
extern int cpupower_set_epp(unsigned int cpu, char *epp);
120120
extern int cpupower_set_amd_pstate_mode(char *mode);
121+
extern int cpupower_set_turbo_boost(int turbo_boost);
121122

122123
/* Read/Write msr ****************************/
123124

@@ -180,6 +181,8 @@ static inline int cpupower_set_epp(unsigned int cpu, char *epp)
180181
{ return -1; };
181182
static inline int cpupower_set_amd_pstate_mode(char *mode)
182183
{ return -1; };
184+
static inline int cpupower_set_turbo_boost(int turbo_boost)
185+
{ return -1; };
183186

184187
/* Read/Write msr ****************************/
185188

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,24 @@ int cpupower_set_amd_pstate_mode(char *mode)
124124
return 0;
125125
}
126126

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+
127145
bool cpupower_amd_pstate_enabled(void)
128146
{
129147
char *driver = cpufreq_get_driver(0);

0 commit comments

Comments
 (0)