Skip to content

Commit 40d2cf9

Browse files
committed
Merge branch 'pm-tools'
Merge power management utilities updates for 6.18-rc1: - Fix and clean up the x86_energy_perf_policy utility and update its documentation (Len Brown, Kaushlendra Kumar) - Fix incorrect sorting of PMT telemetry in turbostat (Kaushlendra Kumar) - Fix incorrect size in cpuidle_state_disable() and the error return value of cpupower_write_sysfs() in cpupower (Kaushlendra Kumar) * pm-tools: tools/power x86_energy_perf_policy.8: Emphasize preference for SW interfaces tools/power x86_energy_perf_policy: Add make snapshot target tools/power x86_energy_perf_policy: Prefer driver HWP limits tools/power x86_energy_perf_policy: EPB access is only via sysfs tools/power x86_energy_perf_policy: Prepare for MSR/sysfs refactoring tools/power x86_energy_perf_policy: Enhance HWP enable tools/power x86_energy_perf_policy: Enhance HWP enabled check tools/power x86_energy_perf_policy: Fix incorrect fopen mode usage tools/power turbostat: Fix incorrect sorting of PMT telemetry tools/cpupower: Fix incorrect size in cpuidle_state_disable() tools/cpupower: fix error return value in cpupower_write_sysfs()
2 parents f58f86d + 17eb881 commit 40d2cf9

6 files changed

Lines changed: 133 additions & 53 deletions

File tree

tools/power/cpupower/lib/cpuidle.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ int cpuidle_state_disable(unsigned int cpu,
233233
{
234234
char value[SYSFS_PATH_MAX];
235235
int bytes_written;
236+
int len;
236237

237238
if (cpuidle_state_count(cpu) <= idlestate)
238239
return -1;
@@ -241,10 +242,10 @@ int cpuidle_state_disable(unsigned int cpu,
241242
idlestate_value_files[IDLESTATE_DISABLE]))
242243
return -2;
243244

244-
snprintf(value, SYSFS_PATH_MAX, "%u", disable);
245+
len = snprintf(value, SYSFS_PATH_MAX, "%u", disable);
245246

246247
bytes_written = cpuidle_state_write_file(cpu, idlestate, "disable",
247-
value, sizeof(disable));
248+
value, len);
248249
if (bytes_written)
249250
return 0;
250251
return -3;

tools/power/cpupower/lib/cpupower.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ unsigned int cpupower_write_sysfs(const char *path, char *buf, size_t buflen)
5656
if (numwritten < 1) {
5757
perror(path);
5858
close(fd);
59-
return -1;
59+
return 0;
6060
}
6161

6262
close(fd);

tools/power/x86/turbostat/turbostat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1890,7 +1890,7 @@ int pmt_telemdir_sort(const struct dirent **a, const struct dirent **b)
18901890
sscanf((*a)->d_name, "telem%u", &aidx);
18911891
sscanf((*b)->d_name, "telem%u", &bidx);
18921892

1893-
return aidx >= bidx;
1893+
return (aidx > bidx) ? 1 : (aidx < bidx) ? -1 : 0;
18941894
}
18951895

18961896
const struct dirent *pmt_diriter_next(struct pmt_diriter_t *iter)

tools/power/x86/x86_energy_perf_policy/Makefile

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# SPDX-License-Identifier: GPL-2.0
22
CC = $(CROSS_COMPILE)gcc
3-
BUILD_OUTPUT := $(CURDIR)
3+
BUILD_OUTPUT := $(CURDIR)
44
PREFIX := /usr
55
DESTDIR :=
6+
DAY := $(shell date +%Y.%m.%d)
7+
SNAPSHOT = x86_energy_perf_policy-$(DAY)
8+
9+
610

711
ifeq ("$(origin O)", "command line")
812
BUILD_OUTPUT := $(O)
@@ -27,3 +31,26 @@ install : x86_energy_perf_policy
2731
install -d $(DESTDIR)$(PREFIX)/share/man/man8
2832
install -m 644 x86_energy_perf_policy.8 $(DESTDIR)$(PREFIX)/share/man/man8
2933

