適用於:Windows Server 2016,Microsoft Hyper-v Server 2016,Windows Server 2019,Microsoft Hyper-v Server 2019Applies To: Windows Server 2016, Microsoft Hyper-V Server 2016, Windows Server 2019, Microsoft Hyper-V Server 2019

虛擬機器資源控制Virtual Machine Resource Controls

本文說明虛擬機器的 Hyper-v 資源和隔離控制。This article describes Hyper-V resource and isolation controls for virtual machines. 這些功能(我們將稱之為虛擬機器 CPU 群組,或只是「CPU 群組」)是在 Windows Server 2016 中引進。These capabilities, which we'll refer to as Virtual Machine CPU Groups, or just “CPU groups”, were introduced in Windows Server 2016. CPU 群組可讓 Hyper-v 系統管理員更有效地管理和配置跨來賓虛擬機器的主機 CPU 資源。CPU groups allow Hyper-V administrators to better manage and allocate the host's CPU resources across guest virtual machines. 使用 CPU 群組時,Hyper-v 系統管理員可以:Using CPU groups, Hyper-V administrators can:

  • 建立虛擬機器群組,其中每個群組各有不同的虛擬化主機總 CPU 資源配置,並在整個群組之間共用。Create groups of virtual machines, with each group having different allocations of the virtualization host's total CPU resources, shared across the entire group. 這可讓主機管理員針對不同類型的 Vm 執行服務的類別。This allows the host administrator to implement classes of service for different types of VMs.

  • 將 CPU 資源限制設定為特定群組。Set CPU resource limits to specific groups. 此「群組上限」設定了整個群組可能會耗用的主機 CPU 資源上限,有效地強制執行該群組所需的服務類別。This “group cap” sets the upper bound for host CPU resources that the entire group may consume, effectively enforcing the desired class of service for that group.

  • 限制 CPU 群組只能在一組特定的主機系統處理器上執行。Constrain a CPU group to run only on a specific set of the host system's processors. 這可以用來隔離屬於不同 CPU 群組的 Vm。This can be used to isolate VMs belonging to different CPU groups from each other.

管理 CPU 群組Managing CPU Groups

CPU 群組是透過 Hyper-v 主機計算服務或 HCS 來管理。CPU groups are managed through the Hyper-V Host Compute Service, or HCS. 如需 HCS、其創世、HCS Api 連結等等的絕佳說明,請前往《主機計算服務(HCS)簡介中的 Microsoft 虛擬化小組的 blog。A great description of the HCS, its genesis, links to the HCS APIs, and more is available on the Microsoft Virtualization team's blog in the posting Introducing the Host Compute Service (HCS).

注意

只有 HCS 可以用來建立和管理 CPU 群組;Hyper-v 管理員 applet、WMI 和 PowerShell 管理介面不支援 CPU 群組。Only the HCS may be used to create and manage CPU groups; the Hyper-V Manager applet, WMI and PowerShell management interfaces don't support CPU groups.

Microsoft 會在Microsoft 下載中心提供命令列公用程式 cpugroups,其使用 HCS 介面來管理 CPU 群組。Microsoft provides a command line utility, cpugroups.exe, on the Microsoft Download Center which uses the HCS interface to manage CPU groups. 此公用程式也可以顯示主機的 CPU 拓撲。This utility can also display the CPU topology of a host.

CPU 群組的工作方式How CPU Groups Work

Hyper-v 虛擬機器會使用計算的 CPU 群組上限,強制執行跨 CPU 群組的主機計算資源配置。Allocation of host compute resources across CPU groups is enforced by the Hyper-V hypervisor, using a computed CPU group cap. CPU 群組上限是 CPU 群組的總 CPU 容量的一小部分。The CPU group cap is a fraction of the total CPU capacity for a CPU group. 群組上限的值取決於群組類別或指派的優先權層級。The value of the group cap depends on the group class, or priority level assigned. 計算的群組上限可視為「一種 LP 的 CPU 時間數量」。The computed group cap can be thought of as “a number of LP's worth of CPU time”. 此群組預算是共用的,因此如果只有單一 VM 處於作用中狀態,則可以使用整個群組的 CPU 配置來進行本身。This group budget is shared, so if only a single VM were active, it could use the entire group's CPU allocation for itself.

