Skip to contentSkip to conversation

kernel/timer.c

DISCUSSION Wojciech Kromer 2 participants 7 messages Apr 11, 2003 – Apr 12, 2003

lore
Share & tools
lore
#0 lore raw

Anyone knows why tehere is a line:

expire = timespec_to_jiffies(&t) + (t.tv_sec || t.tv_nsec);

in kernel/timer.c sys_nanosleep
It adds additional time tick to expire. If anyone uses small HZ value (eg 100 which is default for arch-ppc) this causes aditional 10ms delay when calling nanosleep.

For me ( found by Andrzej Kass)
it should be:

expire = timespec_to_jiffies(&t) + !(t.tv_sec || t.tv_nsec);
//^^add extra tick if there is
// nothing in tv_sec and nothing in tv_nsec

--
* * * * * * * * * * * *
* per pedes ad astra! *
* * * * * * * * * * * * mailto:[email protected]

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

#1 lore raw
Quoted 9 lines

Anyone knows why tehere is a line:

expire = timespec_to_jiffies(&t) + (t.tv_sec || t.tv_nsec);

in kernel/timer.c sys_nanosleep
It adds additional time tick to expire. If anyone uses small HZ value (eg 100 which is default for arch-ppc) this causes aditional 10ms delay when calling nanosleep.

Yes, after a quick scan it looks like a bug to me. Anyone else?

Quoted 8 lines

For me ( found by Andrzej Kass)
it should be:

expire = timespec_to_jiffies(&t) + !(t.tv_sec || t.tv_nsec);
   //^^add extra tick if there is

// nothing in tv_sec and nothing in tv_nsec

hmm, why not just:
expire = timespec_to_jiffies(&t);
if tv_sec and tv_sec are zero, do you need to sleep at all?

Jocke

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

#2 lore raw
Quoted 10 lines

hmm, why not just:
expire = timespec_to_jiffies(&t);
if tv_sec and tv_sec are zero, do you need to sleep at all?

Jocke

sleep(0) could be defined as:
-schedule to next task if there is any (just call schedule() ) -sleep minimum value (1 jiffie)

default kernel (no timer patches) uses second definition,

there is special call schedule_timeout(MAX_SCHEDULE_TIMEOUT) which also calls schedule()

--
* * * * * * * * * * * *
* per pedes ad astra! *
* * * * * * * * * * * * mailto:[email protected]

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

#3 lore raw
Quoted 12 lines
Quoted 8 lines

hmm, why not just:
expire = timespec_to_jiffies(&t);
if tv_sec and tv_sec are zero, do you need to sleep at all?

Jocke

sleep(0) could be defined as:

(quoted diff) +0 -2
-schedule to next task if there is any (just call schedule() )
-sleep minimum value (1 jiffie)
Quoted 1 line

default kernel (no timer patches) uses second definition,

No, linux uses the first definition(or whatever schedule_timeout(0) does). If t is zero then expire also becomes zero.

Quoted 3 lines

there is special call schedule_timeout(MAX_SCHEDULE_TIMEOUT) which also calls schedule()

?

Jocke

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

#4 lore raw
Quoted 7 lines
Quoted 7 lines

sleep(0) could be defined as:

(quoted diff) +0 -2
-schedule to next task if there is any (just call schedule() )
-sleep minimum value (1 jiffie)
Quoted 8 lines
Quoted 3 lines

default kernel (no timer patches) uses second definition,

No, linux uses the first definition(or whatever schedule_timeout(0) does). If t is zero then expire also becomes zero.

maybe, my missunderstood

Quoted 4 lines
Quoted 4 lines

there is special call schedule_timeout(MAX_SCHEDULE_TIMEOUT) which also calls schedule()

see kernel/sched.c

so, anyone knows what linus.t says about adding one jiffie to every non-zero expire?

--
* * * * * * * * * * * *
* per pedes ad astra! *
* * * * * * * * * * * * mailto:[email protected]

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

#5 lore raw
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines

sleep(0) could be defined as:

(quoted diff) +0 -2
-schedule to next task if there is any (just call schedule() )
-sleep minimum value (1 jiffie)
Quoted 8 lines
Quoted 3 lines

default kernel (no timer patches) uses second definition,

No, linux uses the first definition(or whatever schedule_timeout(0) does). If t is zero then expire also becomes zero.

Quoted 4 lines

maybe, my missunderstood

so, anyone knows what linus.t says about adding one jiffie to every non-zero expire?

I think this is a bug. It should be enough to round up to nearest jiffie. Ask on the linux kernel list.

Jocke

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

#6 lore raw
Quoted 8 lines
Quoted 3 lines

so, anyone knows what linus.t says about adding one jiffie to every non-zero expire?

I think this is a bug. It should be enough to round up to nearest jiffie. Ask on the linux kernel list.

Jocke

Actually, I take that back. It's not a bug. schedule_timeout(x), x > 0 will wait somewere between x-1 and x jiffies. Therefore one must add an extra jiffie to make sure that you don't return too early.

Jocke

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/