From: Fam Zheng <famz@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PATCH v3 6/7] poll-glib: Support ppoll
Date: Thu, 16 Apr 2015 12:57:35 +0800 [thread overview]
Message-ID: <1429160256-27231-7-git-send-email-famz@redhat.com> (raw)
In-Reply-To: <1429160256-27231-1-git-send-email-famz@redhat.com>
Signed-off-by: Fam Zheng <famz@redhat.com>
---
poll-glib.c | 29 ++++++++++++++++++++++++++---
1 file changed, 26 insertions(+), 3 deletions(-)
diff --git a/poll-glib.c b/poll-glib.c
index 64fde69..23d528d 100644
--- a/poll-glib.c
+++ b/poll-glib.c
@@ -14,6 +14,9 @@
#include "qemu-common.h"
#include "qemu/timer.h"
#include "qemu/poll.h"
+#if CONFIG_PPOLL
+#include <poll.h>
+#endif
struct QEMUPoll {
/* Array of GPollFD for g_poll() */
@@ -42,13 +45,33 @@ void qemu_poll_free(QEMUPoll *qpoll)
int qemu_poll(QEMUPoll *qpoll, int64_t timeout_ns)
{
int i;
+ void *fds = qpoll->gpollfds->data;
+ int nfds = qpoll->gpollfds->len;
+
for (i = 0; i < qpoll->gpollfds->len; i++) {
GPollFD *p = &g_array_index(qpoll->gpollfds, GPollFD, i);
p->revents = 0;
}
- return g_poll((GPollFD *)qpoll->gpollfds->data,
- qpoll->gpollfds->len,
- qemu_timeout_ns_to_ms(timeout_ns));
+#if CONFIG_PPOLL
+ if (timeout_ns < 0) {
+ return ppoll(fds, nfds, NULL, NULL);
+ } else {
+ struct timespec ts;
+ int64_t tvsec = timeout_ns / 1000000000LL;
+ /* Avoid possibly overflowing and specifying a negative number of
+ * seconds, which would turn a very long timeout into a busy-wait.
+ */
+ if (tvsec > (int64_t)INT32_MAX) {
+ tvsec = INT32_MAX;
+ }
+ ts.tv_sec = tvsec;
+ ts.tv_nsec = timeout_ns % 1000000000LL;
+ return ppoll(fds, nfds, &ts, NULL);
+ }
+
+#else
+ return g_poll(data, nfds, qemu_timeout_ns_to_ms(timeout_ns));
+#endif
}
/* Add an fd to poll. Return -EEXIST if fd already registered. */
--
1.9.3
next prev parent reply other threads:[~2015-04-16 4:58 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-16 4:57 [Qemu-devel] [PATCH v3 0/7] aio: Support epoll by introducing qemu_poll abstraction Fam Zheng
2015-04-16 4:57 ` [Qemu-devel] [PATCH v3 1/7] poll: Introduce QEMU Poll API Fam Zheng
2015-04-16 4:57 ` [Qemu-devel] [PATCH v3 2/7] posix-aio: Use QEMU poll interface Fam Zheng
2015-04-16 4:57 ` [Qemu-devel] [PATCH v3 3/7] poll: Add epoll implementation for qemu_poll Fam Zheng
2015-04-16 4:57 ` [Qemu-devel] [PATCH v3 4/7] main-loop: Replace qemu_poll_ns with qemu_poll Fam Zheng
2015-04-16 4:57 ` [Qemu-devel] [PATCH v3 5/7] tests: Add test case for qemu_poll Fam Zheng
2015-04-16 4:57 ` Fam Zheng [this message]
2015-04-16 4:57 ` [Qemu-devel] [PATCH v3 7/7] poll-linux: Add timerfd support Fam Zheng
2015-04-16 13:00 ` Stefan Hajnoczi
2015-04-16 13:03 ` [Qemu-devel] [PATCH v3 0/7] aio: Support epoll by introducing qemu_poll abstraction Stefan Hajnoczi
2015-04-17 2:02 ` Fam Zheng
2015-04-20 10:36 ` 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=1429160256-27231-7-git-send-email-famz@redhat.com \
--to=famz@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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).