qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/4] qemu-kvm: prepare for adding eventfd usage to upstream
@ 2010-02-10 23:09 Paolo Bonzini
  2010-02-10 23:09 ` [Qemu-devel] [PATCH 1/4] qemu-kvm: morph qemu_kvm_notify_work into qemu.git's qemu_event_increment Paolo Bonzini
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Paolo Bonzini @ 2010-02-10 23:09 UTC (permalink / raw)
  To: qemu-devel; +Cc: kvm

This patch series morphs the code in qemu-kvm's eventfd so that it looks
like the code in upstream qemu.  Patch 4 is not yet in upstream QEMU,
I'm submitting it first to qemu-kvm to avoid conflicts.

Paolo Bonzini (4):
  morph qemu_kvm_notify_work into qemu.git's qemu_event_increment
  morph io_thread_wakeup into qemu.git's qemu_event_read
  fix placement of config-host.h inclusion
  move qemu_eventfd to osdep.c

 compatfd.c    |   26 --------------------------
 compatfd.h    |    2 --
 osdep.c       |   37 +++++++++++++++++++++++++++++++++++--
 qemu-common.h |    1 +
 qemu-kvm.c    |   50 +++++++++++++++++---------------------------------
 5 files changed, 53 insertions(+), 63 deletions(-)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 1/4] qemu-kvm: morph qemu_kvm_notify_work into qemu.git's qemu_event_increment
  2010-02-10 23:09 [Qemu-devel] [PATCH 0/4] qemu-kvm: prepare for adding eventfd usage to upstream Paolo Bonzini
@ 2010-02-10 23:09 ` Paolo Bonzini
  2010-02-10 23:09 ` [Qemu-devel] [PATCH 2/4] qemu-kvm: morph io_thread_wakeup into qemu.git's qemu_event_read Paolo Bonzini
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Paolo Bonzini @ 2010-02-10 23:09 UTC (permalink / raw)
  To: qemu-devel; +Cc: kvm

No need to loop if < 8 bytes are written, since that will happen only
for pipes and is harmless.  eventfd writes of 8 bytes will always succeed
or fail with EAGAIN.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 qemu-kvm.c |   34 ++++++++++++----------------------
 1 files changed, 12 insertions(+), 22 deletions(-)

diff --git a/qemu-kvm.c b/qemu-kvm.c
index a305907..669a784 100644
--- a/qemu-kvm.c
+++ b/qemu-kvm.c
@@ -1991,32 +1991,22 @@ int kvm_init_ap(void)
 
 void qemu_kvm_notify_work(void)
 {
-    uint64_t value = 1;
-    char buffer[8];
-    size_t offset = 0;
+    /* Write 8 bytes to be compatible with eventfd.  */
+    static uint64_t val = 1;
+    ssize_t ret;
 
     if (io_thread_fd == -1)
         return;
 
-    memcpy(buffer, &value, sizeof(value));
-
-    while (offset < 8) {
-        ssize_t len;
-
-        len = write(io_thread_fd, buffer + offset, 8 - offset);
-        if (len == -1 && errno == EINTR)
-            continue;
-
-        /* In case we have a pipe, there is not reason to insist writing
-         * 8 bytes
-         */
-        if (len == -1 && errno == EAGAIN)
-            break;
-
-        if (len <= 0)
-            break;
-
-        offset += len;
+    do {
+        ret = write(io_thread_fd, &val, sizeof(val));
+    } while (ret < 0 && errno == EINTR);
+
+    /* EAGAIN is fine in case we have a pipe.  */
+    if (ret < 0 && errno != EAGAIN) {
+         fprintf(stderr, "qemu_kvm_notify_work: write() filed: %s\n",
+                 strerror(errno));
+         exit (1);
     }
 }
 
-- 
1.6.6

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 2/4] qemu-kvm: morph io_thread_wakeup into qemu.git's qemu_event_read
  2010-02-10 23:09 [Qemu-devel] [PATCH 0/4] qemu-kvm: prepare for adding eventfd usage to upstream Paolo Bonzini
  2010-02-10 23:09 ` [Qemu-devel] [PATCH 1/4] qemu-kvm: morph qemu_kvm_notify_work into qemu.git's qemu_event_increment Paolo Bonzini
