diff options
author | Peter Zijlstra <peterz@infradead.org> | 2015-06-11 08:46:39 -0400 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2015-06-18 18:25:26 -0400 |
commit | 4c9a4bc89a9cca8128bce67d6bc8870d6b7ee0b2 (patch) | |
tree | abb5e04295a140ebe7c12ed16c6c8e70da8a33b1 /kernel/sched | |
parent | dbc7f069b93a249340e974d6e8f55656280d8701 (diff) |
sched: Allow balance callbacks for check_class_changed()
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: Mike Galbraith <umgwanakikbuti@gmail.com>
Signed-off-by: Peter 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.org
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'kernel/sched')
-rw-r--r-- | kernel/sched/core.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/kernel/sched/core.c b/kernel/sched/core.c index b610ef9e522f..ef546e349e75 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c | |||
@@ -1001,7 +1001,11 @@ inline int task_curr(const struct task_struct *p) | |||
1001 | } | 1001 | } |
1002 | 1002 | ||
1003 | /* | 1003 | /* |
1004 | * Can drop rq->lock because from sched_class::switched_from() methods drop it. | 1004 | * switched_from, switched_to and prio_changed must _NOT_ drop rq->lock, |
1005 | * use the balance_callback list if you want balancing. | ||
1006 | * | ||
1007 | * this means any call to check_class_changed() must be followed by a call to | ||
1008 | * balance_callback(). | ||
1005 | */ | 1009 | */ |
1006 | static inline void check_class_changed(struct rq *rq, struct task_struct *p, | 1010 | static inline void check_class_changed(struct rq *rq, struct task_struct *p, |
1007 | const struct sched_class *prev_class, | 1011 | const struct sched_class *prev_class, |
@@ -1010,7 +1014,7 @@ static inline void check_class_changed(struct rq *rq, struct task_struct *p, | |||
1010 | if (prev_class != p->sched_class) { | 1014 | if (prev_class != p->sched_class) { |
1011 | if (prev_class->switched_from) | 1015 | if (prev_class->switched_from) |
1012 | prev_class->switched_from(rq, p); | 1016 | prev_class->switched_from(rq, p); |
1013 | /* Possble rq->lock 'hole'. */ | 1017 | |
1014 | p->sched_class->switched_to(rq, p); | 1018 | p->sched_class->switched_to(rq, p); |
1015 | } else if (oldprio != p->prio || dl_task(p)) | 1019 | } else if (oldprio != p->prio || dl_task(p)) |
1016 | p->sched_class->prio_changed(rq, p, oldprio); | 1020 | p->sched_class->prio_changed(rq, p, oldprio); |
@@ -1491,8 +1495,12 @@ ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags) | |||
1491 | 1495 | ||
1492 | p->state = TASK_RUNNING; | 1496 | p->state = TASK_RUNNING; |
1493 | #ifdef CONFIG_SMP | 1497 | #ifdef CONFIG_SMP |
1494 | if (p->sched_class->task_woken) | 1498 | if (p->sched_class->task_woken) { |
1499 | /* | ||
1500 | * XXX can drop rq->lock; most likely ok. | ||
1501 | */ | ||
1495 | p->sched_class->task_woken(rq, p); | 1502 | p->sched_class->task_woken(rq, p); |
1503 | } | ||
1496 | 1504 | ||
1497 | if (rq->idle_stamp) { | 1505 | if (rq->idle_stamp) { |
1498 | u64 delta = rq_clock(rq) - rq->idle_stamp; | 1506 | u64 delta = rq_clock(rq) - rq->idle_stamp; |
@@ -3100,7 +3108,11 @@ void rt_mutex_setprio(struct task_struct *p, int prio) | |||
3100 | 3108 | ||
3101 | check_class_changed(rq, p, prev_class, oldprio); | 3109 | check_class_changed(rq, p, prev_class, oldprio); |
3102 | out_unlock: | 3110 | out_unlock: |
3111 | preempt_disable(); /* avoid rq from going away on us */ | ||
3103 | __task_rq_unlock(rq); | 3112 | __task_rq_unlock(rq); |
3113 | |||
3114 | balance_callback(rq); | ||
3115 | preempt_enable(); | ||
3104 | } | 3116 | } |
3105 | #endif | 3117 | #endif |
3106 | 3118 | ||
@@ -3661,11 +3673,18 @@ change: | |||
3661 | } | 3673 | } |
3662 | 3674 | ||
3663 | check_class_changed(rq, p, prev_class, oldprio); | 3675 | check_class_changed(rq, p, prev_class, oldprio); |
3676 | preempt_disable(); /* avoid rq from going away on us */ | ||
3664 | task_rq_unlock(rq, p, &flags); | 3677 | task_rq_unlock(rq, p, &flags); |
3665 | 3678 | ||
3666 | if (pi) | 3679 | if (pi) |
3667 | rt_mutex_adjust_pi(p); | 3680 | rt_mutex_adjust_pi(p); |
3668 | 3681 | ||
3682 | /* | ||
3683 | * Run balance callbacks after we've adjusted the PI chain. | ||
3684 | */ | ||
3685 | balance_callback(rq); | ||
3686 | preempt_enable(); | ||
3687 | |||
3669 | return 0; | 3688 | return 0; |
3670 | } | 3689 | } |
3671 | 3690 | ||