kernel 2.3.31 seems to busy wait for sleep < 2 msec, is this not a bad

Gautam H Thaker (gthaker@atl.lmco.com)
Wed, 29 Dec 1999 13:45:58 -0500



Recently someone on the ACE/TAO list pointed me to Linux 2.3.x
development kernels that are being modified to improve scheduler
determinism. When I started to look around Linux 2.3.31 code I noted
this bit of "busy wait" for sleeps < 2 msec using nanosleep().

Frankly, either I don't understand something or this is rather not
good.
One can have a 100% CPU bound machine if doing

for(;;){
nanosleep(2msec);
gettimeofday(args);
}

while:

for(;;){
nanosleep(3msec);
gettimeofday(args);
}

would be 99+% idle!

I still don't know why modifications that KURT group has (called UTIME
patch)
http://hegel.ittc.ukans.edu/projects/kurt/index.html are not being
used.
Below seems to be a much worse hack.

from file kernel/sched.c in Linux 2.3.31 kernel.

Anyway, happy holidays. Gautam Thaker (gthaker@atl.lmco.com)

From 2.3.31 kernel sources:
asmlinkage long sys_nanosleep(struct timespec *rqtp, struct timespec
*rmtp)
{
struct timespec t;
unsigned long expire;

if(copy_from_user(&t, rqtp, sizeof(struct timespec)))
return -EFAULT;

if (t.tv_nsec >= 1000000000L || t.tv_nsec < 0 || t.tv_sec < 0)
return -EINVAL;

if (t.tv_sec == 0 && t.tv_nsec <= 2000000L &&
current->policy != SCHED_OTHER)
{
/*
* Short delay requests up to 2 ms will be handled with
* high precision by a busy wait for all real-time
processes.
*
* Its important on SMP not to do this holding locks.
*/
udelay((t.tv_nsec + 999) / 1000);
return 0;
}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/