每个hypervisor对于guest能看到的cpu model定义都不同,Xen 提供host pass through,所以guest能看到的cpu和host完全相同。

QEMU/KVM中guest能看到自定义的通用cpu model  “qemu32” or “qemu64”,而VMWare 要高级一些,它把host cpu划分成组,guest

能看到每组的baseline CPU model,这样guest就能在改组迁移。

每种CPU models都采用不同方式来暴露其architecture ,比如x86采用CPUID instruction来暴露其cpu的capabilities 。

VMWare and Xen 就直接把CPUID instruction暴露给guest,但QEMU/KVM 不仅仅支持x86,所以不能采用这种方式。

Libvirt采用baseline CPU CPUID +features的方式,其中baseline CPU CPUID是每种CPU model的最大公共子集。

比如某laptop上的cpu信息,一共拥有20个features:

# virsh capabilities

<capabilities>

  <host>

    <cpu>

      <arch>i686</arch>

      <model>pentium3</model>

      <topology sockets='' cores='' threads=''/>

      <feature name='lahf_lm'/>

      <feature name='lm'/>

      <feature name='xtpr'/>

      <feature name='cx16'/>

      <feature name='ssse3'/>

      <feature name='tm2'/>

      <feature name='est'/>

      <feature name='vmx'/>

      <feature name='ds_cpl'/>

      <feature name='monitor'/>

      <feature name='pni'/>

      <feature name='pbe'/>

      <feature name='tm'/>

      <feature name='ht'/>

      <feature name='ss'/>

      <feature name='sse2'/>

      <feature name='acpi'/>

      <feature name='ds'/>

      <feature name='clflush'/>

      <feature name='apic'/>

    </cpu>

    ...snip...

我们知道了libvirt如何描述cpu model和指令集,现在的问题就是暴露哪些CPU capabilities给guest。

如果数据中心中所有的cpu都是完全相同的,那么可以使用host pass through。

如果不是得话,那么久需要暴露这些cpu的公共子集。

Libvirt api提供了这些功能,把描述cpu的xml传给libvirt,它会计算出这些cpu的公共子集。

比如在另外一台server上:

<capabilities>

  <host>

    <cpu>

      <arch>x86_64</arch>

      <model>phenom</model>

      <topology sockets='' cores='' threads=''/>

      <feature name='osvw'/>

      <feature name='3dnowprefetch'/>

      <feature name='misalignsse'/>

      <feature name='sse4a'/>

      <feature name='abm'/>

      <feature name='cr8legacy'/>

      <feature name='extapic'/>

      <feature name='cmp_legacy'/>

      <feature name='lahf_lm'/>

      <feature name='rdtscp'/>

      <feature name='pdpe1gb'/>

      <feature name='popcnt'/>

      <feature name='cx16'/>

      <feature name='ht'/>

      <feature name='vme'/>

    </cpu>

    ...snip...

计算该cpu是否与latptop上的cpu兼容:

$ ./tools/virsh cpu-compare cpu-server.xml

CPU described in cpu-server.xml is incompatible with host CPU

结果是不兼容因为laptop上有些指令集在server是没有。

要找到他们的子集:

# virsh cpu-baseline both-cpus.xml

<cpu match='exact'>

  <model>pentium3</model>

  <feature policy='require' name='lahf_lm'/>

  <feature policy='require' name='lm'/>

  <feature policy='require' name='cx16'/>

  <feature policy='require' name='monitor'/>

  <feature policy='require' name='pni'/>

  <feature policy='require' name='ht'/>

  <feature policy='require' name='sse2'/>

  <feature policy='require' name='clflush'/>

  <feature policy='require' name='apic'/>

</cpu>

子集中只有9个features。

https://www.berrange.com/posts/2010/02/15/guest-cpu-model-configuration-in-libvirt-with-qemukvm/

关于guest cpu模型的详细参数

Table 21.9. CPU model and topology elements

Element Description
<cpu> This element contains all parameters for the vCPU feature set.
<match> Specifies how closely the features indicated in the <cpu> element must match the vCPUs that are available. The match attribute can be omitted if <topology> is the only element nested in the <cpu>element. Possible values for the match attribute are:

  • minimum - The features listed are the minimum requirement. There may be more features available in the vCPU then are indicated, but this is the minimum that will be accepted. This value will fail if the minimum requirements are not met.
  • exact - the virtual CPU provided to the guest virtual machine must exactly match the features specified. If no match is found, an error will result.
  • strict - the guest virtual machine will not be created unless the host physical machine CPU exactly matches the specification.