CPU 群組上限的計算方式為 G = n x C,其中:The CPU group cap is calculated as G = n x C, where:

*G* is the amount of host LP we'd like to assign to the group
*n* is the total number of logical processors (LPs) in the group
*C* is the maximum CPU allocation — that is, the class of service desired for the group, expressed as a percentage of the system's total compute capacity

例如,假設有一個 CPU 群組設定了4個邏輯處理器(LPs),而上限為 50%。For example, consider a CPU group configured with 4 logical processors (LPs), and a cap of 50%.

G = n * C
G = 4 * 50%
G = 2 LP's worth of CPU time for the entire group

在此範例中,CPU 群組 G 會配置2個 LP 的 CPU 時間。In this example, the CPU group G is allocated 2 LP's worth of CPU time.

請注意,不論已指派給該群組的虛擬機器或虛擬處理器數目為何,不論是否已指派給 CPU 群組的虛擬機器的狀態(例如關閉或啟動)為何,群組上限都會套用。Note that the group cap applies regardless of the number of virtual machines or virtual processors bound to the group, and regardless of the state (e.g., shutdown or started) of the virtual machines assigned to the CPU group. 因此,系結至相同 CPU 群組的每個 VM 都會收到群組的總 CPU 配置,而這會隨著系結至 CPU 群組的 Vm 數目而變更。Therefore, each VM bound to the same CPU group will receive a fraction of the group's total CPU allocation, and this will change with the number of VMs bound to the CPU group. 因此,當 Vm 是從 CPU 群組系結或解除系結 Vm 時,整體 CPU 群組上限必須是進行調整並設定,以維持所需的每個 VM 上限。Therefore, as VMs are bound or unbound VMs from a CPU group, the overall CPU group cap must be readjusted and set to maintain the resulting per-VM cap desired. VM 主機管理員或虛擬化管理軟體層負責視需要管理群組上限,以達到所需的每個 VM CPU 資源配置。The VM host administrator or virtualization management software layer is responsible for managing group caps as necessary to achieve the desired per-VM CPU resource allocation.

服務的範例類別Example Classes of Service

讓我們來看一些簡單的範例。Let's look at some simple examples. 首先,假設 Hyper-v 主機系統管理員想要支援來賓 Vm 的兩個服務層級:To start with, assume the Hyper-V host administrator would like to support two tiers of service for guest VMs:

  1. 低端「C」層。A low-end “C” tier. 我們會為這一層提供整個主機計算資源的 10%。We'll give this tier 10% of the entire host's compute resources.

  2. 中間範圍「B」層。A mid-range “B” tier. 這一層配置了整部主機計算資源的 50%。This tier is allocated 50% of the entire host's compute resources.

在我們的範例中,我們將判斷提示不會使用其他 CPU 資源控制,例如個別 VM cap、權數和保留。At this point in our example we'll assert that no other CPU resource controls are in use, such as individual VM caps, weights, and reserves. 不過,個別的 VM cap 很重要,因為我們稍後會看到一些。However, individual VM caps are important, as we'll see a bit later.

為了簡單起見,假設每個 VM 都有1個副總裁,而我們的主機有 8 LPs。For simplicity's sake, let's assume each VM has 1 VP, and that our host has 8 LPs. 我們會從空白主機開始。We'll start with an empty host.

若要建立「B」層,主機 adminstartor 會將群組上限設定為 50%:To create the "B" tier, the host adminstartor sets the group cap to 50%:

G = n * C
G = 8 * 50%
G = 4 LP's worth of CPU time for the entire group

主機管理員會新增單一「B」層 VM。The host administrator adds a single “B” tier VM. 此時,我們的「B」層 VM 最多可使用 50% 的主機 CPU,或在我們的範例系統中相當於4個 LPs。At this point, our “B” tier VM can use at most 50% worth of the host's CPU, or the equivalent of 4 LPs in our example system.

現在,管理員會新增第二個「層 B」 VM。Now, the admin adds a second “Tier B” VM. CPU 群組的配置,會平均分散到所有 Vm。The CPU group's allocation—is divided evenly among all the VMs. 我們總共在群組 B 中有2個 Vm,因此每個 VM 現在都有一半的群組 B 總計 50%、25%,或等於2個 LPs 值得計算時間。We've got a total of 2 VMs in Group B, so each VM now gets half of Group B's total of 50%, 25% each, or the equivalent of 2 LPs worth of compute time.

