Skip to contentSkip to conversation

2 fixes for runqemu

PATCH In review Robert Yang 2 participants 6 messages Jun 25, 2015 – Jun 26, 2015

lore
Share & tools
lore
#0 lore raw

cover 2 fixes for runqemu

Hello,

The 2 patches will make qemu easier to use.

// Robert

The following changes since commit 2587b83faabdc8858e8746201805369ed8d53ba8:

wpa-supplicant: Revert "Make SystemD D-Bus config conditional" (2015-06-24 14:03:25 +0100)

are available in the git repository at:

git://git.openembedded.org/openembedded-core-contrib rbt/qemu
http://cgit.openembedded.org/cgit.cgi/openembedded-core-contrib/log/?h=rbt/qemu

Robert Yang (2):
runqemu: disable graphic when no DISPLAY
runqemu: enable kvm when use tap under sudo

 scripts/runqemu          |   20 ++++++++++++++++----
 scripts/runqemu-internal |   15 +++++++++++++++
 2 files changed, 31 insertions(+), 4 deletions(-)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/2 runqemu: disable graphic when no DISPLAY

Disable graphic when no DISPLAY rather than print an error like:
[snip]
Could not initialize SDL(No available video device) - exiting [snip]

---
 scripts/runqemu |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
scripts/runqemu +9 -2
index 09c507d..d9e91af 100755
@@ -70,6 +70,7 @@ SCRIPT_KERNEL_OPT=""
 SERIALSTDIO=""
 KVM_ENABLED="no"
 KVM_ACTIVE="no"
+GRAPHIC="yes"
 
 # Determine whether the file is a kernel or QEMU image, and set the
 # appropriate variables
@@ -142,8 +143,7 @@ while true; do
 	    ISOFS=true
 	    ;;
         "nographic")
-            SCRIPT_QEMU_OPT="$SCRIPT_QEMU_OPT -nographic"
-            SCRIPT_KERNEL_OPT="$SCRIPT_KERNEL_OPT console=ttyS0"
+            GRAPHIC="no"
             ;;
         "serial")
             SCRIPT_QEMU_OPT="$SCRIPT_QEMU_OPT -serial stdio"
@@ -291,6 +291,13 @@ if [ "x$KVM_ENABLED" = "xyes" ]; then
     fi
 fi
 
+# Disable graphic when no DISPLAY or -nographic is specified.
+if [ -z "$DISPLAY" -o "$GRAPHIC" = "no" ]; then
+    echo "Disabling graphic."
+    SCRIPT_QEMU_OPT="$SCRIPT_QEMU_OPT -nographic"
+    SCRIPT_KERNEL_OPT="$SCRIPT_KERNEL_OPT console=ttyS0"
+fi
+
 machine2=`echo $MACHINE | tr 'a-z' 'A-Z' | sed 's/-/_/'`
 # MACHINE is now set for all cases
 
Signature · 1 line
1.7.9.5
#2 lore raw

Re: [PATCH 1/2] runqemu: disable graphic when no DISPLAY

Quoted 2 lines · Robert Yang

+if [ -z "$DISPLAY" -o "$GRAPHIC" = "no" ]; then

Does this break people using QEMU without SDL that connect to it using VNC?

Ross

#3 lore raw

Re: [PATCH 1/2] runqemu: disable graphic when no DISPLAY

Quoted 8 lines · Ross

On 25 June 2015 at 10:24, Robert Yang <[email protected] <mailto:[email protected]>> wrote:

    +if [ -z "$DISPLAY" -o "$GRAPHIC" = "no" ]; then

Does this break people using QEMU without SDL that connect to it using VNC?

It doesn't break it, but there is a little different, now both the text console and graphic vnc server will start, the text console didn't start before this patch. I'm not sure which is better, I've made another patch to make it work as before, and put the patches here, you can decide which one to use.

git://git.openembedded.org/openembedded-core-contrib rbt/qemu_v2

scripts/runqemu +11 -2
@@ -70,6 +70,8 @@ SCRIPT_KERNEL_OPT=""
 SERIALSTDIO=""
 KVM_ENABLED="no"
 KVM_ACTIVE="no"
