Skip to contentSkip to conversation

sched: only update rq->clock while holding rq->lock

PATCH Peter Zijlstra 2 participants 3 messages Oct 15, 2008 – Oct 16, 2008

lore
Share & tools
lore
#0 lore raw

Vatsa,

you said someone would send a patch to this effect, I don't want to steal credit, but I think this patch is better posted sooner rather than later.

---

Subject: sched: only update rq->clock while holding rq->lock
From: Peter Zijlstra <[email protected]>
Date: Wed Oct 15 20:30:26 CEST 2008

Vatsa noticed rq->clock going funny and tracked it down to an update_rq_clock() outside a rq->lock section.

This is a problem because things like double_rq_lock() update the rq->clock value for both rqs. Therefore disabling interrupts isn't strong enough.

---
 kernel/sched.c |    6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
kernel/sched.c +1 -5
Index: linux-2.6/kernel/sched.c
===================================================================
@@ -4448,12 +4448,8 @@ need_resched_nonpreemptible:
 	if (sched_feat(HRTICK))
 		hrtick_clear(rq);
 
-	/*
-	 * Do the rq-clock update outside the rq lock:
-	 */
-	local_irq_disable();
+	spin_lock_irq(&rq->lock);
 	update_rq_clock(rq);
-	spin_lock(&rq->lock);
 	clear_tsk_need_resched(prev);
 
 	if (prev->state && !(preempt_count() & PREEMPT_ACTIVE)) {
#1 lore raw
Quoted 2 lines · Peter Zijlstra

Vatsa noticed rq->clock going funny and tracked it down to an update_rq_clock() outside a rq->lock section.

For the records, actually Brian King and David Kleikamp noticed this!

Signature · 2 lines
Regards,
vatsa
#2 lore raw
Quoted 5 lines · Srivatsa Vaddagiri
Quoted 2 lines · Peter Zijlstra

Vatsa noticed rq->clock going funny and tracked it down to an update_rq_clock() outside a rq->lock section.

For the records, actually Brian King and David Kleikamp noticed this!

Thanks Brian and Shaggy!