HLT
In the x86 computer architecture, HLT
(halt) is an assembly language instruction which halts the central processing unit (CPU) until the next external interrupt is fired.[1] Interrupts are signals sent by hardware devices to the CPU alerting it that an event occurred to which it should react. For example, hardware timers send interrupts to the CPU at regular intervals.
The HLT
instruction is executed by the operating system when there is no immediate work to be done, and the system enters its idle state. In Windows NT, for example, this instruction is run in the "System Idle Process". On x86 processors, the opcode of HLT
is 0xF4
.
History on x86
All x86 processors from the 8086 onwards had the HLT
instruction, but it was not used by MS-DOS[2] unless POWER.EXE is installed in the CONFIG.SYS[3] and was not specifically designed to reduce power consumption until the release of the Intel DX4 processor in 1994.[4] Some of the first 100 MHz DX chips had a buggy HLT state, prompting the developers of Linux to implement a "no-hlt" option for use when running on those chips,[5] but this was fixed in later chips.
Process
Almost every reasonably modern processor instruction set includes an instruction or sleep mode which halts the processor until more work needs to be done. In interrupt-driven processors, this instruction halts the CPU until an external interrupt is received. On most architectures, executing such an instruction allows the processor to significantly reduce its power usage and heat output, which is why it is commonly used instead of busy waiting for sleeping and idling.
Use in operating systems
Since issuing the HLT
instruction requires ring 0 access, it can only be run by privileged system software such as the kernel. Because of this, it is often best practice in application programming to use the application programming interface (API) provided for that purpose by the operating system when no more work can be done. This is referred to as "yielding" the processor. This allows the operating system's scheduler to decide if other processes are runnable; if not, it will normally issue the HLT instruction to cut power usage.
See also
References
- ↑ "Intel 64 and IA-32 Architectures Software Developer's Manual: Instruction Set Reference A-Z" (PDF). Retrieved 2012-03-01.
- ↑ http://blogs.msdn.com/b/virtual_pc_guy/archive/2004/12/20/327602.aspx
- ↑ "POWER.EXE and Advanced Power Management (APM) Support". Retrieved 2015-09-27.
- ↑ http://www.hardwaresecrets.com/article/Everything-You-Need-to-Know-About-the-CPU-C-States-Power-Saving-Modes/611/2
- ↑ http://www.faqs.org/docs/Linux-HOWTO/BootPrompt-HOWTO.html#ss3.4