From patchwork Thu Oct 21 17:36:16 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 68749 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 850F1B70DC for ; Fri, 22 Oct 2010 05:25:13 +1100 (EST) Received: from localhost ([127.0.0.1]:48800 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P8zFQ-00047z-6F for incoming@patchwork.ozlabs.org; Thu, 21 Oct 2010 13:48:16 -0400 Received: from [140.186.70.92] (port=42447 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P8z4y-0000UT-GF for qemu-devel@nongnu.org; Thu, 21 Oct 2010 13:37:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P8z4w-0005cu-79 for qemu-devel@nongnu.org; Thu, 21 Oct 2010 13:37:28 -0400 Received: from smtp02.citrix.com ([66.165.176.63]:12703) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P8z4w-0005Xu-1M for qemu-devel@nongnu.org; Thu, 21 Oct 2010 13:37:26 -0400 X-IronPort-AV: E=Sophos;i="4.58,218,1286164800"; d="scan'208";a="119106360" Received: from ftlpexchmx02.citrite.net ([10.9.154.127]) by FTLPIPO02.CITRIX.COM with ESMTP; 21 Oct 2010 13:37:25 -0400 Received: from smtp01.ad.xensource.com ([10.219.128.104]) by FTLPEXCHMX02.citrite.net with Microsoft SMTPSVC(6.0.3790.4675); Thu, 21 Oct 2010 13:37:24 -0400 Received: from perard.cam.xci-test.com (perard.cam.xci-test.com [10.80.248.106]) by smtp01.ad.xensource.com (8.13.1/8.13.1) with ESMTP id o9LHb2ik009642; Thu, 21 Oct 2010 10:37:23 -0700 From: anthony.perard@citrix.com To: QEMU-devel Date: Thu, 21 Oct 2010 18:36:16 +0100 Message-Id: <1287682587-18642-5-git-send-email-anthony.perard@citrix.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1287682587-18642-1-git-send-email-anthony.perard@citrix.com> References: <1287682587-18642-1-git-send-email-anthony.perard@citrix.com> X-OriginalArrivalTime: 21 Oct 2010 17:37:24.0933 (UTC) FILETIME=[9F973F50:01CB7146] X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Anthony PERARD , Xen Devel , Stefano Stabellini Subject: [Qemu-devel] [PATCH V6 04/15] Introduce -accel command option. 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 From: Anthony PERARD This option gives the ability to switch one "accelerator" like kvm, xen or the default one tcg. We can specify more than one accelerator by separate them by a comma. QEMU will try each one and use the first whose works. So, -accel xen,kvm,tcg which would try Xen support first, then KVM and finaly tcg if none of the other works. Signed-off-by: Anthony PERARD Acked-by: Alexander Graf --- qemu-options.hx | 10 ++++++ vl.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 85 insertions(+), 11 deletions(-) diff --git a/qemu-options.hx b/qemu-options.hx index 718d47a..ba8385b 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -1925,6 +1925,16 @@ Enable KVM full virtualization support. This option is only available if KVM support is enabled when compiling. ETEXI +DEF("accel", HAS_ARG, QEMU_OPTION_accel, \ + "-accel accel use an accelerator (kvm,xen,tcg), default is tcg\n", QEMU_ARCH_ALL) +STEXI +@item -accel @var{accel}[,@var{accel}[,...]] +@findex -accel +This is use to enable an accelerator, in kvm,xen,tcg. +By default, it use only tcg. If there a more than one accelerator +specified, the next one is used if the first don't work. +ETEXI + DEF("xen-domid", HAS_ARG, QEMU_OPTION_xen_domid, "-xen-domid id specify xen guest domain id\n", QEMU_ARCH_ALL) DEF("xen-create", 0, QEMU_OPTION_xen_create, diff --git a/vl.c b/vl.c index df414ef..40a26ee 100644 --- a/vl.c +++ b/vl.c @@ -1750,6 +1750,74 @@ static int debugcon_parse(const char *devname) return 0; } +static struct { + const char *opt_name; + const char *name; + int (*available)(void); + int (*init)(int smp_cpus); + int *allowed; +} accel_list[] = { + { "tcg", "tcg", NULL, NULL, NULL }, + { "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed }, +}; + +static int accel_parse_init(const char *opts) +{ + const char *p = opts; + char buf[10]; + int i, ret; + bool accel_initalised = 0; + bool init_failed = 0; + + while (!accel_initalised && *p != '\0') { + if (*p == ',') { + p++; + } + p = get_opt_name(buf, sizeof (buf), p, ','); + for (i = 0; i < ARRAY_SIZE(accel_list); i++) { + if (strcmp(accel_list[i].opt_name, buf) == 0) { + if (accel_list[i].init) { + ret = accel_list[i].init(smp_cpus); + } else { + ret = 0; + } + if (ret < 0) { + init_failed = 1; + if (!accel_list[i].available()) { + printf("%s not supported for this target\n", + accel_list[i].name); + } else { + fprintf(stderr, "failed to initialize %s: %s\n", + accel_list[i].name, + strerror(-ret)); + } + } else { + accel_initalised = 1; + if (accel_list[i].allowed) { + *(accel_list[i].allowed) = 1; + } + } + break; + } + } + if (i == ARRAY_SIZE(accel_list) + 1) { + fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf); + exit(1); + } + } + + if (!accel_initalised) { + fprintf(stderr, "No accelerator found!\n"); + exit(1); + } + + if (init_failed) { + fprintf(stderr, "Back to %s accelerator.\n", accel_list[i].name); + } + + return !accel_initalised; +} + void qemu_add_exit_notifier(Notifier *notify) { notifier_list_add(&exit_notifiers, notify); @@ -1829,6 +1897,7 @@ int main(int argc, char **argv, char **envp) const char *incoming = NULL; int show_vnc_port = 0; int defconfig = 1; + const char *accel_list_opts = "tcg"; #ifdef CONFIG_SIMPLE_TRACE const char *trace_file = NULL; @@ -2444,7 +2513,10 @@ int main(int argc, char **argv, char **envp) do_smbios_option(optarg); break; case QEMU_OPTION_enable_kvm: - kvm_allowed = 1; + accel_list_opts = "kvm"; + break; + case QEMU_OPTION_accel: + accel_list_opts = optarg; break; case QEMU_OPTION_usb: usb_enabled = 1; @@ -2754,16 +2826,8 @@ int main(int argc, char **argv, char **envp) 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"); - } else { - fprintf(stderr, "failed to initialize KVM: %s\n", strerror(-ret)); - } - exit(1); - } + if (accel_list_opts) { + accel_parse_init(accel_list_opts); } if (qemu_init_main_loop()) {