]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
runqemu: enable kvm when use tap under sudo rbt/qemu_v2
authorRobert Yang <liezhi.yang@windriver.com>
Thu, 25 Jun 2015 08:56:03 +0000 (01:56 -0700)
committerRobert Yang <liezhi.yang@windriver.com>
Fri, 26 Jun 2015 01:26:06 +0000 (18:26 -0700)
Enable kvm support automatically when use tap interface under sudo, the
thought is, if sudo works well, and qemu-native has been built with kvm
support, and kvm can be enabled, then enable it, it can be disabled by
nokvm option.

The previous command:
$ runqemu qemux86 kvm
may not work since it checks the current user's read/write permission on
/dev/kvm and /dev/vhost-net but failed without sudo, it can't use sudo
to check them since sudo is not a must, sudo is only required when need
create tap interface, this patch can enable it automatically.

Enable kvm can improve qemu's performance a lot, when test perl-5.22's
lib/warnings.t on qemux86-64, 70 times improved.

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
scripts/runqemu
scripts/runqemu-internal

index 78dfd1a047e7b2bbeb222ac7210a1d27b3276707..01f6cbff97b16a4d1f4663ae78484e62931e6926 100755 (executable)
@@ -33,6 +33,7 @@ usage() {
     echo "    nographic - disables video console"
     echo "    serial - enables a serial console on /dev/ttyS0"
     echo "    kvm - enables KVM when running qemux86/qemux86-64 (VT-capable CPU required)"
+    echo "    nokvm - disables KVM"
     echo "    publicvnc - enable a VNC server open to all hosts"
     echo "  qemuparams=\"xyz\" - specify custom parameters to QEMU"
     echo "  bootparams=\"xyz\" - specify custom kernel parameters during boot"
@@ -68,8 +69,10 @@ SCRIPT_QEMU_OPT=""
 SCRIPT_QEMU_EXTRA_OPT=""
 SCRIPT_KERNEL_OPT=""
 SERIALSTDIO=""
-KVM_ENABLED="no"
+KVM_ENABLED="maybe"
+KVM_CAPABLE="`grep -q 'vmx\|svm' /proc/cpuinfo && echo 1`"
 KVM_ACTIVE="no"
+KVM_SUDO=""
 GRAPHIC="yes"
 PUBLICVNC="no"
 
@@ -181,7 +184,9 @@ while true; do
             ;;
         "kvm")
             KVM_ENABLED="yes"
-            KVM_CAPABLE=`grep -q 'vmx\|svm' /proc/cpuinfo && echo 1`
+            ;;
+        "nokvm")
+            KVM_ENABLED="no"
             ;;
         "slirp")
             SLIRP_ENABLED="yes"
index 694815fb7494b4b722c2131976521dc26027f558..25533ecef5aa943e3e0daaa9fad7450560df0b86 100755 (executable)
@@ -217,6 +217,19 @@ else
                 sudo $QEMUIFUP $USERID $GROUPID $OECORE_NATIVE_SYSROOT
                 return 1
             fi
+
+            # Enale kvm when possible since sudo works well, if
+            # /usr/include/linux/kvm.h exists, qemu-native is built with kvm
+            # support.
+            if [ "$KVM_ENABLED" = "maybe" -a -n "$KVM_CAPABLE" -a \
+                -e /dev/kvm -a -e /dev/vhost-net -a -f /usr/include/linux/kvm.h ] && \
+               [ "$MACHINE" = "qemux86" -o "$MACHINE" = "qemux86-64" ]; then
+                    echo "Enabling KVM automatically, can be disabled by nokvm option"
+                    SCRIPT_QEMU_OPT="$SCRIPT_QEMU_OPT -enable-kvm"
+                    KVM_ACTIVE="yes"
+                    KVM_SUDO="sudo"
+            fi
+
             LOCKFILE="$LOCKDIR/$tap"
             echo "Acquiring lockfile for $tap..."
             acquire_lock $LOCKFILE
@@ -685,6 +698,7 @@ if [ "x$SERIALSTDIO" = "x1" ]; then
 fi
 
 echo "Running $QEMU..."
+[ -n "$KVM_SUDO" ] && QEMUBIN="$KVM_SUDO $QEMUBIN"
 # -no-reboot is a mandatory option - see bug #100
 if [ "$FSTYPE" = "vmdk" ]; then
     echo $QEMUBIN $VM $QEMUOPTIONS $SERIALOPTS -no-reboot $SCRIPT_QEMU_OPT $SCRIPT_QEMU_EXTRA_OPT