If the match attribute is omitted from the <cpu>element, the default setting match='exact' is used.

<mode> This optional attribute may be used to make it easier to configure a guest virtual machine CPU to be as close to the host physical machine CPU as possible. Possible values for the mode attribute are:

  • custom - describes how the CPU is presented to the guest virtual machine. This is the default setting when the mode attribute is not specified. This mode makes it so that a persistent guest virtual machine will see the same hardware no matter what host physical machine the guest virtual machine is booted on.
  • host-model - this is essentially a shortcut to copying host physical machine CPU definition from the capabilities XML into the domain XML. As the CPU definition is copied just before starting a domain, the same XML can be used on different host physical machines while still providing the best guest virtual machine CPU each host physical machine supports. Neither the matchattribute nor any feature elements can be used in this mode. For more information see libvirt domain XML CPU models
  • host-passthrough With this mode, the CPU visible to the guest virtual machine is exactly the same as the host physical machine CPU including elements that cause errors within libvirt. The obvious the downside of this mode is that the guest virtual machine environment cannot be reproduced on different hardware and therefore this mode is recommended with great caution. Neither model nor feature elements are allowed in this mode.
  • Note that in both host-model and host-passthrough mode, the real (approximate in host-passthrough mode) CPU definition which would be used on current host physical machine can be determined by specifying VIR_DOMAIN_XML_UPDATE_CPU flag when calling virDomainGetXMLDesc API. When running a guest virtual machine that might be prone to operating system reactivation when presented with different hardware, and which will be migrated between host physical machines with different capabilities, you can use this output to rewrite XML to the custom mode for more robust migration.
<model> Specifies CPU model requested by the guest virtual machine. The list of available CPU models and their definition can be found in cpu_map.xml file installed in libvirt's data directory. If a hypervisor is not able to use the exact CPU model, libvirt automatically falls back to a closest model supported by the hypervisor while maintaining the list of CPU features. An optional fallback attribute can be used to forbid this behavior, in which case an attempt to start a domain requesting an unsupported CPU model will fail. Supported values for fallback attribute are: allow (this is the default), and forbid. The optional vendor_id attribute can be used to set the vendor id seen by the guest virtual machine. It must be exactly 12 characters long. If not set, the vendor id of the host physical machine is used. Typical possible values are AuthenticAMD and GenuineIntel.
<vendor>    Specifies CPU vendor requested by the guest virtual machine. If this element is missing, the guest virtual machine runs on a CPU matching given features regardless of its vendor. The list of supported vendors can be found in cpu_map.xml.
<topology> Specifies requested topology of virtual CPU provided to the guest virtual machine. Three non-zero values have to be given for sockets, cores, and threads: total number of CPU sockets, number of cores per socket, and number of threads per core, respectively.
<feature> Can contain zero or more elements used to fine-tune features provided by the selected CPU model. The list of known feature names can be found in the same file as CPU models. The meaning of each feature element depends on its policy attribute, which has to be set to one of the following values:

  • force - forces the virtual to be supported regardless of whether it is actually supported by host physical machine CPU.
  • require - dictates that guest virtual machine creation will fail unless the feature is supported by host physical machine CPU. This is the default setting
  • optional - this feature is supported by virtual CPU but and only if it is supported by host physical machine CPU.
  • disable - this is not supported by virtual CPU.
  • forbid - guest virtual machine creation will fail if the feature is supported by host physical machine CPU.

