[lug] High resolution timers
Ed Hill
ed at eh3.com
Fri Feb 21 13:01:06 MST 2003
On Fri, 2003-02-21 at 10:55, Steve Sullivan wrote:
> Hi,
> I'm interested in running a high resolution timer (1 microsecond or better)
> with standard redhat 8 or suse 8.1, not with a RT linux system.
> Has anyone done this?
> What hardware timer would you recommend?
> What software did you need?
I've needed microsecond timing (NOT sub-micro) for an oddball device
driver and was satisfied with gettimeofday(). It can easily provide 1us
resolution without any special hardware (or RT kernel extensions) on
most modern machines:
http://www.ibiblio.org/pub/Linux/docs/HOWTO/mini/other-formats/html_single/IO-Port-Programming.html#s4
The code below shows clear differences on my PIII-900 laptop and an
Athlon 1.2Ghz workstation. So obviously this approach will depend on
your hardware.
hth,
Ed
===
#include <stdio.h>
#include <sys/time.h>
int
main( int argc, char **argv ) {
struct timeval tv, tvo;
long i = 0;
while(1) {
++i;
i = i % 10;
if (!i)
usleep(i);
gettimeofday(&tv, NULL);
if ( (tv.tv_sec == tvo.tv_sec) &&
(tv.tv_usec == tvo.tv_usec) )
printf("%ld same!\n", i);
else
printf(".");
tvo.tv_sec = tv.tv_sec;
tvo.tv_usec = tv.tv_usec;
}
return 0;
}
--
Edward H. Hill III, PhD
Post-Doctoral Researcher | Email: ed at eh3.com, ehill at mines.edu
Division of ESE | URLs: http://www.eh3.com
Colorado School of Mines | http://cesep.mines.edu/people/hill.htm
Golden, CO 80401 | Phones: 303-384-2094, 303-273-3483
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20030221/fb1799cc/attachment.pgp>
More information about the LUG
mailing list