Skip to contentSkip to conversation

power utilities update

GIT PULL New Len Brown 1 participant 6 messages May 12, 2017

Subsystems (3)
lore
Share & tools
lore

Len Brown

author maintainer
#0 lore raw

Hi Rafael,

Please pull these power utilities patches.

The x86_energy_perf_policy(8) utility grows the ability to manage HWP.EPP (and Hardware P-states, in-general), on top of its previous ability to manage EPB.

Linux-4.11 grew the ability to disable the cpufreq sub-system entirely with "cpufreq.off=1". On such a system, this utility
is a convenient way to enable HWP with no kernel cpufreq overhead:

sudo x86_energy_perf_policy --cpu all normal

During this effort, we noticed the EPP defaults hard-coded into the intel_state driver were not optimal, so those are updated too.

thanks!
Len Brown, Intel Open Source Technology Center

The following changes since commit c470abd4fde40ea6a0846a2beab642a578c0b8cd:

Linux 4.10 (2017-02-19 14:34:00 -0800)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux.git utilities

for you to fetch changes up to 3cedbc5a6d7f7c5539e139f89ec9f6e1ed668418:

intel_pstate: use updated msr-index.h HWP.EPP values (2017-05-11 21:27:53 -0400)

----------------------------------------------------------------
Len Brown (5):
x86: msr-index.h: define EPB mid-points
x86: msr-index.h: define HWP.EPP values
x86: msr-index.h: fix shifts to ULL results in HWP macros. tools/power x86_energy_perf_policy: support HWP.EPP
intel_pstate: use updated msr-index.h HWP.EPP values

 arch/x86/include/asm/msr-index.h                   |   18 +-
 drivers/cpufreq/intel_pstate.c                     |   34 +-
 tools/power/x86/x86_energy_perf_policy/Makefile    |   27 +-
 .../x86_energy_perf_policy.8                       |  241 +++-
 .../x86_energy_perf_policy.c                       | 1504 +++++++++++++++++---
 5 files changed, 1527 insertions(+), 297 deletions(-)
author maintainer
#1 lore raw

PATCH 1/5 x86: msr-index.h: define EPB mid-points

From: Len Brown <[email protected]>

These are currently open-coded into intel_pstate.c

---
 arch/x86/include/asm/msr-index.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
arch/x86/include/asm/msr-index.h +5 -3
index 710273c617b8..a92d9bd154f6 100644
@@ -462,9 +462,11 @@
 #define MSR_MISC_PWR_MGMT		0x000001aa
 
 #define MSR_IA32_ENERGY_PERF_BIAS	0x000001b0
-#define ENERGY_PERF_BIAS_PERFORMANCE	0
-#define ENERGY_PERF_BIAS_NORMAL		6
-#define ENERGY_PERF_BIAS_POWERSAVE	15
+#define ENERGY_PERF_BIAS_PERFORMANCE		0
+#define ENERGY_PERF_BIAS_BALANCE_PERFORMANCE	4
+#define ENERGY_PERF_BIAS_NORMAL			6
+#define ENERGY_PERF_BIAS_BALANCE_POWERSAVE	8
+#define ENERGY_PERF_BIAS_POWERSAVE		15
 
 #define MSR_IA32_PACKAGE_THERM_STATUS		0x000001b1
 
Signature · 1 line
2.11.0.161.g6610af872
author maintainer
#2 lore raw

PATCH 2/5 x86: msr-index.h: define HWP.EPP values

In reply to Len Brown

From: Len Brown <[email protected]>

The Hardware Performance State request MSR has a field to express the "Energy Performance Preference" (HWP.EPP).

Decode that field so the definition may be shared by by the intel_pstate driver and any utilities that decode the same register.

---
 arch/x86/include/asm/msr-index.h | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/include/asm/msr-index.h +4 -0
index a92d9bd154f6..50c0c3204a92 100644
@@ -239,6 +239,10 @@
 #define HWP_MAX_PERF(x) 		((x & 0xff) << 8)
 #define HWP_DESIRED_PERF(x)		((x & 0xff) << 16)
 #define HWP_ENERGY_PERF_PREFERENCE(x)	((x & 0xff) << 24)
+#define HWP_EPP_PERFORMANCE		0x00
+#define HWP_EPP_BALANCE_PERFORMANCE	0x80
+#define HWP_EPP_BALANCE_POWERSAVE	0xC0
+#define HWP_EPP_POWERSAVE		0xFF
 #define HWP_ACTIVITY_WINDOW(x)		((x & 0xff3) << 32)
 #define HWP_PACKAGE_CONTROL(x)		((x & 0x1) << 42)
 
Signature · 1 line
2.11.0.161.g6610af872
author maintainer
#3 lore raw

PATCH 3/5 x86: msr-index.h: fix shifts to ULL results in HWP macros.

In reply to Len Brown

From: Len Brown <[email protected]>

x = 1
ulong_long = x << 32;

results in:

warning: left shift count >= width of type

x = 8
ulong_long = x << 24;

results in a sign extended ulong_long

