qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/8] Make event_notifier more useful and more used
@ 2010-05-26 14:09 Paolo Bonzini
  2010-05-26 14:09 ` [Qemu-devel] [PATCH 1/8] move event_notifier into the main directory Paolo Bonzini
                   ` (9 more replies)
  0 siblings, 10 replies; 14+ messages in thread
From: Paolo Bonzini @ 2010-05-26 14:09 UTC (permalink / raw)
  To: qemu-devel

Hi,

this patch adds all the eventfd bells and whistles from vl.c/cpus.c
to event_notifier, including pipe emulation and Win32 support.
It then modifies the iothread code to use it instead.

Paolo Bonzini (8):
  move event_notifier into the main directory
  add event_notifier_set
  remove event_notifier_test
  add and use virtqueue_from_guest_notifier
  add and use event_notifier_set_handler
  enable event_notifier to use pipes
  add Win32 implementation of event notifiers
  change ioevent to use event notifiers

 cpus.c              |   95 +++-----------------------------------
 event_notifier.c    |  124 +++++++++++++++++++++++++++++++++++++++++++++++++++
 event_notifier.h    |   28 +++++++++++
 hw/event_notifier.c |   62 -------------------------
 hw/event_notifier.h |   16 -------
 hw/virtio-pci.c     |   11 ++---
 hw/virtio.c         |    5 ++
 hw/virtio.h         |    1 +
 8 files changed, 171 insertions(+), 171 deletions(-)
 create mode 100644 event_notifier.c
 create mode 100644 event_notifier.h
 delete mode 100644 hw/event_notifier.c
 delete mode 100644 hw/event_notifier.h

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

* [Qemu-devel] [PATCH 1/8] move event_notifier into the main directory
  2010-05-26 14:09 [Qemu-devel] [PATCH 0/8] Make event_notifier more useful and more used Paolo Bonzini
@ 2010-05-26 14:09 ` Paolo Bonzini
  2010-05-26 14:09 ` [Qemu-devel] [PATCH 2/8] add event_notifier_set Paolo Bonzini
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Paolo Bonzini @ 2010-05-26 14:09 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/event_notifier.c => event_notifier.c |    1 -
 hw/event_notifier.h => event_notifier.h |    0
 2 files changed, 0 insertions(+), 1 deletions(-)
 rename hw/event_notifier.c => event_notifier.c (98%)
 rename hw/event_notifier.h => event_notifier.h (100%)

diff --git a/hw/event_notifier.c b/event_notifier.c
similarity index 98%
rename from hw/event_notifier.c
rename to event_notifier.c
index 13f3656..2c73555 100644
--- a/hw/event_notifier.c
+++ b/event_notifier.c
@@ -10,7 +10,6 @@
  * the COPYING file in the top-level directory.
  */
 
-#include "hw.h"
 #include "event_notifier.h"
 #ifdef CONFIG_EVENTFD
 #include <sys/eventfd.h>
diff --git a/hw/event_notifier.h b/event_notifier.h
similarity index 100%
rename from hw/event_notifier.h
rename to event_notifier.h
-- 
1.6.6.1

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

* [Qemu-devel] [PATCH 2/8] add event_notifier_set
  2010-05-26 14:09 [Qemu-devel] [PATCH 0/8] Make event_notifier more useful and more used Paolo Bonzini
  2010-05-26 14:09 ` [Qemu-devel] [PATCH 1/8] move event_notifier into the main directory Paolo Bonzini
@ 2010-05-26 14:09 ` Paolo Bonzini
  2010-05-26 14:09 ` [Qemu-devel] [PATCH 3/8] remove event_notifier_test Paolo Bonzini
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Paolo Bonzini @ 2010-05-26 14:09 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 event_notifier.c |    7 +++++++
 event_notifier.h |    1 +
 2 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/event_notifier.c b/event_notifier.c
index 2c73555..3f50568 100644
--- a/event_notifier.c
+++ b/event_notifier.c
@@ -38,6 +38,13 @@ int event_notifier_get_fd(EventNotifier *e)
     return e->fd;
 }
 
+int event_notifier_set(EventNotifier *e)
+{
+    uint64_t value = 1;
+    int r = write(e->fd, &value, sizeof(value));
+    return r == sizeof(value);
+}
+
 int event_notifier_test_and_clear(EventNotifier *e)
 {
     uint64_t value;
diff --git a/event_notifier.h b/event_notifier.h
index 24117ea..8d5735f 100644
--- a/event_notifier.h
+++ b/event_notifier.h
@@ -10,6 +10,7 @@ struct EventNotifier {
 int event_notifier_init(EventNotifier *, int active);
 void event_notifier_cleanup(EventNotifier *);
 int event_notifier_get_fd(EventNotifier *);
+int event_notifier_set(EventNotifier *);
 int event_notifier_test_and_clear(EventNotifier *);
 int event_notifier_test(EventNotifier *);
 
-- 
1.6.6.1

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

* [Qemu-devel] [PATCH 3/8] remove event_notifier_test
  2010-05-26 14:09 [Qemu-devel] [PATCH 0/8] Make event_notifier more useful and more used Paolo Bonzini
  2010-05-26 14:09 ` [Qemu-devel] [PATCH 1/8] move event_notifier into the main directory Paolo Bonzini
  2010-05-26 14:09 ` [Qemu-devel] [PATCH 2/8] add event_notifier_set Paolo Bonzini
@ 2010-05-26 14:09 ` Paolo Bonzini
  2010-05-26 14:09 ` [Qemu-devel] [PATCH 4/8] add and use virtqueue_from_guest_notifier Paolo Bonzini
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Paolo Bonzini @ 2010-05-26 14:09 UTC (permalink / raw)
  To: qemu-devel

This is broken; since the eventfd is used in nonblocking mode there
is a race between reading and writing.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 event_notifier.c |   15 ---------------
 event_notifier.h |    1 -
 2 files changed, 0 insertions(+), 16 deletions(-)

diff --git a/event_notifier.c b/event_notifier.c
index 3f50568..0f7b8da 100644
--- a/event_notifier.c
+++ b/event_notifier.c
@@ -51,18 +51,3 @@ int event_notifier_test_and_clear(EventNotifier *e)
     int r = read(e->fd, &value, sizeof(value));
     return r == sizeof(value);
 }
-
-int event_notifier_test(EventNotifier *e)
-{
-    uint64_t value;
-    int r = read(e->fd, &value, sizeof(value));
-    if (r == sizeof(value)) {
-        /* restore previous value. */
-        int s = write(e->fd, &value, sizeof(value));
-        /* never blocks because we use EFD_SEMAPHORE.
-         * If we didn't we'd get EAGAIN on overflow
-         * and we'd have to write code to ignore it. */
-        assert(s == sizeof(value));
-    }
-    return r == sizeof(value);
-}
diff --git a/event_notifier.h b/event_notifier.h
index 8d5735f..714d690 100644
--- a/event_notifier.h
+++ b/event_notifier.h
@@ -12,6 +12,5 @@ void event_notifier_cleanup(EventNotifier *);
 int event_notifier_get_fd(EventNotifier *);
 int event_notifier_set(EventNotifier *);
 int event_notifier_test_and_clear(EventNotifier *);
-int event_notifier_test(EventNotifier *);
 
 #endif
-- 
1.6.6.1

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

* [Qemu-devel] [PATCH 4/8] add and use virtqueue_from_guest_notifier
  2010-05-26 14:09 [Qemu-devel] [PATCH 0/8] Make event_notifier more useful and more used Paolo Bonzini
                   ` (2 preceding siblings ...)
  2010-05-26 14:09 ` [Qemu-devel] [PATCH 3/8] remove event_notifier_test Paolo Bonzini
@ 2010-05-26 14:09 ` Paolo Bonzini
  2010-05-26 14:09 ` [Qemu-devel] [PATCH 5/8] add and use event_notifier_set_handler Paolo Bonzini
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Paolo Bonzini @ 2010-05-26 14:09 UTC (permalink / raw)
  To: qemu-devel

This changes the opaque pointer passed to the handler, from being
the virtqueue to being the eventnotifier.  It is useful as soon as
the eventnotifier will be able to set its own (type-safe) handler.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
        I don't have a vhost-enabled machine yet.  So only compile-tested
        for now, but pretty trivial.

 hw/virtio-pci.c |    6 +++---
 hw/virtio.c     |    5 +++++
 hw/virtio.h     |    1 +
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 7ddf612..988c75c 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -421,8 +421,8 @@ static unsigned virtio_pci_get_features(void *opaque)
 
 static void virtio_pci_guest_notifier_read(void *opaque)
 {
-    VirtQueue *vq = opaque;
-    EventNotifier *n = virtio_queue_get_guest_notifier(vq);
+    EventNotifier *n = opaque;
+    VirtQueue *vq = virtqueue_from_guest_notifier(n);
     if (event_notifier_test_and_clear(n)) {
         virtio_irq(vq);
     }
@@ -440,7 +440,7 @@ static int virtio_pci_set_guest_notifier(void *opaque, int n, bool assign)
             return r;
         }
         qemu_set_fd_handler(event_notifier_get_fd(notifier),
-                            virtio_pci_guest_notifier_read, NULL, vq);
+                            virtio_pci_guest_notifier_read, NULL, notifier);
     } else {
         qemu_set_fd_handler(event_notifier_get_fd(notifier),
                             NULL, NULL, NULL);
diff --git a/hw/virtio.c b/hw/virtio.c
index 4475bb3..bfce44b 100644
--- a/hw/virtio.c
+++ b/hw/virtio.c
@@ -805,6 +805,11 @@ VirtQueue *virtio_get_queue(VirtIODevice *vdev, int n)
     return vdev->vq + n;
 }
 
+VirtQueue *virtqueue_from_guest_notifier(EventNotifier *e)
+{
+    return container_of(e, VirtQueue, guest_notifier);
+}
+
 EventNotifier *virtio_queue_get_guest_notifier(VirtQueue *vq)
 {
     return &vq->guest_notifier;
diff --git a/hw/virtio.h b/hw/virtio.h
index e4306cd..d6a5b00 100644
--- a/hw/virtio.h
+++ b/hw/virtio.h
@@ -210,6 +210,7 @@ target_phys_addr_t virtio_queue_get_ring_size(VirtIODevice *vdev, int n);
 uint16_t virtio_queue_get_last_avail_idx(VirtIODevice *vdev, int n);
 void virtio_queue_set_last_avail_idx(VirtIODevice *vdev, int n, uint16_t idx);
 VirtQueue *virtio_get_queue(VirtIODevice *vdev, int n);
+VirtQueue *virtqueue_from_guest_notifier(EventNotifier *vq);
 EventNotifier *virtio_queue_get_guest_notifier(VirtQueue *vq);
 EventNotifier *virtio_queue_get_host_notifier(VirtQueue *vq);
 void virtio_irq(VirtQueue *vq);
-- 
1.6.6.1

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

* [Qemu-devel] [PATCH 5/8] add and use event_notifier_set_handler
  2010-05-26 14:09 [Qemu-devel] [PATCH 0/8] Make event_notifier more useful and more used Paolo Bonzini
                   ` (3 preceding siblings ...)
  2010-05-26 14:09 ` [Qemu-devel] [PATCH 4/8] add and use virtqueue_from_guest_notifier Paolo Bonzini
@ 2010-05-26 14:09 ` Paolo Bonzini
  2010-05-26 14:09 ` [Qemu-devel] [PATCH 6/8] enable event_notifier to use pipes Paolo Bonzini
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Paolo Bonzini @ 2010-05-26 14:09 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 event_notifier.c |    7 +++++++
 event_notifier.h |    3 +++
 hw/virtio-pci.c  |    9 +++------
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/event_notifier.c b/event_notifier.c
index 0f7b8da..066adb9 100644
--- a/event_notifier.c
+++ b/event_notifier.c
@@ -11,6 +11,7 @@
  */
 
 #include "event_notifier.h"
+#include "qemu-char.h"
 #ifdef CONFIG_EVENTFD
 #include <sys/eventfd.h>
 #endif
@@ -38,6 +39,12 @@ int event_notifier_get_fd(EventNotifier *e)
     return e->fd;
 }
 
+int event_notifier_set_handler(EventNotifier *e,
+                               EventNotifierHandler *handler)
+{
+    return qemu_set_fd_handler(e->fd, (IOHandler *)handler, NULL, e);
+}
+
 int event_notifier_set(EventNotifier *e)
 {
     uint64_t value = 1;
diff --git a/event_notifier.h b/event_notifier.h
index 714d690..f6ec9ef 100644
--- a/event_notifier.h
+++ b/event_notifier.h
@@ -7,10 +7,13 @@ struct EventNotifier {
 	int fd;
 };
 
+typedef void EventNotifierHandler(EventNotifier *);
+
 int event_notifier_init(EventNotifier *, int active);
 void event_notifier_cleanup(EventNotifier *);
 int event_notifier_get_fd(EventNotifier *);
 int event_notifier_set(EventNotifier *);
 int event_notifier_test_and_clear(EventNotifier *);
+int event_notifier_set_handler(EventNotifier *, EventNotifierHandler *);
 
 #endif
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 988c75c..a7ebc83 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -419,9 +419,8 @@ static unsigned virtio_pci_get_features(void *opaque)
     return proxy->host_features;
 }
 
-static void virtio_pci_guest_notifier_read(void *opaque)
+static void virtio_pci_guest_notifier_read(EventNotifier *n)
 {
-    EventNotifier *n = opaque;
     VirtQueue *vq = virtqueue_from_guest_notifier(n);
     if (event_notifier_test_and_clear(n)) {
         virtio_irq(vq);
@@ -439,11 +438,9 @@ static int virtio_pci_set_guest_notifier(void *opaque, int n, bool assign)
         if (r < 0) {
             return r;
         }
-        qemu_set_fd_handler(event_notifier_get_fd(notifier),
-                            virtio_pci_guest_notifier_read, NULL, notifier);
+        event_notifier_set_handler(notifier, virtio_pci_guest_notifier_read);
     } else {
-        qemu_set_fd_handler(event_notifier_get_fd(notifier),
-                            NULL, NULL, NULL);
+        event_notifier_set_handler(notifier, NULL);
         event_notifier_cleanup(notifier);
     }
 
-- 
1.6.6.1

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

* [Qemu-devel] [PATCH 6/8] enable event_notifier to use pipes
  2010-05-26 14:09 [Qemu-devel] [PATCH 0/8] Make event_notifier more useful and more used Paolo Bonzini
                   ` (4 preceding siblings ...)
  2010-05-26 14:09 ` [Qemu-devel] [PATCH 5/8] add and use event_notifier_set_handler Paolo Bonzini
@ 2010-05-26 14:09 ` Paolo Bonzini
  2010-05-26 18:19   ` Richard Henderson
  2010-05-26 14:09 ` [Qemu-devel] [PATCH 7/8] add Win32 implementation of event notifiers Paolo Bonzini
                   ` (3 subsequent siblings)
  9 siblings, 1 reply; 14+ messages in thread
From: Paolo Bonzini @ 2010-05-26 14:09 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 event_notifier.c |   69 +++++++++++++++++++++++++++++++++++++++---------------
 event_notifier.h |    3 +-
 2 files changed, 52 insertions(+), 20 deletions(-)

diff --git a/event_notifier.c b/event_notifier.c
index 066adb9..a33f3c5 100644
--- a/event_notifier.c
+++ b/event_notifier.c
@@ -10,51 +10,82 @@
  * the COPYING file in the top-level directory.
  */
 
+#include "qemu-common.h"
 #include "event_notifier.h"
 #include "qemu-char.h"
-#ifdef CONFIG_EVENTFD
-#include <sys/eventfd.h>
-#endif
 
 int event_notifier_init(EventNotifier *e, int active)
 {
-#ifdef CONFIG_EVENTFD
-    int fd = eventfd(!!active, EFD_NONBLOCK | EFD_CLOEXEC);
-    if (fd < 0)
+    int fds[2];
+    int err;
+    if (qemu_eventfd (fds) < 0)
         return -errno;
-    e->fd = fd;
+
+    err = fcntl_setfl(fds[0], O_NONBLOCK);
+    if (err < 0)
+        goto fail;
+
+    err = fcntl_setfl(fds[1], O_NONBLOCK);
+    if (err < 0)
+        goto fail;
+
+    e->rfd = fds[0];
+    e->wfd = fds[1];
+    if (active)
+        event_notifier_set(e);
     return 0;
-#else
-    return -ENOSYS;
-#endif
+
+fail:
+    close(fds[0]);
+    close(fds[1]);
+    return err;
 }
 
 void event_notifier_cleanup(EventNotifier *e)
 {
-    close(e->fd);
+    close(e->rfd);
+    close(e->wfd);
 }
 
 int event_notifier_get_fd(EventNotifier *e)
 {
-    return e->fd;
+    return e->wfd;
 }
 
 int event_notifier_set_handler(EventNotifier *e,
                                EventNotifierHandler *handler)
 {
-    return qemu_set_fd_handler(e->fd, (IOHandler *)handler, NULL, e);
+    return qemu_set_fd_handler(e->rfd, (IOHandler *)handler, NULL, e);
 }
 
 int event_notifier_set(EventNotifier *e)
 {
-    uint64_t value = 1;
-    int r = write(e->fd, &value, sizeof(value));
-    return r == sizeof(value);
+    static const uint64_t value = 1;
+    ssize_t ret;
+
+    do {
+        ret = write(e->wfd, &value, sizeof(value));
+    } while (ret < 0 && errno == EINTR);
+
+    /* EAGAIN is fine, a read must be pending.  */
+    if (ret < 0 && errno != EAGAIN) {
+        return -1;
+    }
+    return 0;
 }
 
 int event_notifier_test_and_clear(EventNotifier *e)
 {
-    uint64_t value;
-    int r = read(e->fd, &value, sizeof(value));
-    return r == sizeof(value);
+    int value;
+    ssize_t len;
+    char buffer[512];
+
+    /* Drain the notify pipe.  For eventfd, only 8 bytes will be read.  */
+    value = 0;
+    do {
+        len = read(e->rfd, buffer, sizeof(buffer));
+        value |= (len > 0);
+    } while ((len == -1 && errno == EINTR) || len == sizeof(buffer));
+
+    return value;
 }
diff --git a/event_notifier.h b/event_notifier.h
index f6ec9ef..ff9d6f2 100644
--- a/event_notifier.h
+++ b/event_notifier.h
@@ -4,7 +4,8 @@
 #include "qemu-common.h"
 
 struct EventNotifier {
-	int fd;
+    int rfd;
+    int wfd;
 };
 
 typedef void EventNotifierHandler(EventNotifier *);
-- 
1.6.6.1

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

* [Qemu-devel] [PATCH 7/8] add Win32 implementation of event notifiers
  2010-05-26 14:09 [Qemu-devel] [PATCH 0/8] Make event_notifier more useful and more used Paolo Bonzini
                   ` (5 preceding siblings ...)
  2010-05-26 14:09 ` [Qemu-devel] [PATCH 6/8] enable event_notifier to use pipes Paolo Bonzini
@ 2010-05-26 14:09 ` Paolo Bonzini
  2010-05-26 14:09 ` [Qemu-devel] [PATCH 8/8] change ioevent to use " Paolo Bonzini
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Paolo Bonzini @ 2010-05-26 14:09 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
        Compile-tested only.  iothread is broken anyway on Win32
        due to missing implementation of qemu-threads.

 event_notifier.c |   33 +++++++++++++++++++++++++++++++++
 event_notifier.h |    8 ++++++++
 2 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/event_notifier.c b/event_notifier.c
index a33f3c5..0705dc5 100644
--- a/event_notifier.c
+++ b/event_notifier.c
@@ -11,11 +11,13 @@
  */
 
 #include "qemu-common.h"
+#include "sysemu.h"
 #include "event_notifier.h"
 #include "qemu-char.h"
 
 int event_notifier_init(EventNotifier *e, int active)
 {
+#ifndef _WIN32
     int fds[2];
     int err;
     if (qemu_eventfd (fds) < 0)
@@ -39,27 +41,50 @@ fail:
     close(fds[0]);
     close(fds[1]);
     return err;
+#else
+    e->event = CreateEvent(NULL, FALSE, FALSE, NULL);
+    assert(e->event);
+    return 0;
+#endif
 }
 
 void event_notifier_cleanup(EventNotifier *e)
 {
+#ifndef _WIN32
     close(e->rfd);
     close(e->wfd);
+#else
+    CloseHandle(e->event);
+#endif
 }
 
 int event_notifier_get_fd(EventNotifier *e)
 {
+#ifndef _WIN32
     return e->wfd;
+#else
+    abort();
+#endif
 }
 
 int event_notifier_set_handler(EventNotifier *e,
                                EventNotifierHandler *handler)
 {
+#ifndef _WIN32
     return qemu_set_fd_handler(e->rfd, (IOHandler *)handler, NULL, e);
+#else
+    if (handler) {
+        return qemu_add_wait_object(e->event, (IOHandler *)handler, e);
+    } else {
+        qemu_del_wait_object(e->event, (IOHandler *)handler, e);
+        return 0;
+    }
+#endif
 }
 
 int event_notifier_set(EventNotifier *e)
 {
+#ifndef _WIN32
     static const uint64_t value = 1;
     ssize_t ret;
 
@@ -72,10 +97,15 @@ int event_notifier_set(EventNotifier *e)
         return -1;
     }
     return 0;
+#else
+    SetEvent(e->event);
+    return 0;
+#endif
 }
 
 int event_notifier_test_and_clear(EventNotifier *e)
 {
+#ifndef _WIN32
     int value;
     ssize_t len;
     char buffer[512];
@@ -88,4 +118,7 @@ int event_notifier_test_and_clear(EventNotifier *e)
     } while ((len == -1 && errno == EINTR) || len == sizeof(buffer));
 
     return value;
+#else
+    return WaitForSingleObject(e->event, 0) == WAIT_OBJECT_0;
+#endif
 }
diff --git a/event_notifier.h b/event_notifier.h
index ff9d6f2..f3c272a 100644
--- a/event_notifier.h
+++ b/event_notifier.h
@@ -3,9 +3,17 @@
 
 #include "qemu-common.h"
 
+#ifdef _WIN32
+#include <windows.h>
+#endif
+
 struct EventNotifier {
+#ifdef _WIN32
+    HANDLE event;
+#else
     int rfd;
     int wfd;
+#endif
 };
 
 typedef void EventNotifierHandler(EventNotifier *);
-- 
1.6.6.1

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

* [Qemu-devel] [PATCH 8/8] change ioevent to use event notifiers
  2010-05-26 14:09 [Qemu-devel] [PATCH 0/8] Make event_notifier more useful and more used Paolo Bonzini
                   ` (6 preceding siblings ...)
  2010-05-26 14:09 ` [Qemu-devel] [PATCH 7/8] add Win32 implementation of event notifiers Paolo Bonzini
@ 2010-05-26 14:09 ` Paolo Bonzini
  2010-05-27 14:21 ` [Qemu-devel] Re: [PATCH 0/8] Make event_notifier more useful and more used Michael S. Tsirkin
  2010-06-15 13:53 ` Paolo Bonzini
  9 siblings, 0 replies; 14+ messages in thread
