aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kernel/smpboot.c
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 /arch/x86/kernel/smpboot.c
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
Diffstat (limited to 'arch/x86/kernel/smpboot.c')
-rw-r--r--arch/x86/kernel/smpboot.c80
1 files changed, 79 insertions, 1 deletions
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 */