]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
cpu: Add {Haswell,Broadwell}-noTSX CPU models
authorJiri Denemark <jdenemar@redhat.com>
Mon, 23 Mar 2015 16:19:28 +0000 (17:19 +0100)
committerCole Robinson <crobinso@redhat.com>
Tue, 28 Apr 2015 00:14:49 +0000 (20:14 -0400)
QEMU 2.3 adds these new models to cover Haswell and Broadwell CPUs with
updated microcode. Luckily, they also reverted former the machine type
specific changes to existing models. And since these changes were never
released, we don't need to hack around them in libvirt.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
(cherry picked from commit c563b50605ae9895b981d198e11dbe9f6e18027b)

24 files changed:
src/cpu/cpu_map.xml
tests/cputest.c
tests/cputestdata/x86-Haswell-noTSX-nofallback.xml [new file with mode: 0644]
tests/cputestdata/x86-Haswell-noTSX.xml [new file with mode: 0644]
tests/cputestdata/x86-Haswell.xml [new file with mode: 0644]
tests/cputestdata/x86-baseline-7-result.xml [new file with mode: 0644]
tests/cputestdata/x86-baseline-7.xml [new file with mode: 0644]
tests/cputestdata/x86-baseline-8-result.xml [new file with mode: 0644]
tests/cputestdata/x86-baseline-8.xml [new file with mode: 0644]
tests/cputestdata/x86-host-Haswell-noTSX+Haswell,haswell,Haswell-result.xml [new file with mode: 0644]
tests/cputestdata/x86-host-Haswell-noTSX+Haswell-noTSX,Haswell-noTSX-result.xml [new file with mode: 0644]
tests/cputestdata/x86-host-Haswell-noTSX+Haswell-noTSX,haswell,Haswell-noTSX-result.xml [new file with mode: 0644]
tests/cputestdata/x86-host-Haswell-noTSX.xml [new file with mode: 0644]
tests/qemuxml2argvdata/qemuxml2argv-cpu-Haswell-noTSX.args [new file with mode: 0644]
tests/qemuxml2argvdata/qemuxml2argv-cpu-Haswell-noTSX.xml [new file with mode: 0644]
tests/qemuxml2argvdata/qemuxml2argv-cpu-Haswell.args [new file with mode: 0644]
tests/qemuxml2argvdata/qemuxml2argv-cpu-Haswell.xml [new file with mode: 0644]
tests/qemuxml2argvdata/qemuxml2argv-cpu-Haswell2.args [new file with mode: 0644]
tests/qemuxml2argvdata/qemuxml2argv-cpu-Haswell2.xml [new file with mode: 0644]
tests/qemuxml2argvdata/qemuxml2argv-cpu-Haswell3.args [new file with mode: 0644]
tests/qemuxml2argvdata/qemuxml2argv-cpu-Haswell3.xml [new file with mode: 0644]
tests/qemuxml2argvtest.c
tests/testutilsqemu.c
tests/testutilsqemu.h

index 413148ff6bc6ec47939e281f90252dfd9135e6e6..2110c0b9b2a2a70f0334b2ff63416bd1b704b669 100644 (file)
       <feature name='rdtscp'/>
     </model>
 
-    <model name='Haswell'>
+    <model name='Haswell-noTSX'>
       <model name='SandyBridge'/>
       <feature name='fma'/>
       <feature name='pcid'/>
       <feature name='movbe'/>
       <feature name='fsgsbase'/>
       <feature name='bmi1'/>
-      <feature name='hle'/>
       <feature name='avx2'/>
       <feature name='smep'/>
       <feature name='bmi2'/>
       <feature name='erms'/>
       <feature name='invpcid'/>
+    </model>
+
+    <model name='Haswell'>
+      <model name='Haswell-noTSX'/>
+      <feature name='hle'/>
       <feature name='rtm'/>
     </model>
 
-    <model name='Broadwell'>
-      <model name='Haswell'/>
+    <model name='Broadwell-noTSX'>
+      <model name='Haswell-noTSX'/>
       <feature name='3dnowprefetch'/>
       <feature name='rdseed'/>
       <feature name='adx'/>
       <feature name='smap'/>
     </model>
 
+    <model name='Broadwell'>
+      <model name='Broadwell-noTSX'/>
+      <feature name='hle'/>
+      <feature name='rtm'/>
+    </model>
+
     <!-- AMD CPUs -->
     <model name='athlon'>
       <model name='pentiumpro'/>
