aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2010-10-21 16:45:38 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-10-21 16:45:38 -0400
commit2a8b67fb72c4c4bc15fe8095e3ed613789c8b82f (patch)
tree1dac291641bc5d0a3acff3d1e48b3328ae54462b
parentb6f7e38dbb310557fe890b04b1a376c93f638c3b (diff)
parentce5f68246bf2385d6174856708d0b746dc378f20 (diff)
Merge branch 'x86-idle-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'x86-idle-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: x86, hotplug: In the MWAIT case of play_dead, CLFLUSH the cache line x86, hotplug: Move WBINVD back outside the play_dead loop x86, hotplug: Use mwait to offline a processor, fix the legacy case x86, mwait: Move mwait constants to a common header file
-rw-r--r--arch/x86/include/asm/mwait.h15
-rw-r--r--arch/x86/include/asm/processor.h23
-rw-r--r--arch/x86/kernel/acpi/cstate.c11
-rw-r--r--arch/x86/kernel/smpboot.c80
-rw-r--r--drivers/acpi/acpi_pad.c7
-rw-r--r--drivers/idle/intel_idle.c9
6 files changed, 97 insertions, 48 deletions
diff --git a/arch/x86/include/asm/mwait.h b/arch/x86/include/asm/mwait.h
new file mode 100644
index 000000000000..bcdff997668c
--- /dev/null
+++ b/arch/x86/include/asm/mwait.h
@@ -0,0 +1,15 @@
1#ifndef _ASM_X86_MWAIT_H
2#define _ASM_X86_MWAIT_H
3
4#define MWAIT_SUBSTATE_MASK 0xf
5#define MWAIT_CSTATE_MASK 0xf
6#define MWAIT_SUBSTATE_SIZE 4
7#define MWAIT_MAX_NUM_CSTATES 8
8
9#define CPUID_MWAIT_LEAF 5
10#define CPUID5_ECX_EXTENSIONS_SUPPORTED 0x1
11#define CPUID5_ECX_INTERRUPT_BREAK 0x2
12
13#define MWAIT_ECX_INTERRUPT_BREAK 0x1
14
15#endif /* _ASM_X86_MWAIT_H */
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index a668d66301fe..cae9c3cb95cf 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -766,29 +766,6 @@ extern unsigned long idle_halt;
766extern unsigned long idle_nomwait; 766extern unsigned long idle_nomwait;
767extern bool c1e_detected; 767extern bool c1e_detected;
768 768
769/*
770 * on systems with caches, caches must be flashed as the absolute
771 * last instruction before going into a suspended halt. Otherwise,
772 * dirty data can linger in the cache and become stale on resume,
773 * leading to strange errors.
774 *
775 * perform a variety of operations to guarantee that the compiler
776 * will not reorder instructions. wbinvd itself is serializing
777 * so the processor will not reorder.
778 *
779 * Systems without cache can just go into halt.
780 */
781static inline void wbinvd_halt(void)
782{
783 mb();
784 /* check for clflush to determine if wbinvd is legal */
785 if (cpu_has_clflush)
786 asm volatile("cli; wbinvd; 1: hlt; jmp 1b" : : : "memory");
787 else
788 while (1)
789 halt();
790}
791
792extern void enable_sep_cpu(void); 769extern void enable_sep_cpu(void);
793extern int sysenter_setup(void); 770extern int sysenter_setup(void);
794 771
diff --git a/arch/x86/kernel/acpi/cstate.c b/arch/x86/kernel/acpi/cstate.c
index fb16f17e59be..5812404a0d4c 100644
--- a/arch/x86/kernel/acpi/cstate.c
+++ b/arch/x86/kernel/acpi/cstate.c
@@ -13,6 +13,7 @@
13 13
14#include <acpi/processor.h> 14#include <acpi/processor.h>
15#include <asm/acpi.h> 15#include <asm/acpi.h>
16#include <asm/mwait.h>
16 17
17/* 18/*
18 * Initialize bm_flags based on the CPU cache properties 19 * Initialize bm_flags based on the CPU cache properties
@@ -65,16 +66,6 @@ static struct cstate_entry __percpu *cpu_cstate_entry; /* per CPU ptr */
65 66
66static short mwait_supported[ACPI_PROCESSOR_MAX_POWER]; 67static short mwait_supported[ACPI_PROCESSOR_MAX_POWER];
67 68
68#define MWAIT_SUBSTATE_MASK (0xf)
69#define MWAIT_CSTATE_MASK (0xf)
70#define MWAIT_SUBSTATE_SIZE (4)
71
72#define CPUID_MWAIT_LEAF (5)
73#define CPUID5_ECX_EXTENSIONS_SUPPORTED (0x1)
74#define CPUID5_ECX_INTERRUPT_BREAK (0x2)
75
76#define MWAIT_ECX_INTERRUPT_BREAK (0x1)
77
78#define NATIVE_CSTATE_BEYOND_HALT (2) 69#define NATIVE_CSTATE_BEYOND_HALT (2)
79 70
80static long acpi_processor_ffh_cstate_probe_cpu(void *_cx) 71static long acpi_processor_ffh_cstate_probe_cpu(void *_cx)
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index bc2cc444844a..0116552c950d 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -62,6 +62,7 @@
62#include <asm/pgtable.h> 62#include <asm/pgtable.h>
63#include <asm/tlbflush.h> 63#include <asm/tlbflush.h>
64#include <asm/mtrr.h> 64#include <asm/mtrr.h>
65#include <asm/mwait.h>
65#include <asm/vmi.h> 66#include <asm/vmi.h>
66#include <asm/apic.h> 67#include <asm/apic.h>
67#include <asm/setup.h> 68#include <asm/setup.h>
@@ -1395,11 +1396,88 @@ void play_dead_common(void)
1395 local_irq_disable(); 1396 local_irq_disable();
1396} 1397}
1397 1398
1399/*
1400 * We need to flush the caches before going to sleep, lest we have
1401 * dirty data in our caches when we come back up.
1402 */
1403static inline void mwait_play_dead(void)
1404{
1405 unsigned int eax, ebx, ecx, edx;
1406 unsigned int highest_cstate = 0;
1407 unsigned int highest_subcstate = 0;
1408 int i;
1409 void *mwait_ptr;
1410
1411 if (!cpu_has(&current_cpu_data, X86_FEATURE_MWAIT))
1412 return;
1413 if (!cpu_has(&current_cpu_data, X86_FEATURE_CLFLSH))
1414 return;
1415 if (current_cpu_data.cpuid_level < CPUID_MWAIT_LEAF)
1416 return;
1417
1418 eax = CPUID_MWAIT_LEAF;
1419 ecx = 0;
1420 native_cpuid(&eax, &ebx, &ecx, &edx);
1421
1422 /*
1423 * eax will be 0 if EDX enumeration is not valid.
1424 * Initialized below to cstate, sub_cstate value when EDX is valid.
1425 */
1426 if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED)) {
1427 eax = 0;
1428 } else {
1429 edx >>= MWAIT_SUBSTATE_SIZE;
1430 for (i = 0; i < 7 && edx; i++, edx >>= MWAIT_SUBSTATE_SIZE) {
1431 if (edx & MWAIT_SUBSTATE_MASK) {
1432 highest_cstate = i;
1433 highest_subcstate = edx & MWAIT_SUBSTATE_MASK;
1434 }
1435 }
1436 eax = (highest_cstate << MWAIT_SUBSTATE_SIZE) |
1437 (highest_subcstate - 1);
1438 }
1439
1440 /*
1441 * This should be a memory location in a cache line which is
1442 * unlikely to be touched by other processors. The actual
1443 * content is immaterial as it is not actually modified in any way.
1444 */
1445 mwait_ptr = &current_thread_info()->flags;
1446
1447 wbinvd();
1448
1449 while (1) {
1450 /*
1451 * The CLFLUSH is a workaround for erratum AAI65 for
1452 * the Xeon 7400 series. It's not clear it is actually
1453 * needed, but it should be harmless in either case.
1454 * The WBINVD is insufficient due to the spurious-wakeup
1455 * case where we return around the loop.
1456 */
1457 clflush(mwait_ptr);
1458 __monitor(mwait_ptr, 0, 0);
1459 mb();
1460 __mwait(eax, 0);
1461 }
1462}
1463
1464static inline void hlt_play_dead(void)
1465{
1466 if (current_cpu_data.x86 >= 4)
1467 wbinvd();
1468
1469 while (1) {
1470 native_halt();
1471 }
1472}
1473
1398void native_play_dead(void) 1474void native_play_dead(void)
1399{ 1475{
1400 play_dead_common(); 1476 play_dead_common();
1401 tboot_shutdown(TB_SHUTDOWN_WFS); 1477 tboot_shutdown(TB_SHUTDOWN_WFS);
1402 wbinvd_halt(); 1478
1479 mwait_play_dead(); /* Only returns on failure */
1480 hlt_play_dead();
1403} 1481}
1404 1482
1405#else /* ... !CONFIG_HOTPLUG_CPU */ 1483#else /* ... !CONFIG_HOTPLUG_CPU */
diff --git a/drivers/acpi/acpi_pad.c b/drivers/acpi/acpi_pad.c
index 6b115f6c4313..6afceb3d4034 100644
--- a/drivers/acpi/acpi_pad.c
+++ b/drivers/acpi/acpi_pad.c
@@ -30,18 +30,13 @@
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <acpi/acpi_bus.h> 31#include <acpi/acpi_bus.h>
32#include <acpi/acpi_drivers.h> 32#include <acpi/acpi_drivers.h>
33#include <asm/mwait.h>
33 34
34#define ACPI_PROCESSOR_AGGREGATOR_CLASS "acpi_pad" 35#define ACPI_PROCESSOR_AGGREGATOR_CLASS "acpi_pad"
35#define ACPI_PROCESSOR_AGGREGATOR_DEVICE_NAME "Processor Aggregator" 36#define ACPI_PROCESSOR_AGGREGATOR_DEVICE_NAME "Processor Aggregator"
36#define ACPI_PROCESSOR_AGGREGATOR_NOTIFY 0x80 37#define ACPI_PROCESSOR_AGGREGATOR_NOTIFY 0x80
37static DEFINE_MUTEX(isolated_cpus_lock); 38static DEFINE_MUTEX(isolated_cpus_lock);
38 39
39#define MWAIT_SUBSTATE_MASK (0xf)
40#define MWAIT_CSTATE_MASK (0xf)
41#define MWAIT_SUBSTATE_SIZE (4)
42#define CPUID_MWAIT_LEAF (5)
43#define CPUID5_ECX_EXTENSIONS_SUPPORTED (0x1)
44#define CPUID5_ECX_INTERRUPT_BREAK (0x2)
45static unsigned long power_saving_mwait_eax; 40static unsigned long power_saving_mwait_eax;
46 41
47static unsigned char tsc_detected_unstable; 42static unsigned char tsc_detected_unstable;
diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c
index c37ef64d1465..cb3ccf3ed221 100644
--- a/drivers/idle/intel_idle.c
+++ b/drivers/idle/intel_idle.c
@@ -59,18 +59,11 @@
59#include <linux/hrtimer.h> /* ktime_get_real() */ 59#include <linux/hrtimer.h> /* ktime_get_real() */
60#include <trace/events/power.h> 60#include <trace/events/power.h>
61#include <linux/sched.h> 61#include <linux/sched.h>
62#include <asm/mwait.h>
62 63
63#define INTEL_IDLE_VERSION "0.4" 64#define INTEL_IDLE_VERSION "0.4"
64#define PREFIX "intel_idle: " 65#define PREFIX "intel_idle: "
65 66
66#define MWAIT_SUBSTATE_MASK (0xf)
67#define MWAIT_CSTATE_MASK (0xf)
68#define MWAIT_SUBSTATE_SIZE (4)
69#define MWAIT_MAX_NUM_CSTATES 8
70#define CPUID_MWAIT_LEAF (5)
71#define CPUID5_ECX_EXTENSIONS_SUPPORTED (0x1)
72#define CPUID5_ECX_INTERRUPT_BREAK (0x2)
73
74static struct cpuidle_driver intel_idle_driver = { 67static struct cpuidle_driver intel_idle_driver = {
75 .name = "intel_idle", 68 .name = "intel_idle",
76 .owner = THIS_MODULE, 69 .owner = THIS_MODULE,