Skip to contentSkip to conversation

ISCSI: Optimize how we set up the events

PATCH Applied Ronnie Sahlberg 2 participants 3 messages May 25, 2012 Block layer

lore
Share & tools
lore
#0 lore raw

cover ISCSI: Optimize how we set up the events

Paolo,

Please find an updated patch that implements your suggestion.

This patch updates how iscsi sets up the read and write events so that we only call qemu_aio_set_fd_handler() and qemu_notify_event() when we actually need to.

regards
ronnie sahlberg

#1 lore raw

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

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.

---
 block/iscsi.c |   37 +++++++++++++++++++++++++++----------
 1 files changed, 27 insertions(+), 10 deletions(-)
block/iscsi.c +26 -9
index ed1ad7b..d710b86 100644
@@ -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
Signature · 1 line
1.7.3.1
#2 lore raw
In reply to Ronnie Sahlberg

Il 25/05/2012 12:25, Ronnie Sahlberg ha scritto:

Quoted 3 lines

This patch updates how iscsi sets up the read and write events so that we only call qemu_aio_set_fd_handler() and qemu_notify_event() when we actually need to.

Applied, thanks.

Paolo