(文章來自作者維護的社群微信公衆号【虛拟化雲計算】) (目前有兩個微信群《kvm虛拟化》和《openstack》,掃描二維碼點選“雲-交流”,進群交流提問)

在libvrit的domain的xml檔案中有兩個地方控制cpu數量和拓撲,一個是cpu,一個是vcpu,其中cpu段控制虛拟機cpu的模式和拓撲,vcpu段控制cpu的配置設定和熱插拔情況。 cpu模式和拓撲 cpu段來控制cpu的模式和拓撲,cpu模式一般有下面兩種配置方式: <domain> ... <cpu mode='host-model'> <model fallback='allow'/> <topology sockets='1' cores='2' threads='1'/> </cpu> ... </domain> cpu mode:可取值為custom host-model host-passthrouth <domain> ... <cpu match='exact'> <model fallback='allow'>core2duo</model> <vendor>Intel</vendor> <topology sockets='1' cores='2' threads='1'/> <cache level='3' mode='emulate'/> <feature policy='disable' name='lahf_lm'/> </cpu> ... </domain> cpu match:可取值為exact minimum strict 另外cpu的numa配置也在這裡配。 topology :控制虛拟機的cpu拓撲結構,這隻是控制拓撲結構,具體的虛拟機裡有幾個cpu,實在vcpu段控制的。 vcpu配置設定 <domain> ... <vcpu placement='static' cpuset="1-4,^3,6" current="1">2</vcpu> <vcpus> <vcpu id='0' enabled='yes' hotpluggable='no' order='1'/> <vcpu id='1' enabled='no' hotpluggable='yes'/> </vcpus> ... </domain> vcpu:最大vcpu數量,不能超出cpu拓撲中的數值。 cpuset:指定CPU的親和性,如果cputune中制定了vcpupin的親和性,這裡的将被忽略。 current:開機時給虛拟機配置設定的cpu數量。 vcpus:配置單個vcpu的狀态。 備注:從cpu和vcpu兩段來看,cpu的數量是受到current、vcpu、topology控制的。 cpu熱插 目前配置: <vcpu placement='static' current='2'>4</vcpu> <cpu> <topology sockets='1' cores='4' threads='1'/> </cpu> 根據上述配置,此虛拟機開機時有兩個cpu,另外有兩個cpu可以後插入。 libvirt監控狀态: virsh # vcpucount instance-0000000d maximum config 4 maximum live 4 current config 2 current live 2 virsh # vcpuinfo instance-0000000d VCPU: 0 CPU: 2 State: running CPU time: 1.3s CPU Affinity: yyyy VCPU: 1 CPU: 3 State: running CPU time: 0.5s CPU Affinity: yyyy virsh # cpu-stats instance-0000000d CPU0: cpu_time 0.000000000 seconds vcpu_time 0.000000000 seconds CPU1: cpu_time 0.000000000 seconds vcpu_time 0.000000000 seconds CPU2: cpu_time 1.559106643 seconds vcpu_time 1.149663485 seconds CPU3: cpu_time 1.006847058 seconds vcpu_time 0.701462772 seconds Total: cpu_time 2.565953701 seconds user_time 0.540000000 seconds system_time 0.710000000 seconds 虛拟機内部CPU清單:
插入cpu: # virsh setvcpus instance-0000000d --count 4 --live 在虛拟機内部激活新插入的cpu:
============================================================== 關注微信公衆号【虛拟化雲計算】,閱讀更多虛拟化雲計算知識,純技術幹貨更新不停。