Skip to contentSkip to conversation

nanosleep() granularity bumps up in 2.5.64 (was: [PATCH]

Linux-ia64 Eric Piel 5 participants 5 messages Mar 14, 2003 – Mar 17, 2003 Timekeeping, clocksource core, NTP, alarmtimer

lore
Share & tools
lore

Eric Piel

author
#0 lore raw
Quoted 1 line · David Mosberger

Are you running ntp?

Yes (I hadn't noticed it) but it was not connected to any server and disabling it doesn't change the results.

Quoted 13 lines

On 2.5:

        $ time sleep 16
        real    0m16.002s
        user    0m0.001s
        sys     0m0.002s
        $ time sleep 16.02
        real    0m25.189s
        user    0m0.000s
        sys     0m0.001s
Quoted 4 lines

So clearly something very strange is going on. My suspicion is that the bug was introduced back when x86 switched from 100Hz to 1000Hz ticks, but that's just a guess. Eric, would you be able/willing/interested to look into this?

Sure, I aim at porting the high resolution timers but any annoying bug related to the time can be interesting to remove.

Coincidently Vita has just reported a bug on the lkml which, after a closer look, seems to be the same:

Quoted 3 lines

When playing with select() timeout values I found that granularity
of nanosleep() in 2.5.64 kernel bumps to 256 msec. Trying to get finer granularity it ends up sleeping to the next multiple of 256 msec

From what I understand their is a bug in the timers that causes a big granularity. The case of Vita is a very good example. Also, after 16s it seems the granuality (slowly?!) jumps from 1/64th s to 16s! :
sleep requested time obtained

14.000000000     14.006201744
15.000000000     15.006647110
16.000000000     16.007089615
17.000000000     18.742679596
18.000000000     32.014190674
19.000000000     32.014190674
20.000000000     32.014190674

I think lines like that from patch-2.5.64 are very suspicious to be related to the bug:
+ 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;

Any idea/sugestion/patch is welcomed. Whatever, I will try to fix this as soon as I'm back from my week end :-)

Eric

#1 lore raw

Re: [Linux-ia64] Re: [BUG] nanosleep() granularity bumps up in 2.5.64 (was: [PATCH] settimeofday() n

Quoted 10 lines · Eric Piel

I think lines like that from patch-2.5.64 are very suspicious to be related to the bug:

(quoted diff) +5 -0
+	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;

(quoted diff) +1 -0
+	base->tv5.index = (INITIAL_JIFFIES >> (TVR_BITS+3*TVN_BITS)) &

TVN_MASK;

No, I don't think so. Those lines are for starting `jiffies' at a very high number so we spot jiffie-wrap bugs early on.

Signature · 3 lines
"It's not Hollywood.  War is real, war is primarily not about defeat or
victory, it is about death.  I've seen thousands and thousands of dead bodies.
Do you think I want to have an academic debate on this subject?" -- Robert Fisk
#2 lore raw
In reply to Eric Piel
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Eric Piel

Eric> Sure, I aim at porting the high resolution timers but any Eric> annoying bug related to the time can be interesting to remove.

Great! It would be great to have someone who can focus on that.

Eric> Any idea/sugestion/patch is welcomed. Whatever, I will try to Eric> fix this as soon as I'm back from my week end :-)

Does the x86 show the same behavior? That would be a useful start to narrow down the problem.

	--david
#3 lore raw

Re: [Linux-ia64] Re: [BUG] nanosleep() granularity bumps up in 2.5.64 (was: [PATCH] settimeofday() n

In reply to Eric Piel
Quoted 14 lines · Matthew Wilcox
Quoted 10 lines · Eric Piel

I think lines like that from patch-2.5.64 are very suspicious to be related to the bug:

(quoted diff) +5 -0
+	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;

(quoted diff) +1 -0
+	base->tv5.index = (INITIAL_JIFFIES >> (TVR_BITS+3*TVN_BITS)) &

TVN_MASK;

No, I don't think so. Those lines are for starting `jiffies' at a very high number so we spot jiffie-wrap bugs early on.

The nanosleep() bug narrowed down to 2.5.63-bk2. That's version, the "initial
jiffies" patch went in. And yes, it's on i686 machine.

Cheers,
Vita

#4 lore raw

[Linux-ia64] Re: [BUG] nanosleep() granularity bumps up in 2.5.64

In reply to Eric Piel
Quoted 16 lines · Vitezslav Samel
Quoted 14 lines · Matthew Wilcox
Quoted 10 lines · Eric Piel

I think lines like that from patch-2.5.64 are very suspicious to be related to the bug:

(quoted diff) +5 -0
+	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;

(quoted diff) +1 -0
+	base->tv5.index = (INITIAL_JIFFIES >> (TVR_BITS+3*TVN_BITS)) &

TVN_MASK;

No, I don't think so. Those lines are for starting `jiffies' at a very high number so we spot jiffie-wrap bugs early on.

Quoted 2 lines

The nanosleep() bug narrowed down to 2.5.63-bk2. That's version, the "initial
jiffies" patch went in. And yes, it's on i686 machine.

You can easily check whether it's connected with this change by setting INITIAL_JIFFIES to zero. This should exactly recover the previous situation.
I.e., something like the following (untested, hand-crafted) patch:

include/linux/time.h +1 -1
@@ -28,7 +28,7 @@
  * Have the 32 bit jiffies value wrap 5 minutes after boot
  * so jiffies wrap bugs show up earlier.
  */
- #define INITIAL_JIFFIES ((unsigned int) (-300*HZ))
+ #define INITIAL_JIFFIES 0
 
 /*
  * Change timeval to jiffies, trying to avoid the

Tim