管理 Hyper-v 虛擬程式排程器類型Managing Hyper-V hypervisor scheduler types

適用于: Windows 10、Windows Server 2016、Windows Server、版本1709、Windows Server、版本1803、Windows Server 2019Applies To: Windows 10, Windows Server 2016, Windows Server, version 1709, Windows Server, version 1803, Windows Server 2019

本文說明 Windows Server 2016 中首次引進的虛擬處理器排程邏輯新模式。This article describes new modes of virtual processor scheduling logic first introduced in Windows Server 2016. 這些模式或排程器類型會決定 Hyper-v 虛擬機器如何配置及管理跨來賓虛擬處理器的工作。These modes, or scheduler types, determine how the Hyper-V hypervisor allocates and manages work across guest virtual processors. Hyper-v 主機系統管理員可以選取最適用于來賓虛擬機器(Vm)的虛擬程式排程器類型,並設定 Vm 以利用排程邏輯。A Hyper-V host administrator can select hypervisor scheduler types that are best suited for the guest virtual machines (VMs) and configure the VMs to take advantage of the scheduling logic.

注意

需要進行更新,才能使用本檔中所述的程式管理器排程器功能。Updates are required to use the hypervisor scheduler features described in this document. 如需詳細資訊,請參閱必要的更新For details, see Required updates.

背景Background

在討論 Hyper-v 虛擬處理器排程背後的邏輯和控制項之前,請先參閱這篇文章中涵蓋的基本概念,將有所説明。Before discussing the logic and controls behind Hyper-V virtual processor scheduling, it's helpful to review the basic concepts covered in this article.

瞭解 SMTUnderstanding SMT

同時執行多執行緒或 SMT,是在新式處理器設計中使用的技術,可讓處理器的資源由個別獨立的執行緒共用。Simultaneous multithreading, or SMT, is a technique utilized in modern processor designs that allows the processor's resources to be shared by separate, independent execution threads. SMT 通常會在可能的情況下平行處理計算,為大部分的工作負載提供適度的效能提升,即使在共用處理器資源的執行緒發生爭用時,效能也不會稍微降低。SMT generally offers a modest performance boost to most workloads by parallelizing computations when possible, increasing instruction throughput, though no performance gain or even a slight loss in performance may occur when contention between threads for shared processor resources occurs. Intel 和 AMD 皆提供支援 SMT 的處理器。Processors supporting SMT are available from both Intel and AMD. Intel 是以 Intel 超執行緒技術或 Intel HT 的形式,將其 SMT 供應專案。Intel refers to their SMT offerings as Intel Hyper Threading Technology, or Intel HT.

基於本文的目的,Hyper-v 的 SMT 和其使用方式的描述同樣適用于 Intel 和 AMD 系統。For the purposes of this article, the descriptions of SMT and how it is utilized by Hyper-V apply equally to both Intel and AMD systems.

瞭解 Hyper-v 如何虛擬化處理器Understanding how Hyper-V virtualizes processors

在考慮「基礎程式排程器」類型之前,瞭解 Hyper-v 架構也很有説明。Before considering hypervisor scheduler types, it's also helpful to understand the Hyper-V architecture. 您可以在Hyper-v 技術總覽中找到一般摘要。You can find a general summary in Hyper-V Technology Overview. 以下是這篇文章的重要概念:These are important concepts for this article:

  • Hyper-v 會建立及管理虛擬機器磁碟分割,在這些資料分割中,會在管理者控制下配置和共用計算資源。Hyper-V creates and manages virtual machine partitions, across which compute resources are allocated and shared, under control of the hypervisor. 分割區可在所有來賓虛擬機器之間,以及在來賓 Vm 與根磁碟分割之間提供強式隔離界限。Partitions provide strong isolation boundaries between all guest virtual machines, and between guest VMs and the root partition.

  • 根磁碟分割本身是虛擬機器磁碟分割,雖然它具有與來賓虛擬機器不同的唯一屬性和更高的許可權。The root partition is itself a virtual machine partition, although it has unique properties and much greater privileges than guest virtual machines. 根磁碟分割提供管理服務,可控制所有來賓虛擬機器、提供來賓的虛擬裝置支援,以及管理來賓虛擬機器的所有裝置 i/o。The root partition provides the management services that control all guest virtual machines, provides virtual device support for guests, and manages all device I/O for guest virtual machines. Microsoft 強烈建議您不要在根磁碟分割中執行任何應用程式工作負載。Microsoft strongly recommends not running any application workloads in the root partition.

  • 根磁碟分割的每個虛擬處理器(VP)都會將1:1 對應到基礎邏輯處理器(LP)。Each virtual processor (VP) of the root partition is mapped 1:1 to an underlying logical processor (LP). 主機 VP 一律會在相同的基礎 LP 上執行–不會遷移根磁碟分割的 VPs。A host VP always runs on the same underlying LP – there is no migration of the root partition's VPs.

  • 根據預設,主機 VPs 執行所在的 LPs 也可以執行來賓 VPs。By default, the LPs on which host VPs run can also run guest VPs.

  • 在任何可用的邏輯處理器上執行的虛擬程式都可能會排程來賓副總裁。A guest VP may be scheduled by the hypervisor to run on any available logical processor. 當「執行程式管理者」在排程來賓副總時,會負責考慮時態性快取位置、NUMA 拓朴和許多其他因素,最後就是在任何主機 LP 上排定副總裁。While the hypervisor scheduler takes care to consider temporal cache locality, NUMA topology, and many other factors when scheduling a guest VP, ultimately the VP could be scheduled on any host LP.

程式管理器排程器類型Hypervisor scheduler types

從 Windows Server 2016 開始,Hyper-v 虛擬機器支援數種排程器邏輯模式,可決定程式管理者如何排定基礎邏輯處理器上的虛擬處理器。Starting with Windows Server 2016, the Hyper-V hypervisor supports several modes of scheduler logic, which determine how the hypervisor schedules virtual processors on the underlying logical processors. 這些排程器類型如下:These scheduler types are:

傳統排程器The classic scheduler

傳統排程器是自其開始後所有版本的 Windows Hyper-v 虛擬機器的預設值,包括 Windows Server 2016 Hyper-v。The classic scheduler has been the default for all versions of the Windows Hyper-V hypervisor since its inception, including Windows Server 2016 Hyper-V. 傳統排程器會為來賓虛擬處理器提供公平共用、搶先式迴圈配置資源排程模型。The classic scheduler provides a fair share, preemptive round- robin scheduling model for guest virtual processors.

傳統的排程器類型最適合大部分傳統的 Hyper-v 用途–適用于私人雲端、主機服務提供者等等。The classic scheduler type is the most appropriate for the vast majority of traditional Hyper-V uses – for private clouds, hosting providers, and so on. 效能特性已充分瞭解,且最適合用來支援各種不同的虛擬化案例,例如過度訂閱 VPs 至 LPs、同時執行許多並存的 Vm 和工作負載、執行較大的大規模高效能 Vm、支援 Hyper-v 的完整功能,而不受限制等等。The performance characteristics are well understood and are best optimized to support a wide range of virtualization scenarios, such as over-subscription of VPs to LPs, running many heterogeneous VMs and workloads simultaneously, running larger scale high performance VMs, supporting the full feature set of Hyper-V without restrictions, and more.

核心排程器The core scheduler

「虛擬程式核心排程器」是傳統排程器邏輯的新替代方案,在 Windows Server 2016 和 Windows 10 1607 版中引進。The hypervisor core scheduler is a new alternative to the classic scheduler logic, introduced in Windows Server 2016 and Windows 10 version 1607. 核心排程器為來賓工作負載隔離提供強大的安全性界限,並降低在 SMT 啟用的虛擬化主機上執行之 Vm 內工作負載的效能變化。The core scheduler offers a strong security boundary for guest workload isolation, and reduced performance variability for workloads inside of VMs that are running on an SMT-enabled virtualization host. 核心排程器允許同時在相同的已啟用 SMT 虛擬化主機上同時執行 SMT 和非 SMT 虛擬機器。The core scheduler allows running both SMT and non-SMT virtual machines simultaneously on the same SMT-enabled virtualization host.

