[PATCH 1/3] sched/rt: Fix push_rt_task() to have the same checks as the callerdid

From: Steven Rostedt
Date: Tue Feb 12 2013 - 18:00:27 EST

From: "Steven Rostedt (Red Hat)" <rostedt@xxxxxxxxxxx>

Currently, push_rt_task() only pushes the task if it is lower
priority than the currently running task.

But it can be called for other reasons. Namely, if the current process
that is about to be preempted, is a real time task and is also pinned
to the CPU. This happens on wake up of high priority task. A check
is made in wake_up_rt() to see if the woken task can preempt the
task on its CPU, and the running task is not a pinned RT task. If
the task is pinned, and the woken task can migrate, it will try to
migrate it by calling push_rt_task().

Now in push_rt_task(), it will check if it can preempt the current
task but does not check if that task is pinned. If the woken task
is of higher priority, it wont try to migrate the woken task, even
if the other task is pinned. It will simply not push the task, which
is not consistent with the reason that push_rt_task() was called for
in the first place. Even for other callers of push_rt_task(), the task
should try to avoid preempting pinned RT tasks.

A helper routine is created call "ok_to_push_task()" that is now
used by both the wake_up_rt() and push_rt_task() code.

Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Signed-off-by: Steven Rostedt <rostedt@xxxxxxxxxxx>
kernel/sched/rt.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index c25de14..6f3108e 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -1613,6 +1613,14 @@ static struct task_struct *pick_next_pushable_task(struct rq *rq)
return p;

+static int ok_to_push_task(struct task_struct *p, struct task_struct *curr)
+ return p->nr_cpus_allowed > 1 &&
+ rt_task(curr) &&
+ (curr->nr_cpus_allowed < 2 ||
+ curr->prio <= p->prio);
* If the current CPU has more than one RT task, see if the non
* running task can migrate over to a CPU that is running a task
@@ -1642,7 +1650,7 @@ retry:
* higher priority than current. If that's the case
* just reschedule current.
- if (unlikely(next_task->prio < rq->curr->prio)) {
+ if (!ok_to_push_task(next_task, rq->curr)) {
return 0;
@@ -1807,10 +1815,7 @@ static void task_woken_rt(struct rq *rq, struct task_struct *p)
if (!task_running(rq, p) &&
!test_tsk_need_resched(rq->curr) &&
has_pushable_tasks(rq) &&
- p->nr_cpus_allowed > 1 &&
- rt_task(rq->curr) &&
- (rq->curr->nr_cpus_allowed < 2 ||
- rq->curr->prio <= p->prio))
+ ok_to_push_task(p, rq->curr))


Attachment: signature.asc
Description: This is a digitally signed message part