Skip to contentSkip to conversation

KVM: Use -cpu host as default on x86

PATCH Superseded Alexander Graf 2 participants 3 messages Oct 13, 2011 – Nov 1, 2011

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: Use -cpu host as default on x86

When running QEMU without -cpu parameter, the user usually wants a sane default. So far, we're using the qemu64/qemu32 CPU type, which basically means "the maximum TCG can emulate".

That's a really good default when using TCG, but when running with KVM we much rather want a default saying "the maximum KVM can support".

Fortunately we already have such a CPU type. It's called "host". All we need to do is to select it by default when not getting a -cpu passed in.

This fixes a lot of subtile breakage in the GNU toolchain (libgmp) which hicks up on QEMU's non-existent CPU models.

---
 hw/pc.c      |   10 +++++++---
 hw/pc.h      |    2 +-
 hw/pc_piix.c |    2 +-
 3 files changed, 9 insertions(+), 5 deletions(-)
hw/pc.c +7 -3
index 203627d..e0c48f2 100644
@@ -941,17 +941,21 @@ static CPUState *pc_new_cpu(const char *cpu_model)
     return env;
 }
 
-void pc_cpus_init(const char *cpu_model)
+void pc_cpus_init(const char *cpu_model, int kvm_enabled)
 {
     int i;
 
     /* 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++) {
hw/pc.h +1 -1
index f3e21b6..b5519ff 100644
@@ -130,7 +130,7 @@ void pc_register_ferr_irq(qemu_irq irq);
 void pc_cmos_set_s3_resume(void *opaque, int irq, int level);
 void pc_acpi_smi_interrupt(void *opaque, int irq, int level);
 
-void pc_cpus_init(const char *cpu_model);
+void pc_cpus_init(const char *cpu_model, int kvm_enabled);
 void pc_memory_init(MemoryRegion *system_memory,
                     const char *kernel_filename,
                     const char *kernel_cmdline,
hw/pc_piix.c +1 -1
index ce1c87f..a080191 100644
@@ -99,7 +99,7 @@ static void pc_init1(MemoryRegion *system_memory,
     MemoryRegion *pci_memory;
     MemoryRegion *rom_memory;
 
-    pc_cpus_init(cpu_model);
+    pc_cpus_init(cpu_model, kvm_enabled());
 
     if (kvmclock_enabled) {
         kvmclock_create();
Signature · 1 line
1.7.3.4
#1 lore raw
Quoted 4 lines · Alexander Graf

When running QEMU without -cpu parameter, the user usually wants a sane default. So far, we're using the qemu64/qemu32 CPU type, which basically means "the maximum TCG can emulate".

Quoted 8 lines

That's a really good default when using TCG, but when running with KVM we much rather want a default saying "the maximum KVM can support".

Fortunately we already have such a CPU type. It's called "host". All we need to do is to select it by default when not getting a -cpu passed in.

This fixes a lot of subtile breakage in the GNU toolchain (libgmp) which hicks up on QEMU's non-existent CPU models.

Ping?

Alex

#2 lore raw
In reply to Alexander Graf
Quoted 7 lines · Alexander Graf

When running QEMU without -cpu parameter, the user usually wants a sane default. So far, we're using the qemu64/qemu32 CPU type, which basically means "the maximum TCG can emulate".

That's a really good default when using TCG, but when running with KVM we much rather want a default saying "the maximum KVM can support".

Quoted 7 lines

Fortunately we already have such a CPU type. It's called "host". All we need to do is to select it by default when not getting a -cpu passed in.

This fixes a lot of subtile breakage in the GNU toolchain (libgmp) which hicks up on QEMU's non-existent CPU models.

Need to make sure that older machine types (i.e. pc-0.15, pc-0.14) default to the appropriate CPU model.

Regards,

Anthony Liguori

Quoted 61 lines
---
  hw/pc.c      |   10 +++++++---
  hw/pc.h      |    2 +-
  hw/pc_piix.c |    2 +-
  3 files changed, 9 insertions(+), 5 deletions(-)
hw/pc.c +7 -3
index 203627d..e0c48f2 100644
@@ -941,17 +941,21 @@ static CPUState *pc_new_cpu(const char *cpu_model)
      return env;
  }
 
-void pc_cpus_init(const char *cpu_model)
+void pc_cpus_init(const char *cpu_model, int kvm_enabled)
  {
      int i;
 
      /* 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++) {
hw/pc.h +1 -1
index f3e21b6..b5519ff 100644
@@ -130,7 +130,7 @@ void pc_register_ferr_irq(qemu_irq irq);
  void pc_cmos_set_s3_resume(void *opaque, int irq, int level);
  void pc_acpi_smi_interrupt(void *opaque, int irq, int level);
 
-void pc_cpus_init(const char *cpu_model);
+void pc_cpus_init(const char *cpu_model, int kvm_enabled);
  void pc_memory_init(MemoryRegion *system_memory,
                      const char *kernel_filename,
                      const char *kernel_cmdline,
hw/pc_piix.c +1 -1
index ce1c87f..a080191 100644
@@ -99,7 +99,7 @@ static void pc_init1(MemoryRegion *system_memory,
      MemoryRegion *pci_memory;
      MemoryRegion *rom_memory;
 
-    pc_cpus_init(cpu_model);
+    pc_cpus_init(cpu_model, kvm_enabled());
 
      if (kvmclock_enabled) {
          kvmclock_create();