Jump to content

  • Log In with Google      Sign In   
  • Create Account

Sleep and Electricity


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 KingofNoobs   Members   -  Reputation: 301

Like
0Likes
Like

Posted 19 November 2012 - 03:45 PM

Hello,

I was wondering what sleep() really does. I mean, how does a CPU core go to "sleep?" Electricity always moves by definition at a fixed speed in a given medium, so we can't just "stop" the signal and wait for something to happen. I imagined that the CPU was just one big circuit and that the electricity always flows but the circuit may cut off a loop or the circuit not to be actualized until a voltage from outside the system (i.e. the graphics device) re-activates it. Is this correct and can I understand my system to be doing this when I use the sleep() function, or am I just passing control off to an operating system call that will not recall my code for a given amount of time, at which point my code resumes from the line following sleep()? If the latter is the case, then how can an operating system sleep()? Would that be possible? Can an operating system put an entire core to sleep() but not other cores for power saving reasons or to reduce necessary fan noise? Could a game have the same level of cpu sleep()ing individual cores? To summarize, is sleep() an system call or does it act directly on the hardware CPU? And can operating systems sleep() as a power-saving or noise-reducing feature and can games or other applications do the same?

Thanks.

- Dave Ottley

I wonder as I wander...

http://www.davesgameoflife.com


Sponsor:

#2 frob   Moderators   -  Reputation: 21307

Like
3Likes
Like

Posted 19 November 2012 - 04:05 PM

I was wondering what sleep() really does.

There are many good books about modern operating system internals.

I mean, how does a CPU core go to "sleep?" Electricity always moves by definition at a fixed speed in a given medium, so we can't just "stop" the signal and wait for something to happen. I imagined that the CPU was just one big circuit and that the electricity always flows but the circuit may cut off a loop or the circuit not to be actualized until a voltage from outside the system (i.e. the graphics device) re-activates it.

Quite an imagination you have.

No, it doesn't work that way.

Is this correct and can I understand my system to be doing this when I use the sleep() function, or am I just passing control off to an operating system call that will not recall my code for a given amount of time, at which point my code resumes from the line following sleep()?

That is closer to how it works.

The OS maintains a list of processes, and it has the ability to run them or interrupt them at will.

Many processes will notify the OS that they should be put to sleep. They may request to wake after an event is sent, or a resource has become available, or an amount of time has expired.

It is up to the OS to suspend the process until the wake conditions are met.

If the latter is the case, then how can an operating system sleep()? Would that be possible? Can an operating system put an entire core to sleep() but not other cores for power saving reasons or to reduce necessary fan noise? Could a game have the same level of cpu sleep()ing individual cores? To summarize, is sleep() an system call or does it act directly on the hardware CPU? And can operating systems sleep() as a power-saving or noise-reducing feature and can games or other applications do the same?


The OS can take advantage of power-saving features of the hardware.

The most common is to reduce the clock frequency of the CPU.

Your CPU and graphics card are almost never running at their maximum capacity. They are usually stepped down considerably.

For example, your hardware may have a maximum frequency of 2.4GHz, but most of the time it will be at a much slower CPU step; maybe 2.00Ghz, 1.33GHz, or 1.2 GHz, or something else entirely.

Another example, a handheld device may go from 640MHz, to 512MHz, to 333MHz, progressively slowing and come to a rest at a 30MHz as a sleep state. The moment the OS detects the need for activity it can immediately adjust the CPU speed back up to full throttle.


A multiprocessor device could turn off individual processor cores if they are idle, as you suggested, but that is less common.

Turning off fans is more a function of temperature than performance, but sure, the hardware may allow software-based control for that as well.
Check out my personal indie blog at bryanwagstaff.com.

#3 nobodynews   Crossbones+   -  Reputation: 1916

Like
2Likes
Like

Posted 19 November 2012 - 07:11 PM

Electricity always moves by definition at a fixed speed in a given medium, so we can't just "stop" the signal and wait for something to happen. I imagined that the CPU was just one big circuit and that the electricity always flows but the circuit may cut off a loop or the circuit not to be actualized until a voltage from outside the system (i.e. the graphics device) re-activates it.

You seem to be confused a little about how circuitry works so here's a quick crash course.

Consider first a diode ( http://en.wikipedia.org/wiki/Diode ). A diode's behavior depends upon the source voltage. At low voltages a diode will consume a very low amount of electricity (an ideal diode consumes NO electricity because at infinite resistance no electricity can flow). At high voltage the diode does consume electricity (at which point the diode can be modeled like a normal resistor). Diodes aren't really used in CPUs though, it's just a simpler concept than...

The transistor ( http://en.wikipedia.org/wiki/Transistor ). You can imagine a transistor as behaving like a dam. A dam has a reservoir that's normally filled with water. The dam doesn't have to let any of the water out of the reservoir, a gate must be open first. If the gate is opened then if there's any water at the source of the reservoir then it can drain out. No water at the source and no water flows out the drain, regardless of whether the gate is open.

A transistor works the same way. A transistor has a 'gate', a 'source', and a 'drain'. In this case the gate is opened or closed depending on whether there's voltage there above a certain threshold. If any electricity is present at the source, it can flow through the drain when the gate is open. Like a diode, if the gate is closed then there shouldn't be any electricity usage. Of course also like a diode that's for an 'ideal' transistor'. A real transistor will leak some current, even with a closed gate. So if you shut off enough transistors for some reason this would result in much less current (and this power) being consumed.

Many processors support a standby mode where the CPU is made almost entirely inactive, until an interrupt is triggered awakening the processor. That said, I'm not sure if this processor feature is necessarily *used* by Microsoft in their OS. If it is, it's definitely not going to be used when a random program calls 'sleep', but when the OS decides to go standby mode at which time pretty much nothing is going to happen until the OS wakes up again.

And of course, what frob said about reducing clock frequency.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS