Skip to contentSkip to conversation

glib: fix g_poll early timeout on windows

PATCH Superseded Stanislav Vorobiov 2 participants 4 messages May 7, 2014 – May 8, 2014

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 glib: fix g_poll early timeout on windows

From: Sangho Park <[email protected]>

g_poll has a problem on Windows when using
timeouts < 10ms, in glib/gpoll.c:

/* If not, and we have a significant timeout, poll again with
* timeout then. Note that this will return indication for only
* one event, or only for messages. We ignore timeouts less than
* ten milliseconds as they are mostly pointless on Windows, the
* MsgWaitForMultipleObjectsEx() call will timeout right away
* anyway.
*/
if (retval == 0 && (timeout == INFINITE || timeout >= 10))
retval = poll_rest (poll_msgs, handles, nhandles, fds, nfds, timeout);

so whenever g_poll is called with timeout < 10ms it does a quick poll instead of wait, this causes significant performance degradation of QEMU, thus we should use WaitForMultipleObjectsEx directly

---
 include/glib-compat.h |   19 +++++++++
 include/qemu-common.h |   12 ------
 util/oslib-win32.c    |  112 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 131 insertions(+), 12 deletions(-)
include/glib-compat.h +19 -0
index 8aa77af..1280fb2 100644
@@ -24,4 +24,23 @@ static inline guint g_timeout_add_seconds(guint interval, GSourceFunc function,
 }
 #endif
 
+#ifdef _WIN32
+/*
+ * g_poll has a problem on Windows when using
+ * timeouts < 10ms, so use wrapper.
+ */
+#define g_poll(fds, nfds, timeout) g_poll_fixed(fds, nfds, timeout)
+gint g_poll_fixed(GPollFD *fds, guint nfds, gint timeout);
+#elif !GLIB_CHECK_VERSION(2, 20, 0)
+/*
+ * Glib before 2.20.0 doesn't implement g_poll, so wrap it to compile properly
+ * on older systems.
+ */
+static inline gint g_poll(GPollFD *fds, guint nfds, gint timeout)
+{
+    GMainContext *ctx = g_main_context_default();
+    return g_main_context_get_poll_func(ctx)(fds, nfds, timeout);
+}
+#endif
+
 #endif
include/qemu-common.h +0 -12
index a998e8d..3f3fd60 100644
@@ -124,18 +124,6 @@ int qemu_main(int argc, char **argv, char **envp);
 void qemu_get_timedate(struct tm *tm, int offset);
 int qemu_timedate_diff(struct tm *tm);
 
-#if !GLIB_CHECK_VERSION(2, 20, 0)
-/*
- * Glib before 2.20.0 doesn't implement g_poll, so wrap it to compile properly
- * on older systems.
- */
-static inline gint g_poll(GPollFD *fds, guint nfds, gint timeout)
-{
-    GMainContext *ctx = g_main_context_default();
-    return g_main_context_get_poll_func(ctx)(fds, nfds, timeout);
-}
-#endif
-
 /**
  * is_help_option:
  * @s: string to test
util/oslib-win32.c +112 -0

115 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#2 lore raw

Hi,

IMHO it's not a problem, automerge will resolve this

Quoted 15 lines · Michael Tokarev
Quoted 1 line · Stanislav Vorobiov

From: Sangho Park <[email protected]>

[]

Quoted 2 lines
 include/glib-compat.h |   19 +++++++++
 include/qemu-common.h |   12 ------

JFYI, this will clash with glib cleanup series I posted earlier
(http://thread.gmane.org/gmane.comp.emulators.qemu/270259)
with some of these patches being pushed via trivial tree now (http://thread.gmane.org/gmane.comp.emulators.qemu/270767)

Thanks,

/mjt

#3 lore raw
Quoted 3 lines · Stanislav Vorobiov

Hi,

IMHO it's not a problem, automerge will resolve this

Now the trivial queue pull request has been processed, some of this patch is in the tree. I don't know what is this magic "automerge" which you're talking about. The thing is that your code is a bit different (for one, it wraps g_poll() definition in glib-compat.h into #ifdef WIN32, for another it adds g_poll_fixed()), and the patch does not apply anymore.

I'd suggest you to rebase and resubmit. Hopefully it wont clash with further glib-compat additions which are on the way.

Thank you!

/mjt