本文将mark下Intel的新feature:monitorless MWAIT

Introduction

Prior this feature, execution of the MWAIT instruction causes a logical processor to suspend execution and enter an implementation-dependent optimized state only if the MONITOR instruction was executed previously, specifying an address range to monitor, and there have been no stores to that address range since MONITOR executed. The logical processor leaves the optimized state and resumes execution when there is a write to the monitored address range.

This existing functionality supports software that seeks to suspend execution until an event associated with a write to the monitored address range. For example, that range may contain the head pointer of a work queue that is written when there is work for the suspended logical processor.

It is possible that software may wish to suspend execution with no requirement to resume execution in response to a memory write. Such software is not well served by the existing MWAIT instruction since it must incur the overhead of monitoring some (irrelevant) address range and may resume execution earlier than intended following a memory write.
软件可能希望暂停执行,而不要求在内存写入后恢复执行。现有的 MWAIT 指令并不能很好地满足这类软件的需求,因为它必须承担监控某些(不相关的)地址范围的开销,而且在内存写入后,可能会比预定时间提前恢复执行。

Monitorless MWAIT enhances the MWAIT instruction by allowing suspension of execution without monitoring an address range.
Monitorless MWAIT允许在不监控地址范围的情况下暂停执行,从而增强了 MWAIT 指令。

The feature is defined with an enumeration independent of that of existing MONITOR/MWAIT. That allows a VMM to virtualize monitorless MWAIT without having to virtualize the address-range monitoring of the existing feature.
该特性是用一个独立于现有MONITOR/MWAIT的枚举定义的。这使得 VMM 可以虚拟化monitorless MWAIT,而无需虚拟化现有功能的地址范围监控。

Q && A

Q: 使用了monitorless MWAIT后,logical processor什么时候可以resume execution呢?
A: spec中其实已经给出了答案:

  • an NMI or SMI
  • a debug exception
  • a machine check exception
  • the BINIT# signal
  • the INIT# signal
  • the RESET# signal
  • an external interrupt if ECX[0] = 1

Q: monitorless MWAIT与hlt的区别在哪里?
A: 与hlt相比,monitorless MWAIT resume execution的delay更低(因为monitorless MWAIT的节能程度不如hlt),同时monitorless MWAIT还可以精细地指定C-state及Sub C-state。


参考资料:

  1. Introduction to hlt/pause/monitor/mwait instruction