From: Jan Kiszka <jan.kiszka@siemens.com>
To: Anthony Liguori <aliguori@us.ibm.com>
Cc: qemu-devel <qemu-devel@nongnu.org>, Kevin Wolf <kwolf@redhat.com>,
Marcelo Tosatti <mtosatti@redhat.com>,
Avi Kivity <avi@redhat.com>,
Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH] Use qemu_eventfd for POSIX AIO
Date: Tue, 27 Sep 2011 15:56:25 +0200 [thread overview]
Message-ID: <4E81D609.1060203@siemens.com> (raw)
In-Reply-To: <4E8190BE.3000801@redhat.com>
Move qemu_eventfd unmodified to oslib-posix and use it for signaling
POSIX AIO completions. If native eventfd suport is available, this
avoids multiple read accesses to drain multiple pending signals. As
before we use a pipe if eventfd is not supported.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
os-posix.c | 32 --------------------------------
oslib-posix.c | 32 +++++++++++++++++++++++++++++++-
posix-aio-compat.c | 12 ++++++++----
3 files changed, 39 insertions(+), 37 deletions(-)
diff --git a/os-posix.c b/os-posix.c
index dbf3b24..a918895 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -45,10 +45,6 @@
#include <sys/syscall.h>
#endif
-#ifdef CONFIG_EVENTFD
-#include <sys/eventfd.h>
-#endif
-
static struct passwd *user_pwd;
static const char *chroot_dir;
static int daemonize;
@@ -333,34 +329,6 @@ void os_set_line_buffering(void)
setvbuf(stdout, NULL, _IOLBF, 0);
}
-/*
- * Creates an eventfd that looks like a pipe and has EFD_CLOEXEC set.
- */
-int qemu_eventfd(int fds[2])
-{
-#ifdef CONFIG_EVENTFD
- int ret;
-
- ret = eventfd(0, 0);
- if (ret >= 0) {
- fds[0] = ret;
- qemu_set_cloexec(ret);
- if ((fds[1] = dup(ret)) == -1) {
- close(ret);
- return -1;
- }
- qemu_set_cloexec(fds[1]);
- return 0;
- }
-
- if (errno != ENOSYS) {
- return -1;
- }
-#endif
-
- return qemu_pipe(fds);
-}
-
int qemu_create_pidfile(const char *filename)
{
char buffer[128];
diff --git a/oslib-posix.c b/oslib-posix.c
index a304fb0..8ef7bd7 100644
--- a/oslib-posix.c
+++ b/oslib-posix.c
@@ -47,7 +47,9 @@ extern int daemon(int, int);
#include "trace.h"
#include "qemu_socket.h"
-
+#ifdef CONFIG_EVENTFD
+#include <sys/eventfd.h>
+#endif
int qemu_daemon(int nochdir, int noclose)
{
@@ -139,6 +141,34 @@ int qemu_pipe(int pipefd[2])
return ret;
}
+/*
+ * Creates an eventfd that looks like a pipe and has EFD_CLOEXEC set.
+ */
+int qemu_eventfd(int fds[2])
+{
+#ifdef CONFIG_EVENTFD
+ int ret;
+
+ ret = eventfd(0, 0);
+ if (ret >= 0) {
+ fds[0] = ret;
+ qemu_set_cloexec(ret);
+ if ((fds[1] = dup(ret)) == -1) {
+ close(ret);
+ return -1;
+ }
+ qemu_set_cloexec(fds[1]);
+ return 0;
+ }
+
+ if (errno != ENOSYS) {
+ return -1;
+ }
+#endif
+
+ return qemu_pipe(fds);
+}
+
int qemu_utimensat(int dirfd, const char *path, const struct timespec *times,
int flags)
{
diff --git a/posix-aio-compat.c b/posix-aio-compat.c
index d3c1174..2aa5ba3 100644
--- a/posix-aio-compat.c
+++ b/posix-aio-compat.c
@@ -521,7 +521,7 @@ static void posix_aio_read(void *opaque)
PosixAioState *s = opaque;
ssize_t len;
- /* read all bytes from signal pipe */
+ /* read all bytes from eventfd or signal pipe */
for (;;) {
char bytes[16];
@@ -546,10 +546,14 @@ static PosixAioState *posix_aio_state;
static void posix_aio_notify_event(void)
{
- char byte = 0;
+ /* Write 8 bytes to be compatible with eventfd. */
+ static const uint64_t val = 1;
ssize_t ret;
- ret = write(posix_aio_state->wfd, &byte, sizeof(byte));
+ do {
+ ret = write(posix_aio_state->wfd, &val, sizeof(val));
+ } while (ret < 0 && errno == EINTR);
+
if (ret < 0 && errno != EAGAIN)
die("write()");
}
@@ -665,7 +669,7 @@ int paio_init(void)
s = g_malloc(sizeof(PosixAioState));
s->first_aio = NULL;
- if (qemu_pipe(fds) == -1) {
+ if (qemu_eventfd(fds) == -1) {
fprintf(stderr, "failed to create pipe\n");
return -1;
}
--
1.7.3.4
next parent reply other threads:[~2011-09-27 13:56 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <4E78C42D.5030207@siemens.com>
[not found] ` <20110921080600.GA9847@stefanha-thinkpad.localdomain>
[not found] ` <4E80B50B.9000301@siemens.com>
[not found] ` <4E80B55F.5020203@redhat.com>
[not found] ` <4E80BFF3.8000907@us.ibm.com>
[not found] ` <4E8190BE.3000801@redhat.com>
2011-09-27 13:56 ` Jan Kiszka [this message]
2011-09-27 14:07 ` [Qemu-devel] [PATCH] Use qemu_eventfd for POSIX AIO Anthony Liguori
2011-09-27 14:11 ` Avi Kivity
2011-09-27 14:19 ` Anthony Liguori
2011-09-27 14:22 ` Avi Kivity
2011-09-27 14:22 ` Jan Kiszka
2011-09-27 14:38 ` Anthony Liguori
2011-09-27 14:29 ` Jan Kiszka
2011-09-27 14:34 ` Avi Kivity
2011-09-27 14:36 ` Jan Kiszka
2011-09-27 14:42 ` Avi Kivity
2011-09-27 14:45 ` Jan Kiszka
2011-09-27 14:48 ` Avi Kivity
2011-09-27 14:50 ` Jan Kiszka
2011-09-27 14:54 ` Avi Kivity
2011-09-27 14:57 ` Anthony Liguori
2011-09-27 14:59 ` Jan Kiszka
2011-09-27 14:36 ` Anthony Liguori
2011-09-27 14:41 ` Paolo Bonzini
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=4E81D609.1060203@siemens.com \
--to=jan.kiszka@siemens.com \
--cc=aliguori@us.ibm.com \
--cc=avi@redhat.com \
--cc=kwolf@redhat.com \
--cc=mtosatti@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@linux.vnet.ibm.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).