在個別 Vm 上設定 CPU 限定Setting CPU Caps on Individual VMs

除了群組上限,每個 VM 也可以有個別的「VM 端點」。In addition to the group cap, each VM can also have an individual “VM cap”. 自其簡介以來,每個 VM 的 CPU 資源控制項(包括 CPU 限定、權數和保留)都是 Hyper-v 的一部分。Per-VM CPU resource controls, including a CPU cap, weight, and reserve, have been a part of Hyper-V since its introduction. 結合群組上限時,即使群組有可用的 CPU 資源,VM 上限也會指定每個 VP 可以取得的 CPU 最大數量。When combined with a group cap, a VM cap specifies the maximum amount of CPU that each VP can get, even if the group has CPU resources available.

例如,主機管理員可能會想要在 "C" Vm 上放置 10% 的 VM 上限。For example, the host administrator might want to place a 10% VM cap on “C” VMs. 如此一來,即使大部分的 "C" VPs 都閒置,每副總 VP 也無法超過 10%。That way, even if most “C” VPs are idle, each VP could never get more than 10%. 如果沒有 VM 上限,"C" Vm 可能會都伺機達到其層級所允許的等級以外的效能。Without a VM cap, “C” VMs could opportunistically achieve performance beyond levels allowed by their tier.

將 VM 群組隔離到特定主機處理器Isolating VM Groups to Specific Host Processors

Hyper-v 主機系統管理員可能也想要能夠將計算資源專用於 VM。Hyper-V host administrators may also want the ability to dedicate compute resources to a VM. 例如,假設系統管理員想要提供高階「A」 VM,其類別上限為 100%。For example, imagine the administrator wanted to offer a premium “A” VM that has a class cap of 100%. 這些 premium Vm 也需要最低的排程延遲和抖動;也就是說,它們可能不會被其他任何 VM 取消排程。These premium VMs also require the lowest scheduling latency and jitter possible; that is, they may not be de-scheduled by any other VM. 若要達到此分隔,也可以使用特定的 LP 親和性對應來設定 CPU 群組。To achieve this separation, a CPU group can also be configured with a specific LP affinity mapping.

例如,若要在我們的範例中配合主機上的「A」 VM,系統管理員會建立新的 CPU 群組,並將群組的處理器親和性設定為主機 LPs 的子集。For example, to fit an “A” VM on the host in our example, the administrator would create a new CPU group, and set the group's processor affinity to a subset of the host's LPs. 群組 B 和 C 會相似化為到剩餘的 LPs。Groups B and C would be affinitized to the remaining LPs. 系統管理員可以在群組 A 中建立單一 VM,然後對群組 A 中的所有 LPs 具有獨佔存取權,而較低層群組 B 和 C 則會共用剩餘的 LPs。The administrator could create a single VM in Group A, which would then have exclusive access to all LPs in Group A, while the presumably lower tier groups B and C would share the remaining LPs.

將根 VPs 從來賓 VPs 中分離Segregating Root VPs from Guest VPs

根據預設,Hyper-v 會在每個基礎實體 LP 上建立根副總。By default, Hyper-V will create a root VP on each underlying physical LP. 這些根 VPs 會嚴格對應1:1 與系統 LPs,而且不會遷移—也就是說,每個根副總都一律會在相同的實體 LP 上執行。These root VPs are strictly mapped 1:1 with the system LPs, and do not migrate — that is, each root VP will always execute on the same physical LP. 來賓 VPs 可在任何可用的 LP 上執行,且會與根 VPs 共用執行。Guest VPs may be run on any available LP, and will share execution with root VPs.

不過,您可能會想要完全區分根副總活動與來賓 VPs。However, it may be desirable to completely separate root VP activity from guest VPs. 請考慮我們的範例,我們將在其中實行 premium 「A」層 VM。Consider our example above where we implement a premium “A” tier VM. 為確保我們的「A」 VM 的 VPs 具有最低的可能延遲和「抖動」,或排程變化,我們想要在一組專用的 LPs 上執行,並確保根目錄不會在這些 LPs 上執行。To ensure our “A” VM's VPs have the lowest possible latency and “jitter”, or scheduling variation, we'd like to run them on a dedicated set of LPs and ensure the root does not run on these LPs.