@ 2010-02-10 23:09 ` Paolo Bonzini
  2010-02-10 23:09 ` [Qemu-devel] [PATCH 3/4] qemu-kvm: fix placement of config-host.h inclusion Paolo Bonzini
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Paolo Bonzini @ 2010-02-10 23:09 UTC (permalink / raw)
  To: qemu-devel; +Cc: kvm

Again, no need to loop if less than a full buffer is read, the next
read would return EAGAIN.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 qemu-kvm.c |   16 +++++-----------
 1 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/qemu-kvm.c b/qemu-kvm.c
index 669a784..50e1303 100644
--- a/qemu-kvm.c
+++ b/qemu-kvm.c
@@ -2049,19 +2049,13 @@ static void sigfd_handler(void *opaque)
 static void io_thread_wakeup(void *opaque)
 {
     int fd = (unsigned long) opaque;
-    char buffer[4096];
-
-    /* Drain the pipe/(eventfd) */
-    while (1) {
-        ssize_t len;
+    ssize_t len;
+    char buffer[512];
 
+    /* Drain the notify pipe.  For eventfd, only 8 bytes will be read.  */
+    do {
         len = read(fd, buffer, sizeof(buffer));
-        if (len == -1 && errno == EINTR)
-            continue;
-
-        if (len <= 0)
-            break;
-    }
+    } while ((len == -1 && errno == EINTR) || len == sizeof(buffer));
 }
 
 int kvm_main_loop(void)
-- 
1.6.6

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 3/4] qemu-kvm: fix placement of config-host.h inclusion
  2010-02-10 23:09 [Qemu-devel] [PATCH 0/4] qemu-kvm: prepare for adding eventfd usage to upstream Paolo Bonzini
  2010-02-10 23:09 ` [Qemu-devel] [PATCH 1/4] qemu-kvm: morph qemu_kvm_notify_work into qemu.git's qemu_event_increment Paolo Bonzini
  2010-02-10 23:09 ` [Qemu-devel] [PATCH 2/4] qemu-kvm: morph io_thread_wakeup into qemu.git's qemu_event_read Paolo Bonzini
@ 2010-02-10 23:09 ` Paolo Bonzini
  2010-02-10 23:09 ` [Qemu-devel] [PATCH 4/4] qemu-kvm: move qemu_eventfd to osdep.c Paolo Bonzini
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Paolo Bonzini @ 2010-02-10 23:09 UTC (permalink / raw)
  To: qemu-devel; +Cc: kvm

Cherry-picked from upstream f582af5.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 osdep.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/osdep.c b/osdep.c
index e613e4b..616e821 100644
--- a/osdep.c
+++ b/osdep.c
@@ -28,14 +28,15 @@
 #include <errno.h>
 #include <unistd.h>
 #include <fcntl.h>
+
+/* Needed early for CONFIG_BSD etc. */
+#include "config-host.h"
+
 #ifdef CONFIG_SOLARIS
 #include <sys/types.h>
 #include <sys/statvfs.h>
 #endif
 
-/* Needed early for CONFIG_BSD etc. */
-#include "config-host.h"
-
 #ifdef _WIN32
 #include <windows.h>
 #elif defined(CONFIG_BSD)
-- 
1.6.6

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 4/4] qemu-kvm: move qemu_eventfd to osdep.c
  2010-02-10 23:09 [Qemu-devel] [PATCH 0/4] qemu-kvm: prepare for adding eventfd usage to upstream Paolo Bonzini
                   ` (2 preceding siblings ...)
  2010-02-10 23:09 ` [Qemu-devel] [PATCH 3/4] qemu-kvm: fix placement of config-host.h inclusion Paolo Bonzini
