qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] ISCSI: redo how we set up the events to only call q


From: Ronnie Sahlberg
Subject: [Qemu-devel] [PATCH] ISCSI: redo how we set up the events to only call qemu_aio_set_fd_handler() and qemu_notify_event() if something has changed.
Date: Fri, 25 May 2012 20:25:12 +1000

Also first call out to the socket write functions director, and only set up the 
write event if the socket is full.

This means that we will only need to invoke these two functions very rarely 
which will improve performance.

Signed-off-by: Ronnie Sahlberg <address@hidden>
---
 block/iscsi.c |   37 +++++++++++++++++++++++++++----------
 1 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/block/iscsi.c b/block/iscsi.c
index ed1ad7b..d710b86 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -40,6 +40,7 @@ typedef struct IscsiLun {
     int lun;
     int block_size;
     unsigned long num_blocks;
+    int events;
 } IscsiLun;
 
 typedef struct IscsiAIOCB {
@@ -105,18 +106,34 @@ static void
 iscsi_set_events(IscsiLun *iscsilun)
 {
     struct iscsi_context *iscsi = iscsilun->iscsi;
+    int ev;
 
-    qemu_aio_set_fd_handler(iscsi_get_fd(iscsi), iscsi_process_read,
-                           (iscsi_which_events(iscsi) & POLLOUT)
-                           ? iscsi_process_write : NULL,
-                           iscsi_process_flush, iscsilun);
+    /* Try to write as much as we can to the socket
+     * without setting up an event
+     */
+    if (iscsi_which_events(iscsi) & POLLOUT) {
+        iscsi_process_write(iscsilun);
+    }
+
+    /* We always register a read handler.  */
+    ev = POLLIN;
+    ev |= iscsi_which_events(iscsi);
+    if (ev != iscsilun->events) {
+        qemu_aio_set_fd_handler(iscsi_get_fd(iscsi),
+                      iscsi_process_read,
+                      (ev & POLLOUT) ? iscsi_process_write : NULL,
+                      iscsi_process_flush,
+                      iscsilun);
 
-    /* If we just added the event for writeable we must call
-       and the socket is already writeable the callback might
-       not be invoked until after a short delay unless we call
-       qemu_notify_event().
+    }
+
+    /* If we just added an event, the callback might be delayed
+     * unless we call qemu_notify_event().
      */
-    qemu_notify_event();
+    if (ev & ~iscsilun->events) {
+        qemu_notify_event();
+    }
+    iscsilun->events = ev;
 }
 
 static void
-- 
1.7.3.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]