Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions tools/power/cpupower/man/cpupower-set.1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
cpupower\-set \- Set processor power related kernel or hardware configurations
.SH SYNOPSIS
.ft B
.B cpupower set [ \-b VAL ]
.B cpupower set [ \-b VAL | \-e POLICY | \-m MODE | \-t BOOL ]


.SH DESCRIPTION
Expand All @@ -19,7 +19,7 @@ described in the Options sections.
Use \fBcpupower info \fP to read out current settings and whether they are
supported on the system at all.

.SH Options
.SH OPTIONS
.PP
\-\-perf-bias, \-b
.RS 4
Expand Down Expand Up @@ -56,6 +56,41 @@ Use \fBcpupower -c all info -b\fP to verify.
This options needs the msr kernel driver (CONFIG_X86_MSR) loaded.
.RE

.PP
\-\-epp, \-e
.RS 4
Sets the energy performance policy preference on supported Intel or AMD
processors which use the Intel or AMD P-State cpufreq driver respectively.

Available policies can be found with
\fBcat /sys/devices/system/cpu/cpufreq/policy0/energy_performance_available_preferences\fP :
.RS 4
default performance balance_performance balance_power power
.RE

.RE

.PP
\-\-amd\-pstate\-mode, \-m
.RS 4
Sets the AMD P-State mode for supported AMD processors.
Available modes are "active", "guided" or "passive".

Refer to the AMD P-State kernel documentation for further information.

.RE

.PP
\-\-turbo\-boost, \-\-boost, \-t
.RS 4
This option is used to enable or disable the boost feature on
supported Intel and AMD processors, and other boost supported systems.
(The --boost option is an alias for the --turbo-boost option)

This option takes as parameter either \fB1\fP to enable, or \fB0\fP to disable the feature.

.RE

.SH "SEE ALSO"
cpupower-info(1), cpupower-monitor(1), powertop(1)
.PP
Expand Down
16 changes: 15 additions & 1 deletion tools/power/cpupower/utils/cpufreq-info.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ static int get_boost_mode_x86(unsigned int cpu)
/* ToDo: Make this more global */
unsigned long pstates[MAX_HW_PSTATES] = {0,};

ret = cpufreq_has_boost_support(cpu, &support, &active, &b_states);
ret = cpufreq_has_x86_boost_support(cpu, &support, &active, &b_states);
if (ret) {
printf(_("Error while evaluating Boost Capabilities"
" on CPU %d -- are you root?\n"), cpu);
Expand Down Expand Up @@ -205,6 +205,18 @@ static int get_boost_mode_x86(unsigned int cpu)
return 0;
}

static int get_boost_mode_generic(unsigned int cpu)
{
bool active;

if (!cpufreq_has_generic_boost_support(&active)) {
printf(_(" boost state support:\n"));
printf(_(" Active: %s\n"), active ? _("yes") : _("no"));
}

return 0;
}

/* --boost / -b */

static int get_boost_mode(unsigned int cpu)
Expand All @@ -215,6 +227,8 @@ static int get_boost_mode(unsigned int cpu)
cpupower_cpu_info.vendor == X86_VENDOR_HYGON ||
cpupower_cpu_info.vendor == X86_VENDOR_INTEL)
return get_boost_mode_x86(cpu);
else
get_boost_mode_generic(cpu);

freqs = cpufreq_get_boost_frequencies(cpu);
if (freqs) {
Expand Down
7 changes: 6 additions & 1 deletion tools/power/cpupower/utils/cpupower-set.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ static struct option set_opts[] = {
{"epp", required_argument, NULL, 'e'},
{"amd-pstate-mode", required_argument, NULL, 'm'},
{"turbo-boost", required_argument, NULL, 't'},
{"boost", required_argument, NULL, 't'},
{ },
};

Expand Down Expand Up @@ -123,7 +124,11 @@ int cmd_set(int argc, char **argv)
}

if (params.turbo_boost) {
ret = cpupower_set_turbo_boost(turbo_boost);
if (cpupower_cpu_info.vendor == X86_VENDOR_INTEL)
ret = cpupower_set_intel_turbo_boost(turbo_boost);
else
ret = cpupower_set_generic_turbo_boost(turbo_boost);

if (ret)
fprintf(stderr, "Error setting turbo-boost\n");
}
Expand Down
17 changes: 10 additions & 7 deletions tools/power/cpupower/utils/helpers/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ extern struct cpupower_cpu_info cpupower_cpu_info;

/* cpuid and cpuinfo helpers **************************/

int cpufreq_has_generic_boost_support(bool *active);
int cpupower_set_generic_turbo_boost(int turbo_boost);

/* X86 ONLY ****************************************/
#if defined(__i386__) || defined(__x86_64__)

Expand All @@ -118,7 +121,6 @@ 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_amd_pstate_mode(char *mode);
extern int cpupower_set_turbo_boost(int turbo_boost);

/* Read/Write msr ****************************/

