0

If I had to reverse engineer my operating system, Id naively guess it has a loop that generally looks like this (using a single core, single thread CPU):

while(not shut_down):
    doSomeEnvironmentManagment()
    letProcessesAccessTheCPU()
    checkIfShutDown()
    ...

meaning, my CPU always does something when my computer is on. It either runs a processe's code, or its own. Even when 'idle', electricity always runs through the CPU for it to either execute a program or check what it is bound to do next. Point is, the CPU always does calculations (e.g: update the instruction pointer, etc.)

Now, despite that assumption, my CPU would have a stable lower temperature when idle, and higher temperature when programs are using it more often.

So my question is - why does that happen? according to the assumption electricity always runs in my CPU, for different reasons, so why doesn't it get hot when idle?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
ofek T
  • 19
  • Not long enough/detailed enough for an answer, but the short version is frequency and the number of transistors required to do those calculations. – Robert McKee Oct 31 '19 at 14:04
  • No, when there's nothing to do the OS puts the CPU into low-power sleep until the next interrupt. This gates power and clocks to most of the CPU, even more than just running an idle loop (as opposed to high-throughput FMA code that keeps all the transistors in 256-bit-wide SIMD FMA units switching every clock cycle). – Peter Cordes Oct 31 '19 at 14:07
  • re: heavy vs. light at 100% CPU usage: [Do sse instructions consume more power/energy?](//stackoverflow.com/q/19722950). I might write an answer if nobody's found a duplicate or posted an answer by the time I wake up. But anyway, the most important point is that busy-wait idle loops are a thing of the past. – Peter Cordes Oct 31 '19 at 14:14
  • [How does a CPU idle (or run below 100%)?](//stackoverflow.com/q/18008348) is almost a duplicate, but the answers don't really address power in much detail, and voltage/frequency scaling is out of scope for that question so a complete answer to this couldn't be posted there. – Peter Cordes Oct 31 '19 at 14:33
  • See also https://en.wikichip.org/wiki/File:Intel_Architecture,_Code_Name_Skylake_Deep_Dive-_A_New_Architecture_to_Manage_Power_Performance_and_Energy_Efficiency.pdf from IDF 2015: some neat low-level details on CPU power management in Skylake specifically. If you're starting from this level of knowledge, that might be too technical, though. Especially without the audio from the talk, which might be gone now unfortunately. The original site is down. – Peter Cordes Oct 31 '19 at 14:36
  • barring power saving technologies. with those off or not present, the switching of the gates, if more signals are changing between ones and zeros than before that will consume more energy and create more heat, so even with your assumption, a tiny loop, cached or not, only exercises some percentage of the system. change the program, could still be a small loop, but if it switches more gates or switches them more often, more power, more heat. before these power saving schemes yes the cpu is always running, the notion of idle was kinda silly it was high level notion, etc... – old_timer Oct 31 '19 at 14:39
  • I have worked on systems that consume more power in reset than out and "idle" (no program loaded into the processor, but the whole block is not in reset, it is instead waiting for an enable to start. And then what you run on that core dramatically changes the power consumption, larger more instruction programs dont mean more power you have to design a power consuming routine if that is the goal. single/few clock multiply blocks for example are very large, can flip a lot of gates there. but it is system dependent if you really want to see this in action. – old_timer Oct 31 '19 at 14:42
  • Intel has been well known for making power hungry parts (not just x86) so they have put a lot of effort into attempts to curb that power consumption in the field, underclocking, real-time voltage adjustments, clock gating, etc. So you would need to either have those things disabled in a targeted test or choose a platform (or time period) where the temperature is strictly based on code being run. Your laptop/desktop today are primarily going to be based on how idle/active the part is and the power changes should be dramatic. – old_timer Oct 31 '19 at 16:57

2 Answers2

4

Modern CPUs use CMOS (or more recently FinFET) process technology, which is designed to allow the CPU's transistors consume very little power except while switching state. When a CPU is executing an idle loop many less transistors need to change state than when its performing "heavy calculations". Absent of any specific power saving technology a modern CPU will use less power when idle.

However there are a number of technologies CPUs can use to reduce power consumption even more. Most of them are built around one instruction that almost all CPUs have, the halt instruction.

Halting the Idle loop

Most operating systems actually have an idle loop that looks more like this:

while(true):
    halt()

Where halt() executes a halt instruction. This instruction causes the CPU do nothing until it receives an interrupt. When it does it process that interrupt normally and continues normal execution. While it's executing this instruction, waiting for an interrupt, the CPU is doing very little internally, there's no need to even advance the program counter (instruction pointer), so there's very few transistors changing state reducing power consumption.

An idle loop like this works because the operating system schedules it like a normal processes. When the OS has no processes that need to execute it executes the idle loop instead. The idle loop, or idle task, becomes the absolute lowest priority task. When a hardware device indicates that an operation is complete through an interrupt, another processor sends an interprocessor interrupt indicating that this processor has something to do, or a timer interrupt occurs, the operating scheduler gets a chance to see if a regular process now needs the CPU.

Low power halt states

Additional power saving technologies can be used to reduce power even further when executing the halt instruction. The voltage CPU uses can be reduced. The CPU can can stop its clock to to reduce the transistor state changes that need to occur while waiting. Parts of CPU can be powered down so that even the small amount of power that their transistors use when idle isn't consumed. There can be cost to these using these low power modes, like increased delay when resuming normal execution or reduced interrupt sources capable of ending the wait, so they're not necessary used all of the time when idle.

On low-power embedded CPUs this can reduce the current consumed to a couple hundred nano-amps, which can be less than the self-discharge rate of the batteries used to power these devices. That is, the battery will lose more power sitting on a shelf than these CPUs would consume in the same amount of time when in their lowest power halt states. General purpose processors like x86 CPUs and even the advanced ARM CPUs that power smartphones can't get any near these infinitesimal power numbers, but they can reduce their power consumption a lot when idle compared to their full power states.

Other power saving technologies

There's other power saving technologies that CPUs can use that don't involve the halt instruction, like lowering their clock rates when there isn't much work to do. A related technology is "turbo boosting", that is increasing the clock of rate of one or more CPU cores, but aside from not saving power, in practice this is a more technique of rebalancing the power consumption (and thus heat production) between multiple CPU cores. One or more CPU cores have their clock frequency increased, using more power, while the other cores sit mostly idle using less power. Since most tasks CPUs execute today are still single threaded, this can be a big win for overall performance without increasing power consumption as much as increasing the speed of all the cores would.

Most other power saving technologies used in computers affect overall system power consumption and not the CPU itself and/or are only used when the computer is a suspend, sleep or hibernate state and not just idle.

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
1

I think you have misunderstood how current flows through your CPU. In simple words, your CPU doesn't draw nearly as much power at idle as it does when user load. To conserve power, your CPU ahs a much lesser Voltage draw and it runs at a lower frequency for conserving power. The CPU doesn't just run slower to conserve power according to the workload but also running at max frequency and drawing max power can cause the CPU to run really hot which is bad for the CPU's health in the long run. In short, the CPU only runs as fast as it needs to under lighter workload to conserve power and prevent the CPU from being damaged. Most modern CPU's now have some kind of Turbo Boost technology which allows them to run at higher frequencies when running a task which doesn't require the use of heavy multithreading. If you want to further research this topic please download a wholesome hardware monitoring software like HwInfo and run different tasks like benchmarks of stress tests to see the relation between CPU usage, temperature and power draw. Hope this helped :)

failedCaptcha
  • 49
  • 1
  • 1
  • 5
  • [DVFS](https://en.wikipedia.org/wiki/Dynamic_voltage_scaling) is only a part of the issue. A much more important factor is fully stopping the clock (and power-gating a lot of the core, even some caches) when entering a sleep state. Race To Sleep is an important thing when computers are really idle. – Peter Cordes Oct 31 '19 at 14:15
  • @rcgldr: what's your point? That Nehalem can't save as much power when idle as newer chips? Or that CPUs don't have a lot of thermal mass compared to their non-idle power dissipation? My SKL desktop jumps from ~30C idle to ~65C in under a second when starting x264/x265, and peaks out just under 70C. Anyway, your Nehalem certain still has sleep states, not *just* dynamic frequency / voltage, so this answer is only half the story. – Peter Cordes Nov 01 '19 at 09:23
  • @PeterCordes - The point was how quickly the X6800 can change temp, and after trying it again, it's less than a second. I wasn't sure if the rapid change in temp was unique to the X6800 or a common thing. Probably worth noting how quickly the cpu temp can change somewhere. I'll delete my prior comment and this one later. – rcgldr Nov 01 '19 at 13:12