From: Peter Zijlstra <peterz@infradead.org>
To: Arjan van de Ven <arjan@linux.intel.com>,
lenb@kernel.org, rjw@rjwysocki.net,
Eliezer Tamir <eliezer.tamir@linux.intel.com>,
Chris Leech <christopher.leech@intel.com>,
David Miller <davem@davemloft.net>,
rui.zhang@intel.com, jacob.jun.pan@linux.intel.com,
Mike Galbraith <bitbucket@online.de>,
Ingo Molnar <mingo@kernel.org>,
hpa@zytor.com, Thomas Gleixner <tglx@linutronix.de>,
Peter Zijlstra <peterz@infradead.org>
Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org
Subject: [PATCH 2/7] sched, preempt: Fixup missed PREEMPT_NEED_RESCHED folding
Date: Wed, 20 Nov 2013 17:04:52 +0100 [thread overview]
Message-ID: <20131120162736.446984500@infradead.org> (raw)
In-Reply-To: 20131120160450.072555619@infradead.org
[-- Attachment #1: peterz-preempt_fold_need_resched.patch --]
[-- Type: text/plain, Size: 3313 bytes --]
With various drivers wanting to inject idle time; we get people
calling idle routines outside of the idle loop proper.
Therefore we need to be extra careful about not missing
TIF_NEED_RESCHED -> PREEMPT_NEED_RESCHED propagations.
While looking at this, I also realized there's a small window in the
existing idle loop where we can miss TIF_NEED_RESCHED; when it hits
right after the tif_need_resched() test at the end of the loop but
right before the need_resched() test at the start of the loop.
So move preempt_fold_need_resched() out of the loop where we're
guaranteed to have TIF_NEED_RESCHED set.
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
---
arch/x86/include/asm/mwait.h | 2 +-
include/linux/preempt.h | 10 ++++++++++
include/linux/sched.h | 15 +++++++++++++++
kernel/cpu/idle.c | 14 +++++++-------
kernel/sched/core.c | 3 +--
5 files changed, 34 insertions(+), 10 deletions(-)
--- a/arch/x86/include/asm/mwait.h
+++ b/arch/x86/include/asm/mwait.h
@@ -50,7 +50,7 @@ static inline void mwait_idle_with_hints
if (!need_resched())
__mwait(eax, ecx);
}
- __current_clr_polling();
+ current_clr_polling();
}
#endif /* _ASM_X86_MWAIT_H */
--- a/include/linux/preempt.h
+++ b/include/linux/preempt.h
@@ -116,6 +116,16 @@ do { \
#endif /* CONFIG_PREEMPT_COUNT */
+#ifdef CONFIG_PREEMPT
+#define preempt_fold_need_resched() \
+do { \
+ if (tif_need_resched()) \
+ set_preempt_need_resched(); \
+} while (0)
+#else
+#define preempt_fold_need_resched() do { } while (0)
+#endif
+
#ifdef CONFIG_PREEMPT_NOTIFIERS
struct preempt_notifier;
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -2630,6 +2630,21 @@ static inline bool __must_check current_
}
#endif
+static inline void current_clr_polling(void)
+{
+ __current_clr_polling();
+
+ /*
+ * Ensure we check TIF_NEED_RESCHED after we clear the polling bit.
+ * Once the bit is cleared, we'll get IPIs with every new
+ * TIF_NEED_RESCHED and the IPI handler, scheduler_ipi(), will also
+ * fold.
+ */
+ smp_mb(); /* paired with resched_task() */
+
+ preempt_fold_need_resched();
+}
+
static __always_inline bool need_resched(void)
{
return unlikely(tif_need_resched());
--- a/kernel/cpu/idle.c
+++ b/kernel/cpu/idle.c
@@ -105,14 +105,14 @@ static void cpu_idle_loop(void)
__current_set_polling();
}
arch_cpu_idle_exit();
- /*
- * We need to test and propagate the TIF_NEED_RESCHED
- * bit here because we might not have send the
- * reschedule IPI to idle tasks.
- */
- if (tif_need_resched())
- set_preempt_need_resched();
}
+
+ /*
+ * We need to test and propagate the TIF_NEED_RESCHED bit here
+ * because we might not have send the reschedule IPI to idle
+ * tasks.
+ */
+ preempt_fold_need_resched();
tick_nohz_idle_exit();
schedule_preempt_disabled();
}
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -1499,8 +1499,7 @@ void scheduler_ipi(void)
* TIF_NEED_RESCHED remotely (for the first time) will also send
* this IPI.
*/
- if (tif_need_resched())
- set_preempt_need_resched();
+ preempt_fold_need_resched();
if (llist_empty(&this_rq()->wake_list)
&& !tick_nohz_full_cpu(smp_processor_id())
next prev parent reply other threads:[~2013-11-20 16:32 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-20 16:04 [PATCH 0/7] Cure some vaux idle wrackage Peter Zijlstra
2013-11-20 16:04 ` [PATCH 1/7] x86, acpi, idle: Restructure the mwait idle routines Peter Zijlstra
2013-11-20 16:04 ` Peter Zijlstra [this message]
2013-11-21 8:25 ` [PATCH 2/7] sched, preempt: Fixup missed PREEMPT_NEED_RESCHED folding Peter Zijlstra
2013-11-20 16:04 ` [PATCH 3/7] idle, thermal, acpi: Remove home grown idle implementations Peter Zijlstra
2013-11-20 16:40 ` Arjan van de Ven
2013-11-20 16:59 ` Peter Zijlstra
2013-11-20 17:23 ` Thomas Gleixner
2013-11-20 17:23 ` Arjan van de Ven
2013-11-20 17:55 ` Thomas Gleixner
2013-11-20 18:21 ` Arjan van de Ven
2013-11-20 19:38 ` Thomas Gleixner
2013-11-20 22:08 ` Jacob Pan
2013-11-21 0:54 ` Jacob Pan
2013-11-21 8:21 ` Peter Zijlstra
2013-11-21 16:07 ` Paul E. McKenney
2013-11-21 16:21 ` Arjan van de Ven
2013-11-21 19:19 ` Paul E. McKenney
2013-11-21 19:45 ` Arjan van de Ven
2013-11-21 20:07 ` Paul E. McKenney
2013-11-22 0:10 ` Jacob Pan
2013-11-22 4:20 ` Paul E. McKenney
2013-11-22 11:33 ` Peter Zijlstra
2013-11-22 17:17 ` Paul E. McKenney
2013-11-21 16:29 ` Peter Zijlstra
2013-11-21 17:27 ` Paul E. McKenney
2013-11-20 16:04 ` [PATCH 4/7] preempt, locking: Rework local_bh_{dis,en}able() Peter Zijlstra
2013-11-20 16:04 ` [PATCH 5/7] locking: Optimize lock_bh functions Peter Zijlstra
2013-11-20 16:04 ` [PATCH 6/7] sched: Clean up preempt_enable_no_resched() abuse Peter Zijlstra
2013-11-20 18:02 ` Eliezer Tamir
2013-11-20 18:15 ` Peter Zijlstra
2013-11-20 20:14 ` Eliezer Tamir
2013-11-21 10:10 ` Peter Zijlstra
2013-11-21 13:26 ` Eliezer Tamir
2013-11-21 13:39 ` Peter Zijlstra
2013-11-22 6:56 ` Eliezer Tamir
2013-11-22 11:30 ` Peter Zijlstra
2013-11-26 7:15 ` Eliezer Tamir
2013-11-26 10:51 ` Thomas Gleixner
2013-11-20 16:04 ` [PATCH 7/7] preempt: Take away preempt_enable_no_resched() from modules Peter Zijlstra
2013-11-20 18:54 ` Jacob Pan
2013-11-20 19:00 ` Peter Zijlstra
2013-11-20 19:18 ` Peter Zijlstra
2013-11-20 19:29 ` Jacob Pan
2013-11-20 16:34 ` [PATCH 0/7] Cure some vaux idle wrackage Peter Zijlstra
2013-11-20 17:19 ` Jacob Pan
2013-11-20 17:24 ` Peter Zijlstra
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=20131120162736.446984500@infradead.org \
--to=peterz@infradead.org \
--cc=arjan@linux.intel.com \
--cc=bitbucket@online.de \
--cc=christopher.leech@intel.com \
--cc=davem@davemloft.net \
--cc=eliezer.tamir@linux.intel.com \
--cc=hpa@zytor.com \
--cc=jacob.jun.pan@linux.intel.com \
--cc=lenb@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=rjw@rjwysocki.net \
--cc=rui.zhang@intel.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;
as well as URLs for NNTP newsgroup(s).