Skip to contentSkip to conversation

ohci : strange looking use of round_jiffies_relative. possible bug ?

PATCH In review Richard Kennedy 4 participants 7 messages Mar 26, 2008 – Mar 27, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

I was looking at the uses of round_jiffies and noticed that the ohci unlink_watchdog_func() calls mod_timer(&ohci->unlink_watchdog, round_jiffies_relative(HZ));

Which looks a bit strange as it will set the timer to 0 <= t < HZ. Reading the comments I think that is really is expecting to setup timer to (now + 1s)

mod_timer(&ohci->unlink_watchdog, round_jiffies(jiffies + HZ));

If this is not true then perhaps it needs a comment to explain what it _is_ trying to do, because it's got me baffled ;)

Cheers
Richard

maintainer
#1 lore raw
Quoted 4 lines · Richard Kennedy

I was looking at the uses of round_jiffies and noticed that the ohci unlink_watchdog_func() calls mod_timer(&ohci->unlink_watchdog, round_jiffies_relative(HZ));

Quoted 8 lines

Which looks a bit strange as it will set the timer to 0 <= t < HZ. Reading the comments I think that is really is expecting to setup timer to (now + 1s)

mod_timer(&ohci->unlink_watchdog, round_jiffies(jiffies + HZ));

If this is not true then perhaps it needs a comment to explain what it _is_ trying to do, because it's got me baffled ;)

I'd say it's a bug. Or rather a pair of bugs, since that mod_timer() call appears in two places.

Alan Stern

#2 lore raw
Quoted 12 lines · Alan Stern
Quoted 10 lines · Richard Kennedy

I was looking at the uses of round_jiffies and noticed that the ohci unlink_watchdog_func() calls mod_timer(&ohci->unlink_watchdog, round_jiffies_relative(HZ));

Which looks a bit strange as it will set the timer to 0 <= t < HZ. Reading the comments I think that is really is expecting to setup timer to (now + 1s)

mod_timer(&ohci->unlink_watchdog, round_jiffies(jiffies + HZ));

Quoted 8 lines
Quoted 2 lines

If this is not true then perhaps it needs a comment to explain what it _is_ trying to do, because it's got me baffled ;)

I'd say it's a bug. Or rather a pair of bugs, since that mod_timer() call appears in two places.

Alan Stern

Thanks. In that case I'll post a patch.
Richard

#3 lore raw
Quoted 8 lines · Richard Kennedy
Quoted 6 lines · Alan Stern
Quoted 4 lines · Richard Kennedy

I was looking at the uses of round_jiffies and noticed that the ohci unlink_watchdog_func() calls mod_timer(&ohci->unlink_watchdog, round_jiffies_relative(HZ));

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Which looks a bit strange as it will set the timer to 0 <= t < HZ. Reading the comments I think that is really is expecting to setup timer to (now + 1s)

mod_timer(&ohci->unlink_watchdog, round_jiffies(jiffies + HZ));

If this is not true then perhaps it needs a comment to explain what it _is_ trying to do, because it's got me baffled ;)

Yes, my intent there was a roughly 1 second delay. You're correct, it's wrong.

Quoted 2 lines
Quoted 2 lines

I'd say it's a bug. Or rather a pair of bugs, since that mod_timer() call appears in two places.

Yup.

Mike

#4 lore raw
Quoted 7 lines · Mike Nuss
Quoted 2 lines · Richard Kennedy
Quoted 2 lines

I'd say it's a bug. Or rather a pair of bugs, since that mod_timer() call appears in two places.

Yup.

Although ... one specific to the Compaq ZF Micro chipset, so it's a bug with rather limited impact. Do Not Panic.

#5 lore raw

PATCH 1/1 usb ohci : fix 2 timers to fire at jiffies + 1s

In reply to Alan Stern

Code inspection discovered in 2 places timers were being incorrectly setup using round_jiffies_relative(HZ). The timer would then fire at time (0 <= T < HZ).

Fix them to use round_jiffies(jiffies + HZ);

---

compiled on latest v2.6.25-rc7-11 git head but not otherwise tested. Richard

drivers/usb/host/ohci-hcd.c +1 -1
index dd4798e..33f1c1c 100644
@@ -467,7 +467,7 @@ static void unlink_watchdog_func(unsigned long _ohci)
 out:
 	kfree(seen);
 	if (ohci->eds_scheduled)
-		mod_timer(&ohci->unlink_watchdog, round_jiffies_relative(HZ));
+		mod_timer(&ohci->unlink_watchdog, round_jiffies(jiffies + HZ));
 done:
 	spin_unlock_irqrestore(&ohci->lock, flags);
 }
drivers/usb/host/ohci-q.c +1 -1
index 5181732..9c9f3b5 100644
@@ -169,7 +169,7 @@ static int ed_schedule (struct ohci_hcd *ohci, struct ed *ed)
 	if (quirk_zfmicro(ohci)
 			&& (ed->type == PIPE_INTERRUPT)
 			&& !(ohci->eds_scheduled++))
-		mod_timer(&ohci->unlink_watchdog, round_jiffies_relative(HZ));
+		mod_timer(&ohci->unlink_watchdog, round_jiffies(jiffies + HZ));
 	wmb ();
 
 	/* we care about rm_list when setting CLE/BLE in case the HC was at
Acked-by on v1 1/1
#6 lore raw

Re: [patch] usb ohci : fix 2 timers to fire at jiffies + 1s

Quoted 7 lines · Richard Kennedy

Code inspection discovered in 2 places timers were being incorrectly setup using round_jiffies_relative(HZ). The timer would then fire at time (0 <= T < HZ).

Fix them to use round_jiffies(jiffies + HZ);

Quoted 33 lines

---

compiled on latest v2.6.25-rc7-11 git head but not otherwise tested. Richard

drivers/usb/host/ohci-hcd.c +1 -1
index dd4798e..33f1c1c 100644
@@ -467,7 +467,7 @@ static void unlink_watchdog_func(unsigned long _ohci)
 out:
 	kfree(seen);
 	if (ohci->eds_scheduled)
-		mod_timer(&ohci->unlink_watchdog, round_jiffies_relative(HZ));
+		mod_timer(&ohci->unlink_watchdog, round_jiffies(jiffies + HZ));
 done:
 	spin_unlock_irqrestore(&ohci->lock, flags);
 }
drivers/usb/host/ohci-q.c +1 -1
index 5181732..9c9f3b5 100644
@@ -169,7 +169,7 @@ static int ed_schedule (struct ohci_hcd *ohci, struct ed *ed)
 	if (quirk_zfmicro(ohci)
 			&& (ed->type == PIPE_INTERRUPT)
 			&& !(ohci->eds_scheduled++))
-		mod_timer(&ohci->unlink_watchdog, round_jiffies_relative(HZ));
+		mod_timer(&ohci->unlink_watchdog, round_jiffies(jiffies + HZ));
 	wmb ();
 
 	/* we care about rm_list when setting CLE/BLE in case the HC was at