linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Ingo Molnar <mingo@redhat.com>, Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	linux-kernel@vger.kernel.org, Kirill Tkhai <tkhai@yandex.ru>
Subject: [PATCH 1/1] sched: make finish_task_switch() return struct rq *
Date: Thu, 9 Oct 2014 21:32:32 +0200	[thread overview]
Message-ID: <20141009193232.GB5408@redhat.com> (raw)
In-Reply-To: <20141009193207.GA5408@redhat.com>

Both callers of finish_task_switch() need to recalculate this_rq()
and pass it as an argument, plus __schedule() does this again after
context_switch().

It would be simpler to call this_rq() once in finish_task_switch()
and return the this rq to the callers.

Note: probably "int cpu" in __schedule() should die; it is not used
and both rcu_note_context_switch() and wq_worker_sleeping() do not
really need this argument.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 kernel/sched/core.c |   37 +++++++++++++++----------------------
 1 files changed, 15 insertions(+), 22 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index cfe9905..3bfbd3d 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2200,10 +2200,16 @@ prepare_task_switch(struct rq *rq, struct task_struct *prev,
  * so, we finish that here outside of the runqueue lock. (Doing it
  * with the lock held can cause deadlocks; see schedule() for
  * details.)
+ *
+ * The context switch have flipped the stack from under us and restored the
+ * local variables which were saved when this task called schedule() in the
+ * past. prev == current is still correct but we need to recalculate this_rq
+ * because prev may have moved to another CPU.
  */
-static void finish_task_switch(struct rq *rq, struct task_struct *prev)
+static struct rq *finish_task_switch(struct task_struct *prev)
 	__releases(rq->lock)
 {
+	struct rq *rq = this_rq();
 	struct mm_struct *mm = rq->prev_mm;
 	long prev_state;
 
@@ -2243,6 +2249,7 @@ static void finish_task_switch(struct rq *rq, struct task_struct *prev)
 	}
 
 	tick_nohz_task_switch(current);
+	return rq;
 }
 
 #ifdef CONFIG_SMP
@@ -2281,8 +2288,7 @@ asmlinkage __visible void schedule_tail(struct task_struct *prev)
 
 	/* finish_task_switch() drops rq->lock and enables preemtion */
 	preempt_disable();
-	rq = this_rq();
-	finish_task_switch(rq, prev);
+	rq = finish_task_switch(prev);
 	post_schedule(rq);
 	preempt_enable();
 
@@ -2291,10 +2297,9 @@ asmlinkage __visible void schedule_tail(struct task_struct *prev)
 }
 
 /*
- * context_switch - switch to the new MM and the new
- * thread's register state.
+ * context_switch - switch to the new MM and the new thread's register state.
  */
-static inline void
+static inline struct rq *
 context_switch(struct rq *rq, struct task_struct *prev,
 	       struct task_struct *next)
 {
@@ -2335,14 +2340,9 @@ context_switch(struct rq *rq, struct task_struct *prev,
 	context_tracking_task_switch(prev, next);
 	/* Here we just switch the register state and the stack. */
 	switch_to(prev, next, prev);
-
 	barrier();
-	/*
-	 * this_rq must be evaluated again because prev may have moved
-	 * CPUs since it called schedule(), thus the 'rq' on its stack
-	 * frame will be invalid.
-	 */
-	finish_task_switch(this_rq(), prev);
+
+	return finish_task_switch(prev);
 }
 
 /*
@@ -2802,15 +2802,8 @@ need_resched:
 		rq->curr = next;
 		++*switch_count;
 
-		context_switch(rq, prev, next); /* unlocks the rq */
-		/*
-		 * The context switch have flipped the stack from under us
-		 * and restored the local variables which were saved when
-		 * this task called schedule() in the past. prev == current
-		 * is still correct, but it can be moved to another cpu/rq.
-		 */
-		cpu = smp_processor_id();
-		rq = cpu_rq(cpu);
+		rq = context_switch(rq, prev, next); /* unlocks the rq */
+		cpu = rq->cpu;
 	} else
 		raw_spin_unlock_irq(&rq->lock);
 
-- 
1.5.5.1



  reply	other threads:[~2014-10-09 19:36 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-07 19:50 [PATCH 0/1] sched: fix the PREEMPT_ACTIVE check in __trace_sched_switch_state() Oleg Nesterov
2014-10-07 19:51 ` [PATCH 1/1] " Oleg Nesterov
2014-10-10  9:54   ` Peter Zijlstra
2014-10-10  9:56     ` Peter Zijlstra
2014-10-28 11:05   ` [tip:sched/core] sched: Fix " tip-bot for Oleg Nesterov
2014-10-08  8:00 ` [PATCH 0/1] sched: fix " Peter Zijlstra
2014-10-08 18:33   ` [PATCH 0/2] (Was: sched: fix the PREEMPT_ACTIVE check in __trace_sched_switch_state()) Oleg Nesterov
2014-10-08 18:33     ` [PATCH 1/2] sched: schedule_tail() should disable preemption Oleg Nesterov
2014-10-08 19:36       ` [PATCH v2 " Oleg Nesterov
2014-10-08 21:37         ` Kirill Tkhai
2014-10-09 14:57           ` Oleg Nesterov
2014-10-09 15:17             ` Peter Zijlstra
2014-10-09 16:57               ` Oleg Nesterov
2014-10-09 17:28                 ` Peter Zijlstra
2014-10-09 17:32                   ` Peter Zijlstra
2014-10-09 17:55                     ` Oleg Nesterov
2014-10-28 11:06         ` [tip:sched/core] sched: Fix schedule_tail() to " tip-bot for Oleg Nesterov
2014-10-08 18:33     ` [PATCH 2/2] sched: kill task_preempt_count() Oleg Nesterov
2014-10-28 11:06       ` [tip:sched/core] sched: Kill task_preempt_count() tip-bot for Oleg Nesterov
2014-10-09 19:32 ` [PATCH 0/1] sched: make finish_task_switch() return struct rq * Oleg Nesterov
2014-10-09 19:32   ` Oleg Nesterov [this message]
2014-10-10 10:06     ` [PATCH 1/1] " Peter Zijlstra
2014-10-10 17:06       ` Oleg Nesterov
2014-10-10 20:32         ` Peter Zijlstra
2014-10-14 17:57           ` Oleg Nesterov
2014-10-28 11:06     ` [tip:sched/core] sched: Make finish_task_switch() return ' struct rq *' tip-bot for Oleg Nesterov

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=20141009193232.GB5408@redhat.com \
    --to=oleg@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tkhai@yandex.ru \
    /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).