From patchwork Mon Dec 21 08:09:25 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 41535 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 D56C7B6F0C for ; Mon, 21 Dec 2009 20:06:37 +1100 (EST) Received: from localhost ([127.0.0.1]:42597 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NMeDr-000537-2R for incoming@patchwork.ozlabs.org; Mon, 21 Dec 2009 04:06:35 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NMdL2-0002pG-Tg for qemu-devel@nongnu.org; Mon, 21 Dec 2009 03:09:57 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NMdKv-0002jz-1V for qemu-devel@nongnu.org; Mon, 21 Dec 2009 03:09:53 -0500 Received: from [199.232.76.173] (port=52823 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NMdKs-0002jl-Ho for qemu-devel@nongnu.org; Mon, 21 Dec 2009 03:09:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45175) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NMdKs-0003p4-07 for qemu-devel@nongnu.org; Mon, 21 Dec 2009 03:09:46 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nBL89jUM016518 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 21 Dec 2009 03:09:45 -0500 Received: from localhost.localdomain (vpn2-10-119.ams2.redhat.com [10.36.10.119]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nBL89V3Y011460 for ; Mon, 21 Dec 2009 03:09:44 -0500 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 21 Dec 2009 09:09:25 +0100 Message-Id: <1261382970-23251-15-git-send-email-pbonzini@redhat.com> In-Reply-To: <1261382970-23251-1-git-send-email-pbonzini@redhat.com> References: <1261382970-23251-1-git-send-email-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCH 14/19] disentangle tcg and deadline calculation 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 Just tell main_loop_wait whether to be blocking or nonblocking, so that there is no need to call qemu_cpus_have_work from the timer subsystem. Instead, tcg_cpu_exec can say "we want the main loop not to block because we have stuff to do". Signed-off-by: Paolo Bonzini --- hw/xenfb.c | 6 ++++-- sysemu.h | 2 +- vl.c | 25 ++++++++++++++++--------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/hw/xenfb.c b/hw/xenfb.c index 795a326..422cd53 100644 --- a/hw/xenfb.c +++ b/hw/xenfb.c @@ -983,12 +983,14 @@ void xen_init_display(int domid) wait_more: i++; - main_loop_wait(10); /* miliseconds */ + main_loop_wait(true); xfb = xen_be_find_xendev("vfb", domid, 0); xin = xen_be_find_xendev("vkbd", domid, 0); if (!xfb || !xin) { - if (i < 256) + if (i < 256) { + usleep(10000); goto wait_more; + } xen_be_printf(NULL, 1, "displaystate setup failed\n"); return; } diff --git a/sysemu.h b/sysemu.h index 9d80bb2..1384ef9 100644 --- a/sysemu.h +++ b/sysemu.h @@ -60,7 +60,7 @@ void do_info_snapshots(Monitor *mon); void qemu_announce_self(void); -void main_loop_wait(int timeout); +void main_loop_wait(bool nonblocking); int qemu_savevm_state_begin(Monitor *mon, QEMUFile *f, int blk_enable, int shared); diff --git a/vl.c b/vl.c index 9bf9806..f7472db 100644 --- a/vl.c +++ b/vl.c @@ -592,6 +592,7 @@ struct qemu_alarm_timer { }; static struct qemu_alarm_timer *alarm_timer; +static int qemu_calculate_timeout(void); static inline int qemu_alarm_pending(void) { @@ -3507,7 +3508,7 @@ static void *kvm_cpu_thread_fn(void *arg) return NULL; } -static void tcg_cpu_exec(void); +static bool tcg_cpu_exec(void); static void *tcg_cpu_thread_fn(void *arg) { @@ -3786,14 +3787,20 @@ static void host_main_loop_wait(int *timeout) } #endif -void main_loop_wait(int timeout) +void main_loop_wait(bool nonblocking) { IOHandlerRecord *ioh; fd_set rfds, wfds, xfds; int ret, nfds; struct timeval tv; + int timeout; - qemu_bh_update_timeout(&timeout); + if (nonblocking) + timeout = 0; + else { + timeout = qemu_calculate_timeout(); + qemu_bh_update_timeout(&timeout); + } host_main_loop_wait(&timeout); @@ -3898,7 +3905,7 @@ static int qemu_cpu_exec(CPUState *env) return ret; } -static void tcg_cpu_exec(void) +static bool tcg_cpu_exec(void) { int ret = 0; @@ -3908,7 +3915,7 @@ static void tcg_cpu_exec(void) CPUState *env = cur_cpu = next_cpu; if (!vm_running) - break; + return false; if (qemu_alarm_pending()) break; if (cpu_can_run(env)) @@ -3919,6 +3926,7 @@ static void tcg_cpu_exec(void) break; } } + return qemu_cpus_have_work(); } static int qemu_calculate_timeout(void) @@ -3928,8 +3936,6 @@ static int qemu_calculate_timeout(void) if (!vm_running) timeout = 5000; - else if (qemu_cpus_have_work()) - timeout = 0; else { /* XXX: use timeout computed from timers */ int64_t add; @@ -3989,16 +3995,17 @@ static void main_loop(void) for (;;) { do { + bool nonblocking = false; #ifdef CONFIG_PROFILER int64_t ti; #endif #ifndef CONFIG_IOTHREAD - tcg_cpu_exec(); + nonblocking = tcg_cpu_exec(); #endif #ifdef CONFIG_PROFILER ti = profile_getclock(); #endif - main_loop_wait(qemu_calculate_timeout()); + main_loop_wait(nonblocking); #ifdef CONFIG_PROFILER dev_time += profile_getclock() - ti; #endif