I want to understand the various C-states, most of the CPU in C1 state goes on HLT and in deep C state like c4 goes to WFI.

- 347,512
- 102
- 1,199
- 985

- 878
- 2
- 12
- 20
-
The 'C' states are generally handled by something that is outside the ARM cores. For example, [Exynos ARM power control](http://stackoverflow.com/questions/16003215/can-someone-explain-the-power-control-register-in-exynos-arm/) has an example. Many peripherals, clocks, and voltages are sequenced to minimize power in different sleep states. The WFI is used as the CORE is always halted (waiting for an interrupt) in all sleep states. The other SOC peripherals (what will cause the waking interrupt) are the off-core configuration which is different for each *mode* and beyond the ARM core scope. – artless noise Dec 21 '14 at 16:43
2 Answers
HLT is used for JTAG, WFI and WFE is what you usually use in regular bare metal and userland programs
HLT in ARMv8 is a debug related instruction, i.e. the type of instruction that GDB uses to implement hardware breakpoints / watchpoints or that JTAG uses.
Like every other instruction it is documented in the ARM Reference Manual: https://static.docs.arm.com/ddi0487/db/DDI0487D_b_armv8_arm.pdf
I'm not sure what this one in particular does, but the manual describes it at C6.2.84 "HLT" as:
HLT Halt instruction. A HLT instruction can generate a Halt Instruction debug event, which causes entry into Debug state.
and Chapter H2 "Debug State" describes what Debug State means:
In external debug, debug events allow an external debugger to halt the PE. The PE then enters Debug state.
and further up we see that "external debug" means JTAG-like debug methods.
So HLT seems to be a way to enter JTAG debugging mode from software, much like BRK does for GDB software debugging.
Therefore, unless you are implementing such debug related functionality, you don't want to touch HLT.
Here are minimalistic baremetal example of:
- WFI which is meant to wait for interrupts in a loop in a potentially more energy efficient state than a raw for loop: https://github.com/cirosantilli/linux-kernel-module-cheat/blob/d6d7f15c912ed6371c8cf15a93f43488d6fc5efb/baremetal/arch/aarch64/timer.c#L116
- WFE which is meant to wait for an SEV instruction from another core: What does multicore assembly language look like?

- 347,512
- 102
- 1,199
- 985
This question doesn't make sense. You are mixing up terminology from ARM and x86 systems.
The HLT
instruction exists on x86; it does not exist on ARM. WFI
is the closest equivalent, and similarly, only exists on ARM. Both instructions perform similar tasks on their respective architectures.
C-states are, again, x86-specific terminology. ARM CPUs often have analogous sleep states, but they are typically defined by individual hardware manufacturers, not by ARM itself.
-
c states is a general term uses in ARM too, plz do refer arch/arm/mach-msm/cpuidle.c file, and grep for cstates or C-states. You are right about the HLT instruction though, but still I didnt figure out the difference between two as HLT in x86 happens at C1 state and WFI in ARM happens at much deeper state, I want to know the CPU condition while waiting in both these instructions. I assume wait for HLT must be more power consuming then WFI as it happens at initial C state – Saurabh Sengar Dec 21 '14 at 12:06
-
2nitpick: C-states are defined by ACPI - being more of a desktop/server thing, it happens that the vast majority of ACPI implementations are x86-based, and x86 defines its power management features in ACPI terms. You don't tend to see ACPI in mobile, but it's certainly happening for ARMv8 servers. – Notlikethat Dec 21 '14 at 13:01
-
ARMv8 has a HLT instruction: https://developer.arm.com/documentation/100076/0100/a32-t32-instruction-set-reference/a32-and-t32-instructions/hlt – Błażej Michalik Feb 03 '22 at 17:23