high accuracy timing options?
high accuracy timing options?
- Subject: high accuracy timing options?
- From: "Aaron Turner" <email@hidden>
- Date: Tue, 25 Mar 2008 22:31:33 -0700
I'm trying to implement a high speed (roughly 1usec accuracy) timer
for OS X in C. My process runs as root and it's perfectly acceptable
that I eat a large amount of CPU time.
There seems to be a few ways to do this:
1. Use the RDTSC available in the Intel/PPC cpus. Doesn't seem to be
reliable on my MacBook Pro though. Not sure if this is CPU scaling,
multi-core issues or what. It also seems to be incrementing a lot
slower then the CPU speed.
2. Use HPET in the Intel cpu's. I see how to do this under Linux in
userspace with recent 2.6.x kernels, but I can't figure out how/if the
Darwin kernel exposes the HPET timer. Any sample code for this would
be great.
3. Write to IO port 0x80 on Intel. Should take ~1usec. OS X has
inb/outb to read/write, but no ioperm (like Linux does) to allow
access which is denied by default.
I've heard rumors that both #2 and #3 can be implemented using IOKit,
but after doing some searches on the apple website, I still have no
idea how to do this. Honestly, 1usec is a bit more accurate then I
need (10usec is probably good enough), but 1ms is much too slow.
Ideally, the timer setup should have as little overhead as possible
since this is only going to be used for short periods of time where
things like nanosleep() or select() won't work.
Or if Darwin/OS X has an alternative method that would be great too...
even better if it's more cross platform.
--
Aaron Turner
http://synfin.net/
http://tcpreplay.synfin.net/ - Pcap editing & replay tools for Unix
They that can give up essential liberty to obtain a little temporary
safety deserve neither liberty nor safety. -- Benjamin Franklin
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden