From patchwork Wed Mar 10 10:38:54 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 47246 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 79D5AB7C98 for ; Wed, 10 Mar 2010 22:49:58 +1100 (EST) Received: from localhost ([127.0.0.1]:41309 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NpKPO-00049B-1K for incoming@patchwork.ozlabs.org; Wed, 10 Mar 2010 06:49:02 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NpJJz-0008TK-Q7 for qemu-devel@nongnu.org; Wed, 10 Mar 2010 05:39:23 -0500 Received: from [199.232.76.173] (port=52797 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NpJJy-0008ST-NJ for qemu-devel@nongnu.org; Wed, 10 Mar 2010 05:39:22 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NpJJx-0004wN-8B for qemu-devel@nongnu.org; Wed, 10 Mar 2010 05:39:22 -0500 Received: from mail-ew0-f225.google.com ([209.85.219.225]:62503) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NpJJw-0004sG-P2 for qemu-devel@nongnu.org; Wed, 10 Mar 2010 05:39:21 -0500 Received: by mail-ew0-f225.google.com with SMTP id 25so153293ewy.16 for ; Wed, 10 Mar 2010 02:39:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:from:to:subject:date :message-id:x-mailer:in-reply-to:references; bh=5Pfif5Xr8G49tCtpgpfxBjHpWdvbiDyyrgtyt1t3WO4=; b=yG2n/EcDwVqy0vmNJr0qsqDVtZhG3itL1Qm0UHgNI5XvBcUC/tf9uSQvlz4be2uSAH mn7rvtZhcLJfoZ65PqmzJ/1BTilmNLRaWf6OfPJje0eJOJjcm8LXg2AVBkE4YRhzPRz0 GdCjhNO2iWH1KX7uRdutAl0BQNAlWx5WKNSu0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; b=J8M9SlEvPUYsN1tA+y1SCwFOeZ53x9IFYieycDWSxB+BH+4NsLnOtc1jWoLPGyR1hv WCKonGma1UrgFF/77Dc03QjmVy1omzR6k8vmJmVijrHiF/X16+DuLEOSZ7kn4JDMlq89 4nnGFDBsSrJfGOCvnzpqPLFI2J7KxXSP3urPk= Received: by 10.213.65.138 with SMTP id j10mr5066174ebi.23.1268217555183; Wed, 10 Mar 2010 02:39:15 -0800 (PST) Received: from localhost.localdomain (nat-pool-brq-t.redhat.com [209.132.186.34]) by mx.google.com with ESMTPS id 14sm3836002ewy.2.2010.03.10.02.39.14 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 10 Mar 2010 02:39:14 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 10 Mar 2010 11:38:54 +0100 Message-Id: <1268217535-26554-18-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.6.6 In-Reply-To: <1268217535-26554-1-git-send-email-pbonzini@redhat.com> References: <1268217535-26554-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: [Qemu-devel] [PATCH 17/18] 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 | 23 +++++++++++++++-------- 3 files changed, 20 insertions(+), 11 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 afa11b5..f84413f 100644 --- a/sysemu.h +++ b/sysemu.h @@ -64,7 +64,7 @@ void cpu_synchronize_all_post_init(void); void qemu_announce_self(void); -void main_loop_wait(int timeout); +void main_loop_wait(int nonblocking); int qemu_savevm_state_begin(Monitor *mon, QEMUFile *f, int blk_enable, int shared); diff --git a/vl.c b/vl.c index d97da4d..34d39c0 100644 --- a/vl.c +++ b/vl.c @@ -618,6 +618,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) { @@ -3597,7 +3598,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) { @@ -3915,14 +3916,20 @@ static void host_main_loop_wait(int *timeout) } #endif -void main_loop_wait(int timeout) +void main_loop_wait(int 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); @@ -4029,7 +4036,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; @@ -4054,6 +4061,7 @@ static void tcg_cpu_exec(void) break; } } + return tcg_has_work(); } static int qemu_calculate_timeout(void) @@ -4063,8 +4071,6 @@ static int qemu_calculate_timeout(void) if (!vm_running) timeout = 5000; - else if (tcg_has_work()) - timeout = 0; else { /* XXX: use timeout computed from timers */ int64_t add; @@ -4124,16 +4130,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