Expand All @@ -139,8 +141,9 @@ extern int decode_pstates(unsigned int cpu, int boost_states,

/* AMD HW pstate decoding **************************/

extern int cpufreq_has_boost_support(unsigned int cpu, int *support,
int *active, int * states);
int cpufreq_has_x86_boost_support(unsigned int cpu, int *support,
int *active, int *states);
int cpupower_set_intel_turbo_boost(int turbo_boost);

/* AMD P-State stuff **************************/
bool cpupower_amd_pstate_enabled(void);
Expand Down Expand Up @@ -181,13 +184,13 @@ static inline int cpupower_set_epp(unsigned int cpu, char *epp)
{ return -1; };
static inline int cpupower_set_amd_pstate_mode(char *mode)
{ return -1; };
static inline int cpupower_set_turbo_boost(int turbo_boost)
{ return -1; };

/* Read/Write msr ****************************/

static inline int cpufreq_has_boost_support(unsigned int cpu, int *support,
int *active, int * states)
static inline int cpufreq_has_x86_boost_support(unsigned int cpu, int *support,
int *active, int *states)
{ return -1; }
static inline int cpupower_set_intel_turbo_boost(int turbo_boost)
{ return -1; }

static inline bool cpupower_amd_pstate_enabled(void)
Expand Down
115 changes: 92 additions & 23 deletions tools/power/cpupower/utils/helpers/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@
#include "helpers/helpers.h"
#include "helpers/sysfs.h"
#include "cpufreq.h"
#include "cpupower_intern.h"

#if defined(__i386__) || defined(__x86_64__)

#include "cpupower_intern.h"

#define MSR_AMD_HWCR 0xc0010015

int cpufreq_has_boost_support(unsigned int cpu, int *support, int *active,
int *states)
int cpufreq_has_x86_boost_support(unsigned int cpu, int *support, int *active,
int *states)
{
int ret;
unsigned long long val;
char linebuf[MAX_LINE_LEN];
char path[SYSFS_PATH_MAX];
char *endp;

*support = *active = *states = 0;

Expand All @@ -43,8 +45,42 @@ int cpufreq_has_boost_support(unsigned int cpu, int *support, int *active,
}
} else if (cpupower_cpu_info.caps & CPUPOWER_CAP_AMD_PSTATE) {
amd_pstate_boost_init(cpu, support, active);
} else if (cpupower_cpu_info.caps & CPUPOWER_CAP_INTEL_IDA)
} else if (cpupower_cpu_info.caps & CPUPOWER_CAP_INTEL_IDA) {
*support = *active = 1;

snprintf(path, sizeof(path), PATH_TO_CPU "intel_pstate/no_turbo");

if (!is_valid_path(path))
return 0;

if (cpupower_read_sysfs(path, linebuf, MAX_LINE_LEN) == 0)
return -1;

val = strtol(linebuf, &endp, 0);
if (endp == linebuf || errno == ERANGE)
return -1;

*active = !val;
}
return 0;
}

int cpupower_set_intel_turbo_boost(int turbo_boost)
{
char path[SYSFS_PATH_MAX];
char linebuf[2] = {};

snprintf(path, sizeof(path), PATH_TO_CPU "intel_pstate/no_turbo");

/* Fallback to generic solution when intel_pstate driver not running */
if (!is_valid_path(path))
return cpupower_set_generic_turbo_boost(turbo_boost);

snprintf(linebuf, sizeof(linebuf), "%d", !turbo_boost);

if (cpupower_write_sysfs(path, linebuf, 2) <= 0)
return -1;

return 0;
}

Expand Down Expand Up @@ -124,24 +160,6 @@ int cpupower_set_amd_pstate_mode(char *mode)
return 0;
}

int cpupower_set_turbo_boost(int turbo_boost)
{
char path[SYSFS_PATH_MAX];
char linebuf[2] = {};

snprintf(path, sizeof(path), PATH_TO_CPU "cpufreq/boost");

if (!is_valid_path(path))
return -1;

snprintf(linebuf, sizeof(linebuf), "%d", turbo_boost);

if (cpupower_write_sysfs(path, linebuf, 2) <= 0)
return -1;

return 0;
}

bool cpupower_amd_pstate_enabled(void)
{
char *driver = cpufreq_get_driver(0);
Expand All @@ -160,6 +178,39 @@ bool cpupower_amd_pstate_enabled(void)

#endif /* #if defined(__i386__) || defined(__x86_64__) */

int cpufreq_has_generic_boost_support(bool *active)
{
char path[SYSFS_PATH_MAX];
char linebuf[2] = {};
unsigned long val;
char *endp;

snprintf(path, sizeof(path), PATH_TO_CPU "cpufreq/boost");

if (!is_valid_path(path))
return -EACCES;

if (cpupower_read_sysfs(path, linebuf, 2) <= 0)
return -EINVAL;

val = strtoul(linebuf, &endp, 0);
if (endp == linebuf || errno == ERANGE)
return -EINVAL;

switch (val) {
case 0:
*active = false;
break;
case 1:
*active = true;
break;
default:
return -EINVAL;
}

return 0;
}

/* get_cpustate
*
* Gather the information of all online CPUs into bitmask struct
Expand Down Expand Up @@ -259,3 +310,21 @@ void print_speed(unsigned long speed, int no_rounding)
}
}
}

int cpupower_set_generic_turbo_boost(int turbo_boost)
{
char path[SYSFS_PATH_MAX];
char linebuf[2] = {};

snprintf(path, sizeof(path), PATH_TO_CPU "cpufreq/boost");

if (!is_valid_path(path))
return -1;

snprintf(linebuf, sizeof(linebuf), "%d", turbo_boost);

if (cpupower_write_sysfs(path, linebuf, 2) <= 0)
return -1;

return 0;
}