您的位置:首页 > 其它

libvirt-qemu-虚拟机cpu分配和cpu热插拔

2018-01-28 17:15 681 查看
[align=center](文章来自作者维护的社区微信公众号【虚拟化云计算】)[/align]


    在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           2
virsh # vcpuinfo instance-0000000dVCPU:           0CPU:            2State:          runningCPU time:       1.3sCPU Affinity:   yyyyVCPU:           1CPU:            3State:          runningCPU time:       0.5sCPU Affinity:   yyyy
virsh # 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:

[align=left]==============================================================[/align][align=center]关注微信公众号【虚拟化云计算】,阅读更多虚拟化云计算知识,纯技术干货更新不停。[/align]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: