[libvirt] [PATCH v1 0/4] CPU Model Comparsion via QEMU

Collin Walling walling at linux.ibm.com
Mon Apr 16 23:16:05 UTC 2018


[Overview]

This patch series implements an interface to "query-cpu-model-comparison"
(available QEMU ~2.8.0) via virsh cpu-compare.

[Using This Feature]

Run virsh cpu-compare (ensure you are running the virsh in your build dir) and
pass it an xml file describing a cpu definition. You can copy the cpu xml from
virsh capabilities (if you want to compare the host cpu to itself), or a cpu 
defined in any guest xml. Additionally, you can create a cpu xml as such (e.g.
for s390x):

<cpu>
    <arch>s390x</arch>
    <model fallback='forbid'>model_name</model>
    <feature policy='require|disable' name='feature_name'/>
</cpu>

NOTE: the presence of <arch> is optional and it will treat the cpu defined in 
      the xml as a host cpu. This will disregard all feature policies (i.e. 
      all features listed will behave with policy='require', even if disable 
      is specified).

NOTE: as s390x only supports feature policies 'require' and 'disable', I am
      uncertain how to handle the other policies when parsing CPUDef to JSON.

[Example Output]

On an s390x system running a z13.2, this is the expected output (where each file
describes a CPU model corresponding to the name of the file):

    $ virsh cpu-compare zEC12.xml
    Host CPU is a superset of CPU described in zEC12.xml

    $ virsh cpu-compare z13.2.xml
    CPU described in z13.2.xml is identical to host CPU

    $ virsh cpu-compare z14.xml
    CPU described in z14.xml is incompatible with host CPU

    $ virsh cpu-compare z14.xml --error
    error: Failed to compare host CPU with z14.xml
    error: the CPU is incompatible with host CPU

    $ virsh cpu-compare z12345.xml 
    error: Failed to compare host CPU with z12345cpu.xml
    error: internal error: unable to execute QEMU command 'query-cpu-model-comparison': The CPU definition 'z12345-base' is unknown.

[Patch Rundown]

The first patch copies the host CPU definition from qemuCaps to virCaps so
we can easily access the host CPU model and features when we handle the CPU
comparison in qemu_driver. Note that we take care to not clobber anything
already stored in the host CPU definition until we have successfully 
constructed a new host CPU definition.

The second patch refactors the xml -> CPUDef code. This is used in 
virCPUCompareXML, qemuCompareCPU (and potentially for baseline).

The third patch creates the interface from libvirt to QEMU and handles parsing
the CPUDef -> JSON and JSON -> CPUModelInfo. In order to respect the data
returned from this command, we capture the "responsible_properties" field
from the comparison command even though it is not entirely necessary for what
we are trying to accomplish here (which is to simply report if the comparison
result is "incompatible", "superset", or "identical").

The fourth patch creates the interface from virsh cpu-compare to the qemu driver.
The qemu driver will handle parsing the xml passed to the virsh command and
parsing the result of the QMP command. Note that the "incompatible" and 
"subset" results are grouped together (and report "incompatible").

TODO:
    - implement cpu-baseline (I've noted Chris Venteicher's current progress on this):
        https://www.redhat.com/archives/libvir-list/2018-April/msg01274.html
    - update qemucapabilitiestest files for qemu >= 2.8.0 (need to add comparison command)
    - consider adding a new test file for comparing cpu models via QEMU if necessary

Collin Walling (4):
  qemu: place qemuCaps host cpu model in virCaps
  cpu_conf: xml to cpu definition parse helper
  qemu: implement query-cpu-model-comparison via qemu
  qemu: hook up cpu-comparison to qemu driver

 src/conf/cpu_conf.c          |  30 ++++++++++
 src/conf/cpu_conf.h          |   6 ++
 src/cpu/cpu.c                |  14 +----
 src/libvirt_private.syms     |   1 +
 src/qemu/qemu_capabilities.c | 108 +++++++++++++++++++++++++++++++++++-
 src/qemu/qemu_capabilities.h |   9 +++
 src/qemu/qemu_driver.c       |  96 ++++++++++++++++++++++++++++++++
 src/qemu/qemu_monitor.c      |  14 +++++
 src/qemu/qemu_monitor.h      |   6 ++
 src/qemu/qemu_monitor_json.c | 128 +++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_monitor_json.h |   6 ++
 11 files changed, 404 insertions(+), 14 deletions(-)

-- 
2.7.4




More information about the libvir-list mailing list