@ 2010-02-10 23:09 ` Paolo Bonzini
  2010-02-13 13:26 ` [Qemu-devel] Re: [PATCH 0/4] qemu-kvm: prepare for adding eventfd usage to upstream Marcelo Tosatti
  2010-02-17 12:53 ` Avi Kivity
  5 siblings, 0 replies; 8+ messages in thread
From: Paolo Bonzini @ 2010-02-10 23:09 UTC (permalink / raw)
  To: qemu-devel; +Cc: kvm

Upstream has no compatfd.[ch], so move the code to the most similar
place.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 compatfd.c    |   26 --------------------------
 compatfd.h    |    2 --
 osdep.c       |   32 ++++++++++++++++++++++++++++++++
 qemu-common.h |    1 +
 4 files changed, 33 insertions(+), 28 deletions(-)

diff --git a/compatfd.c b/compatfd.c
index 4a00d95..a7cebc4 100644
--- a/compatfd.c
+++ b/compatfd.c
@@ -115,29 +115,3 @@ int qemu_signalfd(const sigset_t *mask)
 
     return qemu_signalfd_compat(mask);
 }
-
-int qemu_eventfd(int *fds)
-{
-    int ret;
-
-#if defined(CONFIG_EVENTFD)
-    ret = syscall(SYS_eventfd, 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;
-    }
-#endif
-
-    ret = pipe(fds);
-    if (ret != -1) {
-        qemu_set_cloexec(fds[0]);
-        qemu_set_cloexec(fds[1]);
-    }
-    return ret;
-}
diff --git a/compatfd.h b/compatfd.h
index 06b0b6b..fc37915 100644
--- a/compatfd.h
+++ b/compatfd.h
@@ -40,6 +40,4 @@ struct qemu_signalfd_siginfo {
 
 int qemu_signalfd(const sigset_t *mask);
 
-int qemu_eventfd(int *fds);
-
 #endif
diff --git a/osdep.c b/osdep.c
index 616e821..1b1e593 100644
--- a/osdep.c
+++ b/osdep.c
@@ -37,6 +37,10 @@
 #include <sys/statvfs.h>
 #endif
 
+#ifdef CONFIG_EVENTFD
+#include <sys/eventfd.h>
+#endif
+
 #ifdef _WIN32
 #include <windows.h>
 #elif defined(CONFIG_BSD)
@@ -285,6 +289,34 @@ ssize_t qemu_write_full(int fd, const void *buf, size_t count)
 
 #ifndef _WIN32
 /*
+ * Creates an eventfd that looks like a pipe and has EFD_CLOEXEC set.
+ */
+int qemu_eventfd(int fds[2])
+{
+    int ret;
+
+#ifdef CONFIG_EVENTFD
+    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);
+}
+
+/*
  * Creates a pipe with FD_CLOEXEC set on both file descriptors
  */
 int qemu_pipe(int pipefd[2])
diff --git a/qemu-common.h b/qemu-common.h
index bf14a22..f59d5f5 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -170,6 +170,7 @@ ssize_t qemu_write_full(int fd, const void *buf, size_t count)
 void qemu_set_cloexec(int fd);
 
 #ifndef _WIN32
+int qemu_eventfd(int pipefd[2]);
 int qemu_pipe(int pipefd[2]);
 #endif
 
-- 
1.6.6

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] Re: [PATCH 0/4] qemu-kvm: prepare for adding eventfd usage to upstream
  2010-02-10 23:09 [Qemu-devel] [PATCH 0/4] qemu-kvm: prepare for adding eventfd usage to upstream Paolo Bonzini
                   ` (3 preceding siblings ...)
  2010-02-10 23:09 ` [Qemu-devel] [PATCH 4/4] qemu-kvm: move qemu_eventfd to osdep.c Paolo Bonzini
@ 2010-02-13 13:26 ` Marcelo Tosatti
  2010-02-14 12:32   ` Avi Kivity
  2010-02-17 12:53 ` Avi Kivity
  5 siblings, 1 reply; 8+ messages in thread
From: Marcelo Tosatti @ 2010-02-13 13:26 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel, kvm