Guest CPU model configuration in libvirt with QEMU/KVM的更多相关文章

  1. KVM 介绍(8):使用 libvirt 迁移 QEMU/KVM 虚机和 Nova 虚机 [Nova Libvirt QEMU/KVM Live Migration]

    学习 KVM 的系列文章: (1)介绍和安装 (2)CPU 和 内存虚拟化 (3)I/O QEMU 全虚拟化和准虚拟化(Para-virtulizaiton) (4)I/O PCI/PCIe设备直接分 ...

  2. KVM 介绍(7):使用 libvirt 做 QEMU/KVM 快照和 Nova 实例的快照 (Nova Instances Snapshot Libvirt)

    学习 KVM 的系列文章: (1)介绍和安装 (2)CPU 和 内存虚拟化 (3)I/O QEMU 全虚拟化和准虚拟化(Para-virtulizaiton) (4)I/O PCI/PCIe设备直接分 ...

  3. KVM 介绍(6):Nova 通过 libvirt 管理 QEMU/KVM 虚机 [Nova Libvirt QEMU/KVM Domain]

    学习 KVM 的系列文章: (1)介绍和安装 (2)CPU 和 内存虚拟化 (3)I/O QEMU 全虚拟化和准虚拟化(Para-virtulizaiton) (4)I/O PCI/PCIe设备直接分 ...

  4. KVM(七)使用 libvirt 做 QEMU/KVM 快照和 Nova 实例的快照

    本文将梳理 QEMU/KVM 快照相关的知识,以及在 OpenStack Nova 中使用 libvirt 来对 QEMU/KVM 虚机做快照的过程. 1. QEMU/KVM 快照 1.1 概念 QE ...

  5. KVM(六)Nova 通过 libvirt 管理 QEMU/KVM 虚机

    1. Libvirt 在 OpenStack 架构中的位置 在 Nova Compute 节点上运行的 nova-compute 服务调用 Hypervisor API 去管理运行在该 Hypervi ...

  6. KVM(八)使用 libvirt 迁移 QEMU/KVM 虚机和 Nova 虚机

    1. QEMU/KVM 迁移的概念 迁移(migration)包括系统整体的迁移和某个工作负载的迁移.系统整理迁移,是将系统上所有软件包括操作系统完全复制到另一个物理机硬件机器上.虚拟化环境中的迁移, ...

  7. 干货分享: 长达250页的Libvirt Qemu KVM的ppt,不实验无真相

    下载地址:Libvirt Qemu KVM 教程大全 http://files.cnblogs.com/popsuper1982/LibvirtQemuKVM.pptx 1. 概论 1.1 虚拟化的基 ...

  8. QEMU KVM Libvirt手册(10):Managing Virtual Machines with libvirt

    libvirt is a library that provides a common API for managing popular virtualization solutions, among ...

  9. QEMU KVM Libvirt手册(7): 硬件虚拟化

    在openstack中,如果我们启动一个虚拟机,我们会看到非常复杂的参数 qemu-system-x86_64 -enable-kvm -name instance-00000024 -S -mach ...

随机推荐

  1. 导出网页中的table到excel

    导出网页中的table到excel的两种简便方法: 1. 纯 JavaScript 方法,缺点只支持IE浏览器 var elTable = document.getElementById(" ...

  2. 【python】-- Django 中间件、缓存、信号

    Django  中间件.缓存.信号 一. Django  中间件 django 中的中间件(middleware),在django中,中间件其实就是一个类,在请求到来和结束后,django会根据自己的 ...

  3. jquery拓展插件-popup弹窗

    css:<style> /* 公共弹出层 */ .popWrap{position: fixed;left: 0;top: 0; width: 100%;height: 100%;z-in ...

  4. testlink1.9.3测试管理工具安装

    一.下载testlink1.9.3rar安装包 下载地址:http://download.csdn.net/download/u010082992/7678491 二.安装IIS 在Server 20 ...

  5. Elasticsearch之elasticsearch5.x 新特性

    其实,elasticsearch5.x 和 elasticsearch2.x 并不区别很大. 是因为,ELK里之前版本各种很混乱,直接升级到5.0了. 其实,elasticsearch5.x 按理来说 ...

  6. Jmeter关联技术

    JMeter:关联步骤 <1>录制成功,回放失败了: <2>录制两个业务相同的脚本,比对差别,找到动态数据,AptDiff_1.6.zip工具 <3>找到相应请求: ...

  7. 入坑第二式 golang入坑系列

    史前必读: 这是入坑系列的第二式,如果错过了第一式,可以去gitbook( https://andy-zhangtao.gitbooks.io/golang/content/ )点个回放,看个重播.因 ...

  8. 2015.6.30 反弹的教训(想做T)

    心路:在6.29号,市场连续大跌!我到6.29号才想到可以做T+0.6.30消息面已经利好(双降准),已经计划做T+0(X先买后卖).  开市大跌至跌停.午后所有股票开始反弹.但是上午跌停时不敢入市, ...

  9. 深度学习2--安装opencv3.1

    1\opencv的安装参考视频 2\ 以下内容来自:http://blog.csdn.net/l18930738887/article/details/54696148 本人因为被坑过,所以建议各位最 ...

  10. 模块调用,datetime,time,logging,递归,双层装饰器, json,pickle迭代器和生成器

    一.python模块(导入,内置,自定义,开源) 1.模块简介 模块是一个包含所有你定义的函数和变量的文件,其后缀名是.py.模块可以被别的程序引入,以使用该模块中的函数等功能.这也是使用python ...