x86, mwaitt: introduce AMD mwaitt support
Subsystems (2)
v6 cover x86, mwaitt: introduce AMD mwaitt support
Hi,
This patch set introduces a new instruction support on AMD Carrizo (Family 15h, Model 60h-6fh). It adds mwaitx delay function with a configurable timer.
Andy and Boris provide a suggestion which uses mwaitx on delay method.
As Peter's suggestion of last version (v5), the serial of patch set provides a test result.
http://marc.info/?l=linux-kernel&m=143436586513713&w=2
Some discussions of the background, please see:
http://marc.info/?l=linux-kernel&m=143202042530498&w=2
http://marc.info/?l=linux-kernel&m=143161327003541&w=2
http://marc.info/?l=linux-kernel&m=143222815331016&w=2
Patch set is rebased on tip/master.
Changes from v1 -> v2
- Remove mwaitx idle implementation since some disputes without power improvement.
- Add a patch which implement another use case on delay.
- Introduce a kernel parameter (delay) to make delay method configurable.
Changes from v2 -> v3
- Add compared data on commit message
- Remove kernel parameter
- Add hint to avoid to access deep state in future
- Update mwaitx delay method as Petter's suggestion
Changes from v3 -> v4
- Put the MONITORX/MWAITX description into comments
Changes from v4 -> v5
- Remove mwaitx function
- Use mwaitx_delay at init_amd
- Use cpu_tts as montioring address scope
Changes from v5 -> v6
- Move definitions into patch 1
- Completed the power consumption testing both with MWAITX and without MWAITX
- Use mwaitx_delay at bsp_init_amd
In MWAITX delay, the CPU core will be quiesced in a waiting phase, diminishing its power consumption.
Run a simple test to measure power consumption:
cat /sys/bus/pci/devices/0000\:00\:18.4/hwmon/hwmon0/power1_acc; sleep 10000s;
cat /sys/bus/pci/devices/0000\:00\:18.4/hwmon/hwmon0/power1_acc;
* TSC-based default delay: 485115 uWatts average power
* MWAITX-based delay: 252738 uWatts average power
Thus, that's about 240 milliWatts less power consumption. The test method relies on the support of AMD CPU accumulated power algorithm in fam15_power for which patches are forthcoming.
Thanks,
Rui
Huang Rui (2):
x86, mwaitt: add monitorx and mwaitx instruction x86, mwaitt: introduce mwaitx delay with a configurable timer
arch/x86/include/asm/cpufeature.h | 1 + arch/x86/include/asm/delay.h | 1 + arch/x86/include/asm/mwait.h | 43 +++++++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/amd.c | 4 ++++ arch/x86/lib/delay.c | 48 ++++++++++++++++++++++++++++++++++++++- 5 files changed, 96 insertions(+), 1 deletion(-)
Signature · 1 line
1.9.1
PATCH v6 1/2 x86, mwaitt: add monitorx and mwaitx instruction
On AMD Carrizo processors (Family 15h, Model 60h-6fh), there is a new feature called MWAITT (MWAIT with a timer) as an extension of MONITOR/MWAIT.
MWAITT, another name is MWAITX (MWAIT with extensions), has a configurable timer that causes MWAITX to exit on expiration.
Compared with MONITOR/MWAIT, there are minor differences in opcode and input parameters.
MWAITX ECX[1]: enable timer if set
MWAITX EBX[31:0]: max wait time expressed in SW P0 clocks
MWAIT MWAITX
opcode 0f 01 c9 | 0f 01 fb
ECX[0] value of RFLAGS.IF seen by instruction
ECX[1] unused/#GP if set | enable timer if set
ECX[31:2] unused/#GP if set
EAX unused (reserve for hint)
EBX[31:0] unused | max wait time (loops)
MONITOR MONITORX
opcode 0f 01 c8 | 0f 01 fa
EAX (logical) address to monitor
ECX #GP if not zero
The software P0 frequency is the same as the TSC frequency.
Max timeout = EBX/(TSC frequency)
--- arch/x86/include/asm/cpufeature.h | 1 + arch/x86/include/asm/mwait.h | 43 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+)
arch/x86/include/asm/cpufeature.h +1 -0
@@ -177,6 +177,7 @@#define X86_FEATURE_PERFCTR_NB ( 6*32+24)/* NB performance counter extensions */ #define X86_FEATURE_BPEXT (6*32+26)/* data breakpoint extension */ #define X86_FEATURE_PERFCTR_L2 ( 6*32+28)/* L2 performance counter extensions */ +#define X86_FEATURE_MWAITT ( 6*32+29)/* MWAIT extension (MONITORX/MWAITX) */ /* * Auxiliary flags: Linux defined - For features scattered in various
arch/x86/include/asm/mwait.h +43 -0
61 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v6 2/2 x86, mwaitt: introduce mwaitx delay with a configurable timer
In reply to Huang RuiMWAITX can enable a timer and a corresponding timer value specified in SW P0 clocks. The SW P0 frequency is the same as TSC. The timer provides an upper bound on how long the instruction waits before exiting.
The implementation of delay function in kernel can leverage the timer of MWAITX. This patch provides a new method (delay_mwaitx) to measure delay time.
In MWAITX delay, the CPU core will be quiesced in a waiting phase, diminishing its power consumption.
Run a simple test to measure power consumption:
cat /sys/bus/pci/devices/0000\:00\:18.4/hwmon/hwmon0/power1_acc; sleep 10000s;
cat /sys/bus/pci/devices/0000\:00\:18.4/hwmon/hwmon0/power1_acc;
* TSC-based default delay: 485115 uWatts average power
* MWAITX-based delay: 252738 uWatts average power
Thus, that's about 240 milliWatts less power consumption. The test method relies on the support of AMD CPU accumulated power algorithm in fam15_power for which patches are forthcoming.
--- arch/x86/include/asm/delay.h | 1 + arch/x86/kernel/cpu/amd.c | 4 ++++ arch/x86/lib/delay.c | 48 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 52 insertions(+), 1 deletion(-)
arch/x86/include/asm/delay.h +1 -0
@@ -4,5 +4,6 @@#include <asm-generic/delay.h> void use_tsc_delay (void ); +void use_mwaitx_delay (void );#endif /* _ASM_X86_DELAY_H */
arch/x86/kernel/cpu/amd.c +4 -0
@@ -11,6 +11,7 @@#include <asm/cpu.h> #include <asm/smp.h> #include <asm/pci-direct.h> +#include <asm/delay.h> #ifdef CONFIG_X86_64 # include <asm/mmconfig.h>
@@ -506,6 +507,9 @@ static void bsp_init_amd(struct cpuinfo_x86 *c)/* A random value per boot for bit slice [12:upper_bit) */ va_align.bits =get_random_int () & va_align.mask; } + +if (cpu_has (c,X86_FEATURE_MWAITT )) +use_mwaitx_delay (); }static void early_init_amd (struct cpuinfo_x86 *c)
arch/x86/lib/delay.c +47 -1
66 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [PATCH v6 2/2] x86, mwaitt: introduce mwaitx delay with a configurable timer
Quoted 8 lines · Huang Rui
MWAITX can enable a timer and a corresponding timer value specified in SW P0 clocks. The SW P0 frequency is the same as TSC. The timer provides an upper bound on how long the instruction waits before exiting.
The implementation of delay function in kernel can leverage the timer of MWAITX. This patch provides a new method (
delay_mwaitx) to measure delay time.
...
Review
Quoted 4 lines
(quoted diff) +4
-0+static void delay_mwaitx(unsigned long __loops) +{ + u32 delay, loops = __loops; + u64 end, start;
Hmm, this truncates __loops in case someone wants to delay for more than (u32)-1 TSC clocks. I guess the right thing to do is to do the calculation with u64s and MWAITX_MAX_LOOPS will keep us within bounds.
Here's what I did:
---
From: Huang Rui <[email protected]>
Date: Wed, 5 Aug 2015 11:18:52 +0800
Subject: [PATCH] x86/asm: Introduce an MWAITX-based delay with a configurable
timer
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
MWAITX can enable a timer and a corresponding timer value specified in SW P0 clocks. The SW P0 frequency is the same as TSC. The timer provides an upper bound on how long the instruction waits before exiting.
This way, a delay function in the kernel can leverage that MWAITX timer of MWAITX.
When a CPU core executes MWAITX, it will be quiesced in a waiting phase, diminishing its power consumption. This way, we can save power in comparison to our default TSC-based delays.
A simple test shows that:
$ cat /sys/bus/pci/devices/0000\:00\:18.4/hwmon/hwmon0/power1_acc $ sleep 10000s $ cat /sys/bus/pci/devices/0000\:00\:18.4/hwmon/hwmon0/power1_acc
Results:
* TSC-based default delay: 485115 uWatts average power
* MWAITX-based delay: 252738 uWatts average power
Thus, that's about 240 milliWatts less power consumption. The test method relies on the support of AMD CPU accumulated power algorithm in fam15h_power for which patches are forthcoming.
--- arch/x86/include/asm/delay.h | 1 + arch/x86/kernel/cpu/amd.c | 4 ++++ arch/x86/lib/delay.c | 47 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 51 insertions(+), 1 deletion(-)
arch/x86/include/asm/delay.h +1 -0
@@ -4,5 +4,6 @@#include <asm-generic/delay.h> void use_tsc_delay (void ); +void use_mwaitx_delay (void );#endif /* _ASM_X86_DELAY_H */
arch/x86/kernel/cpu/amd.c +4 -0
@@ -11,6 +11,7 @@#include <asm/cpu.h> #include <asm/smp.h> #include <asm/pci-direct.h> +#include <asm/delay.h> #ifdef CONFIG_X86_64 # include <asm/mmconfig.h>
@@ -506,6 +507,9 @@ static void bsp_init_amd(struct cpuinfo_x86 *c)/* A random value per boot for bit slice [12:upper_bit) */ va_align.bits =get_random_int () & va_align.mask; } + +if (cpu_has (c,X86_FEATURE_MWAITX )) +use_mwaitx_delay (); }static void early_init_amd (struct cpuinfo_x86 *c)
arch/x86/lib/delay.c +46 -1
65 lines not on this page · raw message
Signature · 8 lines
2.5.0.rc2.28.g6003e7f
--
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
--Re: [PATCH v6 2/2] x86, mwaitt: introduce mwaitx delay with a configurable timer
Quoted 10 lines · Borislav Petkov
arch/x86/lib/delay.c static void delay_tsc(unsigned long __loops)
Quoted 4 lines · Huang Rui
arch/x86/lib/delay.c +4
-0+static void delay_mwaitx (unsigned long __loops) +{ +u32 delay, loops = __loops; +u64 end, start;Hmm, this truncates
__loopsin case someone wants to delay for more than (u32)-1 TSC clocks. I guess the right thing to do is to do the calculation with u64s andMWAITX_MAX_LOOPSwill keep us within bounds.
Yes, you're right. Thanks to update. :)
Thanks,
Rui
Borislav Petkov
maintainerQuoted 10 lines · Huang Rui
cat /sys/bus/pci/devices/0000\:00\:18.4/hwmon/hwmon0/power1_acc; sleep 10000s;
cat /sys/bus/pci/devices/0000\:00\:18.4/hwmon/hwmon0/power1_acc;* TSC-based default delay: 485115 uWatts average power
* MWAITX-based delay: 252738 uWatts average powerThus, that's about 240 milliWatts less power consumption. The test method relies on the support of AMD CPU accumulated power algorithm in
fam15_powerfor which patches are forthcoming.
Cool power consumption drop is actually even measureable.
Also, I think implementing it as a loop, as Peter suggested, was the right thing to do due to this statement in MWAITX's definition in the APM:
"There is no indication after exiting MWAITX of why the processor exited or if the timer expired. It is up to software to check whether the awaiting store has occurred, and if not, determining how much time has elapsed if it wants to re-establish the MONITORX with a new timer value."
So all in all, those patches are starting to shape up nicely. One small nit I have is using "MWAITT" (with a T) together with MWAITX while the APM calls it only MWAITX. But I can fix that when applying and drop all MWAITT occurrences.
Thanks.
Signature · 5 lines
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
--Borislav Petkov
maintainercover tip-queue 2015-08-10
From: Borislav Petkov <[email protected]>
Hi Ingo,
here's a little stuff which got done baking. More specifically, the use of this new MWAITX insn on AMD as a more power-optimal delay function. Patch 3's commit message has details as to how exactly it was measured. The power measurement interface will be part of fam15h_power soon too.
Please queue for 4.3.
Btw, patch 3 uses rdtsc_ordered() which is in tip/x86/asm... Patch 1 goes to tip/x86/microcode, of course.
Thanks.
Andrzej Hajda (1):
x86/microcode: Use kmemdup() rather than duplicating its
implementation
Huang Rui (2):
x86/asm: Add MONITORX/MWAITX insns support
x86/asm: Introduce an MWAITX-based delay with a configurable timer
Borislav Petkov
maintainerPATCH 1/3 x86/microcode: Use kmemdup() rather than duplicating its implementation
From: Andrzej Hajda <[email protected]>
The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci.
--- arch/x86/kernel/cpu/microcode/amd.c | 4 +--- arch/x86/kernel/cpu/microcode/intel_early.c | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-)
arch/x86/kernel/cpu/microcode/amd.c +1 -3
@@ -366,15 +366,13 @@ static int verify_and_add_patch(u8 family, u8 *fw, unsigned int leftover)return -EINVAL ; } - patch->data =kzalloc (patch_size,GFP_KERNEL ); + patch->data =kmemdup (fw +SECTION_HDR_SIZE , patch_size,GFP_KERNEL );if (!patch->data) {pr_err ("Patch data allocation failure.\n" );kfree (patch);return -EINVAL ; } -/* All looks ok, copy patch... */ -memcpy (patch->data, fw +SECTION_HDR_SIZE , patch_size);INIT_LIST_HEAD (&patch->plist); patch->patch_id = mc_hdr->patch_id; patch->equiv_cpu = proc_id;
arch/x86/kernel/cpu/microcode/intel_early.c +1 -3
@@ -207,13 +207,11 @@ save_microcode(struct mc_saved_data *mc_saved_data, mc_hdr = &mc->hdr; size =get_totalsize (mc_hdr); - saved_ptr[i] =kmalloc (size,GFP_KERNEL ); + saved_ptr[i] =kmemdup (mc, size,GFP_KERNEL );if (!saved_ptr[i]) { ret = -ENOMEM ; goto err; } - -memcpy (saved_ptr[i], mc, size); }/*
Signature · 1 line
2.5.0.rc2.28.g6003e7f
tip-bot for Andrzej Hajda
merge bot[tip:x86/microcode] x86/microcode: Use kmemdup() rather than duplicating its implementation
x86/microcode: Use kmemdup() rather than duplicating its implementation
Commit-ID: d4e963644768b33aa3db7f470c35d74ed78d8354 Gitweb: http://git.kernel.org/tip/d4e963644768b33aa3db7f470c35d74ed78d8354 Author: Andrzej Hajda <[email protected]> AuthorDate: Mon, 10 Aug 2015 12:19:52 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 22 Aug 2015 14:49:35 +0200
x86/microcode: Use kmemdup() rather than duplicating its implementation
The patch was generated using fixed coccinelle semantic patch scripts/coccinelle/api/memdup.cocci.
--- arch/x86/kernel/cpu/microcode/amd.c | 4 +--- arch/x86/kernel/cpu/microcode/intel_early.c | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-)
arch/x86/kernel/cpu/microcode/amd.c +1 -3
@@ -366,15 +366,13 @@ static int verify_and_add_patch(u8 family, u8 *fw, unsigned int leftover)return -EINVAL ; } - patch->data =kzalloc (patch_size,GFP_KERNEL ); + patch->data =kmemdup (fw +SECTION_HDR_SIZE , patch_size,GFP_KERNEL );if (!patch->data) {pr_err ("Patch data allocation failure.\n" );kfree (patch);return -EINVAL ; } -/* All looks ok, copy patch... */ -memcpy (patch->data, fw +SECTION_HDR_SIZE , patch_size);INIT_LIST_HEAD (&patch->plist); patch->patch_id = mc_hdr->patch_id; patch->equiv_cpu = proc_id;
arch/x86/kernel/cpu/microcode/intel_early.c +1 -3
@@ -207,13 +207,11 @@ save_microcode(struct mc_saved_data *mc_saved_data, mc_hdr = &mc->hdr; size =get_totalsize (mc_hdr); - saved_ptr[i] =kmalloc (size,GFP_KERNEL ); + saved_ptr[i] =kmemdup (mc, size,GFP_KERNEL );if (!saved_ptr[i]) { ret = -ENOMEM ; goto err; } - -memcpy (saved_ptr[i], mc, size); }/*
Borislav Petkov
maintainerPATCH 2/3 x86/asm: Add MONITORX/MWAITX insns support
In reply to Borislav PetkovFrom: Huang Rui <[email protected]>
AMD Carrizo processors (Family 15h, Models 60h-6fh) add a new feature called MWAITX (MWAIT with extensions) as an extension to MONITOR/MWAIT.
This new instruction controls a configurable timer which causes the core to exit wait state on timer expiration, in addition to "normal" MWAIT condition of reading from a monitored VA.
Compared to MONITOR/MWAIT, there are minor differences in opcode and input parameters:
MWAITX ECX[1]: enable timer if set
MWAITX EBX[31:0]: max wait time expressed in SW P0 clocks == TSC. The software P0 frequency is the same as the TSC frequency.
MWAIT MWAITX
opcode 0f 01 c9 | 0f 01 fb
ECX[0] value of RFLAGS.IF seen by instruction
ECX[1] unused/#GP if set | enable timer if set
ECX[31:2] unused/#GP if set
EAX unused (reserve for hint)
EBX[31:0] unused | max wait time (SW P0 == TSC)
MONITOR MONITORX
opcode 0f 01 c8 | 0f 01 fa
EAX (logical) address to monitor
ECX #GP if not zero
Max timeout = EBX/(TSC frequency)
--- arch/x86/include/asm/cpufeature.h | 1 + arch/x86/include/asm/mwait.h | 45 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+)
arch/x86/include/asm/cpufeature.h +1 -0
@@ -176,6 +176,7 @@#define X86_FEATURE_PERFCTR_NB ( 6*32+24)/* NB performance counter extensions */ #define X86_FEATURE_BPEXT (6*32+26)/* data breakpoint extension */ #define X86_FEATURE_PERFCTR_L2 ( 6*32+28)/* L2 performance counter extensions */ +#define X86_FEATURE_MWAITX ( 6*32+29)/* MWAIT extension (MONITORX/MWAITX) */ /* * Auxiliary flags: Linux defined - For features scattered in various
arch/x86/include/asm/mwait.h +45 -0
63 lines not on this page · raw message
Signature · 1 line
2.5.0.rc2.28.g6003e7f
tip-bot for Huang Rui
merge bot[tip:x86/asm] x86/asm: Add MONITORX/MWAITX instruction support
x86/asm: Add MONITORX/MWAITX instruction support
Commit-ID: f96756746c7909de37db3d03ac5fd5cfb2757f38 Gitweb: http://git.kernel.org/tip/f96756746c7909de37db3d03ac5fd5cfb2757f38 Author: Huang Rui <[email protected]> AuthorDate: Mon, 10 Aug 2015 12:19:53 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 22 Aug 2015 14:52:16 +0200
x86/asm: Add MONITORX/MWAITX instruction support
AMD Carrizo processors (Family 15h, Models 60h-6fh) added a new feature called MWAITX (MWAIT with extensions) as an extension to MONITOR/MWAIT.
This new instruction controls a configurable timer which causes the core to exit wait state on timer expiration, in addition to "normal" MWAIT condition of reading from a monitored VA.
Compared to MONITOR/MWAIT, there are minor differences in opcode and input parameters:
MWAITX ECX[1]: enable timer if set
MWAITX EBX[31:0]: max wait time expressed in SW P0 clocks == TSC. The software P0 frequency is the same as the TSC frequency.
MWAIT MWAITX
opcode 0f 01 c9 | 0f 01 fb
ECX[0] value of RFLAGS.IF seen by instruction
ECX[1] unused/#GP if set | enable timer if set
ECX[31:2] unused/#GP if set
EAX unused (reserve for hint)
EBX[31:0] unused | max wait time (SW P0 == TSC)
MONITOR MONITORX
opcode 0f 01 c8 | 0f 01 fa
EAX (logical) address to monitor
ECX #GP if not zero
Max timeout = EBX/(TSC frequency)
--- arch/x86/include/asm/cpufeature.h | 1 + arch/x86/include/asm/mwait.h | 45 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+)
arch/x86/include/asm/cpufeature.h +1 -0
@@ -176,6 +176,7 @@#define X86_FEATURE_PERFCTR_NB ( 6*32+24)/* NB performance counter extensions */ #define X86_FEATURE_BPEXT (6*32+26)/* data breakpoint extension */ #define X86_FEATURE_PERFCTR_L2 ( 6*32+28)/* L2 performance counter extensions */ +#define X86_FEATURE_MWAITX ( 6*32+29)/* MWAIT extension (MONITORX/MWAITX) */ /* * Auxiliary flags: Linux defined - For features scattered in various
arch/x86/include/asm/mwait.h +45 -0
63 lines not on this page · raw message
Borislav Petkov
maintainerPATCH 3/3 x86/asm: Introduce an MWAITX-based delay with a configurable timer
In reply to Borislav PetkovFrom: Huang Rui <[email protected]>
MWAITX can enable a timer and a corresponding timer value specified in SW P0 clocks. The SW P0 frequency is the same as TSC. The timer provides an upper bound on how long the instruction waits before exiting.
This way, a delay function in the kernel can leverage that MWAITX timer of MWAITX.
When a CPU core executes MWAITX, it will be quiesced in a waiting phase, diminishing its power consumption. This way, we can save power in comparison to our default TSC-based delays.
A simple test shows that:
$ cat /sys/bus/pci/devices/0000\:00\:18.4/hwmon/hwmon0/power1_acc $ sleep 10000s $ cat /sys/bus/pci/devices/0000\:00\:18.4/hwmon/hwmon0/power1_acc
Results:
* TSC-based default delay: 485115 uWatts average power
* MWAITX-based delay: 252738 uWatts average power
Thus, that's about 240 milliWatts less power consumption. The test method relies on the support of AMD CPU accumulated power algorithm in fam15h_power for which patches are forthcoming.
--- arch/x86/include/asm/delay.h | 1 + arch/x86/kernel/cpu/amd.c | 4 ++++ arch/x86/lib/delay.c | 47 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 51 insertions(+), 1 deletion(-)
arch/x86/include/asm/delay.h +1 -0
@@ -4,5 +4,6 @@#include <asm-generic/delay.h> void use_tsc_delay (void ); +void use_mwaitx_delay (void );#endif /* _ASM_X86_DELAY_H */
arch/x86/kernel/cpu/amd.c +4 -0
@@ -11,6 +11,7 @@#include <asm/cpu.h> #include <asm/smp.h> #include <asm/pci-direct.h> +#include <asm/delay.h> #ifdef CONFIG_X86_64 # include <asm/mmconfig.h>
@@ -506,6 +507,9 @@ static void bsp_init_amd(struct cpuinfo_x86 *c)/* A random value per boot for bit slice [12:upper_bit) */ va_align.bits =get_random_int () & va_align.mask; } + +if (cpu_has (c,X86_FEATURE_MWAITX )) +use_mwaitx_delay (); }static void early_init_amd (struct cpuinfo_x86 *c)
arch/x86/lib/delay.c +46 -1
65 lines not on this page · raw message
Signature · 1 line
2.5.0.rc2.28.g6003e7f
tip-bot for Huang Rui
merge bot[tip:x86/asm] x86/asm/delay: Introduce an MWAITX-based delay with a configurable timer
x86/asm/delay: Introduce an MWAITX-based delay with a configurable timer
Commit-ID: b466bdb614823aaaa7188e85516177d2850f4782 Gitweb: http://git.kernel.org/tip/b466bdb614823aaaa7188e85516177d2850f4782 Author: Huang Rui <[email protected]> AuthorDate: Mon, 10 Aug 2015 12:19:54 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 22 Aug 2015 14:52:16 +0200
x86/asm/delay: Introduce an MWAITX-based delay with a configurable timer
MWAITX can enable a timer and a corresponding timer value specified in SW P0 clocks. The SW P0 frequency is the same as TSC. The timer provides an upper bound on how long the instruction waits before exiting.
This way, a delay function in the kernel can leverage that MWAITX timer of MWAITX.
When a CPU core executes MWAITX, it will be quiesced in a waiting phase, diminishing its power consumption. This way, we can save power in comparison to our default TSC-based delays.
A simple test shows that:
$ cat /sys/bus/pci/devices/0000\:00\:18.4/hwmon/hwmon0/power1_acc $ sleep 10000s $ cat /sys/bus/pci/devices/0000\:00\:18.4/hwmon/hwmon0/power1_acc
Results:
* TSC-based default delay: 485115 uWatts average power
* MWAITX-based delay: 252738 uWatts average power
Thus, that's about 240 milliWatts less power consumption. The test method relies on the support of AMD CPU accumulated power algorithm in fam15h_power for which patches are forthcoming.
--- arch/x86/include/asm/delay.h | 1 + arch/x86/kernel/cpu/amd.c | 4 ++++ arch/x86/lib/delay.c | 47 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 51 insertions(+), 1 deletion(-)
arch/x86/include/asm/delay.h +1 -0
@@ -4,5 +4,6 @@#include <asm-generic/delay.h> void use_tsc_delay (void ); +void use_mwaitx_delay (void );#endif /* _ASM_X86_DELAY_H */
arch/x86/kernel/cpu/amd.c +4 -0
@@ -11,6 +11,7 @@#include <asm/cpu.h> #include <asm/smp.h> #include <asm/pci-direct.h> +#include <asm/delay.h> #ifdef CONFIG_X86_64 # include <asm/mmconfig.h>
@@ -506,6 +507,9 @@ static void bsp_init_amd(struct cpuinfo_x86 *c)/* A random value per boot for bit slice [12:upper_bit) */ va_align.bits =get_random_int () & va_align.mask; } + +if (cpu_has (c,X86_FEATURE_MWAITX )) +use_mwaitx_delay (); }static void early_init_amd (struct cpuinfo_x86 *c)
arch/x86/lib/delay.c +46 -1
65 lines not on this page · raw message