這可以使用 "minroot" 設定的組合來完成,這會限制主機 OS 磁碟分割在整體系統邏輯處理器的子集上執行,以及一或多個相似化為的 CPU 群組。This can be accomplished using a combination of the “minroot” configuration, which limits the host OS partition to running on a subset of the total system logical processors, along with one or more affinitized CPU groups.

虛擬化主機可以設定為將主機磁碟分割限制為特定 LPs,並將一或多個 CPU 群組相似化為到剩餘的 LPs。The virtualization host can be configured to restrict the host partition to specific LPs, with one or more CPU groups affinitized to the remaining LPs. 如此一來,根和來賓磁碟分割就可以在專用的 CPU 資源上執行,而且完全隔離,而不會有 CPU 共用。In this manner, the root and guest partitions can run on dedicated CPU resources, and completely isolated, with no CPU sharing.

如需有關 "minroot" 設定的詳細資訊,請參閱Hyper-v 主機 CPU 資源管理For more information about the "minroot" configuration, see Hyper-V Host CPU Resource Management.

使用 CpuGroups 工具Using the CpuGroups Tool

讓我們看看一些如何使用 CpuGroups 工具的範例。Let's look at some examples of how to use the CpuGroups tool.

注意

CpuGroups 工具的命令列參數只會使用空格做為分隔符號來傳遞。Command line parameters for the CpuGroups tool are passed using only spaces as delimiters. 沒有 '/' 或 '-' 字元應該繼續所需的命令列參數。No ‘/' or ‘-‘ characters should proceed the desired command line switch.

探索 CPU 拓撲Discovering the CPU Topology

使用 GetCpuTopology 執行 CpuGroups 會傳回目前系統的相關資訊,如下所示,包括 LP 索引、LP 所屬的 NUMA 節點、封裝和核心識別碼,以及根 VP 索引。Executing CpuGroups with the GetCpuTopology returns information about the current system, as shown below, including the LP Index, the NUMA node to which the LP belongs, the Package and Core IDs, and the ROOT VP index.

下列範例顯示的系統具有2個 CPU 通訊端和 NUMA 節點、總計 32 LPs 和多執行緒啟用,並已設定為啟用具有8個根 VPs 的 Minroot,每個 NUMA 節點4個。The following example shows a system with 2 CPU sockets and NUMA nodes, a total of 32 LPs, and multi threading enabled, and configured to enable Minroot with 8 root VPs, 4 from each NUMA node. 具有根 VPs 的 LPs 具有 RootVpIndex > = 0;根磁碟分割無法使用 RootVpIndex 為-1 的 LPs,但仍受限於虛擬程式管理,並會執行其他設定的允許來賓 VPs。The LPs that have root VPs have a RootVpIndex >= 0; LPs with a RootVpIndex of -1 are not available to the root partition, but are still managed by the hypervisor and will run guest VPs as allowed by other configuration settings.

C:\vm\tools>CpuGroups.exe GetCpuTopology

LpIndex NodeNumber PackageId CoreId RootVpIndex
------- ---------- --------- ------ -----------
      0          0         0      0           0
      1          0         0      0           1
      2          0         0      1           2
      3          0         0      1           3
      4          0         0      2          -1
      5          0         0      2          -1
      6          0         0      3          -1
      7          0         0      3          -1
      8          0         0      4          -1
      9          0         0      4          -1
     10          0         0      5          -1
     11          0         0      5          -1
     12          0         0      6          -1
     13          0         0      6          -1
     14          0         0      7          -1
     15          0         0      7          -1
     16          1         1     16           4
     17          1         1     16           5
     18          1         1     17           6
     19          1         1     17           7
     20          1         1     18          -1
     21          1         1     18          -1
     22          1         1     19          -1
     23          1         1     19          -1
     24          1         1     20          -1
     25          1         1     20          -1
     26          1         1     21          -1
     27          1         1     21          -1
     28          1         1     22          -1
     29          1         1     22          -1
     30          1         1     23          -1
     31          1         1     23          -1

範例2–列印主機上的所有 CPU 群組Example 2 – Print all CPU groups on the host

在這裡,我們將列出目前主機上的所有 CPU 群組、其 GroupId、群組的 CPU 限定,以及指派給該群組的 LPs indicies。Here, we'll list all CPU groups on the current host, their GroupId, the group's CPU cap, and the indicies of LPs assigned to that group.

請注意,有效的 CPU 限定值位於 [0,65536] 範圍內,而這些值會以百分比表示群組上限(例如 32768 = 50%)。Note that valid CPU cap values are in the range [0, 65536], and these values express the group cap in percent (e.g., 32768 = 50%).

C:\vm\tools>CpuGroups.exe GetGroups

CpuGroupId                          CpuCap  LpIndexes
------------------------------------ ------ --------
36AB08CB-3A76-4B38-992E-000000000002 32768  4,5,6,7,8,9,10,11,20,21,22,23
36AB08CB-3A76-4B38-992E-000000000003 65536  12,13,14,15
36AB08CB-3A76-4B38-992E-000000000004 65536  24,25,26,27,28,29,30,31

範例3–列印單一 CPU 群組Example 3 – Print a single CPU group

在此範例中,我們將使用 GroupId 作為篩選準則來查詢單一 CPU 群組。In this example, we'll query a single CPU Group using the GroupId as a filter.

C:\vm\tools>CpuGroups.exe GetGroups /GroupId:36AB08CB-3A76-4B38-992E-000000000003
CpuGroupId                          CpuCap   LpIndexes
------------------------------------ ------ ----------
36AB08CB-3A76-4B38-992E-000000000003 65536  12,13,14,15

範例4–建立新的 CPU 群組Example 4 – Create a new CPU group

在這裡,我們將建立新的 CPU 群組,並指定要指派給群組的群組識別碼和 LPs 集。Here, we'll create a new CPU group, specifying the Group ID and the set of LPs to assign to the group.

C:\vm\tools>CpuGroups.exe CreateGroup /GroupId:36AB08CB-3A76-4B38-992E-000000000001 /GroupAffinity:0,1,16,17

現在會顯示新加入的群組。Now display our newly added group.

C:\vm\tools>CpuGroups.exe GetGroups
CpuGroupId                          CpuCap LpIndexes
------------------------------------ ------ ---------
36AB08CB-3A76-4B38-992E-000000000001 65536 0,1,16,17
36AB08CB-3A76-4B38-992E-000000000002 32768 4,5,6,7,8,9,10,11,20,21,22,23
36AB08CB-3A76-4B38-992E-000000000003 65536 12,13,14,15
36AB08CB-3A76-4B38-992E-000000000004 65536 24,25,26,27,28,29,30,31

範例5–將 CPU 群組上限設定為 50%Example 5 – Set the CPU group cap to 50%

在這裡,我們會將 CPU 群組上限設定為 50%。Here, we'll set the CPU group cap to 50%.

C:\vm\tools>CpuGroups.exe SetGroupProperty /GroupId:36AB08CB-3A76-4B38-992E-000000000001 /CpuCap:32768

現在讓我們藉由顯示剛剛更新的群組來確認我們的設定。Now let's confirm our setting by displaying the group we just updated.

C:\vm\tools>CpuGroups.exe GetGroups /GroupId:36AB08CB-3A76-4B38-992E-000000000001

CpuGroupId                          CpuCap LpIndexes
------------------------------------ ------ ---------
36AB08CB-3A76-4B38-992E-000000000001 32768 0,1,16,17

範例6–針對主機上的所有 Vm 列印 CPU 群組識別碼Example 6 – Print CPU group ids for all VMs on the host

C:\vm\tools>CpuGroups.exe GetVmGroup

VmName                                 VmId                           CpuGroupId
------ ------------------------------------ ------------------------------------
    G2 4ABCFC2F-6C22-498C-BB38-7151CE678758 36ab08cb-3a76-4b38-992e-000000000002
    P1 973B9426-0711-4742-AD3B-D8C39D6A0DEC 36ab08cb-3a76-4b38-992e-000000000003
    P2 A593D93A-3A5F-48AB-8862-A4350E3459E8 36ab08cb-3a76-4b38-992e-000000000004
    G3 B0F3FCD5-FECF-4A21-A4A2-DE4102787200 36ab08cb-3a76-4b38-992e-000000000002
    G1 F699B50F-86F2-4E48-8BA5-EB06883C1FDC 36ab08cb-3a76-4b38-992e-000000000002

