MONITOR and MWAIT are two separate instructions that are used together to monitor a range of linear memory. MONITOR tells the processor what address range to watch for a STORE instruction. MWAIT hints to the processor that it may enter an implementation dependent power state while waiting for that cache line within the address range to be written to, halting most activity in the core while doing so. These instructions allow an operating system or application to realize incremental power saving features beyond what the built-in Fire-and-Forget AMD PowerNow!™ feature provides, and can also be used to eliminate polling (the situation where an address is regularly checked for changes to data). Since MWAIT is triggered by a STORE instruction, it can also be used in creative ways with devices that handle IO through memory addresses, i.e. data sent to a device or data written to memory from a device would cause the processor to return to a higher power state.
The following sample code shows typical usage of a MONITOR/MWAIT pair:
EAX = Linear_Address_to_Monitor; ECX = 0; // Extensions EDX = 0; // Hints while (!matching_store_done) { MONITOR EAX, ECX, EDX IF (!matching_store_done) { MWAIT EAX, ECX } }
Additional information can be found in the AMD64 Architecture Programmer’s Manual Volume 3.
This post is the opinion of the author and may not represent AMD’s positions, strategies or opinions. Links to third party sites and references to third party trademarks are provided for convenience and illustrative purposes only. Unless explicitly stated, AMD is not responsible for the contents of such links, and no third party endorsement of AMD or any of its products is implied.