Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1234924 > unrolled thread

[RFC][PATCH 04/11] sched: Rework TASK_DEAD preemption exception

Started byPeter Zijlstra <peterz@infradead.org>
First post2015-09-29 11:50 +0200
Last post2015-09-29 17:20 +0200
Articles 3 — 3 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [RFC][PATCH 04/11] sched: Rework TASK_DEAD preemption exception Peter Zijlstra <peterz@infradead.org> - 2015-09-29 11:50 +0200
    Re: [RFC][PATCH 04/11] sched: Rework TASK_DEAD preemption exception Frederic Weisbecker <fweisbec@gmail.com> - 2015-09-29 15:50 +0200
    Re: [RFC][PATCH 04/11] sched: Rework TASK_DEAD preemption exception Steven Rostedt <rostedt@goodmis.org> - 2015-09-29 17:20 +0200

#1234924 — [RFC][PATCH 04/11] sched: Rework TASK_DEAD preemption exception

FromPeter Zijlstra <peterz@infradead.org>
Date2015-09-29 11:50 +0200
Subject[RFC][PATCH 04/11] sched: Rework TASK_DEAD preemption exception
Message-ID<qdZHQ-2IS-23@gated-at.bofh.it>
TASK_DEAD is special in that the final schedule call from do_exit()
must be done with preemption disabled.

This leads to a violation of our new scheduling invariant which states
that the preempt count should be 2. Move the check for TASK_DEAD out
of the debug check and use it to decrement the preempt count (from 2
to 1).

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 kernel/sched/core.c |   19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2955,12 +2955,8 @@ static inline void schedule_debug(struct
 #ifdef CONFIG_SCHED_STACK_END_CHECK
 	BUG_ON(unlikely(task_stack_end_corrupted(prev)));
 #endif
-	/*
-	 * Test if we are atomic. Since do_exit() needs to call into
-	 * schedule() atomically, we ignore that path. Otherwise whine
-	 * if we are scheduling when we should not.
-	 */
-	if (unlikely(in_atomic_preempt_off() && prev->state != TASK_DEAD)) {
+
+	if (unlikely(in_atomic_preempt_off())) {
 		__schedule_bug(prev);
 		preempt_count_set(PREEMPT_DISABLED);
 	}
@@ -3061,6 +3057,17 @@ static void __sched __schedule(void)
 	rcu_note_context_switch();
 	prev = rq->curr;
 
+	/*
+	 * do_exit() calls schedule() with preemption disabled as an exception;
+	 * however we must fix that up, otherwise the next task will see an
+	 * inconsistent preempt count.
+	 *
+	 * It also avoids the below schedule_debug() test from complaining
+	 * about this.
+	 */
+	if (unlikely(prev->state == TASK_DEAD))
+		preempt_enable_no_resched_notrace();
+
 	schedule_debug(prev);
 
 	if (sched_feat(HRTICK))


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1235068

FromFrederic Weisbecker <fweisbec@gmail.com>
Date2015-09-29 15:50 +0200
Message-ID<qe3s6-85D-17@gated-at.bofh.it>
In reply to#1234924
On Tue, Sep 29, 2015 at 11:28:29AM +0200, Peter Zijlstra wrote:
> TASK_DEAD is special in that the final schedule call from do_exit()
> must be done with preemption disabled.
> 
> This leads to a violation of our new scheduling invariant which states
> that the preempt count should be 2. Move the check for TASK_DEAD out
> of the debug check and use it to decrement the preempt count (from 2
> to 1).
> 
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>

Reviewed-by: Frederic Weisbecker <fweisbec@gmail.com>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1235214

FromSteven Rostedt <rostedt@goodmis.org>
Date2015-09-29 17:20 +0200
Message-ID<qe4Rb-1Nk-9@gated-at.bofh.it>
In reply to#1234924
On Tue, 29 Sep 2015 11:28:29 +0200
Peter Zijlstra <peterz@infradead.org> wrote:

> TASK_DEAD is special in that the final schedule call from do_exit()
> must be done with preemption disabled.
> 
> This leads to a violation of our new scheduling invariant which states
> that the preempt count should be 2. Move the check for TASK_DEAD out
> of the debug check and use it to decrement the preempt count (from 2
> to 1).
> 
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>

Reviewed-by: Steven Rostedt <rostedt@goodmis.org>

-- Steve
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web