Re: poll/select timout accuracy

kwrohrer@ce.mediaone.net
Tue, 21 Jul 1998 09:46:01 -0500 (CDT)


And lo, Jean-Marie Sulmont saith unto me:
>
> Hello.
>
> I'm having problems with timer accuracy of both poll() and select()
> system calls on 2.1.xxx on an Intel P6 box where the cpu is clocked at
> 300Mhz. I'm joining a little program that demonstrates the problem.
> In two words, if you do:
> t1 = getclock();
> poll(0,0,10);
> t2 = getclock();
> then t2 - t1 is going to be 19.422559ms in avg. So the error is 9.42ms.
> The little program is computing the standard deviation and arithmetic mean.
> When the timeout given to poll is 100, the error drops to 9.18ms.
> When it is 550, it drops to 7.8ms. At 1second, the error is 6.553135ms.
>
> I'm using the real time 64 bits counter of the P6.
What is "you", your getclock() or your kernel?

> I've tried to read the sys_select() code but does not know what a jiffies
> is. The program works on Sun OK, showing a constant and consistant error.
"jiffies" is the clock value; I believe it gets incremented every 1/HZ
seconds by the timer interrupt.

> This is *very* ennoying. Anyone has an idea? What am I doing wrong?
Get the UTIME patch, apply it to an appropriate kernel, and rebuild
your kernel with UTIME enabled (and, preferably, APM disabled, so
that UTIME can rely on the cycle counter). UTIME is microsecond-
resolution timers; otherwise, you can only wake up from sleep/usleep/
nanosleep at a timer interrupt.

> The behaviour is exactly the same with select().
Yup. The system doesn't happen to get an interrupt which can trigger
the scheduler until the next scheduling interval, and the usual system
call overhead makes this the scheduling interval *after* the one you want.
Just as with sleep(2), you're guaranteed to sleep *at* *least* as long
as you asked for, unless interrupted. So a short-term/portable
solution is to just sleep for less time. The "right" solution is to
not rely on the OS to guarantee more than it really does, possibly
including patching the kernel to enable it to do what you want.

http://hegel.ittc.ukans.edu/projects/utime/ is your friend...

Keith (and pray the system load isn't too heavy...)

-- 
"The avalanche has already started; |Linux: http://www.linuxhq.com     |"Zooty,
it is too late for the pebbles to   |KDE:   http://www.kde.org         | zoot
vote." Kosh, "Believers", Babylon 5 |Keith: kwrohrer@enteract.com      | zoot!"
 www.midwinter.com/lurk/lurker.html |http://www.enteract.com/~kwrohrer | --Rebo

- 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.altern.org/andrebalsa/doc/lkml-faq.html