範例7–解除 VM 與 CPU 群組的系結Example 7 – Unbind a VM from the CPU group

若要從 CPU 群組中移除 VM,請將設定為 VM 的 CpuGroupId 為 Null GUID。To remove a VM from a CPU group, set to VM's CpuGroupId to the NULL GUID. 這會將 VM 從 CPU 群組中解除系結。This unbinds the VM from the CPU group.

C:\vm\tools>CpuGroups.exe SetVmGroup /VmName:g1 /GroupId:00000000-0000-0000-0000-000000000000

C:\vm\tools>CpuGroups.exe GetVmGroup
VmName                                 VmId                           CpuGroupId
------ ------------------------------------ ------------------------------------
    G2 4ABCFC2F-6C22-498C-BB38-7151CE678758 36ab08cb-3a76-4b38-992e-000000000002
    P1 973B9426-0711-4742-AD3B-D8C39D6A0DEC 36ab08cb-3a76-4b38-992e-000000000003
    P2 A593D93A-3A5F-48AB-8862-A4350E3459E8 36ab08cb-3a76-4b38-992e-000000000004
    G3 B0F3FCD5-FECF-4A21-A4A2-DE4102787200 36ab08cb-3a76-4b38-992e-000000000002
    G1 F699B50F-86F2-4E48-8BA5-EB06883C1FDC 00000000-0000-0000-0000-000000000000

範例8–將 VM 系結至現有的 CPU 群組Example 8 – Bind a VM to an existing CPU group

在這裡,我們會將 VM 新增至現有的 CPU 群組。Here, we'll add a VM to an existing CPU group. 請注意,VM 不得系結至任何現有的 CPU 群組,或設定 CPU 群組識別碼將會失敗。Note that the VM must not be bound to any existing CPU group, or setting CPU group id will fail.

C:\vm\tools>CpuGroups.exe SetVmGroup /VmName:g1 /GroupId:36AB08CB-3A76-4B38-992E-000000000001

現在,確認 VM G1 位於所需的 CPU 群組中。Now, confirm the VM G1 is in the desired CPU group.

C:\vm\tools>CpuGroups.exe GetVmGroup
VmName                                 VmId                           CpuGroupId
------ ------------------------------------ ------------------------------------
    G2 4ABCFC2F-6C22-498C-BB38-7151CE678758 36ab08cb-3a76-4b38-992e-000000000002
    P1 973B9426-0711-4742-AD3B-D8C39D6A0DEC 36ab08cb-3a76-4b38-992e-000000000003
    P2 A593D93A-3A5F-48AB-8862-A4350E3459E8 36ab08cb-3a76-4b38-992e-000000000004
    G3 B0F3FCD5-FECF-4A21-A4A2-DE4102787200 36ab08cb-3a76-4b38-992e-000000000002
    G1 F699B50F-86F2-4E48-8BA5-EB06883C1FDC 36AB08CB-3A76-4B38-992E-000000000001

範例 9-列印依 CPU 群組識別碼分組的所有 VmExample 9 – Print all VMs grouped by CPU group id

C:\vm\tools>CpuGroups.exe GetGroupVms
CpuGroupId                           VmName                                 VmId
------------------------------------ ------ ------------------------------------
36AB08CB-3A76-4B38-992E-000000000001     G1 F699B50F-86F2-4E48-8BA5-EB06883C1FDC
36ab08cb-3a76-4b38-992e-000000000002     G2 4ABCFC2F-6C22-498C-BB38-7151CE678758
36ab08cb-3a76-4b38-992e-000000000002     G3 B0F3FCD5-FECF-4A21-A4A2-DE4102787200
36ab08cb-3a76-4b38-992e-000000000003     P1 973B9426-0711-4742-AD3B-D8C39D6A0DEC
36ab08cb-3a76-4b38-992e-000000000004     P2 A593D93A-3A5F-48AB-8862-A4350E3459E8

範例10–列印單一 CPU 群組的所有 VmExample 10 – Print all VMs for a single CPU group

C:\vm\tools>CpuGroups.exe GetGroupVms /GroupId:36ab08cb-3a76-4b38-992e-000000000002

