From patchwork Fri May 25 07:43:15 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ronnie sahlberg X-Patchwork-Id: 161251 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 F35A2B6F62 for ; Fri, 25 May 2012 17:54:58 +1000 (EST) Received: from localhost ([::1]:41715 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SXpMO-00028D-GR for incoming@patchwork.ozlabs.org; Fri, 25 May 2012 03:54:56 -0400 Received: from eggs.gnu.org ([208.118.235.92]:60473) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SXpMD-0001qY-9a for qemu-devel@nongnu.org; Fri, 25 May 2012 03:54:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SXpM7-0007j8-0r for qemu-devel@nongnu.org; Fri, 25 May 2012 03:54:44 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:61936) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SXpM6-0007ha-Of for qemu-devel@nongnu.org; Fri, 25 May 2012 03:54:38 -0400 Received: by mail-pb0-f45.google.com with SMTP id ro12so1588270pbb.4 for ; Fri, 25 May 2012 00:54:37 -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=A0lryWyi1APw5mzm+K3zBHWjEslLHbiboFD+gogVpT8=; b=pzOTQ80zz0Olyvt4ZkXXjZsrxK+xkIl79I6NCCnIUcx7j+rGdHG4sDXeCBKzLh22JB /JwAYk6xeHqYcbDFjc8GY1WFnSXJcnxSNsEJpJandBKIVPA2/Suj6EUJt0vYoHZdxHJt 7CTd0/ytZXqlXYdRJd6BzgvtOlhapIkUt4e/tiBx1DPxEY4PU3KvGGdU9ibitByppPxv o8hfGBRgc4bED3ojdRLfMuFJhHGzLYGB8KRcWV+Om/wW0ZAImRZMr8vkMMiz+XwP3fD/ hUGOhi/jkuJdJNxnkDc/ZpF/iMZLI/BMpwwjQqT0shZExu9zjqICDyZjO04c70ubgI/Q sDJg== Received: by 10.68.131.38 with SMTP id oj6mr29986623pbb.39.1337932477669; Fri, 25 May 2012 00:54:37 -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 in7sm8251620pbc.23.2012.05.25.00.54.34 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 25 May 2012 00:54:37 -0700 (PDT) Received: by ronniesahlberg@gmail.com (sSMTP sendmail emulation); Fri, 25 May 2012 17:43:32 +1000 From: Ronnie Sahlberg To: kwolf@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Date: Fri, 25 May 2012 17:43:15 +1000 Message-Id: <1337931796-2660-2-git-send-email-ronniesahlberg@gmail.com> X-Mailer: git-send-email 1.7.3.1 In-Reply-To: <1337931796-2660-1-git-send-email-ronniesahlberg@gmail.com> References: <1337931796-2660-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 1/2] 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 | 56 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 46 insertions(+), 10 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index ed1ad7b..9642ee6 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -40,6 +40,8 @@ typedef struct IscsiLun { int lun; int block_size; unsigned long num_blocks; + IOHandler *read_handler; + IOHandler *write_handler; } IscsiLun; typedef struct IscsiAIOCB { @@ -105,18 +107,50 @@ static void iscsi_set_events(IscsiLun *iscsilun) { struct iscsi_context *iscsi = iscsilun->iscsi; + int need_set_fd = 0; + int need_notify_event = 0; - 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); - - /* 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(). + /* Try to write as much as we can to the socket + * without setting up an event */ - qemu_notify_event(); + if (iscsi_which_events(iscsi) & POLLOUT) { + iscsi_process_write(iscsilun); + } + + if (iscsilun->read_handler == NULL) { + iscsilun->read_handler = iscsi_process_read; + need_set_fd = 1; + need_notify_event = 1; + } + + if (iscsi_which_events(iscsi) & POLLOUT) { + if (iscsilun->write_handler == NULL) { + iscsilun->write_handler = iscsi_process_write; + need_set_fd = 1; + need_notify_event = 1; + } + } else { + if (iscsilun->write_handler != NULL) { + iscsilun->write_handler = NULL; + need_set_fd = 1; + } + } + + if (need_set_fd) { + qemu_aio_set_fd_handler(iscsi_get_fd(iscsi), + iscsilun->read_handler, + iscsilun->write_handler, + iscsi_process_flush, + iscsilun); + + /* If we just added an event that may trigger almost immediately + the callback might not be invoked until after a short + delay unless we call qemu_notify_event(). + */ + if (need_notify_event) { + qemu_notify_event(); + } + } } static void @@ -790,6 +824,8 @@ static void iscsi_close(BlockDriverState *bs) IscsiLun *iscsilun = bs->opaque; struct iscsi_context *iscsi = iscsilun->iscsi; + iscsilun->read_handler = NULL; + iscsilun->write_handler = NULL; qemu_aio_set_fd_handler(iscsi_get_fd(iscsi), NULL, NULL, NULL, NULL); iscsi_destroy_context(iscsi); memset(iscsilun, 0, sizeof(IscsiLun));