• 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: Terry Lambert <email@hidden>
  • Date: Fri, 2 Feb 2007 23:05:13 -0800

How is it being measured on Linux?

Is it being done as a weighted moving average on scheduler transitions, or is it based on sleeping in the idle loop, or what? Or is a system considered "loaded" only when there are processes on a "ready to run" queue, waiting assignment to a CPU? If the latter, is it loaded 100% any time the value waiting for a CPU is non-zero, or is the load based on number of "runnable" vs. "total", and/or does it include the currently running processes as part of the load, etc.?

Different approaches to measuring will give different answers, and almost all systems

If your answer is coming from "top" vs. "w" vs. "uptime" vs. getloadavg(), you are going to get a subjective measurement.


If this is an Intel system (i.e. you are comparing the same machine running MacOS X with one running Linux), my suggestion is to use the TSC instruction to get cycle counts, and compare those instead of trying to compare fictitious "load average" numbers that are likely calculated in different ways.


-- Terry

On Feb 2, 2007, at 8:38 PM, Greg wrote:
So then why do I barely see 1% CPU utilization on linux?

- Greg

On Feb 2, 2007, at 11:05 PM, Ed Wynne wrote:

From: Greg <email@hidden>
Date: February 2, 2007 10:28:08 PM EST
To: Darwin Kernel <email@hidden>
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


  • Follow-Ups:
    • Re: Sleeping in nanos
      • From: Greg <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>)

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