CpuGroupId                           VmName                                VmId
------------------------------------ ------ ------------------------------------
36ab08cb-3a76-4b38-992e-000000000002     G2 4ABCFC2F-6C22-498C-BB38-7151CE678758
36ab08cb-3a76-4b38-992e-000000000002     G3 B0F3FCD5-FECF-4A21-A4A2-DE4102787200

範例11–嘗試刪除非空白的 CPU 群組Example 11 – Attempting to delete a non-empty CPU Group

只能刪除空白的 CPU 群組(也就是沒有系結 Vm 的 CPU 群組)。Only empty CPU groups—that is, CPU groups with no bound VMs—can be deleted. 嘗試刪除非空白的 CPU 群組將會失敗。Attempting to delete a non-empty CPU group will fail.

C:\vm\tools>CpuGroups.exe DeleteGroup /GroupId:36ab08cb-3a76-4b38-992e-000000000001
(null)
Failed with error 0xc0350070

範例12–從 CPU 群組解除系結唯一的 VM,並刪除群組Example 12 – Unbind the only VM from a CPU group and delete the group

在此範例中,我們將使用數個命令來檢查 CPU 群組、移除屬於該群組的單一 VM,然後刪除該群組。In this example, we'll use several commands to examine a CPU group, remove the single VM belonging to that group, then delete the group.

首先,讓我們列舉群組中的 Vm。First, let's enumerate the VMs in our group.

C:\vm\tools>CpuGroups.exe GetGroupVms /GroupId:36AB08CB-3A76-4B38-992E-000000000001
CpuGroupId                           VmName                                VmId
------------------------------------ ------ ------------------------------------
36AB08CB-3A76-4B38-992E-000000000001     G1 F699B50F-86F2-4E48-8BA5-EB06883C1FDC

我們看到只有名為 G1 的單一 VM 屬於這個群組。We see that only a single VM, named G1, belongs to this group. 讓我們將 VM 的群組識別碼設定為 Null,以將 G1 VM 從群組中移除。Let's remove the G1 VM from our group by setting the VM's group ID to NULL.

C:\vm\tools>CpuGroups.exe SetVmGroup /VmName:g1 /GroupId:00000000-0000-0000-0000-000000000000

並驗證我們的變更 。And verify our change...

C:\vm\tools>CpuGroups.exe GetVmGroup /VmName:g1
VmName                                 VmId                           CpuGroupId
------ ------------------------------------ ------------------------------------
    G1 F699B50F-86F2-4E48-8BA5-EB06883C1FDC 00000000-0000-0000-0000-000000000000

既然群組是空的,我們就可以安全地刪除它。Now that the group is empty, we can safely delete it.

C:\vm\tools>CpuGroups.exe DeleteGroup /GroupId:36ab08cb-3a76-4b38-992e-000000000001

並確認我們的群組已消失。And confirm our group is gone.

C:\vm\tools>CpuGroups.exe GetGroups
CpuGroupId                          CpuCap                     LpIndexes
------------------------------------ ------ -----------------------------
36AB08CB-3A76-4B38-992E-000000000002 32768  4,5,6,7,8,9,10,11,20,21,22,23
36AB08CB-3A76-4B38-992E-000000000003 65536  12,13,14,15
36AB08CB-3A76-4B38-992E-000000000004 65536 24,25,26,27,28,29,30,31

範例13–將 VM 系結回到其原始的 CPU 群組Example 13 – Bind a VM back to its original CPU group

C:\vm\tools>CpuGroups.exe SetVmGroup /VmName:g1 /GroupId:36AB08CB-3A76-4B38-992E-000000000002

C:\vm\tools>CpuGroups.exe GetGroupVms
CpuGroupId VmName VmId
------------------------------------ -------------------------------- ------------------------------------
36ab08cb-3a76-4b38-992e-000000000002 G2 4ABCFC2F-6C22-498C-BB38-7151CE678758
36ab08cb-3a76-4b38-992e-000000000002 G3 B0F3FCD5-FECF-4A21-A4A2-DE4102787200
36AB08CB-3A76-4B38-992E-000000000002 G1 F699B50F-86F2-4E48-8BA5-EB06883C1FDC
36ab08cb-3a76-4b38-992e-000000000003 P1 973B9426-0711-4742-AD3B-D8C39D6A0DEC
36ab08cb-3a76-4b38-992e-000000000004 P2 A593D93A-3A5F-48AB-8862-A4350E3459E8