Commit 070654cc authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ben Hutchings

sched: Allow balance callbacks for check_class_changed()

commit 4c9a4bc8 upstream.

In order to remove dropping rq->lock from the
switched_{to,from}()/prio_changed() sched_class methods, run the
balance callbacks after it.

We need to remove dropping rq->lock because its buggy,
suppose using sched_setattr()/sched_setscheduler() to change a running
task from FIFO to OTHER.

By the time we get to switched_from_rt() the task is already enqueued
on the cfs runqueues. If switched_from_rt() does pull_rt_task() and
drops rq->lock, load-balancing can come in and move our task @p to
another rq.

The subsequent switched_to_fair() still assumes @p is on @rq and bad
things will happen.

By using balance callbacks we delay the load-balancing operations
{rt,dl}x{push,pull} until we've done all the important work and the
task is fully set up.

Furthermore, the balance callbacks do not know about @p, therefore
they cannot get confused like this.
Reported-by: default avatarMike Galbraith <umgwanakikbuti@gmail.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Cc: ktkhai@parallels.com
Cc: rostedt@goodmis.org
Cc: juri.lelli@gmail.com
Cc: pang.xunlei@linaro.org
Cc: oleg@redhat.com
Cc: wanpeng.li@linux.intel.com
Link: http://lkml.kernel.org/r/20150611124742.615343911@infradead.orgSigned-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
[Conflicts: kernel/sched/core.c]
Signed-off-by: default avatarByungchul Park <byungchul.park@lge.com>
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent 0589c024
...@@ -999,6 +999,13 @@ inline int task_curr(const struct task_struct *p) ...@@ -999,6 +999,13 @@ inline int task_curr(const struct task_struct *p)
return cpu_curr(task_cpu(p)) == p; return cpu_curr(task_cpu(p)) == p;
} }
/*
* switched_from, switched_to and prio_changed must _NOT_ drop rq->lock,
* use the balance_callback list if you want balancing.
*
* this means any call to check_class_changed() must be followed by a call to
* balance_callback().
*/
static inline void check_class_changed(struct rq *rq, struct task_struct *p, static inline void check_class_changed(struct rq *rq, struct task_struct *p,
const struct sched_class *prev_class, const struct sched_class *prev_class,
int oldprio) int oldprio)
...@@ -1500,8 +1507,12 @@ ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags) ...@@ -1500,8 +1507,12 @@ ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)
p->state = TASK_RUNNING; p->state = TASK_RUNNING;
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
if (p->sched_class->task_woken) if (p->sched_class->task_woken) {
/*
* XXX can drop rq->lock; most likely ok.
*/
p->sched_class->task_woken(rq, p); p->sched_class->task_woken(rq, p);
}
if (rq->idle_stamp) { if (rq->idle_stamp) {
u64 delta = rq_clock(rq) - rq->idle_stamp; u64 delta = rq_clock(rq) - rq->idle_stamp;
...@@ -3052,7 +3063,11 @@ void rt_mutex_setprio(struct task_struct *p, int prio) ...@@ -3052,7 +3063,11 @@ void rt_mutex_setprio(struct task_struct *p, int prio)
check_class_changed(rq, p, prev_class, oldprio); check_class_changed(rq, p, prev_class, oldprio);
out_unlock: out_unlock:
preempt_disable(); /* avoid rq from going away on us */
__task_rq_unlock(rq); __task_rq_unlock(rq);
balance_callback(rq);
preempt_enable();
} }
#endif #endif
...@@ -3575,10 +3590,17 @@ static int __sched_setscheduler(struct task_struct *p, ...@@ -3575,10 +3590,17 @@ static int __sched_setscheduler(struct task_struct *p,
} }
check_class_changed(rq, p, prev_class, oldprio); check_class_changed(rq, p, prev_class, oldprio);
preempt_disable(); /* avoid rq from going away on us */
task_rq_unlock(rq, p, &flags); task_rq_unlock(rq, p, &flags);
rt_mutex_adjust_pi(p); rt_mutex_adjust_pi(p);
/*
* Run balance callbacks after we've adjusted the PI chain.
*/
balance_callback(rq);
preempt_enable();
return 0; return 0;
} }
......
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