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]

 



Hello,
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.

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.").

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.

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 different machine was a strong one, with 3Ghz CPU.

>From this results it seems that I cannot rely on this outb() for

creating a
microsec delay because it gives such different results on different
machines.
However , the results seems strange :
I have 2 almost similiar machines :
one gave 2.16 and one gave 1.4

Could it be that something in that machine caused it to do it slower
and gicv 2.16 microsec as an average?

I must empasize that "top" showed that there did not run something
heavy on
both these machines.(in terms of cpu and memory)

Any idea?

John Que

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[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