From patchwork Fri May 25 10:25:12 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ronnie sahlberg X-Patchwork-Id: 161277 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 522DBB6F6E for ; Fri, 25 May 2012 20:37:17 +1000 (EST) Received: from localhost ([::1]:51923 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SXrtT-0002LJ-5d for incoming@patchwork.ozlabs.org; Fri, 25 May 2012 06:37:15 -0400 Received: from eggs.gnu.org ([208.118.235.92]:38553) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SXrtG-0001xu-Kc for qemu-devel@nongnu.org; Fri, 25 May 2012 06:37:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SXrtA-0004hG-BW for qemu-devel@nongnu.org; Fri, 25 May 2012 06:37:02 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:35244) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SXrtA-0004gp-2m for qemu-devel@nongnu.org; Fri, 25 May 2012 06:36:56 -0400 Received: by pbbro12 with SMTP id ro12so1777722pbb.4 for ; Fri, 25 May 2012 03:36:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=5r0zgitmiMg0tV5rczpWvdrJXPLNFjwjQLM6HlkqPg8=; b=hzMhakDd07jj0YzwyN0bSaNw0LFkFlv5TF31u2EbaUIJ65NIkdtG0MbOW7BGxgabGZ c1bvgmssM+bgjzJtUDQY7W4G1NaxPr8w7ON9b9i3xnUgKqTmEyneO9m29YHKG6Alf2kh BLLYHm1hbGNCzAVERbG2VmC0QUxrbajm6hqq8h5w4lVsSzwYZUW6AK53XH2GDaa+V7YH Q/A6SBHvdTQkjeO8UoYrruG2RYnApkGMekNGPOPamKNKpZ3gumN2k1uyYTRgSDH528R/ x7pVqaAExMHazsayTlIYUZaAOarIjCxDiYaLIEl+suMucP7ZjxIBICi5PdXcAQ8R593i 3ZQg== Received: by 10.68.232.73 with SMTP id tm9mr28129377pbc.43.1337942213878; Fri, 25 May 2012 03:36:53 -0700 (PDT) Received: from ronniesahlberg@gmail.com (CPE-138-130-106-226.lns3.cht.bigpond.net.au. [138.130.106.226]) by mx.google.com with ESMTPS id wo8sm8676705pbc.9.2012.05.25.03.36.50 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 25 May 2012 03:36:53 -0700 (PDT) Received: by ronniesahlberg@gmail.com (sSMTP sendmail emulation); Fri, 25 May 2012 20:25:34 +1000 From: Ronnie Sahlberg To: pbonzini@redhat.com, qemu-devel@nongnu.org Date: Fri, 25 May 2012 20:25:12 +1000 Message-Id: <1337941512-10091-2-git-send-email-ronniesahlberg@gmail.com> X-Mailer: git-send-email 1.7.3.1 In-Reply-To: <1337941512-10091-1-git-send-email-ronniesahlberg@gmail.com> References: <1337941512-10091-1-git-send-email-ronniesahlberg@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.45 Cc: 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. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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