Skip to contentSkip to conversation

sched: finish fixing kthread_bind()

PATCH New Mike Galbraith 1 participant 1 message Nov 22, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched: finish fixing kthread_bind()

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.

Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>

LKML-Reference: <new-submission>

---
 kernel/sched.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
kernel/sched.c +5 -3
Index: 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);