Cast x to unsigned long long in these macros
to prevent these errors.

---
 arch/x86/include/asm/msr-index.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/include/asm/msr-index.h +3 -3
index 50c0c3204a92..6da2b30781ff 100644
@@ -238,13 +238,13 @@
 #define HWP_MIN_PERF(x) 		(x & 0xff)
 #define HWP_MAX_PERF(x) 		((x & 0xff) << 8)
 #define HWP_DESIRED_PERF(x)		((x & 0xff) << 16)
-#define HWP_ENERGY_PERF_PREFERENCE(x)	((x & 0xff) << 24)
+#define HWP_ENERGY_PERF_PREFERENCE(x)	(((unsigned long long) x & 0xff) << 24)
 #define HWP_EPP_PERFORMANCE		0x00
 #define HWP_EPP_BALANCE_PERFORMANCE	0x80
 #define HWP_EPP_BALANCE_POWERSAVE	0xC0
 #define HWP_EPP_POWERSAVE		0xFF
-#define HWP_ACTIVITY_WINDOW(x)		((x & 0xff3) << 32)
-#define HWP_PACKAGE_CONTROL(x)		((x & 0x1) << 42)
+#define HWP_ACTIVITY_WINDOW(x)		((unsigned long long)(x & 0xff3) << 32)
+#define HWP_PACKAGE_CONTROL(x)		((unsigned long long)(x & 0x1) << 42)
 
 /* IA32_HWP_STATUS */
 #define HWP_GUARANTEED_CHANGE(x)	(x & 0x1)
Signature · 1 line
2.11.0.161.g6610af872
author maintainer
#4 lore raw

PATCH 4/5 tools/power x86_energy_perf_policy: support HWP.EPP

In reply to Len Brown

From: Len Brown <[email protected]>

x86_energy_perf_policy(8) was created as an example of how the user, or upper-level OS, can manage MSR_IA32_ENERGY_PERF_BIAS (EPB).

Hardware consults EPB when it makes internal decisions balancing energy-saving vs performance.
For example, should HW quickly or slowly transition into and out of power-saving idles states? Should HW quickly or slowly ramp frequency up or down in response to demand in the turbo-frequency range?

Depending on the processor, EPB may have package, core, or CPU thread scope. As such, the only general policy is to write the same value to EPB on every CPU in the system.

Recent platforms add support for Hardware Performance States (HWP). HWP effectively extends hardware frequency control from the opportunistic turbo-frequency range to control the entire range of available processor frequencies.

Just as turbo-mode used EPB, HWP can use EPB to help decicde how quickly to ramp frequency and voltage up and down in response to changing demand. Indeed, BDX and BDX-DE, the first processors to support HWP, use EPB for this purpose.

Starting in SKL, HWP no longer looks to EPB for influence. Instead, it looks in a new MSR specifically for this purpose:
IA32_HWP_REQUEST.Energy_Performance_Preference (HWP.EPP). HWP.EPP is like EPB, except that it is specific to HWP-mode frequency selection. Also, HWP.EPP is defined to have per CPU-thread scope.

Starting in SKX, IA32_HWP_REQUEST is augmented by IA32_HWP_REQUEST_PKG -- which has the same function, but is defined to have package-wide scope. A new bit in IA32_HWP_REQUEST determines if it over-rides the IA32_HWP_REQUEST_PKG or not.

Note that HWP-mode can be enabled in several ways.
The "in-band" method is for HWP to be exposed in CPUID,
and for the Linux intel_pstate driver to recognized that, and thus enable HWP. In this case, starting in Linux 4.10, intel_pstate exports cpufreq sysfs attribute "energy_performance_preference" which can be used to manage HWP.EPP. This interface can be used to set HWP.EPP to these values:

0 performance
128 balance_performance (default)
192 balance_power
255 power

Here, x86_energy_performance_policy is updated to use idential strings and values as intel_pstate.

But HWP-mode may also be enabled by firmware before the OS boots, and the OS may not be aware of HWP. In this case, intel_pstate is not available to provide sysfs attributes, and x86_energy_perf_policy or a similar utility is invaluable for managing HWP.EPP, for this utility works the same, no matter if cpufreq is enabled or not.

---
 tools/power/x86/x86_energy_perf_policy/Makefile    |   37 +-
 .../x86_energy_perf_policy.8                       |  317 ++--
 .../x86_energy_perf_policy.c                       | 1750 ++++++++++++++++----
 3 files changed, 1666 insertions(+), 438 deletions(-)

rewrite tools/power/x86/x86_energy_perf_policy/Makefile (72%) rewrite tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.8 (80%) rewrite tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c (78%)

