[pve-devel] [PATCH 1/3] enable x2apic by default for kvm machines

Alexandre Derumier aderumier at odiso.com
Mon Jul 15 08:51:35 CEST 2013


This reduce context switch with multicore guests.

Even if the host cpu don't have x2apic, it's working because qemu have an virtual x2apic implementation for guest.
We need  in-kernel irqchip support for this, which is enable for kvm guest since qemu 1.3.
(I don't enable it if nokvm param is set)

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/QemuServer.pm |   14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 31d8103..f0a3c01 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -2225,6 +2225,7 @@ sub config_to_command {
     my $globalFlags = [];
     my $machineFlags = [];
     my $rtcFlags = [];
+    my $cpuFlags = [];
     my $devices = [];
     my $pciaddr = '';
     my $bridges = {};
@@ -2318,11 +2319,8 @@ sub config_to_command {
     $sockets = $conf->{sockets} if  $conf->{sockets};
 
     my $cores = $conf->{cores} || 1;
-
     push @$cmd, '-smp', "sockets=$sockets,cores=$cores";
 
-    push @$cmd, '-cpu', $conf->{cpu} if $conf->{cpu};
-
     push @$cmd, '-nodefaults';
 
     my $bootorder = $conf->{boot} || $confdesc->{boot}->{default};
@@ -2395,6 +2393,15 @@ sub config_to_command {
 	push @$rtcFlags, 'base=localtime';
     }
 
+    my $cpu = $nokvm ? "qemu64" : "kvm64";
+    $cpu = $conf->{cpu} if $conf->{cpu};
+
+    push @$cpuFlags , '+x2apic' if !$nokvm;
+
+    $cpu .= ",".join(',', @$cpuFlags) if scalar(@$cpuFlags);
+
+    push @$cmd, '-cpu', $cpu;
+
     push @$cmd, '-S' if $conf->{freeze};
 
     # set keyboard layout
@@ -2423,7 +2430,6 @@ sub config_to_command {
 	#$x509 .= ",x509-cacert-file=/etc/pve/pve-root-ca.pem";
 
 	my $socket = spice_socket($vmid);
-
 	push @$cmd, '-spice', "unix=$socket";
 	push @$cmd, '-device', "virtio-serial,id=spice$pciaddr";
 	push @$cmd, '-chardev', "spicevmc,id=vdagent,name=vdagent";
-- 
1.7.10.4




More information about the pve-devel mailing list