Patchwork ISCSI: redo how we set up the events to only call qemu_aio_set_fd_handler() and qemu_notify_event() if something has changed.

login
register
mail settings
Submitter ronniesahlberg@gmail.com
Date May 25, 2012, 10:25 a.m.
Message ID <1337941512-10091-2-git-send-email-ronniesahlberg@gmail.com>
Download mbox | patch
Permalink /patch/161277/
State New
Headers show

Comments

ronniesahlberg@gmail.com - May 25, 2012, 10:25 a.m.
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 <ronniesahlberg@gmail.com>
---
 block/iscsi.c |   37 +++++++++++++++++++++++++++----------
 1 files changed, 27 insertions(+), 10 deletions(-)

Patch

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