(文章来自作者维护的社区微信公众号【虚拟化云计算】)
(目前有两个微信群《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:
==============================================================
关注微信公众号【虚拟化云计算】,阅读更多虚拟化云计算知识,纯技术干货更新不停。
 
 
 
Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