high accuracy timing options?
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; bh=XgqVrPjEnJ0SGxFh8HZtLcRKpUZvqBVs015GT2PZXr4=; b=cAVuA1SChMnWCS6fV6BUvXndN0PJLd2ZBa0eUNjTXbA7X/yHc0zXv8D+ZLl81OadXyi0E7y47iPG2SjXHHsgM/MFDc3TAp+JnO9FGnJ2zOZ1RGqeeHyllMiLNv8mbhoSceHvO6qgGhdoF6zx4jX+Zg6c8zpKquJhWfARh2W1OHU= Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=F9BGomEyIWF0b3b0ttXQY8Scea386eHzsM7B+TErzr+VQRHgfUAkzFAIURg8w0HhyprcoU04N6N1CmnkTPsgREdQNyFq6mC6yo0q8NvWfTx7r0oMqM198Ur1G1CR6vuunSor3YogJCWQ1xrH5ChnYJd/B9jMk4i8lHGiQWkCjJ0= 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 (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... This email sent to site_archiver@lists.apple.com
participants (1)
-
Aaron Turner