Skip to contentSkip to conversation

pc: enable -cpu host as default

PATCH New Alexander Graf 1 participant 4 messages Jun 14, 2011

lore
Share & tools
lore
#0 lore raw

cover pc: enable -cpu host as default

As discussed during the community call, -cpu qemu64 breaks for a bunch of workloads, most prominently recent gcc versions thanks to libgmp.

To work around this and to also give the user the best possible performance when running with default command line options, let's use -cpu host as default when running with KVM enabled!

Alexander Graf (3):
pc: add compat machine types for 0.14 and 0.15
pc: use old default cpu type for 0.14 and 0.15 compat machines
pc: use -cpu host as default for kvm

 hw/pc.c      |    9 +++++++--
 hw/pc_piix.c |   48 +++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 54 insertions(+), 3 deletions(-)
Signature · 1 line
1.7.3.4
#1 lore raw

PATCH 1/3 pc: add compat machine types for 0.14 and 0.15

We change virtual hardware from time to time, so in order to ensure that the guest doesn't get confused, we have compatibility machines for the PC machine.

This patch adds compatibility definitions for 0.14 and 0.15 versions.

---
 hw/pc_piix.c |   32 +++++++++++++++++++++++++++++++-
 1 files changed, 31 insertions(+), 1 deletions(-)
hw/pc_piix.c +31 -1
index 9a22a8a..3b3ef84 100644
@@ -213,6 +213,18 @@ static void pc_init_pci(ram_addr_t ram_size,
              initrd_filename, cpu_model, 1, 1);
 }
 
+static void pc_init_pci_014(ram_addr_t ram_size,
+                            const char *boot_device,
+                            const char *kernel_filename,
+                            const char *kernel_cmdline,
+                            const char *initrd_filename,
+                            const char *cpu_model)
+{
+    pc_init1(ram_size, boot_device,
+             kernel_filename, kernel_cmdline,
+             initrd_filename, cpu_model, 1, 1);
+}
+
 static void pc_init_pci_no_kvmclock(ram_addr_t ram_size,
                                     const char *boot_device,
                                     const char *kernel_filename,
@@ -258,7 +270,7 @@ static void pc_xen_hvm_init(ram_addr_t ram_size,
 #endif
 
 static QEMUMachine pc_machine = {
-    .name = "pc-0.14",
+    .name = "pc-0.16",
     .alias = "pc",
     .desc = "Standard PC",
     .init = pc_init_pci,
@@ -266,6 +278,22 @@ static QEMUMachine pc_machine = {
     .is_default = 1,
 };
 
+static QEMUMachine pc_machine_v0_15 = {
+    .name = "pc-0.15",
+    .desc = "Standard PC",
+    .init = pc_init_pci_014,
+    .max_cpus = 255,
+    .is_default = 1,
+};
+
+static QEMUMachine pc_machine_v0_14 = {
+    .name = "pc-0.14",
+    .desc = "Standard PC",
+    .init = pc_init_pci_014,
+    .max_cpus = 255,
+    .is_default = 1,
+};
+
 static QEMUMachine pc_machine_v0_13 = {
     .name = "pc-0.13",
     .desc = "Standard PC",
@@ -434,6 +462,8 @@ static QEMUMachine xenfv_machine = {
 static void pc_machine_init(void)
 {
     qemu_register_machine(&pc_machine);
+    qemu_register_machine(&pc_machine_v0_15);
+    qemu_register_machine(&pc_machine_v0_14);
     qemu_register_machine(&pc_machine_v0_13);
     qemu_register_machine(&pc_machine_v0_12);
     qemu_register_machine(&pc_machine_v0_11);
Signature · 1 line
1.7.3.4
#2 lore raw

PATCH 2/3 pc: use old default cpu type for 0.14 and 0.15 compat machines

In reply to Alexander Graf

When running with the 0.14 or 0.15 machine types, use the old mechanism of determining the default CPU to choose, so that the guest sees the same default CPU when running qemu in compat mode.

---
 hw/pc_piix.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
hw/pc_piix.c +16 -0
index 3b3ef84..84d5650 100644
@@ -220,6 +220,14 @@ static void pc_init_pci_014(ram_addr_t ram_size,
                             const char *initrd_filename,
                             const char *cpu_model)
 {
+    if (cpu_model == NULL) {
+#ifdef TARGET_X86_64
+        cpu_model = "qemu64";
+#else
+        cpu_model = "qemu32";
+#endif
+    }
+
     pc_init1(ram_size, boot_device,
              kernel_filename, kernel_cmdline,
              initrd_filename, cpu_model, 1, 1);
@@ -232,6 +240,14 @@ static void pc_init_pci_no_kvmclock(ram_addr_t ram_size,
                                     const char *initrd_filename,
                                     const char *cpu_model)
 {
+    if (cpu_model == NULL) {
+#ifdef TARGET_X86_64
+        cpu_model = "qemu64";
+#else
+        cpu_model = "qemu32";
+#endif
+    }
+
     pc_init1(ram_size, boot_device,
              kernel_filename, kernel_cmdline,
              initrd_filename, cpu_model, 1, 0);
Signature · 1 line
1.7.3.4
#3 lore raw

PATCH 3/3 pc: use -cpu host as default for kvm

In reply to Alexander Graf

When running with KVM, people expect to get the best possible performance inside the VM. To really get this, the guest needs to know about the CPU features it can use.

We have a CPU type that exports exactly this information to the guest, but hasn't been used much, as it wasn't the default. Set it as default for the PC machine now, so people get good performance without changing options.

---
 hw/pc.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
hw/pc.c +7 -2
index a3e8539..475d20e 100644
@@ -41,6 +41,7 @@
 #include "sysemu.h"
 #include "blockdev.h"
 #include "ui/qemu-spice.h"
+#include "kvm.h"
 
 /* output Bochs bios info messages */
 //#define DEBUG_BIOS
@@ -945,11 +946,15 @@ void pc_cpus_init(const char *cpu_model)
 
     /* init CPUs */
     if (cpu_model == NULL) {
+        if (kvm_enabled()) {
+            cpu_model = "host";
+        } else {
 #ifdef TARGET_X86_64
-        cpu_model = "qemu64";
+            cpu_model = "qemu64";
 #else
-        cpu_model = "qemu32";
+            cpu_model = "qemu32";
 #endif
+        }
     }
 
     for(i = 0; i < smp_cpus; i++) {
Signature · 1 line
1.7.3.4