On Thu, Feb 11, 2010 at 12:09:12AM +0100, Paolo Bonzini wrote:
> This patch series morphs the code in qemu-kvm's eventfd so that it looks
> like the code in upstream qemu.  Patch 4 is not yet in upstream QEMU,
> I'm submitting it first to qemu-kvm to avoid conflicts.
> 
> Paolo Bonzini (4):
>   morph qemu_kvm_notify_work into qemu.git's qemu_event_increment
>   morph io_thread_wakeup into qemu.git's qemu_event_read
>   fix placement of config-host.h inclusion
>   move qemu_eventfd to osdep.c
> 
>  compatfd.c    |   26 --------------------------
>  compatfd.h    |    2 --
>  osdep.c       |   37 +++++++++++++++++++++++++++++++++++--
>  qemu-common.h |    1 +
>  qemu-kvm.c    |   50 +++++++++++++++++---------------------------------
>  5 files changed, 53 insertions(+), 63 deletions(-)

Looks good to me.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] Re: [PATCH 0/4] qemu-kvm: prepare for adding eventfd usage to upstream
  2010-02-13 13:26 ` [Qemu-devel] Re: [PATCH 0/4] qemu-kvm: prepare for adding eventfd usage to upstream Marcelo Tosatti
@ 2010-02-14 12:32   ` Avi Kivity
  0 siblings, 0 replies; 8+ messages in thread
From: Avi Kivity @ 2010-02-14 12:32 UTC (permalink / raw)
  To: Marcelo Tosatti; +Cc: Paolo Bonzini, qemu-devel, kvm

On 02/13/2010 03:26 PM, Marcelo Tosatti wrote:
> On Thu, Feb 11, 2010 at 12:09:12AM +0100, Paolo Bonzini wrote:
>    
>> This patch series morphs the code in qemu-kvm's eventfd so that it looks
>> like the code in upstream qemu.  Patch 4 is not yet in upstream QEMU,
>> I'm submitting it first to qemu-kvm to avoid conflicts.
>>      
> Looks good to me.
>    

Me too.

-- 
error compiling committee.c: too many arguments to function

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] Re: [PATCH 0/4] qemu-kvm: prepare for adding eventfd usage to upstream
  2010-02-10 23:09 [Qemu-devel] [PATCH 0/4] qemu-kvm: prepare for adding eventfd usage to upstream Paolo Bonzini
                   ` (4 preceding siblings ...)
  2010-02-13 13:26 ` [Qemu-devel] Re: [PATCH 0/4] qemu-kvm: prepare for adding eventfd usage to upstream Marcelo Tosatti
@ 2010-02-17 12:53 ` Avi Kivity
  5 siblings, 0 replies; 8+ messages in thread
From: Avi Kivity @ 2010-02-17 12:53 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel, kvm

On 02/11/2010 01:09 AM, Paolo Bonzini wrote:
> This patch series morphs the code in qemu-kvm's eventfd so that it looks
> like the code in upstream qemu.  Patch 4 is not yet in upstream QEMU,
> I'm submitting it first to qemu-kvm to avoid conflicts.
>    

Applied, thanks.

-- 
error compiling committee.c: too many arguments to function

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-02-17 12:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-10 23:09 [Qemu-devel] [PATCH 0/4] qemu-kvm: prepare for adding eventfd usage to upstream Paolo Bonzini
2010-02-10 23:09 ` [Qemu-devel] [PATCH 1/4] qemu-kvm: morph qemu_kvm_notify_work into qemu.git's qemu_event_increment Paolo Bonzini
2010-02-10 23:09 ` [Qemu-devel] [PATCH 2/4] qemu-kvm: morph io_thread_wakeup into qemu.git's qemu_event_read Paolo Bonzini
2010-02-10 23:09 ` [Qemu-devel] [PATCH 3/4] qemu-kvm: fix placement of config-host.h inclusion Paolo Bonzini
2010-02-10 23:09 ` [Qemu-devel] [PATCH 4/4] qemu-kvm: move qemu_eventfd to osdep.c Paolo Bonzini
2010-02-13 13:26 ` [Qemu-devel] Re: [PATCH 0/4] qemu-kvm: prepare for adding eventfd usage to upstream Marcelo Tosatti
2010-02-14 12:32   ` Avi Kivity
2010-02-17 12:53 ` Avi Kivity

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).