libvirt-cpu分配和cpu热插拔

时间:2022-05-07
本文章向大家介绍libvirt-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配置也在这里配。

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 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:


关注本公众号,了解更多关于云计算虚拟化的知识。