From: Paolo Bonzini @ 2010-05-26 14:09 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 cpus.c |   95 +++++-----------------------------------------------------------
 1 files changed, 9 insertions(+), 86 deletions(-)

diff --git a/cpus.c b/cpus.c
index 8341f6c..7a1dd06 100644
--- a/cpus.c
+++ b/cpus.c
@@ -26,6 +26,7 @@
 #include "config-host.h"
 
 #include "monitor.h"
+#include "event_notifier.h"
 #include "sysemu.h"
 #include "gdbstub.h"
 #include "dma.h"
@@ -141,97 +142,19 @@ static int tcg_has_work(void)
     return 0;
 }
 
-#ifndef _WIN32
-static int io_thread_fd = -1;
-
-static void qemu_event_increment(void)
-{
-    /* Write 8 bytes to be compatible with eventfd.  */
-    static const uint64_t val = 1;
-    ssize_t ret;
-
-    if (io_thread_fd == -1)
-        return;
-
-    do {
-        ret = write(io_thread_fd, &val, sizeof(val));
-    } 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);
-    }
-}
-
-static void qemu_event_read(void *opaque)
-{
-    int fd = (unsigned long)opaque;
-    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));
-    } while ((len == -1 && errno == EINTR) || len == sizeof(buffer));
-}
+static EventNotifier io_thread_notifier;
 
 static int qemu_event_init(void)
 {
     int err;
-    int fds[2];
-
-    err = qemu_eventfd(fds);
-    if (err == -1)
-        return -errno;
+    err = event_notifier_init(&io_thread_notifier, 0);
+    if (err == 0)
+        event_notifier_set_handler(&io_thread_notifier,
+                                   (EventNotifierHandler *)
+                                   event_notifier_test_and_clear);
 
-    err = fcntl_setfl(fds[0], O_NONBLOCK);
-    if (err < 0)
-        goto fail;
-
-    err = fcntl_setfl(fds[1], O_NONBLOCK);
-    if (err < 0)
-        goto fail;
-
-    qemu_set_fd_handler2(fds[0], NULL, qemu_event_read, NULL,
-                         (void *)(unsigned long)fds[0]);
-
-    io_thread_fd = fds[1];
-    return 0;
-
-fail:
-    close(fds[0]);
-    close(fds[1]);
     return err;
 }
