From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Anthony Liguori <aliguori@us.ibm.com>,
Jan Kiszka <jan.kiszka@siemens.com>,
Fabien Chouteau <chouteau@adacore.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>, Amos Kong <akong@redhat.com>
Subject: [Qemu-devel] [PATCH v2 3/9] main-loop: switch POSIX glib integration to GPollFD
Date: Fri, 1 Feb 2013 14:53:22 +0100 [thread overview]
Message-ID: <1359726808-11728-4-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1359726808-11728-1-git-send-email-stefanha@redhat.com>
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>
---
main-loop.c | 71 +++++++++++++++++++------------------------------------------
1 file changed, 22 insertions(+), 49 deletions(-)
diff --git a/main-loop.c b/main-loop.c
index f1dcd14..12b0213 100644
--- a/main-loop.c
+++ b/main-loop.c
@@ -145,8 +145,6 @@ int qemu_init_main_loop(void)
static fd_set rfds, wfds, xfds;
static int nfds;
-static GPollFD poll_fds[1024 * 2]; /* this is probably overkill */
-static int n_poll_fds;
static int max_priority;
/* Load rfds/wfds/xfds into gpollfds. Will be removed a few commits later. */
@@ -206,65 +204,39 @@ static void gpollfds_to_select(int ret)
}
#ifndef _WIN32
-static void glib_select_fill(int *max_fd, fd_set *rfds, fd_set *wfds,
- fd_set *xfds, uint32_t *cur_timeout)
+static int glib_pollfds_idx;
+static int glib_n_poll_fds;
+
+static void glib_pollfds_fill(uint32_t *cur_timeout)
{
GMainContext *context = g_main_context_default();
- int i;
int timeout = 0;
+ int n;
g_main_context_prepare(context, &max_priority);
- n_poll_fds = g_main_context_query(context, max_priority, &timeout,
- poll_fds, ARRAY_SIZE(poll_fds));
- g_assert(n_poll_fds <= ARRAY_SIZE(poll_fds));
-
- for (i = 0; i < n_poll_fds; i++) {
- GPollFD *p = &poll_fds[i];
-
- if ((p->events & G_IO_IN)) {
- FD_SET(p->fd, rfds);
- *max_fd = MAX(*max_fd, p->fd);
- }
- if ((p->events & G_IO_OUT)) {
- FD_SET(p->fd, wfds);
- *max_fd = MAX(*max_fd, p->fd);
- }
- if ((p->events & G_IO_ERR)) {
- FD_SET(p->fd, xfds);
- *max_fd = MAX(*max_fd, p->fd);
- }
- }
+ glib_pollfds_idx = gpollfds->len;
+ n = glib_n_poll_fds;
+ do {
+ GPollFD *pfds;
+ glib_n_poll_fds = n;
+ g_array_set_size(gpollfds, glib_pollfds_idx + glib_n_poll_fds);
+ pfds = &g_array_index(gpollfds, GPollFD, glib_pollfds_idx);
+ n = g_main_context_query(context, max_priority, &timeout, pfds,
+ glib_n_poll_fds);
+ } while (n != glib_n_poll_fds);
if (timeout >= 0 && timeout < *cur_timeout) {
*cur_timeout = timeout;
}
}
-static void glib_select_poll(fd_set *rfds, fd_set *wfds, fd_set *xfds,
- bool err)
+static void glib_pollfds_poll(void)
{
GMainContext *context = g_main_context_default();
+ GPollFD *pfds = &g_array_index(gpollfds, GPollFD, glib_pollfds_idx);
- if (!err) {
- int i;
-
- for (i = 0; i < n_poll_fds; i++) {
- GPollFD *p = &poll_fds[i];
-
- if ((p->events & G_IO_IN) && FD_ISSET(p->fd, rfds)) {
- p->revents |= G_IO_IN;
- }
- if ((p->events & G_IO_OUT) && FD_ISSET(p->fd, wfds)) {
- p->revents |= G_IO_OUT;
- }
- if ((p->events & G_IO_ERR) && FD_ISSET(p->fd, xfds)) {
- p->revents |= G_IO_ERR;
- }
- }
- }
-
- if (g_main_context_check(context, max_priority, poll_fds, n_poll_fds)) {
+ if (g_main_context_check(context, max_priority, pfds, glib_n_poll_fds)) {
g_main_context_dispatch(context);
}
}
@@ -273,7 +245,7 @@ static int os_host_main_loop_wait(uint32_t timeout)
{
int ret;
- glib_select_fill(&nfds, &rfds, &wfds, &xfds, &timeout);
+ glib_pollfds_fill(&timeout);
if (timeout > 0) {
qemu_mutex_unlock_iothread();
@@ -292,7 +264,7 @@ static int os_host_main_loop_wait(uint32_t timeout)
qemu_mutex_lock_iothread();
}
- glib_select_poll(&rfds, &wfds, &xfds, (ret < 0));
+ glib_pollfds_poll();
return ret;
}
#else
@@ -438,8 +410,9 @@ static void pollfds_poll(GArray *pollfds, int nfds, fd_set *rfds,
static int os_host_main_loop_wait(uint32_t timeout)
{
GMainContext *context = g_main_context_default();
+ GPollFD poll_fds[1024 * 2]; /* this is probably overkill */
int select_ret = 0;
- int g_poll_ret, ret, i;
+ int g_poll_ret, ret, i, n_poll_fds;
PollingEntry *pe;
WaitObjects *w = &wait_objects;
gint poll_timeout;
--
1.8.1
next prev parent reply other threads:[~2013-02-01 13:54 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-01 13:53 [Qemu-devel] [PATCH v2 0/9] main-loop: switch to g_poll(3) on POSIX hosts Stefan Hajnoczi
2013-02-01 13:53 ` [Qemu-devel] [PATCH v2 1/9] main-loop: fix select_ret uninitialized variable warning Stefan Hajnoczi
2013-02-01 13:53 ` [Qemu-devel] [PATCH v2 2/9] main-loop: switch to g_poll() on POSIX hosts Stefan Hajnoczi
2013-02-01 13:53 ` Stefan Hajnoczi [this message]
2013-02-01 13:53 ` [Qemu-devel] [PATCH v2 4/9] slirp: switch to GPollFD Stefan Hajnoczi
2013-02-02 12:46 ` Blue Swirl
2013-02-01 13:53 ` [Qemu-devel] [PATCH v2 5/9] iohandler: " Stefan Hajnoczi
2013-02-01 13:53 ` [Qemu-devel] [PATCH v2 6/9] main-loop: drop rfds/wfds/xfds for good Stefan Hajnoczi
2013-02-01 13:53 ` [Qemu-devel] [PATCH v2 7/9] aio: extract aio_dispatch() from aio_poll() Stefan Hajnoczi
2013-02-01 13:53 ` [Qemu-devel] [PATCH v2 8/9] aio: convert aio_poll() to g_poll(3) Stefan Hajnoczi
2013-02-01 13:53 ` [Qemu-devel] [PATCH v2 9/9] aio: support G_IO_HUP and G_IO_ERR Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1359726808-11728-4-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=akong@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=chouteau@adacore.com \
--cc=jan.kiszka@siemens.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).