qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Ronnie Sahlberg <ronniesahlberg@gmail.com>
To: pbonzini@redhat.com, qemu-devel@nongnu.org
Cc: Ronnie Sahlberg <ronniesahlberg@gmail.com>
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	[thread overview]
Message-ID: <1337941512-10091-2-git-send-email-ronniesahlberg@gmail.com> (raw)
In-Reply-To: <1337941512-10091-1-git-send-email-ronniesahlberg@gmail.com>

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

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	other threads:[~2012-05-25 10:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-25 10:25 [Qemu-devel] [PATCH 0/1] ISCSI: Optimize how we set up the events Ronnie Sahlberg
2012-05-25 10:25 ` Ronnie Sahlberg [this message]
2012-05-25 11:12 ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1337941512-10091-2-git-send-email-ronniesahlberg@gmail.com \
    --to=ronniesahlberg@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).