From patchwork Mon Jun 7 23:52:07 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 54914 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AEBB7B7D1C for ; Tue, 8 Jun 2010 10:24:42 +1000 (EST) Received: from localhost ([127.0.0.1]:53153 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OLmcQ-0004kZ-Sf for incoming@patchwork.ozlabs.org; Mon, 07 Jun 2010 20:24:38 -0400 Received: from [140.186.70.92] (port=44036 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OLm7L-0004S4-An for qemu-devel@nongnu.org; Mon, 07 Jun 2010 19:52:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OLm7I-0003Ci-1f for qemu-devel@nongnu.org; Mon, 07 Jun 2010 19:52:31 -0400 Received: from e5.ny.us.ibm.com ([32.97.182.145]:37935) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OLm7H-0003CZ-VD for qemu-devel@nongnu.org; Mon, 07 Jun 2010 19:52:28 -0400 Received: from d01relay06.pok.ibm.com (d01relay06.pok.ibm.com [9.56.227.116]) by e5.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id o57NZiN4032113 for ; Mon, 7 Jun 2010 19:35:45 -0400 Received: from d01av02.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216]) by d01relay06.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o57NqRwx1671362 for ; Mon, 7 Jun 2010 19:52:27 -0400 Received: from d01av02.pok.ibm.com (loopback [127.0.0.1]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o57NqQlP010969 for ; Mon, 7 Jun 2010 20:52:27 -0300 Received: from localhost.localdomain (sig-9-65-84-205.mts.ibm.com [9.65.84.205]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o57NqDr8009965; Mon, 7 Jun 2010 20:52:26 -0300 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Mon, 7 Jun 2010 18:52:07 -0500 Message-Id: <1275954730-8196-20-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1275954730-8196-1-git-send-email-aliguori@us.ibm.com> References: <1275954730-8196-1-git-send-email-aliguori@us.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Glauber Costa , Marcelo Tosatti , Anthony Liguori , Avi Kivity Subject: [Qemu-devel] [PATCH 19/22] machine: introduce accel option to allow selection of kvm or tcg X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 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); } }