public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: venkatesh.pallipadi@intel.com
To: mingo@elte.hu, tglx@linutronix.de, hpa@zytor.com
Cc: linux-kernel@vger.kernel.org, lenb@kernel.org,
	shaohua.li@intel.com, svaidy@linux.vnet.ibm.com,
	a.p.zijlstra@chello.nl,
	Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
Subject: [patch 2/2] x86: put offline CPUs into deepest mwait cstate_subcstate
Date: Fri, 22 May 2009 16:19:42 -0700	[thread overview]
Message-ID: <20090522232230.162239000@intel.com> (raw)
In-Reply-To: 20090522231940.553094000@intel.com

[-- Attachment #1: 0002-x86-put-offline-CPUs-into-deepest-mwait-cstate_subc.patch --]
[-- Type: text/plain, Size: 2075 bytes --]

Offline CPUs can save power by going into deepest cstate, subcstate
instead of hlt loop.

Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
---
 arch/x86/kernel/acpi/cstate.c |   51 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 51 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kernel/acpi/cstate.c b/arch/x86/kernel/acpi/cstate.c
index bbbe4bb..5b0988a 100644
--- a/arch/x86/kernel/acpi/cstate.c
+++ b/arch/x86/kernel/acpi/cstate.c
@@ -150,6 +150,54 @@ void acpi_processor_ffh_cstate_enter(struct acpi_processor_cx *cx)
 }
 EXPORT_SYMBOL_GPL(acpi_processor_ffh_cstate_enter);
 
+static unsigned long mwait_play_dead_eax;
+
+static void mwait_play_dead(void)
+{
+	if (boot_cpu_data.x86 >= 4)
+		wbinvd();
+
+	while (1) {
+		__monitor((void *)&current_thread_info()->flags, 0, 0);
+		smp_mb();
+		__mwait(mwait_play_dead_eax, 0);
+	}
+}
+
+static void mwait_play_dead_init(void *unused)
+{
+	unsigned int eax, ebx, ecx, edx;
+	unsigned int highest_cstate = 0;
+	unsigned int highest_subcstate = 0;
+	int i;
+
+	if (!boot_cpu_has(X86_FEATURE_MWAIT))
+		return;
+	
+	if (boot_cpu_data.cpuid_level < CPUID_MWAIT_LEAF)
+		return;
+
+	pm_play_dead = mwait_play_dead;
+
+	cpuid(CPUID_MWAIT_LEAF, &eax, &ebx, &ecx, &edx);
+	/*
+	 * mwait_play_dead_eax will be 0 if EDX enumeration is not valid.
+	 * Initialized below to cstate, sub_cstate value when EDX is valid.
+	 */
+	if (!(ecx & 0x1))
+		return;
+		
+	edx >>= MWAIT_SUBSTATE_SIZE;
+	for (i = 0; i < 7 && edx; i++, edx >>= MWAIT_SUBSTATE_SIZE) {
+		if (edx & MWAIT_SUBSTATE_MASK) {
+			highest_cstate = i;
+			highest_subcstate = edx & MWAIT_SUBSTATE_MASK;
+		}
+	}
+	mwait_play_dead_eax = (highest_cstate << MWAIT_SUBSTATE_SIZE) |
+			      (highest_subcstate - 1);
+}
+
 static int __init ffh_cstate_init(void)
 {
 	struct cpuinfo_x86 *c = &boot_cpu_data;
@@ -157,6 +205,9 @@ static int __init ffh_cstate_init(void)
 		return -1;
 
 	cpu_cstate_entry = alloc_percpu(struct cstate_entry);
+
+	smp_call_function_single(0, mwait_play_dead_init, NULL, 1);
+
 	return 0;
 }
 
-- 
1.6.0.6

-- 


  parent reply	other threads:[~2009-05-22 23:25 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-22 23:19 [patch 0/2] x86: Make offline cpus to go to deepest idle state using mwait venkatesh.pallipadi
2009-05-22 23:19 ` [patch 1/2] x86: Add pm_play_dead funcptr to power-efficiently offline CPUs venkatesh.pallipadi
2009-05-23 10:44   ` Peter Zijlstra
2009-05-23 15:07     ` Pallipadi, Venkatesh
2009-06-22 17:25     ` Pallipadi, Venkatesh
2009-05-22 23:19 ` venkatesh.pallipadi [this message]
2009-05-25  0:56   ` [patch 2/2] x86: put offline CPUs into deepest mwait cstate_subcstate Shaohua Li
2009-05-26 21:17     ` Pallipadi, Venkatesh
2010-09-17 23:46   ` [tip:x86/idle] x86, hotplug: Use mwait to offline a processor, fix the legacy case tip-bot for H. Peter Anvin
2010-09-18  0:13     ` [tip:x86/idle] x86, hotplug: Move WBINVD back outside the play_dead loop tip-bot for H. Peter Anvin
2010-09-18  0:48       ` Venkatesh Pallipadi
2010-09-20 18:20         ` H. Peter Anvin
2010-09-20 20:11           ` H. Peter Anvin
2010-09-20 22:34             ` Venkatesh Pallipadi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090522232230.162239000@intel.com \
    --to=venkatesh.pallipadi@intel.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=hpa@zytor.com \
    --cc=lenb@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=shaohua.li@intel.com \
    --cc=svaidy@linux.vnet.ibm.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox