Commit dfa50b60 authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Ingo Molnar

sched: Make finish_task_switch() return 'struct rq *'

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: default avatarOleg Nesterov <oleg@redhat.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Cc: Kirill Tkhai <tkhai@yandex.ru>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: http://lkml.kernel.org/r/20141009193232.GB5408@redhat.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 1a43a14a
...@@ -2220,7 +2220,6 @@ prepare_task_switch(struct rq *rq, struct task_struct *prev, ...@@ -2220,7 +2220,6 @@ prepare_task_switch(struct rq *rq, struct task_struct *prev,
/** /**
* finish_task_switch - clean up after a task-switch * finish_task_switch - clean up after a task-switch
* @rq: runqueue associated with task-switch
* @prev: the thread we just switched away from. * @prev: the thread we just switched away from.
* *
* finish_task_switch must be called after the context switch, paired * finish_task_switch must be called after the context switch, paired
...@@ -2232,10 +2231,16 @@ prepare_task_switch(struct rq *rq, struct task_struct *prev, ...@@ -2232,10 +2231,16 @@ prepare_task_switch(struct rq *rq, struct task_struct *prev,
* so, we finish that here outside of the runqueue lock. (Doing it * so, we finish that here outside of the runqueue lock. (Doing it
* with the lock held can cause deadlocks; see schedule() for * with the lock held can cause deadlocks; see schedule() for
* details.) * 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) __releases(rq->lock)
{ {
struct rq *rq = this_rq();
struct mm_struct *mm = rq->prev_mm; struct mm_struct *mm = rq->prev_mm;
long prev_state; long prev_state;
...@@ -2275,6 +2280,7 @@ static void finish_task_switch(struct rq *rq, struct task_struct *prev) ...@@ -2275,6 +2280,7 @@ static void finish_task_switch(struct rq *rq, struct task_struct *prev)
} }
tick_nohz_task_switch(current); tick_nohz_task_switch(current);
return rq;
} }
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
...@@ -2313,8 +2319,7 @@ asmlinkage __visible void schedule_tail(struct task_struct *prev) ...@@ -2313,8 +2319,7 @@ asmlinkage __visible void schedule_tail(struct task_struct *prev)
/* finish_task_switch() drops rq->lock and enables preemtion */ /* finish_task_switch() drops rq->lock and enables preemtion */
preempt_disable(); preempt_disable();
rq = this_rq(); rq = finish_task_switch(prev);
finish_task_switch(rq, prev);
post_schedule(rq); post_schedule(rq);
preempt_enable(); preempt_enable();
...@@ -2323,10 +2328,9 @@ asmlinkage __visible void schedule_tail(struct task_struct *prev) ...@@ -2323,10 +2328,9 @@ asmlinkage __visible void schedule_tail(struct task_struct *prev)
} }
/* /*
* context_switch - switch to the new MM and the new * context_switch - switch to the new MM and the new thread's register state.
* thread's register state.
*/ */
static inline void static inline struct rq *
context_switch(struct rq *rq, struct task_struct *prev, context_switch(struct rq *rq, struct task_struct *prev,
struct task_struct *next) struct task_struct *next)
{ {
...@@ -2365,14 +2369,9 @@ context_switch(struct rq *rq, struct task_struct *prev, ...@@ -2365,14 +2369,9 @@ context_switch(struct rq *rq, struct task_struct *prev,
context_tracking_task_switch(prev, next); context_tracking_task_switch(prev, next);
/* Here we just switch the register state and the stack. */ /* Here we just switch the register state and the stack. */
switch_to(prev, next, prev); switch_to(prev, next, prev);
barrier(); barrier();
/*
* this_rq must be evaluated again because prev may have moved return finish_task_switch(prev);
* CPUs since it called schedule(), thus the 'rq' on its stack
* frame will be invalid.
*/
finish_task_switch(this_rq(), prev);
} }
/* /*
...@@ -2854,15 +2853,8 @@ static void __sched __schedule(void) ...@@ -2854,15 +2853,8 @@ static void __sched __schedule(void)
rq->curr = next; rq->curr = next;
++*switch_count; ++*switch_count;
context_switch(rq, prev, next); /* unlocks the rq */ rq = context_switch(rq, prev, next); /* unlocks the rq */
/* cpu = cpu_of(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);
} else } else
raw_spin_unlock_irq(&rq->lock); raw_spin_unlock_irq(&rq->lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment