AMD Patch To Use MWAIT Instead Of HALT For Certain Cases Yield A ~21% Improvement

Written by Michael Larabel in AMD on 6 April 2022 at 03:19 PM EDT. 8 Comments
AMD --
As a Linux kernel change for benefiting AMD CPUs going back to Zen 1 and for matching behavior Intel has had in place since the Core 2 times, AMD submitted a patch for having the Linux kernel use the MWAIT instruction instead of HALT for when the system isn't using the CPU idle driver either for C-states being disabled by the BIOS or the driver not part of the kernel build. In turn this can lead to around a 21% improvement in exit latency on affected systems.

The Monitor Wait "MWAIT" instruction can be used for power management purposes to hint that the processor can enter a specified target C state while waiting for an event or a MONITOR'ed store operation to complete. Usage of MWAIT is intended to be more efficient than the HALT instruction.


Intel Core 2 and later have already preferred MWAIT over HALT instruction for entering the C1 state and that has been the behavior in the Linux kernel. AMD CPUs though continue using HALT in this code path for cases like not using the CPU idle driver (either due to being disabled or not part of the kernel build) or when C-states are disabled by the system BIOS, so admittedly somewhat niche.

The patch proposed this week by AMD now switches over to using MWAIT for all AMD Zen processors for Zen 1 and newer plus Hygon Dhyana too. On AMD Zen 3 (and similar results for older Zen too) the exit latency was found to be around 21% lower using MWAIT rather than HALT. Most users will find themselves using the CPU idle driver and thus unaffected by this patch, but for those that aren't this change can be beneficial. The high latency with HALT had apparently come up in real-world testing/usage when exploring packet loss in an unspecified network program as part of "customer performance observations".


This AMD change is currently under review on the kernel mailing list.
Related News
About The Author
Author picture

Michael Larabel is the principal author of Phoronix.com and founded the site in 2004 with a focus on enriching the Linux hardware experience. Michael has written more than 20,000 articles covering the state of Linux hardware support, Linux performance, graphics drivers, and other topics. Michael is also the lead developer of the Phoronix Test Suite, Phoromatic, and OpenBenchmarking.org automated benchmarking software. He can be followed via Twitter, LinkedIn, or contacted via MichaelLarabel.com.

Popular News This Week