CPU host-passthrough技术与应用

为了保证虚拟机在不同宿主机之间迁移的时候的兼容性,Libvirt对CPU提炼出标准的几种类型,在/usr/share/libvirt/cpu_map.xml中可以查到。cpu_map.xml不仅是CPU型号,还有生产商信息、每种型号的CPU特性定义等信息,如下所示:

<cpus>
  <arch name='x86'>
    <!-- vendor definitions -->
    <vendor name='Intel' string='GenuineIntel'/>
    <vendor name='AMD' string='AuthenticAMD'/>

    <!-- standard features, EDX -->
    <feature name='fpu'> <!-- CPUID_FP87 -->
      <cpuid function='0x00000001' edx='0x00000001'/>
    </feature>
    <feature name='vme'> <!-- CPUID_VME -->
      <cpuid function='0x00000001' edx='0x00000002'/>
    </feature>
    <feature name='de'> <!-- CPUID_DE -->
      <cpuid function='0x00000001' edx='0x00000004'/>
    </feature>
    <feature name='pse'> <!-- CPUID_PSE -->
      <cpuid function='0x00000001' edx='0x00000008'/>
    </feature>
    <feature name='tsc'> <!-- CPUID_TSC -->
      <cpuid function='0x00000001' edx='0x00000010'/>
    </feature>
    <feature name='msr'> <!-- CPUID_MSR -->
      <cpuid function='0x00000001' edx='0x00000020'/>
    </feature>
 ...
<!-- models -->
    <model name='486'>
      <feature name='fpu'/>
      <feature name='vme'/>
      <feature name='pse'/>
    </model>
...
  <!-- Intel CPU models -->
    <model name='Conroe'>
      <model name='pentiumpro'/>
      <vendor name='Intel'/>
      <feature name='mtrr'/>
      <feature name='mca'/>
      <feature name='pse36'/>
      <feature name='clflush'/>
      <feature name='pni'/>
      <feature name='ssse3'/>
      <feature name='syscall'/>
      <feature name='nx'/>
      <feature name='lm'/>
      <feature name='lahf_lm'/>
    </model>

Centos6.6所带的Libvirt主要规定了以下几种CPU型号:'486','pentium','pentium2','pentium3','pentiumpro','coreduo'

CPU模式配置

1)custom模式

xml配置文件如下:

<cpu mode='custom' match='exact'>
    <model fallback='allow'>kvm64</model>
</cpu>

2)host-model模式

根据物理CPU的特性,选择一个最靠近的标准CPU型号。如果没有指定CPU模式,默认也是使用这种模式,xml配置文件如下:

<cpu mode='host-model' />

3)host-passthrough模式

直接将物理CPU暴露给虚拟机使用,在虚拟机上完全可以看到的就是物理CPU的型号,xml配置文件如下:

<cpu mode='host-passthrough' />

注意:使用host-model模式,Libvirt会根据物理CPU的型号,从规定的CPU中选择一种最接近的CPU型号,而使用host-passthrough模式直接看到的就是物理CPU的型号

CPU host-passthrough技术的应用场景

HOST技术使用于以下场景

1)需要将物理CPU的一些特性传给虚拟机使用,比如使用虚拟机嵌套的nested技术的时候

2)需要在虚拟机里面看到和物理CPU一模一样的CPU品牌型号,这个在公有云很有意义,用户体验比较好

注意:使用CPU host-passthrough技术需要注意,不同型号的CPU宿主机之间虚拟机不能迁移

原文地址:https://www.cnblogs.com/uglyliu/p/6066569.html