From patchwork Fri Dec 12 17:10:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 420605 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 EA6F51400E9 for ; Sat, 13 Dec 2014 04:20:23 +1100 (AEDT) Received: from localhost ([::1]:58665 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XzTt8-0005YA-3h for incoming@patchwork.ozlabs.org; Fri, 12 Dec 2014 12:20:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53295) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XzTk5-0006Y7-O0 for qemu-devel@nongnu.org; Fri, 12 Dec 2014 12:11:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XzTjz-0004Lc-Jo for qemu-devel@nongnu.org; Fri, 12 Dec 2014 12:11:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35431) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XzTjz-0004LN-Cr for qemu-devel@nongnu.org; Fri, 12 Dec 2014 12:10:55 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sBCHArD8005337 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 12 Dec 2014 12:10:53 -0500 Received: from localhost (ovpn-112-32.ams2.redhat.com [10.36.112.32]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sBCHAonY007142; Fri, 12 Dec 2014 12:10:52 -0500 From: Stefan Hajnoczi To: Date: Fri, 12 Dec 2014 17:10:05 +0000 Message-Id: <1418404205-6213-20-git-send-email-stefanha@redhat.com> In-Reply-To: <1418404205-6213-1-git-send-email-stefanha@redhat.com> References: <1418404205-6213-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Peter Maydell , Stefan Hajnoczi , Paolo Bonzini Subject: [Qemu-devel] [PULL 19/19] 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 From: Paolo Bonzini 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 Reviewed-by: Kevin Wolf Message-id: 1418305950-30924-6-git-send-email-pbonzini@redhat.com Signed-off-by: Stefan Hajnoczi --- 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 d433b90..42bcadf 100644 --- a/include/qemu/queue.h +++ b/include/qemu/queue.h @@ -268,6 +268,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); \