From 4bf2a5b045ebf8b5e90d9210ad5190699bddb592 Mon Sep 17 00:00:00 2001 From: Ankur Arora Date: Sat, 20 Mar 2021 02:14:21 +0800 Subject: MdePkg: use CpuPause() in CpuDeadLoop() CpuPause() might allow the CPU to go into a lower power state state while we spin. On X86, CpuPause() executes a PAUSE instruction which the Intel and AMD specs describe as follows: Intel: "PAUSE: An additional function of the PAUSE instruction is to reduce the power consumed by a processor while executing a spin loop. A processor can execute a spin-wait loop extremely quickly, causing the processor to consume a lot of power while it waits for the resource it is spinning on to become available. Inserting a pause instruction in a spin-wait loop greatly reduces the processor?s power consumption." AMD: "PAUSE: Improves the performance of spin loops, by providing a hint to the processor that the current code is in a spin loop. The processor may use this to optimize power consumption while in the spin loop. Architecturally, this instruction behaves like a NOP instruction." On RISC-V and ARM64, CpuPause() executes a NOP, which is no worse than the tight loop we have. Cc: Liming Gao Signed-off-by: Ankur Arora Reviewed-by: Michael D Kinney Reviewed-by: Laszlo Ersek Reviewed-by: Liming Gao --- MdePkg/Library/BaseLib/CpuDeadLoop.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'MdePkg') diff --git a/MdePkg/Library/BaseLib/CpuDeadLoop.c b/MdePkg/Library/BaseLib/CpuDeadLoop.c index 9e110cacbc..3cd304351a 100644 --- a/MdePkg/Library/BaseLib/CpuDeadLoop.c +++ b/MdePkg/Library/BaseLib/CpuDeadLoop.c @@ -28,5 +28,7 @@ CpuDeadLoop ( { volatile UINTN Index; - for (Index = 0; Index == 0;); + for (Index = 0; Index == 0;) { + CpuPause(); + } } -- cgit v1.2.3