Re: Sleeping in nanos
Re: Sleeping in nanos
- Subject: Re: Sleeping in nanos
- From: Ed Wynne <email@hidden>
- Date: Fri, 2 Feb 2007 23:05:09 -0500
Date: February 2, 2007 10:28:08 PM EST Subject: Sleeping in nanos
Is there a way on OS X to sleep for 1000 nanoseconds without causing 65% CPU usage? I have tried nanosleep and clock_sleep (using TIME_RELATIVE and a REALTIME_CLOCK), and both seem to simply cause a busy loop.
Assuming an instruction takes one cycle (some do, lots don't) and a 2Ghz CPU, each instruction will take .5ns. That means the CPU can run 2000 instructions, at most, while your sleeping for 1us.
Given that any kind of sleep function will be a syscall into the kernel and invoke the scheduler, I'd be willing to bet it takes a lot more than 2000 instructions just to put yourself to sleep and then wake back up. Your 65% CPU usage is probably indicative of this. It is taking longer to setup and recover from sleep than your spending sleeping.
-Ed
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden