Skip to contentSkip to conversation

fix nanosleep() granularity bumps

PATCH New Tim Schmielau 1 participant 1 message Mar 18, 2003

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix nanosleep() granularity bumps

Quoted 2 lines · Tim Schmielau

I've re-checked that the problem does not occur with the original "initial jiffies" patch for 2.4.

Stupid me - 2.4 with the patch has the same problem, it just takes 10x as long to show up, a range that was not covered by the testcase.

The actual problem is that I didn't fully understand the, well, 'elaborated' way of counting jiffies in the timer cascade:

When starting out with timer_jiffies=0, the timer cascade is (unneccessarily) triggered on the first timer interrupt, incrementing all the higher indices.
When starting with any other initial jiffies value, we miss that and end up with all higher indices being off by one.

Fix is as follows:

kernel/timer.c +8 -4
@@ -1183,10 +1183,14 @@
 
 	base->timer_jiffies = INITIAL_JIFFIES;
 	base->tv1.index = INITIAL_JIFFIES & TVR_MASK;
-	base->tv2.index = (INITIAL_JIFFIES >> TVR_BITS) & TVN_MASK;
-	base->tv3.index = (INITIAL_JIFFIES >> (TVR_BITS+TVN_BITS)) & TVN_MASK;
-	base->tv4.index = (INITIAL_JIFFIES >> (TVR_BITS+2*TVN_BITS)) & TVN_MASK;
-	base->tv5.index = (INITIAL_JIFFIES >> (TVR_BITS+3*TVN_BITS)) & TVN_MASK;
+	base->tv2.index = ((INITIAL_JIFFIES >> TVR_BITS)
+	                   + (INITIAL_JIFFIES!=0)) & TVN_MASK;
+	base->tv3.index = ((INITIAL_JIFFIES >> (TVR_BITS+TVN_BITS))
+	                   + (INITIAL_JIFFIES!=0)) & TVN_MASK;
+	base->tv4.index = ((INITIAL_JIFFIES >> (TVR_BITS+2*TVN_BITS))
+	                   + (INITIAL_JIFFIES!=0)) & TVN_MASK;
+	base->tv5.index = ((INITIAL_JIFFIES >> (TVR_BITS+3*TVN_BITS))
+	                   + (INITIAL_JIFFIES!=0)) & TVN_MASK;
 }
 
 static int __devinit timer_cpu_notify(struct notifier_block *self,

Sorry for all the trouble,
Tim