In the
x86 computer architecture,
HLT
(halt) is an
assembly language
In computing, assembly language (alternatively assembler language or symbolic machine code), often referred to simply as assembly and commonly abbreviated as ASM or asm, is any low-level programming language with a very strong correspondence bet ...
instruction which halts the
central processing unit
A central processing unit (CPU), also called a central processor, main processor, or just processor, is the primary Processor (computing), processor in a given computer. Its electronic circuitry executes Instruction (computing), instructions ...
(CPU) until the next external
interrupt
In digital computers, an interrupt (sometimes referred to as a trap) is a request for the processor to ''interrupt'' currently executing code (when permitted), so that the event can be processed in a timely manner. If the request is accepted ...
is fired. 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.
Most
operating system
An operating system (OS) is system software that manages computer hardware and software resources, and provides common daemon (computing), services for computer programs.
Time-sharing operating systems scheduler (computing), schedule tasks for ...
s execute a
HLT
instruction when there is no immediate work to be done, putting the processor into an
idle state. In
Windows NT
Windows NT is a Proprietary software, proprietary Graphical user interface, graphical operating system produced by Microsoft as part of its Windows product line, the first version of which, Windows NT 3.1, was released on July 27, 1993. Original ...
, for example, this instruction is run in the "
System Idle Process". On x86 processors, the
opcode
In computing, an opcode (abbreviated from operation code) is an enumerated value that specifies the operation to be performed. Opcodes are employed in hardware devices such as arithmetic logic units (ALUs), central processing units (CPUs), and ...
of
HLT
is
0xF4
.
On ARM processors, the similar instructions are
WFI
(Wait For Interrupt) and
WFE
(Wait For Event).
History on x86
All x86 processors from the 8086 onward had the
HLT
instruction, but it was not used by
MS-DOS
MS-DOS ( ; acronym for Microsoft Disk Operating System, also known as Microsoft DOS) is an operating system for x86-based personal computers mostly developed by Microsoft. Collectively, MS-DOS, its rebranding as IBM PC DOS, and a few op ...
prior to 6.0 and was not specifically designed to reduce power consumption until the release of the
Intel DX4 processor in 1994. MS-DOS 6.0 provided a POWER.EXE that could be installed in
CONFIG.SYS and in Microsoft's tests it saved 5%. Some of the first 100 MHz DX chips had a buggy HLT state, prompting the developers of
Linux
Linux ( ) is a family of open source Unix-like operating systems based on the Linux kernel, an kernel (operating system), operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically package manager, pac ...
to implement a "no-hlt" option for use when running on those chips, but this was fixed in later chips.
Intel has since introduced additional processor-yielding instructions. These include:
* in
SSE2
SSE2 (Streaming SIMD Extensions 2) is one of the Intel SIMD (Single Instruction, Multiple Data) processor supplementary instruction sets introduced by Intel with the initial version of the Pentium 4 in 2000. SSE2 instructions allow the use of ...
intended for spin loops. Available to userspace (low-privilege rings).
* / in
SSE3
SSE3, Streaming SIMD Extensions 3, also known by its Intel code name Prescott New Instructions (PNI), is the third iteration of the SSE instruction set for the IA-32 (x86) architecture. Intel introduced SSE3 in early 2004 with the Prescott revis ...
for thread synchronization.
* (timed pause) and / (userspace monitor/mwait). Available to userspace.
Process
Almost every modern processor
instruction set
In computer science, an instruction set architecture (ISA) is an abstract model that generally defines how software controls the CPU in a computer or a family of computers. A device or program that executes instructions described by that ISA, s ...
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. In most processors, halting (instead of looping) also reduces the
latency of the next interrupt.
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
An application programming interface (API) is a connection between computers or between computer programs. It is a type of software Interface (computing), interface, offering a service to other pieces of software. A document or standard that des ...
(API) provided for that purpose by the operating system when no more work can be done, such as Linux's
sched_yield()
.
This is referred to as "yielding" the processor. This allows the operating system's
scheduler to decide whether other processes are runnable; if not. If every process is sleeping or waiting, it will normally execute a HLT instruction to cut power usage until the next hardware interrupt.
See also
*
Advanced Configuration and Power Interface (ACPI)
*
Advanced Power Management (APM)
*
Computer architecture
*
Halt and Catch Fire
*
Idle (CPU)
*
Instruction set architecture
In computer science, an instruction set architecture (ISA) is an abstract model that generally defines how software controls the CPU in a computer or a family of computers. A device or program that executes instructions described by that ISA, ...
*
NOP (code)
In computer science, a NOP, no-op, or NOOP (pronounced "no op"; short for no operation) is a machine language instruction and its assembly language mnemonic, programming language statement, or computer protocol command that does nothing.
M ...
References
{{Reflist, 30em
Machine code
X86 instructions