Skip to content

Commit a076cc7

Browse files
committed
Merge branch 'pm-tools'
Merge cpupower utility updates, including a fix and improvements of the existing functionality, for 7.0-rc4. * pm-tools: cpupower: Add intel_pstate turbo boost support for Intel platforms cpupower: Add support for setting EPP via systemd service cpupower: fix swapped power/energy unit labels
2 parents d557640 + 06c2a67 commit a076cc7

6 files changed

Lines changed: 61 additions & 6 deletions

File tree

tools/power/cpupower/cpupower-service.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,8 @@
3030
# its policy for the relative importance of performance versus energy savings to
3131
# the processor. See man CPUPOWER-SET(1) for additional details
3232
#PERF_BIAS=
33+
34+
# Set the Energy Performance Preference
35+
# Available options can be read from
36+
# /sys/devices/system/cpu/cpufreq/policy0/energy_performance_available_preferences
37+
#EPP=

tools/power/cpupower/cpupower.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,10 @@ then
2323
cpupower set -b "$PERF_BIAS" > /dev/null || ESTATUS=1
2424
fi
2525

26+
# apply Energy Performance Preference
27+
if test -n "$EPP"
28+
then
29+
cpupower set -e "$EPP" > /dev/null || ESTATUS=1
30+
fi
31+
2632
exit $ESTATUS

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ int cmd_set(int argc, char **argv)
124124
}
125125

126126
if (params.turbo_boost) {
127-
ret = cpupower_set_turbo_boost(turbo_boost);
127+
if (cpupower_cpu_info.vendor == X86_VENDOR_INTEL)
128+
ret = cpupower_set_intel_turbo_boost(turbo_boost);
129+
else
130+
ret = cpupower_set_generic_turbo_boost(turbo_boost);
131+
128132
if (ret)
129133
fprintf(stderr, "Error setting turbo-boost\n");
130134
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ extern struct cpupower_cpu_info cpupower_cpu_info;
104104
/* cpuid and cpuinfo helpers **************************/
105105

106106
int cpufreq_has_generic_boost_support(bool *active);
107-
int cpupower_set_turbo_boost(int turbo_boost);
107+
int cpupower_set_generic_turbo_boost(int turbo_boost);
108108

109109
/* X86 ONLY ****************************************/
110110
#if defined(__i386__) || defined(__x86_64__)
@@ -143,6 +143,7 @@ extern int decode_pstates(unsigned int cpu, int boost_states,
143143

144144
int cpufreq_has_x86_boost_support(unsigned int cpu, int *support,
145145
int *active, int *states);
146+
int cpupower_set_intel_turbo_boost(int turbo_boost);
146147

147148
/* AMD P-State stuff **************************/
148149
bool cpupower_amd_pstate_enabled(void);
@@ -189,6 +190,8 @@ static inline int cpupower_set_amd_pstate_mode(char *mode)
189190
static inline int cpufreq_has_x86_boost_support(unsigned int cpu, int *support,
190191
int *active, int *states)
191192
{ return -1; }
193+
static inline int cpupower_set_intel_turbo_boost(int turbo_boost)
194+
{ return -1; }
192195

193196
static inline bool cpupower_amd_pstate_enabled(void)
194197
{ return false; }

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

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ int cpufreq_has_x86_boost_support(unsigned int cpu, int *support, int *active,
1919
{
2020
int ret;
2121
unsigned long long val;
22+
char linebuf[MAX_LINE_LEN];
23+
char path[SYSFS_PATH_MAX];
24+
char *endp;
2225

2326
*support = *active = *states = 0;
2427

@@ -42,8 +45,42 @@ int cpufreq_has_x86_boost_support(unsigned int cpu, int *support, int *active,
4245
}
4346
} else if (cpupower_cpu_info.caps & CPUPOWER_CAP_AMD_PSTATE) {
4447
amd_pstate_boost_init(cpu, support, active);
45-
} else if (cpupower_cpu_info.caps & CPUPOWER_CAP_INTEL_IDA)
48+
} else if (cpupower_cpu_info.caps & CPUPOWER_CAP_INTEL_IDA) {
4649
*support = *active = 1;
50+
51+
snprintf(path, sizeof(path), PATH_TO_CPU "intel_pstate/no_turbo");
52+
53+
if (!is_valid_path(path))
54+
return 0;
55+
56+
if (cpupower_read_sysfs(path, linebuf, MAX_LINE_LEN) == 0)
57+
return -1;
58+
59+
val = strtol(linebuf, &endp, 0);
60+
if (endp == linebuf || errno == ERANGE)
61+
return -1;
62+
63+
*active = !val;
64+
}
65+
return 0;
66+
}
67+
68+
int cpupower_set_intel_turbo_boost(int turbo_boost)
69+
{
70+
char path[SYSFS_PATH_MAX];
71+
char linebuf[2] = {};
72+
73+
snprintf(path, sizeof(path), PATH_TO_CPU "intel_pstate/no_turbo");
74+
75+
/* Fallback to generic solution when intel_pstate driver not running */
76+
if (!is_valid_path(path))
77+
return cpupower_set_generic_turbo_boost(turbo_boost);
78+
79+
snprintf(linebuf, sizeof(linebuf), "%d", !turbo_boost);
80+
81+
if (cpupower_write_sysfs(path, linebuf, 2) <= 0)
82+
return -1;
83+
4784
return 0;
4885
}
4986

@@ -274,7 +311,7 @@ void print_speed(unsigned long speed, int no_rounding)
274311
}
275312
}
276313

277-
int cpupower_set_turbo_boost(int turbo_boost)
314+
int cpupower_set_generic_turbo_boost(int turbo_boost)
278315
{
279316
char path[SYSFS_PATH_MAX];
280317
char linebuf[2] = {};

tools/power/cpupower/utils/powercap-info.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ static int powercap_print_one_zone(struct powercap_zone *zone)
3838
printf(" (%s)\n", mode ? "enabled" : "disabled");
3939

4040
if (zone->has_power_uw)
41-
printf(_("%sPower can be monitored in micro Jules\n"),
41+
printf(_("%sPower can be monitored in micro Watts\n"),
4242
pr_prefix);
4343

4444
if (zone->has_energy_uj)
45-
printf(_("%sPower can be monitored in micro Watts\n"),
45+
printf(_("%sPower can be monitored in micro Jules\n"),
4646
pr_prefix);
4747

4848
printf("\n");

0 commit comments

Comments
 (0)