1. 程式人生 > >libvirt-qemu-虛擬機器cpu分配和cpu熱插拔

libvirt-qemu-虛擬機器cpu分配和cpu熱插拔

(文章來自作者維護的社群微信公眾號【虛擬化雲端計算】)
    在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-0000000dmaximum      config         4maximum      live           4current      config         2current      live           2virsh # vcpuinfo instance-0000000dVCPU:           0CPU:            2State:          runningCPU time:       1.3sCPU Affinity:   yyyyVCPU:           1CPU:            3State:          runningCPU time:       0.5sCPU Affinity:   yyyyvirsh # cpu-stats instance-0000000dCPU0:        cpu_time             0.000000000 seconds        vcpu_time            0.000000000 secondsCPU1:        cpu_time             0.000000000 seconds        vcpu_time            0.000000000 secondsCPU2:        cpu_time             1.559106643 seconds        vcpu_time            1.149663485 secondsCPU3:        cpu_time             1.006847058 seconds        vcpu_time            0.701462772 secondsTotal:        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:==============================================================關注微信公眾號【虛擬化雲端計算】,閱讀更多虛擬化雲端計算知識,純技術乾貨更新不停。