From: Mike Galbraith <umgwanakikbuti@gmail.com>
To: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: linux-rt-users <linux-rt-users@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
rostedt@goodmis.org, John Kacur <jkacur@redhat.com>
Subject: [patch-3.18.7-rt1] sched/context-tracking: fix PREEMPT_LAZY explosions
Date: Wed, 18 Feb 2015 12:21:54 +0100 [thread overview]
Message-ID: <1424258514.3819.39.camel@gmail.com> (raw)
In-Reply-To: <20150216111822.GA21649@linutronix.de>
On Mon, 2015-02-16 at 12:18 +0100, Sebastian Andrzej Siewior wrote:
> Known issues:
>
> - lazy preempt on x86_64 leads to a crash with some load.
The below still works for me. (it doesn't make nohz_full actually work
in rt, but at least folks who want to tinker with it can do so)
If context tracking is enabled, we can recurse, and explode violently.
Add missing checks to preempt_schedule_context().
Fix other inconsistencies spotted while searching for the little SOB.
Signed-off-by: Mike Galbraith <umgwanakikbuti@gmail.com>
---
arch/x86/Kconfig | 2 +-
arch/x86/include/asm/thread_info.h | 1 +
include/linux/preempt.h | 2 +-
include/linux/preempt_mask.h | 10 ++++++++--
kernel/fork.c | 1 +
kernel/sched/core.c | 18 ++++++------------
kernel/sched/fair.c | 2 +-
7 files changed, 19 insertions(+), 17 deletions(-)
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -21,7 +21,7 @@ config X86_64
### Arch settings
config X86
def_bool y
- select HAVE_PREEMPT_LAZY if X86_32
+ select HAVE_PREEMPT_LAZY
select ARCH_MIGHT_HAVE_ACPI_PDC if ACPI
select ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
select ARCH_HAS_FAST_MULTIPLIER
--- a/arch/x86/include/asm/thread_info.h
+++ b/arch/x86/include/asm/thread_info.h
@@ -46,6 +46,7 @@ struct thread_info {
.flags = 0, \
.cpu = 0, \
.saved_preempt_count = INIT_PREEMPT_COUNT, \
+ .preempt_lazy_count = 0, \
.addr_limit = KERNEL_DS, \
.restart_block = { \
.fn = do_no_restart_syscall, \
--- a/include/linux/preempt.h
+++ b/include/linux/preempt.h
@@ -91,8 +91,8 @@ do { \
#define preempt_lazy_enable() \
do { \
- dec_preempt_lazy_count(); \
barrier(); \
+ dec_preempt_lazy_count(); \
preempt_check_resched(); \
} while (0)
--- a/include/linux/preempt_mask.h
+++ b/include/linux/preempt_mask.h
@@ -118,9 +118,15 @@ extern int in_serving_softirq(void);
((preempt_count() & ~PREEMPT_ACTIVE) != PREEMPT_CHECK_OFFSET)
#ifdef CONFIG_PREEMPT_COUNT
-# define preemptible() (preempt_count() == 0 && !irqs_disabled())
+# define preemptible() (preempt_count() == 0 && !irqs_disabled())
+#ifdef CONFIG_PREEMPT_LAZY
+# define preemptible_lazy() (preempt_lazy_count() == 0 || need_resched_now())
#else
-# define preemptible() 0
+# define preemptible_lazy() 1
+#endif
+#else
+# define preemptible() 0
+# define preemptible_lazy() 0
#endif
#endif /* LINUX_PREEMPT_MASK_H */
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -348,6 +348,7 @@ static struct task_struct *dup_task_stru
setup_thread_stack(tsk, orig);
clear_user_return_notifier(tsk);
clear_tsk_need_resched(tsk);
+ clear_tsk_need_resched_lazy(tsk);
set_task_stack_end_magic(tsk);
#ifdef CONFIG_CC_STACKPROTECTOR
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2861,8 +2861,8 @@ void migrate_enable(void)
p->migrate_disable = 0;
unpin_current_cpu();
- preempt_enable();
preempt_lazy_enable();
+ preempt_enable();
}
EXPORT_SYMBOL(migrate_enable);
#else
@@ -3099,19 +3099,13 @@ asmlinkage __visible void __sched notrac
{
/*
* If there is a non-zero preempt_count or interrupts are disabled,
- * we do not want to preempt the current task. Just return..
+ * we do not want to preempt the current task. Just return. For
+ * lazy preemption we also check for non-zero preempt_count_lazy,
+ * and bail if no immediate preemption is required.
*/
- if (likely(!preemptible()))
+ if (likely(!preemptible() || !preemptible_lazy()))
return;
-#ifdef CONFIG_PREEMPT_LAZY
- /*
- * Check for lazy preemption
- */
- if (current_thread_info()->preempt_lazy_count &&
- !test_thread_flag(TIF_NEED_RESCHED))
- return;
-#endif
do {
__preempt_count_add(PREEMPT_ACTIVE);
/*
@@ -3155,7 +3149,7 @@ asmlinkage __visible void __sched notrac
{
enum ctx_state prev_ctx;
- if (likely(!preemptible()))
+ if (likely(!preemptible() || !preemptible_lazy()))
return;
do {
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -4761,7 +4761,7 @@ static void check_preempt_wakeup(struct
* prevents us from potentially nominating it as a false LAST_BUDDY
* below.
*/
- if (test_tsk_need_resched(curr))
+ if (test_tsk_need_resched(curr) || test_tsk_need_resched_lazy(curr))
return;
/* Idle tasks are by definition preempted by non-idle tasks. */
next prev parent reply other threads:[~2015-02-18 11:21 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-16 11:18 [ANNOUNCE] 3.18.7-rt1 Sebastian Andrzej Siewior
2015-02-16 18:13 ` Sebastian Andrzej Siewior
2015-02-16 20:12 ` Richard Cochran
2015-02-16 20:21 ` Steven Rostedt
2015-02-17 8:37 ` Daniel Wagner
2015-02-19 9:36 ` Joakim Hernberg
2015-02-25 13:55 ` Sebastian Andrzej Siewior
2015-02-26 8:48 ` Sebastian Andrzej Siewior
2015-02-27 6:40 ` Daniel Wagner
2015-02-27 7:58 ` Sebastian Andrzej Siewior
2015-02-18 11:21 ` Mike Galbraith [this message]
2015-02-18 11:27 ` [rfc patch-3.18.7-rt1] rt/nohz_full: Fix can_stop_full_tick() gripe within softirq Mike Galbraith
2015-02-19 4:50 ` Mike Galbraith
2015-02-19 6:30 ` [patch-3.18.7-rt1] sched/context-tracking: fix PREEMPT_LAZY explosions Mike Galbraith
2015-03-09 13:45 ` Sebastian Andrzej Siewior
2015-03-09 14:36 ` Mike Galbraith
2015-03-09 14:45 ` Sebastian Andrzej Siewior
2015-03-10 9:35 ` Mike Galbraith
2015-03-11 6:18 ` Mike Galbraith
2015-03-12 9:38 ` [rfc patch] rt,nohz_full: fix nohz_full for PREEMPT_RT_FULL Mike Galbraith
2015-03-12 15:09 ` Steven Rostedt
2015-03-13 2:13 ` Mike Galbraith
2015-03-13 3:03 ` Steven Rostedt
2015-03-13 4:53 ` [rfc patch v2] " Mike Galbraith
2015-03-16 20:24 ` Sebastian Andrzej Siewior
2015-03-17 1:53 ` Mike Galbraith
2015-03-17 4:45 ` Mike Galbraith
2015-04-10 14:15 ` Sebastian Andrzej Siewior
2015-04-10 14:24 ` Mike Galbraith
2015-04-10 14:28 ` Mike Galbraith
2015-04-11 13:15 ` Mike Galbraith
2015-04-11 13:36 ` Mike Galbraith
2015-04-11 14:22 ` Mike Galbraith
2015-04-13 9:43 ` Sebastian Andrzej Siewior
2015-04-13 9:41 ` Sebastian Andrzej Siewior
2015-02-18 14:09 ` [patch-3.18.7-rt1] snd/pcm: fix snd_pcm_stream_lock*() irqs_disabled() splats Mike Galbraith
2015-02-25 14:08 ` Sebastian Andrzej Siewior
2015-02-18 15:05 ` [patch-3.18.7-rt1]sunrpc: make svc_xprt_do_enqueue() use get_cpu_light() Mike Galbraith
2015-02-25 14:14 ` Sebastian Andrzej Siewior
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=1424258514.3819.39.camel@gmail.com \
--to=umgwanakikbuti@gmail.com \
--cc=bigeasy@linutronix.de \
--cc=jkacur@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=rostedt@goodmis.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).