核心排程器會利用虛擬化主機的 SMT 拓撲,並選擇性地將 SMT 配對公開給來賓虛擬機器,並將來自相同虛擬機器的來賓虛擬處理器群組排程到 SMT 邏輯處理器群組。The core scheduler utilizes the virtualization host's SMT topology, and optionally exposes SMT pairs to guest virtual machines, and schedules groups of guest virtual processors from the same virtual machine onto groups of SMT logical processors. 這是以對稱方式完成,因此,如果 LPs 位於兩個群組中,VPs 會以兩個群組排程,而在 Vm 之間不會共用核心。This is done symmetrically so that if LPs are in groups of two, VPs are scheduled in groups of two, and a core is never shared between VMs. 若已為虛擬機器排程 VP,而未啟用 SMT,則 VP 會在執行時使用整個核心。When the VP is scheduled for a virtual machine without SMT enabled, that VP consumes the entire core when it runs.

核心排程器的整體結果如下:The overall result of the core scheduler is that:

  • 來賓 VPs 受限於在基礎實體核心配對上執行,將 VM 隔離到處理器核心界限,進而減少對來自惡意 Vm 的側通路窺探攻擊的弱點。Guest VPs are constrained to run on underlying physical core pairs, isolating a VM to processor core boundaries, thus reducing vulnerability to side-channel snooping attacks from malicious VMs.

  • 輸送量的變化大幅降低。Variability in throughput is significantly reduced.

  • 效能可能會降低,因為如果只有一個 VPs 群組可以執行,則核心中只有一個指令資料流程會執行,另一個則是閒置。Performance is potentially reduced, because if only one of a group of VPs can run, only one of the instruction streams in the core executes while the other is left idle.

  • 在來賓虛擬機器中執行的作業系統和應用程式,可以利用 SMT 行為和程式設計介面(Api)來控制和散佈跨 SMT 執行緒的工作,就像執行非虛擬化一樣。The OS and applications running in the guest virtual machine can utilize SMT behavior and programming interfaces (APIs) to control and distribute work across SMT threads, just as they would when run non-virtualized.

  • 來賓工作負載隔離的強式安全性界限-來賓 VPs 受限於在基礎實體核心配對上執行,以降低對側通道窺探攻擊的弱點。A strong security boundary for guest workload isolation - Guest VPs are constrained to run on underlying physical core pairs, reducing vulnerability to side-channel snooping attacks.

從 Windows Server 2019 開始,預設會使用核心排程器。The core scheduler is used by default starting in Windows Server 2019. 在 Windows Server 2016 上,核心排程器是選擇性的,而且必須由 Hyper-v 主機管理員明確啟用,而且傳統排程器是預設值。On Windows Server 2016, the core scheduler is optional and must be explicitly enabled by the Hyper-V host administrator, and the classic scheduler is the default.

已停用主機 SMT 的核心排程器行為Core scheduler behavior with host SMT disabled

如果虛擬機器已設定為使用核心排程器類型,但 SMT 功能已停用或不存在於虛擬化主機上,則無論是否使用 [程式管理器排程器] 類型設定,管理器都會使用傳統排程器行為。If the hypervisor is configured to use the core scheduler type but the SMT capability is disabled or not present on the virtualization host, then the hypervisor uses the classic scheduler behavior, regardless of the hypervisor scheduler type setting.

根排程器The root scheduler

根排程器是在 Windows 10 1803 版中引進。The root scheduler was introduced with Windows 10 version 1803. 當根排程器類型為 [已啟用] 時,[處理常式 cedes] 會對根磁碟分割進行工作排程的控制。When the root scheduler type is enabled, the hypervisor cedes control of work scheduling to the root partition. 根磁碟分割的 OS 實例中的 NT 排程器會管理將工作排程到系統 LPs 的所有層面。The NT scheduler in the root partition's OS instance manages all aspects of scheduling work to system LPs.

