From patchwork Fri Apr 13 18:35:04 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 152378 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AD887B700F for ; Sat, 14 Apr 2012 04:31:51 +1000 (EST) Received: from localhost ([::1]:50128 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SIlHh-0005ig-JX for incoming@patchwork.ozlabs.org; Fri, 13 Apr 2012 14:31:49 -0400 Received: from eggs.gnu.org ([208.118.235.92]:44138) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SIlGy-0003aO-C1 for qemu-devel@nongnu.org; Fri, 13 Apr 2012 14:31:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SIlGv-0006Dv-AG for qemu-devel@nongnu.org; Fri, 13 Apr 2012 14:31:03 -0400 Received: from smtp02.citrix.com ([66.165.176.63]:6091) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SIlGv-0006D7-1c for qemu-devel@nongnu.org; Fri, 13 Apr 2012 14:31:01 -0400 X-IronPort-AV: E=Sophos;i="4.75,418,1330923600"; d="scan'208";a="190286925" Received: from ftlpmailmx02.citrite.net ([10.13.107.66]) by FTLPIPO02.CITRIX.COM with ESMTP/TLS/RC4-MD5; 13 Apr 2012 14:30:56 -0400 Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.66) with Microsoft SMTP Server id 8.3.213.0; Fri, 13 Apr 2012 14:30:56 -0400 Received: from kaball.uk.xensource.com ([10.80.2.59] helo=localhost.localdomain) by ukmail1.uk.xensource.com with esmtp (Exim 4.69) (envelope-from ) id 1SIlGk-0003Dp-R2; Fri, 13 Apr 2012 19:30:50 +0100 From: Stefano Stabellini To: qemu-devel@nongnu.org Date: Fri, 13 Apr 2012 19:35:04 +0100 Message-ID: <1334342104-30546-5-git-send-email-stefano.stabellini@eu.citrix.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: References: MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.63 Cc: pbonzini@redhat.com, xen-devel@lists.xensource.com, jan.kiszka@siemens.com, avi@redhat.com, Stefano Stabellini Subject: [Qemu-devel] [PATCH v6 5/5] main_loop_wait: block indefinitely 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 - remove qemu_calculate_timeout; - explicitly size timeout to uint32_t; - introduce slirp_update_timeout; - pass NULL as timeout argument to select in case timeout is the maximum value; Signed-off-by: Stefano Stabellini Acked-by: Paul Brook --- async.c | 2 +- main-loop.c | 23 ++++++++++++++--------- main-loop.h | 2 +- qemu-timer.c | 5 ----- qemu-timer.h | 1 - qemu-tool.c | 4 ++++ slirp/libslirp.h | 1 + slirp/slirp.c | 7 +++++++ 8 files changed, 28 insertions(+), 17 deletions(-) diff --git a/async.c b/async.c index 332d511..ecdaf15 100644 --- a/async.c +++ b/async.c @@ -120,7 +120,7 @@ void qemu_bh_delete(QEMUBH *bh) bh->deleted = 1; } -void qemu_bh_update_timeout(int *timeout) +void qemu_bh_update_timeout(uint32_t *timeout) { QEMUBH *bh; diff --git a/main-loop.c b/main-loop.c index 1ebdc4b..f363748 100644 --- a/main-loop.c +++ b/main-loop.c @@ -226,7 +226,7 @@ static int max_priority; #ifndef _WIN32 static void glib_select_fill(int *max_fd, fd_set *rfds, fd_set *wfds, - fd_set *xfds, int *cur_timeout) + fd_set *xfds, uint32_t *cur_timeout) { GMainContext *context = g_main_context_default(); int i; @@ -288,20 +288,24 @@ static void glib_select_poll(fd_set *rfds, fd_set *wfds, fd_set *xfds, } } -static int os_host_main_loop_wait(int timeout) +static int os_host_main_loop_wait(uint32_t timeout) { - struct timeval tv; + struct timeval tv, *tvarg = NULL; int ret; glib_select_fill(&nfds, &rfds, &wfds, &xfds, &timeout); + if (timeout < UINT32_MAX) { + tvarg = &tv; + tv.tv_sec = timeout / 1000; + tv.tv_usec = (timeout % 1000) * 1000; + } + if (timeout > 0) { qemu_mutex_unlock_iothread(); } - tv.tv_sec = timeout / 1000; - tv.tv_usec = (timeout % 1000) * 1000; - ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv); + ret = select(nfds + 1, &rfds, &wfds, &xfds, tvarg); if (timeout > 0) { qemu_mutex_lock_iothread(); @@ -400,7 +404,7 @@ void qemu_fd_register(int fd) FD_CONNECT | FD_WRITE | FD_OOB); } -static int os_host_main_loop_wait(int timeout) +static int os_host_main_loop_wait(uint32_t timeout) { GMainContext *context = g_main_context_default(); int ret, i; @@ -463,12 +467,12 @@ static int os_host_main_loop_wait(int timeout) int main_loop_wait(int nonblocking) { - int ret, timeout; + int ret; + uint32_t timeout = UINT32_MAX; if (nonblocking) { timeout = 0; } else { - timeout = qemu_calculate_timeout(); qemu_bh_update_timeout(&timeout); } @@ -480,6 +484,7 @@ int main_loop_wait(int nonblocking) FD_ZERO(&xfds); #ifdef CONFIG_SLIRP + slirp_update_timeout(&timeout); slirp_select_fill(&nfds, &rfds, &wfds, &xfds); #endif qemu_iohandler_fill(&nfds, &rfds, &wfds, &xfds); diff --git a/main-loop.h b/main-loop.h index e743aa0..c06b8bc 100644 --- a/main-loop.h +++ b/main-loop.h @@ -365,6 +365,6 @@ void qemu_iohandler_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds, int rc void qemu_bh_schedule_idle(QEMUBH *bh); int qemu_bh_poll(void); -void qemu_bh_update_timeout(int *timeout); +void qemu_bh_update_timeout(uint32_t *timeout); #endif diff --git a/qemu-timer.c b/qemu-timer.c index 1166beb..887babf 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -821,8 +821,3 @@ fail: return err; } -int qemu_calculate_timeout(void) -{ - return 1000; -} - diff --git a/qemu-timer.h b/qemu-timer.h index 661bbe7..094e730 100644 --- a/qemu-timer.h +++ b/qemu-timer.h @@ -63,7 +63,6 @@ void qemu_run_timers(QEMUClock *clock); void qemu_run_all_timers(void); int qemu_alarm_pending(void); void configure_alarms(char const *opt); -int qemu_calculate_timeout(void); void init_clocks(void); int init_timer_alarm(void); diff --git a/qemu-tool.c b/qemu-tool.c index edb84f5..a0544d7 100644 --- a/qemu-tool.c +++ b/qemu-tool.c @@ -91,6 +91,10 @@ int qemu_init_main_loop(void) return main_loop_init(); } +void slirp_update_timeout(uint32_t *timeout) +{ +} + void slirp_select_fill(int *pnfds, fd_set *readfds, fd_set *writefds, fd_set *xfds) { diff --git a/slirp/libslirp.h b/slirp/libslirp.h index 890fd86..77527ad 100644 --- a/slirp/libslirp.h +++ b/slirp/libslirp.h @@ -15,6 +15,7 @@ Slirp *slirp_init(int restricted, struct in_addr vnetwork, struct in_addr vnameserver, void *opaque); void slirp_cleanup(Slirp *slirp); +void slirp_update_timeout(uint32_t *timeout); void slirp_select_fill(int *pnfds, fd_set *readfds, fd_set *writefds, fd_set *xfds); diff --git a/slirp/slirp.c b/slirp/slirp.c index 1502830..90473eb 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -258,6 +258,13 @@ void slirp_cleanup(Slirp *slirp) #define CONN_CANFRCV(so) (((so)->so_state & (SS_FCANTRCVMORE|SS_ISFCONNECTED)) == SS_ISFCONNECTED) #define UPD_NFDS(x) if (nfds < (x)) nfds = (x) +void slirp_update_timeout(uint32_t *timeout) +{ + if (!QTAILQ_EMPTY(&slirp_instances)) { + *timeout = MIN(1000, *timeout); + } +} + void slirp_select_fill(int *pnfds, fd_set *readfds, fd_set *writefds, fd_set *xfds) {