-#else
-HANDLE qemu_event_handle;
-
-static void dummy_event_handler(void *opaque)
-{
-}
-
-static int qemu_event_init(void)
-{
-    qemu_event_handle = CreateEvent(NULL, FALSE, FALSE, NULL);
-    if (!qemu_event_handle) {
-        fprintf(stderr, "Failed CreateEvent: %ld\n", GetLastError());
-        return -1;
-    }
-    qemu_add_wait_object(qemu_event_handle, dummy_event_handler, NULL);
-    return 0;
-}
-
-static void qemu_event_increment(void)
-{
-    if (!SetEvent(qemu_event_handle)) {
-        fprintf(stderr, "qemu_event_increment: SetEvent failed: %ld\n",
-                GetLastError());
-        exit (1);
-    }
-}
-#endif
 
 #ifndef CONFIG_IOTHREAD
 int qemu_init_main_loop(void)
@@ -281,7 +203,7 @@ void qemu_notify_event(void)
 {
     CPUState *env = cpu_single_env;
 
-    qemu_event_increment ();
+    event_notifier_set(&io_thread_notifier);
     if (env) {
         cpu_exit(env);
     }
@@ -709,7 +631,7 @@ void qemu_init_vcpu(void *_env)
 
 void qemu_notify_event(void)
 {
-    qemu_event_increment();
+    event_notifier_set(&io_thread_notifier);
 }
 
 static void qemu_system_vmstop_request(int reason)
-- 
1.6.6.1

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

* Re: [Qemu-devel] [PATCH 6/8] enable event_notifier to use pipes
  2010-05-26 14:09 ` [Qemu-devel] [PATCH 6/8] enable event_notifier to use pipes Paolo Bonzini
@ 2010-05-26 18:19   ` Richard Henderson
  2010-05-26 19:48     ` [Qemu-devel] " Paolo Bonzini
  0 siblings, 1 reply; 14+ messages in thread
From: Richard Henderson @ 2010-05-26 18:19 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On 05/26/2010 07:09 AM, Paolo Bonzini wrote:
> -#ifdef CONFIG_EVENTFD
> -#include <sys/eventfd.h>
> -#endif

Is there a reason not to use eventfd if it is available?


r~

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

* [Qemu-devel] Re: [PATCH 6/8] enable event_notifier to use pipes
  2010-05-26 18:19   ` Richard Henderson
@ 2010-05-26 19:48     ` Paolo Bonzini
  0 siblings, 0 replies; 14+ messages in thread
From: Paolo Bonzini @ 2010-05-26 19:48 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On 05/26/2010 08:19 PM, Richard Henderson wrote:
> On 05/26/2010 07:09 AM, Paolo Bonzini wrote:
>> -#ifdef CONFIG_EVENTFD
>> -#include<sys/eventfd.h>
>> -#endif
>
> Is there a reason not to use eventfd if it is available?

qemu_eventfd chooses between eventfd or pipes.  The reads and writes are 
done so that both cases are accomodated.

Paolo

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

* [Qemu-devel] Re: [PATCH 0/8] Make event_notifier more useful and more used
  2010-05-26 14:09 [Qemu-devel] [PATCH 0/8] Make event_notifier more useful and more used Paolo Bonzini
                   ` (7 preceding siblings ...)
  2010-05-26 14:09 ` [Qemu-devel] [PATCH 8/8] change ioevent to use " Paolo Bonzini
@ 2010-05-27 14:21 ` Michael S. Tsirkin
  2010-05-27 15:37   ` Paolo Bonzini
  2010-06-15 13:53 ` Paolo Bonzini
  9 siblings, 1 reply; 14+ messages in thread
From: Michael S. Tsirkin @ 2010-05-27 14:21 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Wed, May 26, 2010 at 04:09:30PM +0200, Paolo Bonzini wrote:
> Hi,
> 
> this patch adds all the eventfd bells and whistles from vl.c/cpus.c
> to event_notifier, including pipe emulation and Win32 support.
> It then modifies the iothread code to use it instead.

I only seem to have got patches 4 and 5. Error at my end?

> Paolo Bonzini (8):
>   move event_notifier into the main directory
>   add event_notifier_set
>   remove event_notifier_test
>   add and use virtqueue_from_guest_notifier
>   add and use event_notifier_set_handler
>   enable event_notifier to use pipes
>   add Win32 implementation of event notifiers
>   change ioevent to use event notifiers
> 
>  cpus.c              |   95 +++-----------------------------------
>  event_notifier.c    |  124 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  event_notifier.h    |   28 +++++++++++
>  hw/event_notifier.c |   62 -------------------------
>  hw/event_notifier.h |   16 -------
>  hw/virtio-pci.c     |   11 ++---
>  hw/virtio.c         |    5 ++
>  hw/virtio.h         |    1 +
>  8 files changed, 171 insertions(+), 171 deletions(-)
>  create mode 100644 event_notifier.c
>  create mode 100644 event_notifier.h
>  delete mode 100644 hw/event_notifier.c
>  delete mode 100644 hw/event_notifier.h
> 

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

* [Qemu-devel] Re: [PATCH 0/8] Make event_notifier more useful and more used
  2010-05-27 14:21 ` [Qemu-devel] Re: [PATCH 0/8] Make event_notifier more useful and more used Michael S. Tsirkin
@ 2010-05-27 15:37   ` Paolo Bonzini
  0 siblings, 0 replies; 14+ messages in thread
From: Paolo Bonzini @ 2010-05-27 15:37 UTC (permalink / raw)
  To: qemu-devel; +Cc: Michael S. Tsirkin

On 05/27/2010 04:21 PM, Michael S. Tsirkin wrote:
> On Wed, May 26, 2010 at 04:09:30PM +0200, Paolo Bonzini wrote:
>> Hi,
>>
>> this patch adds all the eventfd bells and whistles from vl.c/cpus.c
>> to event_notifier, including pipe emulation and Win32 support.
>> It then modifies the iothread code to use it instead.
>
> I only seem to have got patches 4 and 5. Error at my end?

Maybe Savannah's, OTOH gmane and patchwork show all eight.

>>    move event_notifier into the main directory

http://patchwork.ozlabs.org/patch/53626/

>>    add event_notifier_set

http://patchwork.ozlabs.org/patch/53627/

>>    remove event_notifier_test

http://patchwork.ozlabs.org/patch/53628/

>>    add and use virtqueue_from_guest_notifier

http://patchwork.ozlabs.org/patch/53632/

>>    add and use event_notifier_set_handler

http://patchwork.ozlabs.org/patch/53630/

>>    enable event_notifier to use pipes

http://patchwork.ozlabs.org/patch/53619/

>>    add Win32 implementation of event notifiers

http://patchwork.ozlabs.org/patch/53621/

>>    change ioevent to use event notifiers

http://patchwork.ozlabs.org/patch/53635/

Paolo

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

* [Qemu-devel] Re: [PATCH 0/8] Make event_notifier more useful and more used
  2010-05-26 14:09 [Qemu-devel] [PATCH 0/8] Make event_notifier more useful and more used Paolo Bonzini
                   ` (8 preceding siblings ...)
  2010-05-27 14:21 ` [Qemu-devel] Re: [PATCH 0/8] Make event_notifier more useful and more used Michael S. Tsirkin
@ 2010-06-15 13:53 ` Paolo Bonzini
  9 siblings, 0 replies; 14+ messages in thread
From: Paolo Bonzini @ 2010-06-15 13:53 UTC (permalink / raw)
  Cc: qemu-devel

On 05/26/2010 04:09 PM, Paolo Bonzini wrote:
> Hi,
>
> this patch adds all the eventfd bells and whistles from vl.c/cpus.c
> to event_notifier, including pipe emulation and Win32 support.
> It then modifies the iothread code to use it instead.
>
> Paolo Bonzini (8):
>    move event_notifier into the main directory
>    add event_notifier_set
>    remove event_notifier_test
>    add and use virtqueue_from_guest_notifier
>    add and use event_notifier_set_handler
>    enable event_notifier to use pipes
>    add Win32 implementation of event notifiers
>    change ioevent to use event notifiers
>
>   cpus.c              |   95 +++-----------------------------------
>   event_notifier.c    |  124 +++++++++++++++++++++++++++++++++++++++++++++++++++
>   event_notifier.h    |   28 +++++++++++
>   hw/event_notifier.c |   62 -------------------------
>   hw/event_notifier.h |   16 -------
>   hw/virtio-pci.c     |   11 ++---
>   hw/virtio.c         |    5 ++
>   hw/virtio.h         |    1 +
>   8 files changed, 171 insertions(+), 171 deletions(-)
>   create mode 100644 event_notifier.c
>   create mode 100644 event_notifier.h
>   delete mode 100644 hw/event_notifier.c
>   delete mode 100644 hw/event_notifier.h

I'll redo the patches starting from qemu-kvm, since there's a bit more 
to do there.  I'll post the master and uq/master sometime next week.

Paolo

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

end of thread, other threads:[~2010-06-15 13:53 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-26 14:09 [Qemu-devel] [PATCH 0/8] Make event_notifier more useful and more used Paolo Bonzini
2010-05-26 14:09 ` [Qemu-devel] [PATCH 1/8] move event_notifier into the main directory Paolo Bonzini
2010-05-26 14:09 ` [Qemu-devel] [PATCH 2/8] add event_notifier_set Paolo Bonzini
2010-05-26 14:09 ` [Qemu-devel] [PATCH 3/8] remove event_notifier_test Paolo Bonzini
2010-05-26 14:09 ` [Qemu-devel] [PATCH 4/8] add and use virtqueue_from_guest_notifier Paolo Bonzini
2010-05-26 14:09 ` [Qemu-devel] [PATCH 5/8] add and use event_notifier_set_handler Paolo Bonzini
2010-05-26 14:09 ` [Qemu-devel] [PATCH 6/8] enable event_notifier to use pipes Paolo Bonzini
2010-05-26 18:19   ` Richard Henderson
2010-05-26 19:48     ` [Qemu-devel] " Paolo Bonzini
2010-05-26 14:09 ` [Qemu-devel] [PATCH 7/8] add Win32 implementation of event notifiers Paolo Bonzini
2010-05-26 14:09 ` [Qemu-devel] [PATCH 8/8] change ioevent to use " Paolo Bonzini
2010-05-27 14:21 ` [Qemu-devel] Re: [PATCH 0/8] Make event_notifier more useful and more used Michael S. Tsirkin
2010-05-27 15:37   ` Paolo Bonzini
2010-06-15 13:53 ` Paolo Bonzini

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