根排程器會解決支援公用程式磁碟分割所固有的獨特需求,以提供與 Windows Defender 應用程式防護(WDAG)搭配使用的強式工作負載隔離。The root scheduler addresses the unique requirements inherent with supporting a utility partition to provide strong workload isolation, as used with Windows Defender Application Guard (WDAG). 在此案例中,將排程責任留給根 OS 會提供幾個優點。In this scenario, leaving scheduling responsibilities to the root OS offers several advantages. 例如,適用于容器案例的 CPU 資源控制可以搭配公用程式分割使用,以簡化管理和部署。For example, CPU resource controls applicable to container scenarios may be used with the utility partition, simplifying management and deployment. 此外,根 OS 排程器可以隨時收集容器內工作負載 CPU 使用率的相關計量,並使用此資料做為與系統中所有其他工作負載適用的相同排程原則的輸入。In addition, the root OS scheduler can readily gather metrics about workload CPU utilization inside the container and use this data as input to the same scheduling policy applicable to all other workloads in the system. 這些相同的計量也有助於清楚地將應用程式容器中所執行的屬性,設定為主機系統。These same metrics also help clearly attribute work done in an application container to the host system. 使用傳統虛擬機器工作負載來追蹤這些計量會比較棘手,因為所有執行中 VM 的工作都是在根磁碟分割中進行。Tracking these metrics is more difficult with traditional virtual machine workloads, where some work on all running VM's behalf takes place in the root partition.

根排程器在用戶端系統上使用Root scheduler use on client systems

從 Windows 10 1803 版開始,預設會在用戶端系統上使用根排程器,在此情況下,系統管理人員可能會啟用以支援虛擬化安全性和 WDAG 工作負載隔離,以及使用異類核心架構進行未來系統的適當操作。Starting with Windows 10 version 1803, the root scheduler is used by default on client systems only, where the hypervisor may be enabled in support of virtualization-based security and WDAG workload isolation, and for proper operation of future systems with heterogeneous core architectures. 這是用戶端系統唯一支援的程式管理器排程器設定。This is the only supported hypervisor scheduler configuration for client systems. 管理員不應嘗試覆寫 Windows 10 用戶端系統上的預設「虛擬程式管理者」類型。Administrators should not attempt to override the default hypervisor scheduler type on Windows 10 client systems.

虛擬機器 CPU 資源控制和根排程器Virtual Machine CPU resource controls and the root scheduler

當虛擬機器根排程器因為根作業系統的排程器邏輯以全域方式管理主機資源,且不知道 VM 的特定設定時,不支援 Hyper-v 所提供的虛擬機器處理器資源控制。The virtual machine processor resource controls provided by Hyper-V are not supported when the hypervisor root scheduler is enabled as the root operating system's scheduler logic is managing host resources on a global basis and does not have knowledge of a VM's specific configuration settings. Hyper-v 每個 VM 的處理器資源控制,例如 cap、權數和保留,僅適用于管理者直接控制 VP 排程的情況,例如使用傳統和核心排程器類型。The Hyper-V per-VM processor resource controls, such as caps, weights, and reserves, are only applicable where the hypervisor directly controls VP scheduling, such as with the classic and core scheduler types.

根排程器在伺服器系統上使用Root scheduler use on server systems

目前不建議將根排程器與伺服器上的 Hyper-v 搭配使用,因為它的效能特性尚未具備完整的特性和微調,以容納許多伺服器虛擬化部署的一般工作負載。The root scheduler is not recommended for use with Hyper-V on servers at this time, as its performance characteristics have not yet been fully characterized and tuned to accommodate the wide range of workloads typical of many server virtualization deployments.

在來賓虛擬機器中啟用 SMTEnabling SMT in guest virtual machines

當虛擬化主機的虛擬機器設定為使用核心排程器類型時,可以視需要將來賓虛擬機器設定為利用 SMT。Once the virtualization host's hypervisor is configured to use the core scheduler type, guest virtual machines may be configured to utilize SMT if desired. 公開 VPs 超執行緒至來賓虛擬機器的事實,可讓客體作業系統中的排程器和 VM 中執行的工作負載,在自己的工作排程中偵測並使用 SMT 拓撲。Exposing the fact that VPs are hyperthreaded to a guest virtual machine allows the scheduler in the guest operating system and workloads running in the VM to detect and utilize the SMT topology in their own work scheduling. 在 Windows Server 2016 上,預設不會設定來賓 SMT,而且必須由 Hyper-v 主機管理員明確啟用。On Windows Server 2016, guest SMT is not configured by default and must be explicitly enabled by the Hyper-V host administrator. 從 Windows Server 2019 開始,在主機上建立的新 Vm 預設會繼承主機的 SMT 拓撲。Starting with Windows Server 2019, new VMs created on the host inherits the host's SMT topology by default. 也就是,在每個核心有2個 SMT 執行緒的主機上建立的9.0 版 VM,也會看到每個核心2個 SMT 執行緒。That is, a version 9.0 VM created on a host with 2 SMT threads per core would also see 2 SMT threads per core.

