From: Mike Galbraith <umgwanakikbuti@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: mingo@kernel.org, tglx@linutronix.de, luto@amacapital.net,
nicolas.pitre@linaro.org, daniel.lezcano@linaro.org,
linux-kernel@vger.kernel.org
Subject: Re: [RFC][PATCH 0/8] sched,idle: need resched polling rework
Date: Sat, 12 Apr 2014 10:35:02 +0200 [thread overview]
Message-ID: <1397291702.6038.43.camel@marge.simpson.net> (raw)
In-Reply-To: <20140411134243.160989490@infradead.org>
On Fri, 2014-04-11 at 15:42 +0200, Peter Zijlstra wrote:
> A while ago both Mike and Andy complained that we still get pointless wakeup
> IPIs, we had a few patches back and forth but eventually more or less agreed
> and then nothing... :-)
>
> So here's a number of patches that implement something near what we left off
> with.
>
> Its only been compile/boot tested on x86_64, I've no actually looked at the IPI
> numbers yet.
'course this didn't do much for my Q6600 box, or core2 lappy when booted
max_cstate=1, but series didn't seem to break anything, both boxen still
work fine with the below on top.
Subject: [PATCH REGRESSION FIX] x86 idle: restore mwait_idle()
From: Len Brown <lenb@kernel.org>
Date: Wed, 15 Jan 2014 00:37:34 -0500
From: Len Brown <len.brown@intel.com>
In Linux-3.9 we removed the mwait_idle() loop:
'x86 idle: remove mwait_idle() and "idle=mwait" cmdline param'
(69fb3676df3329a7142803bb3502fa59dc0db2e3)
The reasoning was that modern machines should be sufficiently
happy during the boot process using the default_idle() HALT loop,
until cpuidle loads and either acpi_idle or intel_idle
invoke the newer MWAIT-with-hints idle loop.
But two machines reported problems:
1. Certain Core2-era machines support MWAIT-C1 and HALT only.
MWAIT-C1 is preferred for optimal power and performance.
But if they support just C1, cpuidle never loads and
so they use the boot-time default idle loop forever.
2. Some laptops will boot-hang if HALT is used,
but will boot successfully if MWAIT is used.
This appears to be a hidden assumption in BIOS SMI,
that is presumably valid on the proprietary OS
where the BIOS was validated.
https://bugzilla.kernel.org/show_bug.cgi?id=60770
So here we effectively revert the patch above, restoring
the mwait_idle() loop. However, we don't bother restoring
the idle=mwait cmdline parameter, since it appears to add
no value.
Maintainer notes:
For 3.9, simply revert 69fb3676df
for 3.10, patch -F3 applies, fuzz needed due to __cpuinit use in context
For 3.11, 3.12, 3.13, this patch applies cleanly
Mike: add clflush barriers and resched IPI avoidance.
Cc: Mike Galbraith <bitbucket@online.de>
Cc: Ian Malone <ibmalone@gmail.com>
Cc: Josh Boyer <jwboyer@redhat.com>
Cc: <stable@vger.kernel.org> # 3.9, 3.10, 3.11, 3.12, 3.13
Signed-off-by: Len Brown <len.brown@intel.com>
Signed-off-by: Mike Galbraith <bitbucket@online.de>
---
arch/x86/include/asm/mwait.h | 8 ++++++
arch/x86/kernel/process.c | 50 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 58 insertions(+)
--- a/arch/x86/include/asm/mwait.h
+++ b/arch/x86/include/asm/mwait.h
@@ -30,6 +30,14 @@ static inline void __mwait(unsigned long
:: "a" (eax), "c" (ecx));
}
+static inline void __sti_mwait(unsigned long eax, unsigned long ecx)
+{
+ trace_hardirqs_on();
+ /* "mwait %eax, %ecx;" */
+ asm volatile("sti; .byte 0x0f, 0x01, 0xc9;"
+ :: "a" (eax), "c" (ecx));
+}
+
/*
* This uses new MONITOR/MWAIT instructions on P4 processors with PNI,
* which can obviate IPI to trigger checking of need_resched.
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -28,6 +28,7 @@
#include <asm/fpu-internal.h>
#include <asm/debugreg.h>
#include <asm/nmi.h>
+#include <asm/mwait.h>
/*
* per-CPU TSS segments. Threads are completely 'soft' on Linux,
@@ -395,6 +396,52 @@ static void amd_e400_idle(void)
default_idle();
}
+/*
+ * Intel Core2 and older machines prefer MWAIT over HALT for C1.
+ * We can't rely on cpuidle installing MWAIT, because it will not load
+ * on systems that support only C1 -- so the boot default must be MWAIT.
+ *
+ * Some AMD machines are the opposite, they depend on using HALT.
+ *
+ * So for default C1, which is used during boot until cpuidle loads,
+ * use MWAIT-C1 on Intel HW that has it, else use HALT.
+ */
+static int prefer_mwait_c1_over_halt(const struct cpuinfo_x86 *c)
+{
+ if (c->x86_vendor != X86_VENDOR_INTEL)
+ return 0;
+
+ if (!cpu_has(c, X86_FEATURE_MWAIT))
+ return 0;
+
+ return 1;
+}
+
+/*
+ * MONITOR/MWAIT with no hints, used for default default C1 state.
+ * This invokes MWAIT with interrutps enabled and no flags,
+ * which is backwards compatible with the original MWAIT implementation.
+ */
+
+static void mwait_idle(void)
+{
+ if (!current_set_polling_and_test()) {
+ if (this_cpu_has(X86_FEATURE_CLFLUSH_MONITOR)) {
+ mb();
+ clflush((void *)¤t_thread_info()->flags);
+ mb();
+ }
+
+ __monitor((void *)¤t_thread_info()->flags, 0, 0);
+ if (!need_resched())
+ __sti_mwait(0, 0);
+ else
+ local_irq_enable();
+ } else
+ local_irq_enable();
+ current_clr_polling();
+}
+
void select_idle_routine(const struct cpuinfo_x86 *c)
{
#ifdef CONFIG_SMP
@@ -408,6 +455,9 @@ void select_idle_routine(const struct cp
/* E400: APIC timer interrupt does not wake up CPU from C1e */
pr_info("using AMD E400 aware idle routine\n");
x86_idle = amd_e400_idle;
+ } else if (prefer_mwait_c1_over_halt(c)) {
+ pr_info("using mwait in idle threads\n");
+ x86_idle = mwait_idle;
} else
x86_idle = default_idle;
}
prev parent reply other threads:[~2014-04-12 8:35 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-11 13:42 [RFC][PATCH 0/8] sched,idle: need resched polling rework Peter Zijlstra
2014-04-11 13:42 ` [RFC][PATCH 1/8] sched,idle,alpha: Switch from TS_POLLING to TIF_POLLING_NRFLAG Peter Zijlstra
2014-04-11 14:38 ` Richard Henderson
2014-04-11 13:42 ` [RFC][PATCH 2/8] sched,idle,tile: " Peter Zijlstra
2014-04-11 15:15 ` Chris Metcalf
2014-04-11 15:30 ` Peter Zijlstra
2014-04-11 13:42 ` [RFC][PATCH 3/8] sched,idle,ia64: " Peter Zijlstra
2014-04-11 13:42 ` [RFC][PATCH 4/8] sched,idle,x86: " Peter Zijlstra
2014-04-11 13:42 ` [RFC][PATCH 5/8] sched,idle: Remove TS_POLLING support Peter Zijlstra
2014-04-11 13:42 ` [RFC][PATCH 6/8] sched,idle: Avoid spurious wakeup IPIs Peter Zijlstra
2014-04-13 21:41 ` Nicolas Pitre
2014-05-09 13:37 ` James Hogan
2014-05-09 14:15 ` Peter Zijlstra
2014-05-09 14:40 ` Catalin Marinas
2014-05-09 14:50 ` Peter Zijlstra
2014-05-09 14:57 ` Catalin Marinas
2014-05-09 17:02 ` Peter Zijlstra
2014-05-09 17:06 ` Peter Zijlstra
2014-05-09 17:09 ` Catalin Marinas
2014-05-09 17:20 ` Peter Zijlstra
2014-05-19 12:54 ` [tip:sched/arch] arm64: Remove TIF_POLLING_NRFLAG tip-bot for Peter Zijlstra
2014-05-22 12:26 ` [tip:sched/core] " tip-bot for Peter Zijlstra
2014-05-09 14:51 ` [RFC][PATCH 6/8] sched,idle: Avoid spurious wakeup IPIs James Hogan
2014-05-15 9:17 ` James Hogan
2014-05-19 12:54 ` [tip:sched/arch] metag: Remove TIF_POLLING_NRFLAG tip-bot for James Hogan
2014-05-22 12:26 ` [tip:sched/core] " tip-bot for James Hogan
2014-04-11 13:42 ` [RFC][PATCH 7/8] sched,idle: Delay clearing the polling bit Peter Zijlstra
2014-04-13 21:51 ` Nicolas Pitre
2014-04-11 13:42 ` [RFC][PATCH 8/8] sched,idle: Reflow cpuidle_idle_call() Peter Zijlstra
2014-04-13 21:36 ` Nicolas Pitre
2014-04-14 8:59 ` Peter Zijlstra
2014-04-14 9:25 ` Peter Zijlstra
2014-04-14 13:55 ` Nicolas Pitre
2014-04-11 15:00 ` [RFC][PATCH 0/8] sched,idle: need resched polling rework Andy Lutomirski
2014-04-11 15:14 ` Peter Zijlstra
2014-05-22 12:58 ` Peter Zijlstra
2014-05-22 13:09 ` Peter Zijlstra
2014-05-29 0:01 ` Andy Lutomirski
2014-05-29 6:48 ` Peter Zijlstra
2014-06-03 6:40 ` Andy Lutomirski
2014-06-03 6:51 ` Peter Zijlstra
2014-06-03 10:43 ` Peter Zijlstra
2014-06-03 14:02 ` Peter Zijlstra
2014-06-03 16:05 ` Andy Lutomirski
2014-06-03 16:19 ` Peter Zijlstra
2014-06-03 16:52 ` Andy Lutomirski
2014-06-03 17:00 ` Peter Zijlstra
2014-06-03 18:28 ` Peter Zijlstra
2014-06-03 18:44 ` Andy Lutomirski
2014-06-03 20:07 ` Andy Lutomirski
2014-04-12 8:35 ` Mike Galbraith [this message]
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=1397291702.6038.43.camel@marge.simpson.net \
--to=umgwanakikbuti@gmail.com \
--cc=daniel.lezcano@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=mingo@kernel.org \
--cc=nicolas.pitre@linaro.org \
--cc=peterz@infradead.org \
--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;
as well as URLs for NNTP newsgroup(s).