tools/power/x86/x86_energy_perf_policy/Makefile +27 -10
dissimilarity index 72%
index 971c9ffdcb50..a711eec0c895 100644
@@ -1,10 +1,27 @@
-DESTDIR ?=
-
-x86_energy_perf_policy : x86_energy_perf_policy.c
-
-clean :
-	rm -f x86_energy_perf_policy
-
-install :
-	install x86_energy_perf_policy ${DESTDIR}/usr/bin/
-	install x86_energy_perf_policy.8 ${DESTDIR}/usr/share/man/man8/
+CC		= $(CROSS_COMPILE)gcc
+BUILD_OUTPUT    := $(CURDIR)
+PREFIX		:= /usr
+DESTDIR		:=
+
+ifeq ("$(origin O)", "command line")
+	BUILD_OUTPUT := $(O)
+endif
+
+x86_energy_perf_policy : x86_energy_perf_policy.c
+CFLAGS +=	-Wall
+CFLAGS +=	-DMSRHEADER='"../../../../arch/x86/include/asm/msr-index.h"'
+
+%: %.c
+	@mkdir -p $(BUILD_OUTPUT)
+	$(CC) $(CFLAGS) $< -o $(BUILD_OUTPUT)/$@
+
+.PHONY : clean
+clean :
+	@rm -f $(BUILD_OUTPUT)/x86_energy_perf_policy
+
+install : x86_energy_perf_policy
+	install -d  $(DESTDIR)$(PREFIX)/bin
+	install $(BUILD_OUTPUT)/x86_energy_perf_policy $(DESTDIR)$(PREFIX)/bin/x86_energy_perf_policy
+	install -d  $(DESTDIR)$(PREFIX)/share/man/man8
+	install x86_energy_perf_policy.8 $(DESTDIR)$(PREFIX)/share/man/man8
+
tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.8 +213 -104

317 lines not on this page · raw message

tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c +1426 -324

1,750 lines not on this page · raw message

Signature · 1 line
2.11.0.161.g6610af872
author maintainer
#5 lore raw

PATCH 5/5 intel_pstate: use updated msr-index.h HWP.EPP values

In reply to Len Brown

From: Len Brown <[email protected]>

intel_pstate exports sysfs attributes for setting and observing HWP.EPP. These attributes use strings to describe 4 operating states, and inside the driver, these strings are mapped to numerical register values.

The authorative mapping between the strings and numerical HWP.EPP values are now globally defined in msr-index.h, replacing the out-dated mapping that were open-coded into intel_pstate.c

new old string
--- --- ------
0 0 performance
128 64 balance_performance
192 128 balance_power
255 192 power

Note that the HW and BIOS default value on most system is 128, which intel_pstate will now call "balance_performance" while it used to call it "balance_power".

---
 drivers/cpufreq/intel_pstate.c | 34 +++++++++++++++-------------------
 1 file changed, 15 insertions(+), 19 deletions(-)
drivers/cpufreq/intel_pstate.c +15 -19
index 50bd6d987fc3..ab8ebaeb3621 100644
@@ -716,6 +716,12 @@ static const char * const energy_perf_strings[] = {
 	"power",
 	NULL
 };
+static const unsigned int epp_values[] = {
+	HWP_EPP_PERFORMANCE,
+	HWP_EPP_BALANCE_PERFORMANCE,
+	HWP_EPP_BALANCE_POWERSAVE,
+	HWP_EPP_POWERSAVE
+};
 
 static int intel_pstate_get_energy_pref_index(struct cpudata *cpu_data)
 {
@@ -727,17 +733,14 @@ static int intel_pstate_get_energy_pref_index(struct cpudata *cpu_data)
 		return epp;
 
 	if (static_cpu_has(X86_FEATURE_HWP_EPP)) {
-		/*
-		 * Range:
-		 *	0x00-0x3F	:	Performance
-		 *	0x40-0x7F	:	Balance performance
-		 *	0x80-0xBF	:	Balance power
-		 *	0xC0-0xFF	:	Power
-		 * The EPP is a 8 bit value, but our ranges restrict the
-		 * value which can be set. Here only using top two bits
-		 * effectively.
-		 */
-		index = (epp >> 6) + 1;
+		if (epp == HWP_EPP_PERFORMANCE)
+			return 1;
+		if (epp <= HWP_EPP_BALANCE_PERFORMANCE)
+			return 2;
+		if (epp <= HWP_EPP_BALANCE_POWERSAVE)
+			return 3;
+		else
+			return 4;
 	} else if (static_cpu_has(X86_FEATURE_EPB)) {
 		/*
 		 * Range:
@@ -775,15 +778,8 @@ static int intel_pstate_set_energy_pref_index(struct cpudata *cpu_data,
 
 		value &= ~GENMASK_ULL(31, 24);
 
-		/*
-		 * If epp is not default, convert from index into
-		 * energy_perf_strings to epp value, by shifting 6
-		 * bits left to use only top two bits in epp.
-		 * The resultant epp need to shifted by 24 bits to
-		 * epp position in MSR_HWP_REQUEST.
-		 */
 		if (epp == -EINVAL)
-			epp = (pref_index - 1) << 6;
+			epp = epp_values[pref_index - 1];
 
 		value |= (u64)epp << 24;
 		ret = wrmsrl_on_cpu(cpu_data->cpu, MSR_HWP_REQUEST, value);
Signature · 1 line
2.11.0.161.g6610af872