PowerShell 必須用來在來賓虛擬機器中啟用 SMT;Hyper-v 管理員中沒有提供使用者介面。PowerShell must be used to enable SMT in a guest virtual machine; there is no user interface provided in Hyper-V Manager. 若要在來賓虛擬機器中啟用 SMT,請以足夠的許可權開啟 PowerShell 視窗,然後輸入:To enable SMT in a guest virtual machine, open a PowerShell window with sufficient permissions, and type:

Set-VMProcessor -VMName <VMName> -HwThreadCountPerCore <n>

其中 是來賓 VM 所看到之每個核心的 SMT 執行緒數目。Where is the number of SMT threads per core the guest VM sees. 請注意, = 0 會將 HwThreadCountPerCore 值設定為符合主機的每個核心值的 SMT 執行緒計數。Note that = 0 sets the HwThreadCountPerCore value to match the host's SMT thread count per core value.

注意

從 Windows Server 2019 開始支援設定 HwThreadCountPerCore = 0。Setting HwThreadCountPerCore = 0 is supported beginning with Windows Server 2019.

以下是從在虛擬機器中執行且已啟用2個虛擬處理器和 SMT 的客體作業系統所取得的系統資訊範例。Below is an example of System Information taken from the guest operating system running in a virtual machine with 2 virtual processors and SMT enabled. 客體作業系統偵測到屬於相同核心的2個邏輯處理器。The guest operating system is detecting 2 logical processors belonging to the same core.

顯示已啟用 SMT 之來賓 VM 中的 msinfo32 的螢幕擷取畫面

在 Windows Server 2016 Hyper-v 上設定虛擬程式排程器類型Configuring the hypervisor scheduler type on Windows Server 2016 Hyper-V

Windows Server 2016 Hyper-v 預設會使用傳統的虛擬程式管理器排程器模型。Windows Server 2016 Hyper-V uses the classic hypervisor scheduler model by default. 您可以選擇性地將管理程式設定為使用核心排程器,藉由限制來賓 VPs 在對應的實體 SMT 組上執行,以及支援使用虛擬機器與其來賓 VPs 的 SMT 排程,來提高安全性。The hypervisor can be optionally configured to use the core scheduler, to increase security by restricting guest VPs to run on corresponding physical SMT pairs, and to support the use of virtual machines with SMT scheduling for their guest VPs.

注意

Microsoft 建議所有執行 Windows Server 2016 Hyper-v 的客戶選取核心排程器,以確保其虛擬化主機能以最佳的方式受到保護,以防止潛在的惡意來賓 Vm。Microsoft recommends that all customers running Windows Server 2016 Hyper-V select the core scheduler to ensure their virtualization hosts are optimally protected against potentially malicious guest VMs.

Windows Server 2019 Hyper-v 預設為使用核心排程器Windows Server 2019 Hyper-V defaults to using the core scheduler

為了協助確保 Hyper-v 主機已部署在最佳的安全性設定中,Windows Server 2019 Hyper-v 現在預設會使用核心程式管理者排程器模型。To help ensure Hyper-V hosts are deployed in the optimal security configuration, Windows Server 2019 Hyper-V now uses the core hypervisor scheduler model by default. 主機管理員可以選擇性地將主機設定為使用舊版傳統排程器。The host administrator may optionally configure the host to use the legacy classic scheduler. 在覆寫排程器類型的預設設定之前,系統管理員應該仔細閱讀、瞭解和考慮每個排程器類型對虛擬化主機的安全性和效能的影響。Administrators should carefully read, understand and consider the impacts each scheduler type has on the security and performance of virtualization hosts prior to overriding the scheduler type default settings. 如需詳細資訊,請參閱瞭解 hyper-v 排程器類型選取專案See Understanding Hyper-V scheduler type selection for more information.

