summaryrefslogtreecommitdiffstats
path: root/main-loop.c
Commit message (Collapse)AuthorAgeFilesLines
* Revert "main-loop.c: Handle SIGINT, SIGHUP and SIGTERM synchronously"Jan Kiszka2014-10-271-3/+5
| | | | | | | | | | | | | | This reverts commit 15124e142034d21341ec9f1a304a1dc5a6c25681. It breaks debuggability of qemu and is no longer needed as the problem has now been addressed in a different way. Instead we provide a comment about why these signals must be handled asynchronously. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Reviewed-by: Gonglei <arei.gonglei@huawei.com> [PMM: added comment] Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
* main-loop.c: Handle SIGINT, SIGHUP and SIGTERM synchronouslyPeter Maydell2014-09-261-0/+3
| | | | | | | | | | | | | | | | | | | | | Add the termination signals SIGINT, SIGHUP and SIGTERM to the list of signals which we handle synchronously via a signalfd. This avoids a race condition where if we took the SIGTERM in the middle of qemu_shutdown_requested: int r = shutdown_requested; [SIGTERM here...] shutdown_requested = 0; then the setting of the shutdown_requested flag by termsig_handler() would be lost and QEMU would fail to shut down. This was causing 'make check' to hang occasionally. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Tested-by: Alex Bennée <alex.bennee@linaro.org> Message-id: 1411660269-11081-1-git-send-email-peter.maydell@linaro.org Cc: qemu-stable@nongnu.org
* async: aio_context_new(): Handle event_notifier_init failureChrysostomos Nanakos2014-09-221-2/+7
| | | | | | | | | | | | | | | | | | | | | On a system with a low limit of open files the initialization of the event notifier could fail and QEMU exits without printing any error information to the user. The problem can be easily reproduced by enforcing a low limit of open files and start QEMU with enough I/O threads to hit this limit. The same problem raises, without the creation of I/O threads, while QEMU initializes the main event loop by enforcing an even lower limit of open files. This commit adds an error message on failure: # qemu [...] -object iothread,id=iothread0 -object iothread,id=iothread1 qemu: Failed to initialize event notifier: Too many open files in system Signed-off-by: Chrysostomos Nanakos <cnanakos@grnet.gr> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
* block: drop aio functions that operate on the main AioContextPaolo Bonzini2014-07-091-21/+0
| | | | | | | | The main AioContext should be accessed explicitly via qemu_get_aio_context(). Most of the time, using it is not the right thing to do. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* main-loop: Suppress "I/O thread spun" warnings for qtestPeter Maydell2014-03-131-1/+2
| | | | | | | | | | | | When running under qtest we don't actually have any vcpu threads to be starved, so the warning about the I/O thread spinning isn't relevant, and the way qtest manipulates the simulated clock means the warning is produced a lot as a false positive. Suppress it if qtest_enabled(), so 'make check' output is less noisy. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
* slirp: set mainloop timeout with more precise valueLiu Ping Fan2013-09-171-2/+1
| | | | | | | | | | If slirp needs to emulate tcp timeout, then the timeout value for mainloop should be more precise, which is determined by slirp's fasttimo or slowtimo. Achieve this by swap the logic sequence of slirp_pollfds_fill and slirp_update_timeout. Signed-off-by: Liu Ping Fan <pingfank@linux.vnet.ibm.com> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
* aio / timers: Rearrange timer.h & make legacy functions call non-legacyAlex Bligh2013-08-221-1/+1
| | | | | | | | | | | Rearrange timer.h so it is in order by function type. Make legacy functions call non-legacy functions rather than vice-versa. Convert cpus.c to use new API. Signed-off-by: Alex Bligh <alex@alex.org.uk> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
* aio / timers: Remove alarm timersAlex Bligh2013-08-221-4/+0
| | | | | | | | Remove alarm timers from qemu-timers.c now we use g_poll / ppoll instead. Signed-off-by: Alex Bligh <alex@alex.org.uk> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
* aio / timers: Convert mainloop to use timeoutAlex Bligh2013-08-221-14/+37
| | | | | | | | | | | | Convert mainloop to use timeout from default timerlist group (i.e. the current 3 static timers) main-loop.c produces a (possibly spurious) warning about multiple iterations. Adapt the way this works for a signed timeout and make the warning a bit safer. Signed-off-by: Alex Bligh <alex@alex.org.uk> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
* aio: drop io_flush argumentStefan Hajnoczi2013-08-191-6/+3
| | | | | | | | | | | The .io_flush() handler no longer exists and has no users. Drop the io_flush argument to aio_set_fd_handler() and related functions. The AioFlushEventNotifierHandler and AioFlushHandler typedefs are no longer used and are dropped too. Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
* main-loop: do not include slirp/slirp.h, use libslirp.h insteadMichael Tokarev2013-06-121-1/+2
| | | | | | | | | | | | | | | | | | The header slirp/slirp.h is an internal header for slirp, and main-loop.c does not use internals from there. Instead, it uses public functions (slirp_update_timeout(), slirp_pollfds_fill() etc) which are declared in slirp/libslirp.h. Including slirp/slirp.h is somewhat dangerous since it redefines errno on WIN32, so any file including it may misbehave wrt errno. Unfortunately libslirp isn't self-contained, it needs declaration of struct in_addr, which is provided by qemu/sockets.h. Maybe instead of #including qemu/sockets.h before libslirp.h, it is better to make the latter self-contained. Signed-off-by: Michael Tokarev <mjt@tls.msk.ru> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
* main-loop: partial revert of 5e3bc73Stefan Hajnoczi2013-05-161-18/+14
| | | | | | | | | | | | | | This patch reverts part of 5e3bc735d93dd23f074b5116fd11e1ad8cd4962f. Paolo Bonzini wrote this patch and commented: "WSAEventSelect is edge-triggered and the event will not be signaled if the socket handler does not consume all the data in the socket buffer." Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Message-id: 1368718561-7816-3-git-send-email-stefanha@redhat.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* main-loop: narrow win32 pollfds_fill() event bitmasksStefan Hajnoczi2013-05-161-4/+4
| | | | | | | | | | | | | | | | | | | | | pollfds_fill() and pollfds_poll() translate GPollFD to rfds/wfds/xfds for sockets on win32. select(2) is the underlying system call which is used to monitor sockets for activity. Currently file descriptors that monitor G_IO_ERR will be included in both rfds and wfds. As a result, select(2) will report writability on file descriptors where we only really wanted to monitor readability (with errors). slirp_pollfds_poll() hit this issue: UDP sockets are blocking sockets so we hang in sorecvfrom() when G_IO_ERR is set due to the socket being writable (we only wanted to check for readability). This patch fixes the slirp_pollfds_poll() hang. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Message-id: 1368718561-7816-2-git-send-email-stefanha@redhat.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* main-loop: drop the BQL if the I/O appears to be spinningAnthony Liguori2013-04-051-0/+25
| | | | | | | | | | | | | | | | | | | | The char-flow refactoring introduced a busy-wait that depended on an action from the VCPU thread. However, the VCPU thread could never take that action because the busy-wait starved the VCPU thread of the BQL because it never dropped the mutex while running select. Paolo doesn't want to drop this optimization for fear that we will stop detecting these busy waits. I'm afraid to keep this optimization even with the busy-wait fixed because I think a similar problem can occur just with heavy I/O thread load manifesting itself as VCPU pauses. As a compromise, introduce an artificial timeout after a thousand iterations but print a rate limited warning when this happens. This let's us still detect when this condition occurs without it being a fatal error. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> Message-id: 1365169560-11012-1-git-send-email-aliguori@us.ibm.com
* main-loop: add qemu_get_aio_context()Stefan Hajnoczi2013-03-151-0/+5
| | | | | | | | | | | | | | It is very useful to get the main loop AioContext, which is a static variable in main-loop.c. I'm not sure whether qemu_get_aio_context() will be necessary in the future once devices focus on using their own AioContext instead of the main loop AioContext, but for now it allows us to refactor code to support multiple AioContext while actually passing the main loop AioContext. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
* main-loop: drop rfds/wfds/xfds for goodStefan Hajnoczi2013-02-211-75/+2
| | | | | | | | | | | | Now that all *_fill() and *_poll() functions use GPollFD we no longer need rfds/wfds/xfds or pollfds_from_select()/pollfds_to_select(). >From now on everything uses GPollFD. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Message-id: 1361356113-11049-8-git-send-email-stefanha@redhat.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* iohandler: switch to GPollFDStefan Hajnoczi2013-02-211-2/+2
| | | | | | | | | | Convert iohandler_select_fill() and iohandler_select_poll() to use GPollFD instead of rfds/wfds/xfds. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Message-id: 1361356113-11049-7-git-send-email-stefanha@redhat.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* slirp: switch to GPollFDStefan Hajnoczi2013-02-211-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Slirp uses rfds/wfds/xfds more extensively than other QEMU components. The rarely-used out-of-band TCP data feature is used. That means we need the full table of select(2) to g_poll(3) events: rfds -> G_IO_IN | G_IO_HUP | G_IO_ERR wfds -> G_IO_OUT | G_IO_ERR xfds -> G_IO_PRI I came up with this table by looking at Linux fs/select.c which maps select(2) to poll(2) internally. Another detail to watch out for are the global variables that reference rfds/wfds/xfds during slirp_select_poll(). sofcantrcvmore() and sofcantsendmore() use these globals to clear fd_set bits. When sofcantrcvmore() is called, the wfds bit is cleared so that the write handler will no longer be run for this iteration of the event loop. This actually seems buggy to me since TCP connections can be half-closed and we'd still want to handle data in half-duplex fashion. I think the real intention is to avoid running the read/write handler when the socket has been fully closed. This is indicated with the SS_NOFDREF state bit so we now check for it before invoking the TCP write handler. Note that UDP/ICMP code paths don't care because they are connectionless. Note that slirp/ has a lot of tabs and sometimes mixed tabs with spaces. I followed the style of the surrounding code. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Message-id: 1361356113-11049-6-git-send-email-stefanha@redhat.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* main-loop: switch POSIX glib integration to GPollFDStefan Hajnoczi2013-02-211-49/+22
| | | | | | | | | | | | Convert glib file descriptor polling from rfds/wfds/xfds to GPollFD. The Windows code still needs poll_fds[] and n_poll_fds but they can now become local variables. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Message-id: 1361356113-11049-4-git-send-email-stefanha@redhat.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* main-loop: switch to g_poll() on POSIX hostsStefan Hajnoczi2013-02-211-8/+129
| | | | | | | | | | | | | | | | | | | | | | | | Use g_poll(3) instead of select(2). Well, this is kind of a cheat. It's true that we're now using g_poll(3) on POSIX hosts but the *_fill() and *_poll() functions are still using rfds/wfds/xfds. We've set the scene to start converting *_fill() and *_poll() functions step-by-step until no more rfds/wfds/xfds users remain. Then we'll drop the temporary gpollfds_from_select() and gpollfds_to_select() functions and be left with native g_poll(2). On Windows things are a little crazy: convert from rfds/wfds/xfds to GPollFDs, back to rfds/wfds/xfds, call select(2), rfds/wfds/xfds back to GPollFDs, and finally back to rfds/wfds/xfds again. This is only temporary and keeps the Windows build working through the following patches. We'll drop this excessive conversion later and be left with a single GPollFDs -> select(2) -> GPollFDs sequence that allows Windows to use select(2) while the rest of QEMU only knows about GPollFD. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Message-id: 1361356113-11049-3-git-send-email-stefanha@redhat.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* main-loop: fix select_ret uninitialized variable warningStefan Hajnoczi2013-02-211-1/+2
| | | | | | | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Message-id: 1361356113-11049-2-git-send-email-stefanha@redhat.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* Check return values from g_poll and selectFabien Chouteau2013-01-091-14/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The current implementation of os_host_main_loop_wait() on Windows, returns 1 only when a g_poll() event occurs because the return value of select() is overridden. This is wrong as we may skip a socket event, as shown in this example: 1. select() returns 0 2. g_poll() returns 1 (socket event occurs) 3. os_host_main_loop_wait() returns 1 4. qemu_iohandler_poll() sees no socket event because select() has return before the event occurs 5. select() returns 1 6. g_poll() returns 0 (g_poll overrides select's return value) 7. os_host_main_loop_wait() returns 0 8. qemu_iohandler_poll() doesn't check for socket events because the return value of os_host_main_loop_wait() is zero. 9. goto 5 This patch use one variable for each of these return values, so we don't miss a select() event anymore. Also move the call to select() after g_poll(), this will improve latency as we don't have to go through two os_host_main_loop_wait() calls to detect a socket event. Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Fabien Chouteau <chouteau@adacore.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* misc: move include files to include/qemu/Paolo Bonzini2012-12-191-3/+3
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* block: move include files to include/block/Paolo Bonzini2012-12-191-1/+1
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* aio: Get rid of qemu_aio_flush()Kevin Wolf2012-12-111-5/+0
| | | | | | | There are no remaining users, and new users should probably be using bdrv_drain_all() in the first place. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* vl: delay thread initialization after daemonizationPaolo Bonzini2012-11-021-1/+0
| | | | | | | | | | | | | | | | | | Commit ac4119c (chardev: Use timer instead of bottom-half to postpone open event, 2012-10-12) moved the alarm timer initialization to an earlier point but failed to consider that it depends on qemu_init_main_loop. Later, commit 1c53786 (vl: init main loop earlier, 2012-10-30) fixed this, but left -daemonize in two different ways. First, timers need to be reinitialized after forking. Second, the global mutex was being held by the parent, and thus dropped after forking. The first is now fixed using pthread_atfork. For the second part, make sure that the global mutex is not taken before daemonization, and similarly delay qemu_thread_self. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* vl: unify calls to init_timer_alarmPaolo Bonzini2012-11-021-1/+4
| | | | | | | init_timer_alarm was being called twice. This is not needed. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* main-loop: use aio_notify for qemu_notify_eventPaolo Bonzini2012-10-301-98/+8
| | | | | Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* main-loop: use GSource to poll AIO file descriptorsPaolo Bonzini2012-10-301-17/+6
| | | | | | | This lets us remove the hooks for the main loop in async.c. Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* aio: add Win32 implementationPaolo Bonzini2012-10-301-1/+1
| | | | | | | | | The Win32 implementation will only accept EventNotifiers, thus a few drivers are disabled under Windows. EventNotifiers are a good match for the GSource implementation, too, because the Win32 port of glib allows to place their HANDLEs in a GPollFD. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* aio: add non-blocking variant of aio_waitPaolo Bonzini2012-10-301-1/+1
| | | | | | | This will be used when polling the GSource attached to an AioContext. Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* aio: add I/O handlers to the AioContext interfacePaolo Bonzini2012-10-301-0/+33
| | | | | | | With this patch, I/O handlers (including event notifier handlers) can be attached to a single AioContext. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* aio: introduce AioContext, move bottom halves therePaolo Bonzini2012-10-301-1/+17
| | | | | | | | | | | | Start introducing AioContext, which will let us remove globals from aio.c/async.c, and introduce multiple I/O threads. The bottom half functions now take an additional AioContext argument. A bottom half is created with a specific AioContext that remains the same throughout the lifetime. qemu_bh_new is just a wrapper that uses a global context. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* main-loop: unify qemu_init_main_loop between QEMU and toolsPaolo Bonzini2012-10-301-1/+4
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* main-loop: Calculate poll timeout using timeout argumentStefan Weil2012-05-011-1/+5
| | | | | | | | | | The timeout argument was unused up to now, but it can be used to reduce the poll_timeout when it is infinite (negative value) or larger than timeout. Signed-off-by: Stefan Weil <sw@weilnetz.de> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* main-loop: Fix build for w32 and w64Stefan Weil2012-04-281-3/+4
| | | | | | | | | | | | | | This patch fixes a build regression with MinGW which was introduced by commit 7c7db75576bd5a31508208f153c5aada64b2c8df. The 3rd argument of g_main_context_query must point to a gint value. Using a pointer to an uint32_t value is wrong. The timeout argument of function os_host_main_loop_wait was never used for w32 / w64. Signed-off-by: Stefan Weil <sw@weilnetz.de> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* main_loop_wait: block indefinitelyStefano Stabellini2012-04-261-9/+14
| | | | | | | | | | | | | | | - 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 <stefano.stabellini@eu.citrix.com> Acked-by: Paul Brook <paul@codesourcery.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* w64: Fix type cast in os_host_main_loop_waitStefan Weil2012-04-151-1/+1
| | | | | | | Casting a pointer to an integer must use (DWORD_PTR) instead of (DWORD). This also matches the definition of 'fd' (gint for w32, gint64 for w64). Signed-off-by: Stefan Weil <sw@weilnetz.de>
* Merge remote-tracking branch 'stefanha/trivial-patches' into stagingAnthony Liguori2012-04-101-1/+1
|\ | | | | | | | | | | | | | | | | | | | | | | * stefanha/trivial-patches: make: fix clean rule by removing build file in qom/ configure: Link qga against UST tracing related libraries configure: Link QEMU against 'liburcu-bp' main-loop: make qemu_event_handle static block/curl: Replace usleep by g_usleep qtest: Add missing GCC_FMT_ATTR w32: Undefine error constants before their redefinition configure: fix mingw32 libs_qga typo
| * main-loop: make qemu_event_handle staticFrediano Ziglio2012-04-031-1/+1
| | | | | | | | | | Signed-off-by: Frediano Ziglio <freddy77@gmail.com> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
* | main-loop: integrate glib sources for w32Paolo Bonzini2012-04-071-6/+15
| | | | | | | | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* | main-loop: replace WaitForMultipleObjects with g_pollPaolo Bonzini2012-04-071-23/+17
| | | | | | | | | | | | | | | | | | | | On w32, glib implements g_poll using WaitForMultipleObjects or MsgWaitForMultipleObjects. This means that we can simplify our code by switching to g_poll, and at the same time prepare for adding back glib sources. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* | main-loop: interrupt wait when data arrives on a socketPaolo Bonzini2012-04-071-25/+44
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Right now, the main loop is not interrupted when data arrives on a socket. To fix this, register each socket to interrupt the main loop with WSAEventSelect. This does not replace select, it only communicates a change in socket state that requires a select call. Since the interrupt fires only once per recv call, or only once after a send call returns EWOULDBLOCK we can activate it on all events unconditionally. If QEMU is momentarily uninterested on some condition, the main loop will not busy wait. Instead, it may get one extra wakeup, but then it will ignore the condition until progress occurs and/or qemu_set_fd_handler is called to set a callback. At this point the condition will be tested via select and the callback will be invoked even if it is still disabled on the event. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* | main-loop: disable fd_set-based glib integration under w32Paolo Bonzini2012-04-071-30/+33
| | | | | | | | | | | | | | | | Using select with glib pollfds is wrong under w32. Restrict the code to the POSIX case. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* | main loop: use msec-based timeout in glib_select_fillPaolo Bonzini2012-04-071-12/+10
|/ | | | | | | | | The timeval-based timeout is not needed until we actually invoke select, so compute it only then. Also group the two calls that modify the timeout, glib_select_fill and os_host_main_loop_wait. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* main-loop: For tools, initialize timers as part of qemu_init_main_loop()Michael Roth2012-02-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | In some cases initializing the alarm timers can lead to non-negligable overhead from programs that link against qemu-tool.o. At least, setting a max-resolution WinMM alarm timer via mm_start_timer() (the current default for Windows) can increase the "tick rate" on Windows OSs and affect frequency scaling, and in the case of tools that run in guest OSs such has qemu-ga, the impact can be fairly dramatic (+20%/20% user/sys time on a core 2 processor was observed from an idle Windows XP guest). This patch doesn't address the issue directly (not sure what a good solution would be for Windows, or what other situations it might be noticeable), but it at least limits the scope of the issue to programs that "opt-in" to using the main-loop.c functions by only enabling alarm timers when qemu_init_main_loop() is called, which is already required to make use of those facilities, so existing users shouldn't be affected. Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* main-loop: Fix SetEvent() on uninitialized handle on win32Michael Roth2012-02-011-1/+4
| | | | | | | | | | | | | | | | | The __attribute__((constructor)) init_main_loop() automatically get called if qemu-tool.o is linked in. On win32, this leads to a qemu_notify_event() call which attempts to SetEvent() on a HANDLE that won't be initialized until qemu_init_main_loop() is manually called, breaking qemu-tools.o programs on Windows at runtime. This patch checks for an initialized event handle before attempting to set it, which is analoguous to how we deal with an unitialized io_thread_fd in the posix implementation. Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com> Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* cleanup, save a syscallLai Jiangshan2012-01-121-3/+1
| | | | | Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* main-loop: Add missing include fileStefan Weil2011-10-251-25/+5
| | | | | | | | | | | stdint.h defines the POSIX data types and is needed for MinGW-w64 (and maybe other hosts). v2: Instead of adding stdint.h directly, qemu-common.h is now included and duplicate include statements were removed. Signed-off-by: Stefan Weil <sw@weilnetz.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* main-loop: create main-loop.cPaolo Bonzini2011-10-211-0/+495
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
OpenPOWER on IntegriCloud