Skip to contentSkip to conversation

Event signaling tweaks

PATCH Applied Paolo Bonzini 2 participants 5 messages Feb 2, 2010 – Feb 10, 2010

lore
Share & tools
lore
#0 lore raw

cover Event signaling tweaks

This series of three patches makes two small changes to qemu_event_read and qemu_event_increment. These are preparatory to merging eventfd usage in the iothread from qemu-kvm (which would have conflicts, so it has to be done with some care).

Paolo Bonzini (3):
do not loop on an incomplete io_thread_fd read
loop qemu_event_increment if we have an EINTR
fix placement of config-host.h inclusion

 osdep.c |    7 ++++---
 vl.c    |   12 ++++++++----
 2 files changed, 12 insertions(+), 7 deletions(-)
#1 lore raw

PATCH 1/3 do not loop on an incomplete io_thread_fd read

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

---
 vl.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
vl.c +2 -2
index 6f1e1ab..46c1118 100644
@@ -3210,12 +3210,12 @@ static void qemu_event_read(void *opaque)
 {
     int fd = (unsigned long)opaque;
     ssize_t len;
+    char buffer[512];
 
     /* Drain the notify pipe */
     do {
-        char buffer[512];
         len = read(fd, buffer, sizeof(buffer));
-    } while ((len == -1 && errno == EINTR) || len > 0);
+    } while ((len == -1 && errno == EINTR) || len == sizeof(buffer));
 }
 
 static int qemu_event_init(void)
Signature · 1 line
1.6.6
#2 lore raw

Re: [Qemu-devel] [PATCH 1/3] do not loop on an incomplete io_thread_fd read

Quoted 5 lines · Paolo Bonzini

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

Applied all. Thanks.

Regards,

Anthony Liguori

Quoted 24 lines
---
  vl.c |    4 ++--
  1 files changed, 2 insertions(+), 2 deletions(-)
vl.c +2 -2
index 6f1e1ab..46c1118 100644
@@ -3210,12 +3210,12 @@ static void qemu_event_read(void *opaque)
  {
      int fd = (unsigned long)opaque;
      ssize_t len;
+    char buffer[512];
 
      /* Drain the notify pipe */
      do {
-        char buffer[512];
          len = read(fd, buffer, sizeof(buffer));
-    } while ((len == -1&&  errno == EINTR) || len>  0);
+    } while ((len == -1&&  errno == EINTR) || len == sizeof(buffer));
  }
 
  static int qemu_event_init(void)
#3 lore raw

PATCH 2/3 loop write in qemu_event_increment upon EINTR

In reply to Paolo Bonzini

Same as what qemu-kvm does.

---
 vl.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
vl.c +6 -2
index 46c1118..f150eca 100644
@@ -3198,8 +3198,12 @@ static void qemu_event_increment(void)
     if (io_thread_fd == -1)
         return;
 
-    ret = write(io_thread_fd, &byte, sizeof(byte));
-    if (ret < 0 && (errno != EINTR && errno != EAGAIN)) {
+    do {
+        ret = write(io_thread_fd, &byte, sizeof(byte));
+    } while (ret < 0 && errno == EINTR);
+
+    /* EAGAIN is fine, a read must be pending.  */
+    if (ret < 0 && errno != EAGAIN) {
         fprintf(stderr, "qemu_event_increment: write() filed: %s\n",
                 strerror(errno));
         exit (1);
Signature · 1 line
1.6.6
#4 lore raw

PATCH 3/3 fix placement of config-host.h inclusion

In reply to Paolo Bonzini

The #ifdef CONFIG_SOLARIS below was useless without this patch.

---
 osdep.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
osdep.c +4 -3
index cf3a2c6..9059f01 100644
@@ -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)
Signature · 1 line
1.6.6