From patchwork Wed Nov 6 14:53:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 288947 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id ECC762C00CA for ; Thu, 7 Nov 2013 01:51:43 +1100 (EST) Received: from localhost ([::1]:34359 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ve4SL-0005Sl-If for incoming@patchwork.ozlabs.org; Wed, 06 Nov 2013 09:51:41 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49953) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ve4Ry-0005LI-HU for qemu-devel@nongnu.org; Wed, 06 Nov 2013 09:51:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ve4Rs-0003uo-IG for qemu-devel@nongnu.org; Wed, 06 Nov 2013 09:51:18 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46976) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ve4Rs-0003uY-B7 for qemu-devel@nongnu.org; Wed, 06 Nov 2013 09:51:12 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rA6EoAEG014843 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 6 Nov 2013 09:50:10 -0500 Received: from redhat.com (vpn1-7-165.ams2.redhat.com [10.36.7.165]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id rA6Eo4e3025909; Wed, 6 Nov 2013 09:50:05 -0500 Date: Wed, 6 Nov 2013 16:53:05 +0200 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <1383749487-4823-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Paolo Bonzini , Anthony Liguori Subject: [Qemu-devel] [PATCH v2 1/2] qtest: split configuration of qtest accelerator and chardev X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Paolo Bonzini qtest uses the icount infrastructure to implement a test-driven vm_clock. This however is not necessary when using -qtest as a "probe" together with a normal TCG-, KVM- or Xen-based virtual machine. Hence, split out the call to configure_icount into a new function that is called only for "-machine accel=qtest"; and disable those commands when running with an accelerator other than qtest. This also fixes an assertion failure with "qemu-system-x86_64 -machine accel=qtest" but no -qtest option. This is a valid case, albeit somewhat weird; nothing will happen in the VM but you'll still be able to interact with the monitor or the GUI. Now that qtest_init is not limited to an int(void) function, change global variables that are not used outside qtest_init to arguments. And finally, cleanup useless parts of include/sysemu/qtest.h. The file is not used at all for user-only emulation, and qtest is not available on Win32 due to its usage of sigwait. Reported-by: Michael S. Tsirkin Reviewed-by: Michael S. Tsirkin Tested-by: Michael S. Tsirkin Signed-off-by: Paolo Bonzini Signed-off-by: Michael S. Tsirkin --- include/sysemu/qtest.h | 25 +++++-------------------- qtest.c | 20 ++++++++++---------- vl.c | 8 +++++--- 3 files changed, 20 insertions(+), 33 deletions(-) diff --git a/include/sysemu/qtest.h b/include/sysemu/qtest.h index 9a0c6b3..112a661 100644 --- a/include/sysemu/qtest.h +++ b/include/sysemu/qtest.h @@ -16,38 +16,23 @@ #include "qemu-common.h" -#if !defined(CONFIG_USER_ONLY) extern bool qtest_allowed; -extern const char *qtest_chrdev; -extern const char *qtest_log; static inline bool qtest_enabled(void) { return qtest_allowed; } +int qtest_init_accel(void); +void qtest_init(const char *qtest_chrdev, const char *qtest_log); + static inline int qtest_available(void) { +#ifdef CONFIG_POSIX return 1; -} - -int qtest_init(void); #else -static inline bool qtest_enabled(void) -{ - return false; -} - -static inline int qtest_available(void) -{ - return 0; -} - -static inline int qtest_init(void) -{ return 0; -} - #endif +} #endif diff --git a/qtest.c b/qtest.c index 584c707..dcf1301 100644 --- a/qtest.c +++ b/qtest.c @@ -22,8 +22,6 @@ #define MAX_IRQ 256 -const char *qtest_chrdev; -const char *qtest_log; bool qtest_allowed; static DeviceState *irq_intercept_dev; @@ -406,7 +404,7 @@ static void qtest_process_command(CharDriverState *chr, gchar **words) qtest_send_prefix(chr); qtest_send(chr, "OK\n"); - } else if (strcmp(words[0], "clock_step") == 0) { + } else if (qtest_enabled() && strcmp(words[0], "clock_step") == 0) { int64_t ns; if (words[1]) { @@ -417,7 +415,7 @@ static void qtest_process_command(CharDriverState *chr, gchar **words) qtest_clock_warp(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + ns); qtest_send_prefix(chr); qtest_send(chr, "OK %"PRIi64"\n", (int64_t)qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); - } else if (strcmp(words[0], "clock_set") == 0) { + } else if (qtest_enabled() && strcmp(words[0], "clock_set") == 0) { int64_t ns; g_assert(words[1]); @@ -502,13 +500,17 @@ static void qtest_event(void *opaque, int event) } } -int qtest_init(void) +int qtest_init_accel(void) { - CharDriverState *chr; + configure_icount("0"); - g_assert(qtest_chrdev != NULL); + return 0; +} + +void qtest_init(const char *qtest_chrdev, const char *qtest_log) +{ + CharDriverState *chr; - configure_icount("0"); chr = qemu_chr_new("qtest", qtest_chrdev, NULL); qemu_chr_add_handlers(chr, qtest_can_read, qtest_read, qtest_event, chr); @@ -525,6 +527,4 @@ int qtest_init(void) } qtest_chr = chr; - - return 0; } diff --git a/vl.c b/vl.c index bf03524..f28674f 100644 --- a/vl.c +++ b/vl.c @@ -2622,7 +2622,7 @@ static struct { { "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed }, { "xen", "Xen", xen_available, xen_init, &xen_allowed }, { "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed }, - { "qtest", "QTest", qtest_available, qtest_init, &qtest_allowed }, + { "qtest", "QTest", qtest_available, qtest_init_accel, &qtest_allowed }, }; static int configure_accelerator(void) @@ -2834,6 +2834,8 @@ int main(int argc, char **argv, char **envp) QEMUMachine *machine; const char *cpu_model; const char *vga_model = "none"; + const char *qtest_chrdev = NULL; + const char *qtest_log = NULL; const char *pid_file = NULL; const char *incoming = NULL; #ifdef CONFIG_VNC @@ -4039,8 +4041,8 @@ int main(int argc, char **argv, char **envp) configure_accelerator(); - if (!qtest_enabled() && qtest_chrdev) { - qtest_init(); + if (qtest_chrdev) { + qtest_init(qtest_chrdev, qtest_log); } machine_opts = qemu_get_machine_opts();