Skip to contentSkip to conversation

Nasty suprise with uptime

PATCH Petr Vandrovec 1 participant 1 message Nov 1, 2001

lore
Share & tools
lore
#0 lore raw

Review

Quoted 8 lines · Tim Schmielau
(quoted diff) +8 -0
+   static unsigned long jiffies_hi = 0;
+   static unsigned long jiffies_last = INITIAL_JIFFIES;
+   unsigned long jiffies_tmp;
+
+   jiffies_tmp = jiffies;   /* avoid races */
+   if (jiffies_tmp < jiffies_last)   /* We have a wrap */
+       jiffies_hi++;
+   jiffies_last = jiffies_tmp;

There is very small race - if two processes will call get_jiffies64() at same time, they can both happen to test jiffies_tmp < jiffies_last with old jiffies_last - incrementing jiffies_hi twice :-( This race window is only few microseconds every 497 days, but if we want correct kernel...
Best regards,
Petr Vandrovec [email protected]