qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 19/22] machine: introduce accel option to allow sele


From: Anthony Liguori
Subject: [Qemu-devel] [PATCH 19/22] machine: introduce accel option to allow selection of kvm or tcg
Date: Mon, 7 Jun 2010 18:52:07 -0500

Syntax is -machine accel=kvm
          -machine accel=tcg
          -machine accel=kvm|tcg

kvm|tcg tries kvm and fallbacks on tcg if kvm support isn't available.

Signed-off-by: Anthony Liguori <address@hidden>

diff --git a/hw/boards.h b/hw/boards.h
index 947fa33..1097561 100644
--- a/hw/boards.h
+++ b/hw/boards.h
@@ -81,6 +81,9 @@ void machine_set_default(const char *name);
     },{                                 \
         .name = "sockets",              \
         .type = QEMU_OPT_NUMBER,        \
+    },{                                 \
+        .name = "accel",                \
+        .type = QEMU_OPT_STRING,        \
     }
 
 
diff --git a/vl.c b/vl.c
index d84fc65..7cb5865 100644
--- a/vl.c
+++ b/vl.c
@@ -2654,6 +2654,8 @@ int main(int argc, char **argv, char **envp)
     int defconfig = 1;
     QemuOpts *machine_opts = NULL;
     int max_cpus = 0;
+    const char *accel;
+    int tcg_fallback = 0;
 
     error_set_progname(argv[0]);
 
@@ -3272,7 +3274,10 @@ int main(int argc, char **argv, char **envp)
                 do_smbios_option(optarg);
                 break;
             case QEMU_OPTION_enable_kvm:
-                kvm_allowed = 1;
+                if (!qemu_opts_parsef(&qemu_machine_opts, "accel=kvm")) {
+                    printf("failed\n");
+                    exit(1);
+                }
                 break;
             case QEMU_OPTION_usb:
                 usb_enabled = 1;
@@ -3629,15 +3634,36 @@ int main(int argc, char **argv, char **envp)
         exit(1);
     }
 
+    accel = qemu_opt_get(machine_opts, "accel");
+    if (accel) {
+        if (!strcmp(accel, "kvm")) {
+            kvm_allowed = 1;
+        } else if (!strcmp(accel, "tcg")) {
+            kvm_allowed = 0;
+        } else if (!strcmp(accel, "kvm|tcg")) {
+            kvm_allowed = 1;
+            tcg_fallback = 1;
+        } else {
+            fprintf(stderr, "accel: invalid option %s\n", accel);
+            exit(1);
+        }
+    }
+
     if (kvm_allowed) {
         int ret = kvm_init(smp_cpus);
         if (ret < 0) {
             if (!kvm_available()) {
                 printf("KVM not supported for this target\n");
+                exit(1);
             } else {
                 fprintf(stderr, "failed to initialize KVM: %s\n", 
strerror(-ret));
+
+                if (tcg_fallback) {
+                    kvm_allowed = 0;
+                } else {
+                    exit(1);
+                }
             }
-            exit(1);
         }
     }
 
-- 
1.7.0.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]