From patchwork Thu Dec 11 13:52:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 420149 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id A883F1400D5 for ; Fri, 12 Dec 2014 01:47:38 +1100 (AEDT) Received: from localhost ([::1]:51865 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xz51k-0004ml-LH for incoming@patchwork.ozlabs.org; Thu, 11 Dec 2014 09:47:36 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34963) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xz511-0003Wx-K8 for qemu-devel@nongnu.org; Thu, 11 Dec 2014 09:46:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xz50v-000482-3G for qemu-devel@nongnu.org; Thu, 11 Dec 2014 09:46:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60063) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xz50u-00047K-Rm for qemu-devel@nongnu.org; Thu, 11 Dec 2014 09:46:45 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sBBEjgCk021733 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 11 Dec 2014 09:46:36 -0500 Received: from donizetti.redhat.com (ovpn-112-79.ams2.redhat.com [10.36.112.79]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sBBDqVXM003650; Thu, 11 Dec 2014 08:52:46 -0500 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 11 Dec 2014 14:52:30 +0100 Message-Id: <1418305950-30924-6-git-send-email-pbonzini@redhat.com> In-Reply-To: <1418305950-30924-1-git-send-email-pbonzini@redhat.com> References: <1418305950-30924-1-git-send-email-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, ming.lei@canonical.com, pl@kamp.de, stefanha@redhat.com Subject: [Qemu-devel] [PATCH v2 5/5] linux-aio: simplify removal of completed iocbs from the list 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 There is no need to do another O(n) pass on the list; the iocb to split the list at is already available through the array we passed to io_submit. Signed-off-by: Paolo Bonzini --- block/linux-aio.c | 12 ++++++------ include/qemu/queue.h | 11 +++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/block/linux-aio.c b/block/linux-aio.c index 8474378..c991443 100644 --- a/block/linux-aio.c +++ b/block/linux-aio.c @@ -186,9 +186,10 @@ static void ioq_init(LaioQueue *io_q) static void ioq_submit(struct qemu_laio_state *s) { - int ret, i, len; + int ret, len; struct qemu_laiocb *aiocb; struct iocb *iocbs[MAX_QUEUED_IO]; + QSIMPLEQ_HEAD(, qemu_laiocb) completed; do { len = 0; @@ -201,16 +202,15 @@ static void ioq_submit(struct qemu_laio_state *s) ret = io_submit(s->ctx, len, iocbs); if (ret == -EAGAIN) { - ret = 0; + break; } if (ret < 0) { abort(); } - for (i = 0; i < ret; i++) { - s->io_q.n--; - QSIMPLEQ_REMOVE_HEAD(&s->io_q.pending, next); - } + s->io_q.n -= ret; + aiocb = container_of(iocbs[ret - 1], struct qemu_laiocb, iocb); + QSIMPLEQ_SPLIT_AFTER(&s->io_q.pending, aiocb, next, &completed); } while (ret == len && !QSIMPLEQ_EMPTY(&s->io_q.pending)); s->io_q.blocked = (s->io_q.n > 0); } diff --git a/include/qemu/queue.h b/include/qemu/queue.h index 0dedd29..a98eb3a 100644 --- a/include/qemu/queue.h +++ b/include/qemu/queue.h @@ -279,6 +279,17 @@ struct { \ (head)->sqh_last = &(head)->sqh_first; \ } while (/*CONSTCOND*/0) +#define QSIMPLEQ_SPLIT_AFTER(head, elm, field, removed) do { \ + QSIMPLEQ_INIT(removed); \ + if (((removed)->sqh_first = (head)->sqh_first) != NULL) { \ + if (((head)->sqh_first = (elm)->field.sqe_next) == NULL) { \ + (head)->sqh_last = &(head)->sqh_first; \ + } \ + (removed)->sqh_last = &(elm)->field.sqe_next; \ + (elm)->field.sqe_next = NULL; \ + } \ +} while (/*CONSTCOND*/0) + #define QSIMPLEQ_REMOVE(head, elm, type, field) do { \ if ((head)->sqh_first == (elm)) { \ QSIMPLEQ_REMOVE_HEAD((head), field); \