index 76cc9d415a51d7e057135d7e1391c3373c1346c6..eb0d66fca45f651144de0db9e23bc00d6127a4f2 100644 (file)
@@ -122,8 +122,10 @@ cpuTestLoadMultiXML(const char *arch,
         goto cleanup;
 
     n = virXPathNodeSet("/cpuTest/cpu", ctxt, &nodes);
-    if (n <= 0 || (VIR_ALLOC_N(cpus, n) < 0))
+    if (n <= 0 || (VIR_ALLOC_N(cpus, n) < 0)) {
+        fprintf(stderr, "\nNo /cpuTest/cpu elements found in %s\n", xml);
         goto cleanup;
+    }
 
     for (i = 0; i < n; i++) {
         ctxt->node = nodes[i];
@@ -495,6 +497,7 @@ cpuTestRun(const char *name, const struct data *data)
 static const char *model486[]   = { "486" };
 static const char *nomodel[]    = { "nomodel" };
 static const char *models[]     = { "qemu64", "core2duo", "Nehalem" };
+static const char *haswell[]    = { "SandyBridge", "Haswell" };
 static const char *ppc_models[]     = { "POWER7", "POWER7_v2.1", "POWER8_v1.0"};
 
 static int
@@ -640,6 +643,14 @@ mymain(void)
     DO_TEST_GUESTDATA("x86", "host", "host+host-model", models, "Penryn", 0);
     DO_TEST_GUESTDATA("x86", "host", "host+host-model-nofallback",
                       models, "Penryn", -1);
+    DO_TEST_GUESTDATA("x86", "host-Haswell-noTSX", "Haswell",
+                      haswell, "Haswell", 0);
+    DO_TEST_GUESTDATA("x86", "host-Haswell-noTSX", "Haswell-noTSX",
+                      haswell, "Haswell-noTSX", 0);
+    DO_TEST_GUESTDATA("x86", "host-Haswell-noTSX", "Haswell-noTSX-nofallback",
+                      haswell, "Haswell-noTSX", -1);
+    DO_TEST_GUESTDATA("x86", "host-Haswell-noTSX", "Haswell-noTSX",
+                      NULL, "Haswell-noTSX", 0);
 
     DO_TEST_GUESTDATA("ppc64", "host", "guest", ppc_models, NULL, 0);
     DO_TEST_GUESTDATA("ppc64", "host", "guest-nofallback", ppc_models, "POWER7_v2.1", -1);
diff --git a/tests/cputestdata/x86-Haswell-noTSX-nofallback.xml b/tests/cputestdata/x86-Haswell-noTSX-nofallback.xml
new file mode 100644 (file)
index 0000000..c23c3f3
--- /dev/null
@@ -0,0 +1,4 @@
+<cpu mode='custom' match='exact'>
+  <model fallback='forbid'>Haswell-noTSX</model>
+  <topology sockets='1' cores='2' threads='2'/>
+</cpu>
diff --git a/tests/cputestdata/x86-Haswell-noTSX.xml b/tests/cputestdata/x86-Haswell-noTSX.xml
new file mode 100644 (file)
index 0000000..3b74089
--- /dev/null
@@ -0,0 +1,4 @@
+<cpu mode='custom' match='exact'>
+  <model fallback='allow'>Haswell-noTSX</model>
+  <topology sockets='1' cores='2' threads='2'/>
+</cpu>
diff --git a/tests/cputestdata/x86-Haswell.xml b/tests/cputestdata/x86-Haswell.xml
new file mode 100644 (file)
index 0000000..630cb99
--- /dev/null
@@ -0,0 +1,6 @@
+<cpu match='exact'>
+  <model fallback='allow'>Haswell</model>
+  <topology sockets='1' cores='2' threads='2'/>
+  <feature name='rtm' policy='disable'/>
+  <feature name='hle' policy='disable'/>
+</cpu>
diff --git a/tests/cputestdata/x86-baseline-7-result.xml b/tests/cputestdata/x86-baseline-7-result.xml
new file mode 100644 (file)
index 0000000..2af549e
--- /dev/null
@@ -0,0 +1,4 @@
+<cpu mode='custom' match='exact'>
+  <model fallback='allow'>Haswell-noTSX</model>
+  <vendor>Intel</vendor>
+</cpu>
diff --git a/tests/cputestdata/x86-baseline-7.xml b/tests/cputestdata/x86-baseline-7.xml
new file mode 100644 (file)
index 0000000..b7e61b1
--- /dev/null
@@ -0,0 +1,24 @@
+<cpuTest>
+    <cpu>
+      <arch>x86_64</arch>
+      <model>SandyBridge</model>
+      <vendor>Intel</vendor>
+      <topology sockets='1' cores='2' threads='2'/>
+      <feature name='invpcid'/>
+      <feature name='erms'/>
+      <feature name='bmi2'/>
+      <feature name='smep'/>
+      <feature name='avx2'/>
+      <feature name='bmi1'/>
+      <feature name='fsgsbase'/>
+      <feature name='movbe'/>
+      <feature name='pcid'/>
+      <feature name='fma'/>
+    </cpu>
+    <cpu>
+      <arch>x86_64</arch>
+      <model>Haswell-noTSX</model>
+      <vendor>Intel</vendor>
+      <topology sockets='1' cores='2' threads='2'/>
+    </cpu>
+</cpuTest>
diff --git a/tests/cputestdata/x86-baseline-8-result.xml b/tests/cputestdata/x86-baseline-8-result.xml
new file mode 100644 (file)
index 0000000..88226b3
--- /dev/null
@@ -0,0 +1,4 @@
+<cpu mode='custom' match='exact'>
+  <model fallback='allow'>Broadwell-noTSX</model>
+  <vendor>Intel</vendor>
+</cpu>
diff --git a/tests/cputestdata/x86-baseline-8.xml b/tests/cputestdata/x86-baseline-8.xml
new file mode 100644 (file)
index 0000000..f1ee67d
--- /dev/null
@@ -0,0 +1,28 @@
+<cpuTest>
+    <cpu>
+      <arch>x86_64</arch>
+      <model>SandyBridge</model>
+      <vendor>Intel</vendor>
+      <topology sockets='1' cores='2' threads='2'/>
+      <feature name='invpcid'/>
+      <feature name='erms'/>
+      <feature name='bmi2'/>
+      <feature name='smep'/>
+      <feature name='avx2'/>
+      <feature name='bmi1'/>
+      <feature name='fsgsbase'/>
+      <feature name='movbe'/>
+      <feature name='pcid'/>
+      <feature name='fma'/>
+      <feature name='3dnowprefetch'/>
+      <feature name='rdseed'/>
+      <feature name='adx'/>
+      <feature name='smap'/>
+    </cpu>
+    <cpu>
+      <arch>x86_64</arch>
+      <model>Broadwell-noTSX</model>
+      <vendor>Intel</vendor>
+      <topology sockets='1' cores='2' threads='2'/>
+    </cpu>
+</cpuTest>
diff --git a/tests/cputestdata/x86-host-Haswell-noTSX+Haswell,haswell,Haswell-result.xml b/tests/cputestdata/x86-host-Haswell-noTSX+Haswell,haswell,Haswell-result.xml
new file mode 100644 (file)
index 0000000..087aa7d
--- /dev/null
@@ -0,0 +1,6 @@
+<cpu mode='custom' match='exact'>
+  <arch>x86_64</arch>
+  <model fallback='allow'>Haswell</model>
+  <feature policy='disable' name='rtm'/>
+  <feature policy='disable' name='hle'/>
+</cpu>
diff --git a/tests/cputestdata/x86-host-Haswell-noTSX+Haswell-noTSX,Haswell-noTSX-result.xml b/tests/cputestdata/x86-host-Haswell-noTSX+Haswell-noTSX,Haswell-noTSX-result.xml
new file mode 100644 (file)
index 0000000..f5a67fb
--- /dev/null
@@ -0,0 +1,4 @@
+<cpu mode='custom' match='exact'>
+  <arch>x86_64</arch>
+  <model fallback='allow'>Haswell-noTSX</model>
+</cpu>
diff --git a/tests/cputestdata/x86-host-Haswell-noTSX+Haswell-noTSX,haswell,Haswell-noTSX-result.xml b/tests/cputestdata/x86-host-Haswell-noTSX+Haswell-noTSX,haswell,Haswell-noTSX-result.xml
new file mode 100644 (file)
index 0000000..087aa7d
--- /dev/null
@@ -0,0 +1,6 @@
+<cpu mode='custom' match='exact'>
+  <arch>x86_64</arch>
+  <model fallback='allow'>Haswell</model>
+  <feature policy='disable' name='rtm'/>
+  <feature policy='disable' name='hle'/>
+</cpu>
diff --git a/tests/cputestdata/x86-host-Haswell-noTSX.xml b/tests/cputestdata/x86-host-Haswell-noTSX.xml
new file mode 100644 (file)
index 0000000..c003085
--- /dev/null
@@ -0,0 +1,6 @@
+<cpu>
+  <arch>x86_64</arch>
+  <model>Haswell-noTSX</model>
+  <vendor>Intel</vendor>
+  <topology sockets='1' cores='2' threads='2'/>
+</cpu>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-Haswell-noTSX.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-Haswell-noTSX.args
new file mode 100644 (file)
index 0000000..d64cc83
--- /dev/null
@@ -0,0 +1,4 @@
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
+/usr/bin/qemu-kvm -S -M pc -cpu Haswell-noTSX -m 214 -smp 6 \
+-nographic -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot n -usb -net \
+none -serial none -parallel none
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-Haswell-noTSX.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-Haswell-noTSX.xml
new file mode 100644 (file)
index 0000000..9ef24cd
--- /dev/null
@@ -0,0 +1,21 @@
+<domain type='kvm'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219100</memory>
+  <currentMemory unit='KiB'>219100</currentMemory>
+  <vcpu placement='static'>6</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc'>hvm</type>
+    <boot dev='network'/>
+  </os>
+  <cpu mode='custom' match='exact'>
+    <model fallback='forbid'>Haswell-noTSX</model>
+  </cpu>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+      <emulator>/usr/bin/qemu-kvm</emulator>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-Haswell.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-Haswell.args
new file mode 100644 (file)
index 0000000..f9bea62
--- /dev/null
@@ -0,0 +1,4 @@
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
+/usr/bin/qemu-kvm -S -M pc -cpu Haswell -m 214 -smp 6 \
+-nographic -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot n -usb -net \
+none -serial none -parallel none
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-Haswell.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-Haswell.xml
new file mode 100644 (file)
index 0000000..3af49f9
--- /dev/null
@@ -0,0 +1,21 @@
+<domain type='kvm'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219100</memory>
+  <currentMemory unit='KiB'>219100</currentMemory>
+  <vcpu placement='static'>6</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc'>hvm</type>
+    <boot dev='network'/>
+  </os>
+  <cpu mode='custom' match='exact'>
+    <model fallback='forbid'>Haswell</model>
+  </cpu>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+      <emulator>/usr/bin/qemu-kvm</emulator>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-Haswell2.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-Haswell2.args
new file mode 100644 (file)
index 0000000..a398ab8
--- /dev/null
@@ -0,0 +1,4 @@
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
+/usr/bin/qemu-kvm -S -M pc -cpu Haswell,-rtm,-hle -m 214 -smp 6 \
+-nographic -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot n -usb -net \
+none -serial none -parallel none
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-Haswell2.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-Haswell2.xml
new file mode 100644 (file)
index 0000000..0d4efa1
--- /dev/null
@@ -0,0 +1,23 @@
+<domain type='kvm'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219100</memory>
+  <currentMemory unit='KiB'>219100</currentMemory>
+  <vcpu placement='static'>6</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc'>hvm</type>
+    <boot dev='network'/>
+  </os>
+  <cpu mode='custom' match='exact'>
+    <model fallback='forbid'>Haswell</model>
+    <feature policy='disable' name='rtm'/>
+    <feature policy='disable' name='hle'/>
+  </cpu>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+      <emulator>/usr/bin/qemu-kvm</emulator>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-Haswell3.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-Haswell3.args
new file mode 100644 (file)
index 0000000..f9bea62
--- /dev/null
@@ -0,0 +1,4 @@
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
+/usr/bin/qemu-kvm -S -M pc -cpu Haswell -m 214 -smp 6 \
+-nographic -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot n -usb -net \
+none -serial none -parallel none
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-Haswell3.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-Haswell3.xml
new file mode 100644 (file)
index 0000000..00617eb
--- /dev/null
@@ -0,0 +1,23 @@
+<domain type='kvm'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219100</memory>
+  <currentMemory unit='KiB'>219100</currentMemory>
+  <vcpu placement='static'>6</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc'>hvm</type>
+    <boot dev='network'/>
+  </os>
+  <cpu mode='custom' match='exact'>
+    <model fallback='forbid'>Haswell</model>
+    <feature policy='require' name='rtm'/>
+    <feature policy='force' name='hle'/>
+  </cpu>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+      <emulator>/usr/bin/qemu-kvm</emulator>
+  </devices>
+</domain>
index 7eba5c95fb9f67889cfccc5dc7b51c8c36c8f82e..7f7a9923df163e682198409fffab79c76666559a 100644 (file)
@@ -457,6 +457,7 @@ testAddCPUModels(virQEMUCapsPtr caps, bool skipLegacy)
     const char *newModels[] = {
         "Opteron_G3", "Opteron_G2", "Opteron_G1",
         "Nehalem", "Penryn", "Conroe",
+        "Haswell-noTSX", "Haswell",
     };
     const char *legacyModels[] = {
         "n270", "athlon", "pentium3", "pentium2", "pentium",
@@ -1251,6 +1252,13 @@ mymain(void)
     DO_TEST_FAILURE("cpu-qemu-host-passthrough",
                     QEMU_CAPS_KVM, QEMU_CAPS_CPU_HOST);
 
+    driver.caps->host.cpu = cpuHaswell;
+    DO_TEST("cpu-Haswell", QEMU_CAPS_KVM);
+    DO_TEST("cpu-Haswell2", QEMU_CAPS_KVM);
+    DO_TEST("cpu-Haswell3", QEMU_CAPS_KVM);
+    DO_TEST("cpu-Haswell-noTSX", QEMU_CAPS_KVM);
+    driver.caps->host.cpu = cpuDefault;
+
     DO_TEST("memtune", QEMU_CAPS_NAME);
     DO_TEST("memtune-unlimited", QEMU_CAPS_NAME);
     DO_TEST("blkiotune", QEMU_CAPS_NAME);
index e3d4503079f12adf5bd1a39b963b299aa7384998..95b84e6aaa6ddf67dd81d71b4f2a9bf64382083d 100644 (file)
 
 # define VIR_FROM_THIS VIR_FROM_QEMU
 
+virCPUDefPtr cpuDefault;
+virCPUDefPtr cpuHaswell;
+
+static virCPUFeatureDef cpuDefaultFeatures[] = {
+    { (char *) "lahf_lm",   -1 },
+    { (char *) "xtpr",      -1 },
+    { (char *) "cx16",      -1 },
+    { (char *) "tm2",       -1 },
+    { (char *) "est",       -1 },
+    { (char *) "vmx",       -1 },
+    { (char *) "ds_cpl",    -1 },
+    { (char *) "pbe",       -1 },
+    { (char *) "tm",        -1 },
+    { (char *) "ht",        -1 },
+    { (char *) "ss",        -1 },
+    { (char *) "acpi",      -1 },
+    { (char *) "ds",        -1 }
+};
+static virCPUDef cpuDefaultData = {
+    VIR_CPU_TYPE_HOST,      /* type */
+    0,                      /* mode */
+    0,                      /* match */
+    VIR_ARCH_X86_64,        /* arch */
+    (char *) "core2duo",    /* model */
+    NULL,                   /* vendor_id */
+    0,                      /* fallback */
+    (char *) "Intel",       /* vendor */
+    1,                      /* sockets */
+    2,                      /* cores */
+    1,                      /* threads */
+    ARRAY_CARDINALITY(cpuDefaultFeatures), /* nfeatures */
+    ARRAY_CARDINALITY(cpuDefaultFeatures), /* nfeatures_max */
+    cpuDefaultFeatures,     /* features */
+};
+
+static virCPUFeatureDef cpuHaswellFeatures[] = {
+    { (char *) "lahf_lm",   -1 },
+    { (char *) "invtsc",    -1 },
+    { (char *) "abm",       -1 },
+    { (char *) "pdpe1gb",   -1 },
+    { (char *) "rdrand",    -1 },
+    { (char *) "f16c",      -1 },
+    { (char *) "osxsave",   -1 },
+    { (char *) "pdcm",      -1 },
+    { (char *) "xtpr",      -1 },
+    { (char *) "tm2",       -1 },
+    { (char *) "est",       -1 },
+    { (char *) "smx",       -1 },
+    { (char *) "vmx",       -1 },
+    { (char *) "ds_cpl",    -1 },
+    { (char *) "monitor",   -1 },
+    { (char *) "dtes64",    -1 },
+    { (char *) "pbe",       -1 },
+    { (char *) "tm",        -1 },
+    { (char *) "ht",        -1 },
+    { (char *) "ss",        -1 },
+    { (char *) "acpi",      -1 },
+    { (char *) "ds",        -1 },
+    { (char *) "vme",       -1 },
+};
+static virCPUDef cpuHaswellData = {
+    VIR_CPU_TYPE_HOST,      /* type */
+    0,                      /* mode */
+    0,                      /* match */
+    VIR_ARCH_X86_64,        /* arch */
+    (char *) "Haswell",     /* model */
+    NULL,                   /* vendor_id */
+    0,                      /* fallback */
+    (char *) "Intel",       /* vendor */
+    1,                      /* sockets */
+    2,                      /* cores */
+    2,                      /* threads */
+    ARRAY_CARDINALITY(cpuHaswellFeatures), /* nfeatures */
+    ARRAY_CARDINALITY(cpuHaswellFeatures), /* nfeatures_max */
+    cpuHaswellFeatures,     /* features */
+};
+
 static virCapsGuestMachinePtr *testQemuAllocMachines(int *nmachines)
 {
     virCapsGuestMachinePtr *machines;
@@ -212,40 +289,8 @@ virCapsPtr testQemuCapsInit(void)
     static const char *const xen_machines[] = {
         "xenner"
     };
-    static virCPUFeatureDef host_cpu_features[] = {
-        { (char *) "lahf_lm",   -1 },
-        { (char *) "xtpr",      -1 },
-        { (char *) "cx16",      -1 },
-        { (char *) "tm2",       -1 },
-        { (char *) "est",       -1 },
-        { (char *) "vmx",       -1 },
-        { (char *) "ds_cpl",    -1 },
-        { (char *) "pbe",       -1 },
-        { (char *) "tm",        -1 },
-        { (char *) "ht",        -1 },
-        { (char *) "ss",        -1 },
-        { (char *) "acpi",      -1 },
-        { (char *) "ds",        -1 }
-    };
-    static virCPUDef host_cpu = {
-        VIR_CPU_TYPE_HOST,      /* type */
-        0,                      /* mode */
-        0,                      /* match */
-        VIR_ARCH_X86_64,        /* arch */
-        (char *) "core2duo",    /* model */
-        NULL,                   /* vendor_id */
-        0,                      /* fallback */
-        (char *) "Intel",       /* vendor */
-        1,                      /* sockets */
-        2,                      /* cores */
-        1,                      /* threads */
-        ARRAY_CARDINALITY(host_cpu_features), /* nfeatures */
-        ARRAY_CARDINALITY(host_cpu_features), /* nfeatures_max */
-        host_cpu_features,      /* features */
-    };
 
-    if ((caps = virCapabilitiesNew(host_cpu.arch,
-                                   false, false)) == NULL)
+    if (!(caps = virCapabilitiesNew(VIR_ARCH_X86_64, false, false)))
         return NULL;
 
     /* Add dummy 'none' security_driver. This is equal to setting
@@ -258,8 +303,13 @@ virCapsPtr testQemuCapsInit(void)
         VIR_STRDUP(caps->host.secModels[0].doi, "0") < 0)
         goto cleanup;
 
-    if ((caps->host.cpu = virCPUDefCopy(&host_cpu)) == NULL ||
-        (machines = testQemuAllocMachines(&nmachines)) == NULL)
+    if (!(cpuDefault = virCPUDefCopy(&cpuDefaultData)) ||
+        !(cpuHaswell = virCPUDefCopy(&cpuHaswellData)))
+        goto cleanup;
+
+    caps->host.cpu = cpuDefault;
+
+    if ((machines = testQemuAllocMachines(&nmachines)) == NULL)
         goto cleanup;
 
     if ((guest = virCapabilitiesAddGuest(caps, "hvm", VIR_ARCH_I686,
@@ -356,6 +406,10 @@ virCapsPtr testQemuCapsInit(void)
 
  cleanup:
     virCapabilitiesFreeMachines(machines, nmachines);
+    if (caps->host.cpu != cpuDefault)
+        virCPUDefFree(cpuDefault);
+    if (caps->host.cpu != cpuHaswell)
+        virCPUDefFree(cpuHaswell);
     virObjectUnref(caps);
     return NULL;
 }
index 79ee1434c2c37c1fa5b267eeb5ce5dd0ef662571..0ec5dadd2f6b63a340a1ba419ec208b77bea6804 100644 (file)
@@ -10,4 +10,10 @@ virDomainXMLOptionPtr testQemuXMLConfInit(void);
 extern qemuBuildCommandLineCallbacks testCallbacks;
 
 virQEMUCapsPtr qemuTestParseCapabilities(const char *capsFile);
+
+extern virCPUDefPtr cpuDefault;
+extern virCPUDefPtr cpuHaswell;
+void testQemuCapsSetCPU(virCapsPtr caps,
+                        virCPUDefPtr hostCPU);
+
 #endif