Tuesday, January 13, 2015

What Happens When an Idle CPU Goes in a Sleep Mode?

Every task or program that is performed on a system takes some time to process on the CPU. When the CPU has done all its tasks it is free and goes in a sleep mode. 

Modern processors in this free time save power by reducing the speed of clock and the voltage of CPU and sending part of the processor in a sleep mode. Some processors have halt instruction that stops an idle CPU from saving power when an interrupt occurs. An example is the x86’s HLT instruction. By the time instruction is executed, the processor may save considerable amount of power and heat if the idle task is a loop that continually gives HLT instructions.

CPU Idle Loop’s Syntax:




This idle task for CPU is shown by most of the operating systems and can be understood by the fact that CPU is always doing something, even when something is same as nothing. 
The idle task for x86 supporting Windows is the halt instructions (HLT) and the Windows System Idle Process. The idle process on a CPU core is scheduled by Windows only when there is no program running on that CPU. On looking at a list of programs running on a Windows system, you will find that the System Idle Process has a very high percentage. However, this actually shows how little the CPU works as against how much it works. The objective of designing the HLT instruction is to use as little power as possible and getting the CPU into sleep mode saving considerable energy. 

 The HLT:

The operating system gives HLT instructions when it is idle without any work and enters a sleep mode. For instance, ‘System Idle Process” run these instructions on Windows NT. The opcode of HLT on x86 processor is 0xF4.

Turn Off Sleep Mode with Interrupts:

Now, the CPU also needs something to come out of its sleep mode when it is instructed to sleep. By interrupts CPU is spurred into action from its halted state. Putting together everything, the below image shows what is done by your system most of the time as you go through a completely rendered page on the web.   


Apart from the interrupt made by the timer, there are other interrupts that move the processor. The same thing happens on a web page when you click on it. In this case, your mouse instructs an interrupt, which is processed by its driver, and a process starts running. At this point, the free time is booted out in support of your browser. 

Now that appears like an unpleasant lot of useless work for a CPU that is idle. Without getting new input from outside, the CPU continues to remain in this sleep mode getting awakened about 250 times a second whereas the battery of your laptop is exhausted. If, on the other hand, this is operating in a virtual machine, you are burning power as well as valuable cycles out of the CPU.

To solve this, you need to use dynamic tick as this would either deactivate or reprogram the timer interrupt at a time where kernel is aware that there is work for idle CPU. If you can’t do this by yourself, feel free to call online technical experts. 

No comments:

Post a Comment