Re: Sleep for about microsecond in a user space program in 2.6 or 2.4 kernel

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Aug 18, 2005 at 09:22:55AM -0400, John Que wrote:
> I want to use delays of 1 microsend on linux 2.4 or linux 2.6 kernel
> on x386 platform.
> 
> As we know, usleep depends on the HZ of the system.

It is?

> So both in  2.4 and in 2.6 we cannot achieve 1 microsec delay calling
> udelay (the man page of usleep says itslef that
> "Probably  not accurate on many machines down to the microsecond.").

You certainly can. RTFM, usleep(2) says in the NOTES section:

       This function is obsolete. Use nanosleep(2) or setitimer(2) instead.

> According to "Linux I/O port programming mini-HOWTO"
> (http://www.tldp.org/HOWTO/IO-P ort-Programming-2.html)
> you can use outb on 0x80 to create a dealy.

The outb() trick can't be used in userland, you're stalling the
complete machine by doing so!

> So I added this snippest of code
> and trird to use outb('a',0x80) for creating a sleep time in
>         resolution of microseconds thus:
> ............
> 
>        ioperm(0x80, 1, 1);
> 
>        for (i=0;i<10000;i++)
>                 outb('a',0x80);
> ............
> 
> On 3 machines (each of them had a different strength, one of the with
> 2.6
> kernel and the other two with 2.6 kernek) it gave a result of
> about 1.4 microsec for every such call, while on a differnet macine it
> gave a much
> higher average of 2.16 microsec.

That doesn't surprise me, the kernel is allowed to reschedule your
process during the for() loop, so depending on the system load, the
actual delay varies a lot.


Erik

-- 
Erik Mouw
J.A.K.Mouw@xxxxxxxxxxxxxx  mouw@xxxxxxxxxxxx

Attachment: signature.asc
Description: Digital signature


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux