[patch] sched: finish fixing kthread_bind()

From: Mike Galbraith
Date: Sun Nov 22 2009 - 07:13:49 EST



sched: finish fixing kthread_bind()

kthread_bind() diddles task state without the task's runqueue locked,
which is against the rules. Lock the task's runqueue, and update both
runqueue clocks in the event that the task is being bound to a remote cpu.

Signed-off-by: Mike Galbraith <efault@xxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxx>
Cc: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
LKML-Reference: <new-submission>

---
kernel/sched.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

Index: linux-2.6/kernel/sched.c
===================================================================
--- linux-2.6.orig/kernel/sched.c
+++ linux-2.6/kernel/sched.c
@@ -2007,7 +2007,7 @@ static inline void check_class_changed(s
*/
void kthread_bind(struct task_struct *p, unsigned int cpu)
{
- struct rq *rq = cpu_rq(cpu);
+ struct rq *rq, *dest_rq = cpu_rq(cpu);
unsigned long flags;

/* Must have done schedule() in kthread() before we set_task_cpu */
@@ -2016,13 +2016,15 @@ void kthread_bind(struct task_struct *p,
return;
}

- spin_lock_irqsave(&rq->lock, flags);
+ rq = task_rq_lock(p, &flags);
update_rq_clock(rq);
+ if (rq != dest_rq)
+ update_rq_clock(dest_rq);
set_task_cpu(p, cpu);
p->cpus_allowed = cpumask_of_cpu(cpu);
p->rt.nr_cpus_allowed = 1;
p->flags |= PF_THREAD_BOUND;
- spin_unlock_irqrestore(&rq->lock, flags);
+ task_rq_unlock(rq, &flags);
}
EXPORT_SYMBOL(kthread_bind);



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/