Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KvyP3-0007sY-Mf for qemu-devel@nongnu.org; Fri, 31 Oct 2008 14:07:21 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KvyP2-0007sK-HZ for qemu-devel@nongnu.org; Fri, 31 Oct 2008 14:07:20 -0400 Received: from [199.232.76.173] (port=41787 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KvyP2-0007sH-CK for qemu-devel@nongnu.org; Fri, 31 Oct 2008 14:07:20 -0400 Received: from savannah.gnu.org ([199.232.41.3]:52589 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KvyP1-0000Yi-W9 for qemu-devel@nongnu.org; Fri, 31 Oct 2008 14:07:20 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1KvyP0-0006AG-6L for qemu-devel@nongnu.org; Fri, 31 Oct 2008 18:07:18 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1KvyOz-0006AC-Ov for qemu-devel@nongnu.org; Fri, 31 Oct 2008 18:07:18 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Fri, 31 Oct 2008 18:07:17 +0000 Subject: [Qemu-devel] [5577] Main loop fixes/cleanup Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 5577 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5577 Author: aliguori Date: 2008-10-31 18:07:17 +0000 (Fri, 31 Oct 2008) Log Message: ----------- Main loop fixes/cleanup Tidy up win32 main loop bits, allow timeout >= 1s, and force timeout to 0 if there is a pending bottom half. Modified Paths: -------------- trunk/sysemu.h trunk/vl.c Modified: trunk/sysemu.h =================================================================== --- trunk/sysemu.h 2008-10-31 17:42:00 UTC (rev 5576) +++ trunk/sysemu.h 2008-10-31 18:07:17 UTC (rev 5577) @@ -58,6 +58,7 @@ int qemu_savevm_state(QEMUFile *f); int qemu_loadvm_state(QEMUFile *f); +#ifdef _WIN32 /* Polling handling */ /* return TRUE if no sleep should be done afterwards */ @@ -66,7 +67,6 @@ int qemu_add_polling_cb(PollingFunc *func, void *opaque); void qemu_del_polling_cb(PollingFunc *func, void *opaque); -#ifdef _WIN32 /* Wait objects handling */ typedef void WaitObjectFunc(void *opaque); Modified: trunk/vl.c =================================================================== --- trunk/vl.c 2008-10-31 17:42:00 UTC (rev 5576) +++ trunk/vl.c 2008-10-31 18:07:17 UTC (rev 5577) @@ -6140,6 +6140,7 @@ return qemu_set_fd_handler2(fd, NULL, fd_read, fd_write, opaque); } +#ifdef _WIN32 /***********************************************************/ /* Polling handling */ @@ -6177,7 +6178,6 @@ } } -#ifdef _WIN32 /***********************************************************/ /* Wait objects support */ typedef struct WaitObjects { @@ -7688,6 +7688,26 @@ bh->deleted = 1; } +static void qemu_bh_update_timeout(int *timeout) +{ + QEMUBH *bh; + + for (bh = first_bh; bh; bh = bh->next) { + if (!bh->deleted && bh->scheduled) { + if (bh->idle) { + /* idle bottom halves will be polled at least + * every 10ms */ + *timeout = MIN(10, *timeout); + } else { + /* non-idle bottom halves will be executed + * immediately */ + *timeout = 0; + break; + } + } + } +} + /***********************************************************/ /* machine registration */ @@ -7890,15 +7910,10 @@ cpu_interrupt(cpu_single_env, CPU_INTERRUPT_EXIT); } -void main_loop_wait(int timeout) +#ifdef _WIN32 +void host_main_loop_wait(int *timeout) { - IOHandlerRecord *ioh; - fd_set rfds, wfds, xfds; - int ret, nfds; -#ifdef _WIN32 - int ret2, i; -#endif - struct timeval tv; + int ret, ret2, i; PollingEntry *pe; @@ -7907,12 +7922,11 @@ for(pe = first_polling_entry; pe != NULL; pe = pe->next) { ret |= pe->func(pe->opaque); } -#ifdef _WIN32 if (ret == 0) { int err; WaitObjects *w = &wait_objects; - ret = WaitForMultipleObjects(w->num, w->events, FALSE, timeout); + ret = WaitForMultipleObjects(w->num, w->events, FALSE, *timeout); if (WAIT_OBJECT_0 + 0 <= ret && ret <= WAIT_OBJECT_0 + w->num - 1) { if (w->func[ret - WAIT_OBJECT_0]) w->func[ret - WAIT_OBJECT_0](w->opaque[ret - WAIT_OBJECT_0]); @@ -7937,7 +7951,26 @@ fprintf(stderr, "WaitForMultipleObjects error %d %d\n", ret, err); } } + + *timeout = 0; +} +#else +void host_main_loop_wait(int *timeout) +{ +} #endif + +void main_loop_wait(int timeout) +{ + IOHandlerRecord *ioh; + fd_set rfds, wfds, xfds; + int ret, nfds; + struct timeval tv; + + qemu_bh_update_timeout(&timeout); + + host_main_loop_wait(&timeout); + /* poll any events */ /* XXX: separate device handlers from system ones */ nfds = -1; @@ -7961,12 +7994,9 @@ } } - tv.tv_sec = 0; -#ifdef _WIN32 - tv.tv_usec = 0; -#else - tv.tv_usec = timeout * 1000; -#endif + tv.tv_sec = timeout / 1000; + tv.tv_usec = (timeout % 1000) * 1000; + #if defined(CONFIG_SLIRP) if (slirp_inited) { slirp_select_fill(&nfds, &rfds, &wfds, &xfds);