+GRAPHIC="yes"
+PUBLICVNC="no"
 
 # Determine whether the file is a kernel or QEMU image, and set the
 # appropriate variables
@@ -142,8 +144,7 @@ while true; do
        ISOFS=true
        ;;
         "nographic")
-            SCRIPT_QEMU_OPT="$SCRIPT_QEMU_OPT -nographic"
-            SCRIPT_KERNEL_OPT="$SCRIPT_KERNEL_OPT console=ttyS0"
+            GRAPHIC="no"
             ;;
         "serial")
             SCRIPT_QEMU_OPT="$SCRIPT_QEMU_OPT -serial stdio"
@@ -187,6 +188,7 @@ while true; do
             ;;
         "publicvnc")
             SCRIPT_QEMU_OPT="$SCRIPT_QEMU_OPT -vnc 0.0.0.0:0"
+            PUBLICVNC="yes"
             ;;
         "") break ;;
         *)
@@ -291,6 +293,13 @@ if [ "x$KVM_ENABLED" = "xyes" ]; then
     fi
 fi
 
+# Disable graphic when no DISPLAY or -nographic is specified.
+if [ "$GRAPHIC" = "no" ] || [ -z "$DISPLAY" -a "$PUBLICVNC" = "no" ] ; then
+    echo "Disabling graphic."
+    SCRIPT_QEMU_OPT="$SCRIPT_QEMU_OPT -nographic"
+    SCRIPT_KERNEL_OPT="$SCRIPT_KERNEL_OPT console=ttyS0"
+fi
+
 machine2=`echo $MACHINE | tr 'a-z' 'A-Z' | sed 's/-/_/'`
 # MACHINE is now set for all cases
 

// Robert

Quoted 2 lines

Ross

#4 lore raw

PATCH 2/2 runqemu: enable kvm when use tap under sudo

In reply to Robert Yang

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.

---
 scripts/runqemu          |    9 +++++++--
 scripts/runqemu-internal |   15 +++++++++++++++
 2 files changed, 22 insertions(+), 2 deletions(-)
scripts/runqemu +7 -2
index d9e91af..926d76e 100755
@@ -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"
 
 # Determine whether the file is a kernel or QEMU image, and set the
@@ -180,7 +183,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"
scripts/runqemu-internal +15 -0
index 694815f..91385ba 100755
@@ -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
@@ -237,6 +250,7 @@ else
             echo "Releasing lockfile of preconfigured tap device '$TAP'"
             release_lock $LOCKFILE
 
+
             if [ "$NFSRUNNING" = "true" ]; then
                 echo "Shutting down the userspace NFS server..."
                 echo "runqemu-export-rootfs stop $ROOTFS"
@@ -685,6 +699,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
Signature · 1 line
1.7.9.5
#5 lore raw

Re: [PATCH 2/2] runqemu: enable kvm when use tap under sudo

Quoted 81 lines · Robert Yang

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.

---
  scripts/runqemu          |    9 +++++++--
  scripts/runqemu-internal |   15 +++++++++++++++
  2 files changed, 22 insertions(+), 2 deletions(-)
scripts/runqemu +7 -2
index d9e91af..926d76e 100755
@@ -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"
 
  # Determine whether the file is a kernel or QEMU image, and set the
@@ -180,7 +183,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"
scripts/runqemu-internal +13 -0
index 694815f..91385ba 100755
@@ -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

scripts/runqemu-internal else · line 253

Quoted 4 lines
scripts/runqemu-internal +1 -0
@@ -237,6 +250,7 @@ else
              echo "Releasing lockfile of preconfigured tap device '$TAP'"
              release_lock $LOCKFILE
 
+

Sorry, I removed this blank line in the repo.

// Robert

Quoted 12 lines
scripts/runqemu-internal +1 -0
              if [ "$NFSRUNNING" = "true" ]; then
                  echo "Shutting down the userspace NFS server..."
                  echo "runqemu-export-rootfs stop $ROOTFS"
@@ -685,6 +699,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