34+
snapshot: x86_energy_perf_policy
35+
@rm -rf $(SNAPSHOT)
36+
@mkdir $(SNAPSHOT)
37+
@cp x86_energy_perf_policy Makefile x86_energy_perf_policy.c x86_energy_perf_policy.8 $(SNAPSHOT)
38+
39+
@sed -e 's/^#include <linux\/bits.h>/#include "bits.h"/' -e 's/u64/unsigned long long/' ../../../../arch/x86/include/asm/msr-index.h > $(SNAPSHOT)/msr-index.h
40+
@echo '#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))' >> $(SNAPSHOT)/msr-index.h
41+
@echo "#define BIT(x) (1 << (x))" > $(SNAPSHOT)/bits.h
42+
@echo "#define BIT_ULL(nr) (1ULL << (nr))" >> $(SNAPSHOT)/bits.h
43+
@echo "#define GENMASK(h, l) (((~0UL) << (l)) & (~0UL >> (sizeof(long) * 8 - 1 - (h))))" >> $(SNAPSHOT)/bits.h
44+
@echo "#define GENMASK_ULL(h, l) (((~0ULL) << (l)) & (~0ULL >> (sizeof(long long) * 8 - 1 - (h))))" >> $(SNAPSHOT)/bits.h
45+
46+
@echo '#define BUILD_BUG_ON(cond) do { enum { compile_time_check ## __COUNTER__ = 1/(!(cond)) }; } while (0)' > $(SNAPSHOT)/build_bug.h
47+
@echo '#define __must_be_array(arr) 0' >> $(SNAPSHOT)/build_bug.h
48+
49+
@echo PWD=. > $(SNAPSHOT)/Makefile
50+
@echo "CFLAGS += -DMSRHEADER='\"msr-index.h\"'" >> $(SNAPSHOT)/Makefile
51+
@echo "CFLAGS += -DBUILD_BUG_HEADER='\"build_bug.h\"'" >> $(SNAPSHOT)/Makefile
52+
@sed -e's/.*MSRHEADER.*//' Makefile >> $(SNAPSHOT)/Makefile
53+
54+
@rm -f $(SNAPSHOT).tar.gz
55+
tar cvzf $(SNAPSHOT).tar.gz $(SNAPSHOT)
56+

tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.8

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.\" Distributed under the GPL, Copyleft 1994.
33
.TH X86_ENERGY_PERF_POLICY 8
44
.SH NAME
5-
x86_energy_perf_policy \- Manage Energy vs. Performance Policy via x86 Model Specific Registers
5+
x86_energy_perf_policy \- Manage Energy vs. Performance Policy
66
.SH SYNOPSIS
77
.B x86_energy_perf_policy
88
.RB "[ options ] [ scope ] [field \ value]"
@@ -19,9 +19,14 @@ x86_energy_perf_policy \- Manage Energy vs. Performance Policy via x86 Model Spe
1919
.SH DESCRIPTION
2020
\fBx86_energy_perf_policy\fP
2121
displays and updates energy-performance policy settings specific to
22-
Intel Architecture Processors. Settings are accessed via Model Specific Register (MSR)
23-
updates, no matter if the Linux cpufreq sub-system is enabled or not.
22+
Intel Architecture Processors. It summarizes settings available
23+
in standard Linux interfaces (eg. cpufreq),
24+
and also decodes underlying Model Specific Register (MSRs).
25+
While \fBx86_energy_perf_policy\fP can manage energy-performance policy
26+
using only MSR access, it prefers standard
27+
Linux kernel interfaces, when they are available.
2428

29+
.SH BACKGROUND
2530
Policy in MSR_IA32_ENERGY_PERF_BIAS (EPB)
2631
may affect a wide range of hardware decisions,
2732
such as how aggressively the hardware enters and exits CPU idle states (C-states)
@@ -200,7 +205,9 @@ runs only as root.
200205
.SH FILES
201206
.ta
202207
.nf
203-
/dev/cpu/*/msr
208+
EPB: /sys/devices/system/cpu/cpu*/power/energy_perf_bias
209+
EPP: /sys/devices/system/cpu/cpu*/cpufreq/energy_performance_preference
210+
MSR: /dev/cpu/*/msr
204211
.fi
205212
.SH "SEE ALSO"
206213
.nf

0 commit comments

Comments
 (0)