• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Sleeping in nanos
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sleeping in nanos


  • Subject: Re: Sleeping in nanos
  • From: Greg <email@hidden>
  • Date: Sat, 3 Feb 2007 11:36:29 -0500

Ah... perfect! Thanks for that, I should have tried the "time" command, that is really useful! Our linux machines are running 2.6 kernels and sleeping for 1000 nanos or 1 nano results in a sleep time of 2 milliseconds (apparently they changed this from 2.4). Running my program using that I get a CPU usage of about 3.5%, which is much more acceptable.

Finally, running the "time" command on this code in OS X shows that each nanosleep(1) call results in a sleep time of about 50 microseconds. Trying to sleep this amount of time on linux does not work using usleep, it will still sleep for 2 milliseconds each time.

It seems this case is closed gentlemen, thank you all for your help!

- Greg

On Feb 3, 2007, at 10:21 AM, Colin Hirsch wrote:

On Sat, Feb 03, 2007 at 03:24:15AM -0500, Ed Wynne wrote:

On Feb 3, 2007, at 3:03 AM, Jan Brittenson wrote:
Greg wrote:
So then why do I barely see 1% CPU utilization on linux?
But how accurate is it?  When I last dealt with this a few years
ago, nanosleep
always slept at least 10ms on Linux.  Some quick googling shows
this still seems
to be the case.

I assume you ment 10us?

10 milliseconds is quite feasible, corrresponds to a timer tick of 100 Hz, which is quite common... Quick test on a 2.4.18 box gives me the following; seems to be running 50 Hz (or is under some load):

colin:~$ cat t.cc
#include <time.h>

int main( int argc, char ** argv )
{
  timespec t = { 0, 1 };

  for ( unsigned i = 0; i < 100; ++i )
    ::nanosleep( & t, 0 );

  return 0;
}
colin:~$ g++ -O t.cc
colin:~$ time ./a.out

real    0m2.002s
user    0m0.000s
sys     0m0.010s


Regards, Colin
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40kinostudios.com


This email sent to email@hidden

_______________________________________________ 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
References: 
 >Sleeping in nanos (From: Greg <email@hidden>)
 >Fwd: Sleeping in nanos (From: Greg <email@hidden>)
 >Re: Sleeping in nanos (From: Ed Wynne <email@hidden>)
 >Re: Sleeping in nanos (From: Greg <email@hidden>)
 >Re: Sleeping in nanos (From: Jan Brittenson <email@hidden>)
 >Re: Sleeping in nanos (From: Ed Wynne <email@hidden>)
 >Re: Sleeping in nanos (From: Colin Hirsch <email@hidden>)

  • Prev by Date: Re: Sleeping in nanos
  • Next by Date: Re: Sleeping in nanos
  • Previous by thread: Re: Sleeping in nanos
  • Next by thread: Re: Sleeping in nanos
  • Index(es):
    • Date
    • Thread