必要的更新Required updates

注意

若要使用本檔中所述的程式管理器排程器功能,必須進行下列更新。The following updates are required to use the hypervisor scheduler features described in this document. 這些更新包含變更,以支援 hypervisorschedulertype 主機設定所需的新 BCD 選項。These updates include changes to support the new hypervisorschedulertype BCD option, which is necessary for host configuration.

版本Version 版本Release 需要更新Update Required 知識庫文章KB Article
Windows Server 2016Windows Server 2016 16071607 2018.07 C2018.07 C KB4338822KB4338822
Windows Server 2016Windows Server 2016 17031703 2018.07 C2018.07 C KB4338827KB4338827
Windows Server 2016Windows Server 2016 17091709 2018.07 C2018.07 C KB4338817KB4338817
Windows Server 2019Windows Server 2019 18041804 NoneNone NoneNone

選取 Windows Server 上的虛擬程式排程器類型Selecting the hypervisor scheduler type on Windows Server

虛擬程式管理器排程器設定是透過 hypervisorschedulertype BCD 專案來控制。The hypervisor scheduler configuration is controlled via the hypervisorschedulertype BCD entry.

若要選取排程器類型,請使用系統管理員許可權開啟命令提示字元:To select a scheduler type, open a command prompt with administrator privileges:

bcdedit /set hypervisorschedulertype type

其中 type 是下列其中一個:Where type is one of:

  • 傳統Classic
  • 核心Core
  • RootRoot

系統必須重新開機,程式管理器排程器類型的任何變更才會生效。The system must be rebooted for any changes to the hypervisor scheduler type to take effect.

注意

Windows Server Hyper-v 目前不支援虛擬程式根排程器。The hypervisor root scheduler is not supported on Windows Server Hyper-V at this time. Hyper-v 系統管理員不應嘗試設定根排程器來與伺服器虛擬化案例搭配使用。Hyper-V administrators should not attempt to configure the root scheduler for use with server virtualization scenarios.

判斷目前的排程器類型Determining the current scheduler type

您可以藉由檢查最新的程式管理器啟動事件識別碼2的事件檢視器中的系統記錄,來判斷目前使用中的管理器排程器類型,這會報告在啟動程式管理程式時所設定的管理器排程器類型。You can determine the current hypervisor scheduler type in use by examining the System log in Event Viewer for the most recent hypervisor launch event ID 2, which reports the hypervisor scheduler type configured at hypervisor launch. 您可以從 Windows 事件檢視器或透過 PowerShell 來取得「虛擬程式啟動」事件。Hypervisor launch events can be obtained from the Windows Event Viewer, or via PowerShell.

「虛擬程式啟動事件識別碼2」代表「管理器排程器」類型,其中:Hypervisor launch event ID 2 denotes the hypervisor scheduler type, where:

  • 1 = 傳統排程器,SMT 已停用1 = Classic scheduler, SMT disabled

  • 2 = 傳統排程器2 = Classic scheduler

  • 3 = 核心排程器3 = Core scheduler

  • 4 = 根排程器4 = Root scheduler

顯示管理程式啟動事件識別碼2詳細資料的螢幕擷取畫面

顯示事件檢視器顯示虛擬程式啟動事件識別碼2的螢幕擷取畫面

使用 PowerShell 查詢 Hyper-v 虛擬機器排程器類型的啟動事件Querying the Hyper-V hypervisor scheduler type launch event using PowerShell

若要使用 PowerShell 查詢虛擬程式事件識別碼2,請從 PowerShell 提示字元輸入下列命令。To query for hypervisor event ID 2 using PowerShell, enter the following commands from a PowerShell prompt.

Get-WinEvent -FilterHashTable @{ProviderName="Microsoft-Windows-Hyper-V-Hypervisor"; ID=2} -MaxEvents 1

顯示虛擬機器啟動事件識別碼2之 PowerShell 查詢和結果的螢幕擷取畫面