mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2025-01-16 02:44:26 +08:00
cpupower: Add support for amd_pstate mode change
amd_pstate supports changing of its mode dynamically via `status` sysfs file. Add the same capability in cpupower. To change the mode to active mode use below command: cpupower set --amd-pstate-mode active 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>
This commit is contained in:
parent
f2ab555711
commit
df8776b036
@ -19,6 +19,7 @@
|
|||||||
static struct option set_opts[] = {
|
static struct option set_opts[] = {
|
||||||
{"perf-bias", required_argument, NULL, 'b'},
|
{"perf-bias", required_argument, NULL, 'b'},
|
||||||
{"epp", required_argument, NULL, 'e'},
|
{"epp", required_argument, NULL, 'e'},
|
||||||
|
{"amd-pstate-mode", required_argument, NULL, 'm'},
|
||||||
{ },
|
{ },
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -39,12 +40,13 @@ int cmd_set(int argc, char **argv)
|
|||||||
struct {
|
struct {
|
||||||
int perf_bias:1;
|
int perf_bias:1;
|
||||||
int epp:1;
|
int epp:1;
|
||||||
|
int mode:1;
|
||||||
};
|
};
|
||||||
int params;
|
int params;
|
||||||
} params;
|
} params;
|
||||||
int perf_bias = 0;
|
int perf_bias = 0;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
char epp[30];
|
char epp[30], mode[20];
|
||||||
|
|
||||||
ret = uname(&uts);
|
ret = uname(&uts);
|
||||||
if (!ret && (!strcmp(uts.machine, "ppc64le") ||
|
if (!ret && (!strcmp(uts.machine, "ppc64le") ||
|
||||||
@ -58,7 +60,7 @@ int cmd_set(int argc, char **argv)
|
|||||||
|
|
||||||
params.params = 0;
|
params.params = 0;
|
||||||
/* parameter parsing */
|
/* parameter parsing */
|
||||||
while ((ret = getopt_long(argc, argv, "b:e:",
|
while ((ret = getopt_long(argc, argv, "b:e:m:",
|
||||||
set_opts, NULL)) != -1) {
|
set_opts, NULL)) != -1) {
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case 'b':
|
case 'b':
|
||||||
@ -81,6 +83,17 @@ int cmd_set(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
params.epp = 1;
|
params.epp = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'm':
|
||||||
|
if (cpupower_cpu_info.vendor != X86_VENDOR_AMD)
|
||||||
|
print_wrong_arg_exit();
|
||||||
|
if (params.mode)
|
||||||
|
print_wrong_arg_exit();
|
||||||
|
if (sscanf(optarg, "%19s", mode) != 1) {
|
||||||
|
print_wrong_arg_exit();
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
params.mode = 1;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
print_wrong_arg_exit();
|
print_wrong_arg_exit();
|
||||||
}
|
}
|
||||||
@ -89,6 +102,12 @@ int cmd_set(int argc, char **argv)
|
|||||||
if (!params.params)
|
if (!params.params)
|
||||||
print_wrong_arg_exit();
|
print_wrong_arg_exit();
|
||||||
|
|
||||||
|
if (params.mode) {
|
||||||
|
ret = cpupower_set_amd_pstate_mode(mode);
|
||||||
|
if (ret)
|
||||||
|
fprintf(stderr, "Error setting mode\n");
|
||||||
|
}
|
||||||
|
|
||||||
/* Default is: set all CPUs */
|
/* Default is: set all CPUs */
|
||||||
if (bitmask_isallclear(cpus_chosen))
|
if (bitmask_isallclear(cpus_chosen))
|
||||||
bitmask_setall(cpus_chosen);
|
bitmask_setall(cpus_chosen);
|
||||||
@ -123,6 +142,7 @@ int cmd_set(int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -117,6 +117,7 @@ extern int cpupower_intel_get_perf_bias(unsigned int cpu);
|
|||||||
extern unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu);
|
extern unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu);
|
||||||
|
|
||||||
extern int cpupower_set_epp(unsigned int cpu, char *epp);
|
extern int cpupower_set_epp(unsigned int cpu, char *epp);
|
||||||
|
extern int cpupower_set_amd_pstate_mode(char *mode);
|
||||||
|
|
||||||
/* Read/Write msr ****************************/
|
/* Read/Write msr ****************************/
|
||||||
|
|
||||||
@ -177,6 +178,8 @@ static inline unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu)
|
|||||||
|
|
||||||
static inline int cpupower_set_epp(unsigned int cpu, char *epp)
|
static inline int cpupower_set_epp(unsigned int cpu, char *epp)
|
||||||
{ return -1; };
|
{ return -1; };
|
||||||
|
static inline int cpupower_set_amd_pstate_mode(char *mode)
|
||||||
|
{ return -1; };
|
||||||
|
|
||||||
/* Read/Write msr ****************************/
|
/* Read/Write msr ****************************/
|
||||||
|
|
||||||
|
@ -106,6 +106,24 @@ int cpupower_set_epp(unsigned int cpu, char *epp)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int cpupower_set_amd_pstate_mode(char *mode)
|
||||||
|
{
|
||||||
|
char path[SYSFS_PATH_MAX];
|
||||||
|
char linebuf[20] = {};
|
||||||
|
|
||||||
|
snprintf(path, sizeof(path), PATH_TO_CPU "amd_pstate/status");
|
||||||
|
|
||||||
|
if (!is_valid_path(path))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
snprintf(linebuf, sizeof(linebuf), "%s\n", mode);
|
||||||
|
|
||||||
|
if (cpupower_write_sysfs(path, linebuf, 20) <= 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
bool cpupower_amd_pstate_enabled(void)
|
bool cpupower_amd_pstate_enabled(void)
|
||||||
{
|
{
|
||||||
char *driver = cpufreq_get_driver(0);
|
char *driver = cpufreq_get_driver(0);
|
||||||
|
Loading…
Reference in New Issue
Block a user