Re: About the timer in linux-kernel

Robert Wuest (rwuest@sire.vt.com)
Fri, 08 Aug 1997 05:36:01 -0500


Benoit ROBINET wrote:
>
> I would like to implement timers that allow to go to sleep for a shorter
> time than a hundredth of second (which is the unit of jiffies).
> I know I could use udelay() function, but I must say that I don't really
> want to, because I think udelay() blocks the whole kernel when
> working...
> I am highly frustrated because I have a Pentium Pro 200, and I don't
> really see how to be more accurate than hundredth of seconds...
> Could anyone help me ?
> Thanks, and regards
>
> Benoit ROBINET

This is my understanding (someone correct me if I am wrong):

If you really want to go to "sleep", the smallest amount you can delay
is one clock tick, assuming nothing else is running. On the Intel
platform, that is 10 mS.

You can use select() to get uS timing. I've never really eveluated the
precision of this, but the following function does use select() that
way:

int delay_us(int microseconds)
{
struct timeval tv;

if( microseconds >= 1000000 )
{
tv.tv_sec = microseconds % 1000000;
tv.tv_usec = microseconds / 1000000;
}
else
{
tv.tv_sec = 0;
tv.tv_usec = microseconds;
}
select (0,0,0,0,&tv); /* block 'til timeout */
return 0;
}

I'm guessing that when select blocks, you lose your timeslice. Can
anyone tell me what this is really doing. (The program I needed this
for works, so I've never spent any more time on it).

-- 
Robert Wuest, PE                Empowered           Kemet Electronics
Sirius Engineering Company         by           robertwuest@kemet.com
mailto:rwuest@sire.vt.com        Linux