From patchwork Sun Nov 9 07:42:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 408518 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 A3B5F1400B6 for ; Sun, 9 Nov 2014 18:46:29 +1100 (AEDT) Received: from localhost ([::1]:37962 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XnNCd-0005QN-QN for incoming@patchwork.ozlabs.org; Sun, 09 Nov 2014 02:46:27 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38027) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XnNA0-0001CP-Gu for qemu-devel@nongnu.org; Sun, 09 Nov 2014 02:43:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XnN9u-00014e-1Z for qemu-devel@nongnu.org; Sun, 09 Nov 2014 02:43:44 -0500 Received: from mail-pd0-f182.google.com ([209.85.192.182]:50240) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XnN9t-00014O-Sd for qemu-devel@nongnu.org; Sun, 09 Nov 2014 02:43:37 -0500 Received: by mail-pd0-f182.google.com with SMTP id fp1so5904564pdb.13 for ; Sat, 08 Nov 2014 23:43:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cjtNRLvNF7wOtVHyvzUT66bOX2zcvV2nGIZybw6zV80=; b=eSC35hcS42iUBh8J4iEaxoQbI0zatz1PBvruh9agoqEF5Vxq56ONnCNuxr1i/wkiUS M7UKSLE4zFsavtNDK02Q5E7a+4bGhNKmpLxk6BuVCcStR3EGf8nMYcEts1A8gNtn91LW XjYgcyKfnLvdrzKPmGtCLeQROTlQwYNACSJE9XbVNZP5PBqbwDN1QpikxOtXJl1Wq3eq m+fcyEFyLmA11hw2/9DRot3tNHnmWmbg/3sDqzXvKz/+Dv/8tPUUEsbGtTrTA26QQKeV ZDQ1iyq5TxiiaxaJftrOF7XopBoH3MpIrkxEeaQnvZqWu5A0KnpJVfiNs/iCbb94fBGv OCYA== X-Received: by 10.70.127.231 with SMTP id nj7mr23760324pdb.125.1415519017193; Sat, 08 Nov 2014 23:43:37 -0800 (PST) Received: from localhost ([183.14.16.86]) by mx.google.com with ESMTPSA id cf12sm13135874pdb.77.2014.11.08.23.43.36 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 08 Nov 2014 23:43:36 -0800 (PST) From: Ming Lei To: qemu-devel@nongnu.org, Peter Maydell , Paolo Bonzini , Stefan Hajnoczi , Kevin Wolf Date: Sun, 9 Nov 2014 15:42:52 +0800 Message-Id: <1415518978-2837-8-git-send-email-ming.lei@canonical.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1415518978-2837-1-git-send-email-ming.lei@canonical.com> References: <1415518978-2837-1-git-send-email-ming.lei@canonical.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.192.182 Cc: Ming Lei , Fam Zheng Subject: [Qemu-devel] [PATCH 07/13] block/linux-aio: support IO submission as batch in AioContext wide 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 This patch supports IO submission as batch in AioContext wide by sharing 'struct qemu_laio_state' instance among all linux-aio backend in same AioContext. Signed-off-by: Ming Lei --- block/linux-aio.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/block/linux-aio.c b/block/linux-aio.c index 17de2e3..c5c7944 100644 --- a/block/linux-aio.c +++ b/block/linux-aio.c @@ -52,6 +52,11 @@ typedef struct { QEMUBH *retry; } LaioQueue; +typedef struct LaioTrackedBs { + BlockDriverState *bs; + QLIST_ENTRY(LaioTrackedBs) list; +} LaioTrackedBs; + /* lifetime: between aio_attach and aio_detach */ struct qemu_laio_state { io_context_t ctx; @@ -65,6 +70,9 @@ struct qemu_laio_state { struct io_event events[MAX_EVENTS]; int event_idx; int event_max; + + /* All BS in the list shared this 'qemu_laio_state' */ + QLIST_HEAD(, LaioTrackedBs) tracked_bs; }; typedef struct { @@ -433,6 +441,23 @@ void laio_detach_aio_context(void *s_, BlockDriverState *bs, AioContext *old_context) { QemuLaioState *qs = s_; + LaioTrackedBs *tbs, *ntbs; + + QLIST_FOREACH_SAFE(tbs, &qs->state->tracked_bs, list, ntbs) { + if (tbs->bs == bs) { + QLIST_REMOVE(tbs, list); + g_free(tbs); + } + } + + if (!aio_detach_aio_bs(old_context, bs)) { + /* assign new master aio bs for the aio context */ + if (old_context->master_aio_bs == bs) { + tbs = QLIST_FIRST(&qs->state->tracked_bs); + old_context->master_aio_bs = tbs->bs; + } + return; + } laio_state_free(qs->state, old_context); qs->state = NULL; @@ -442,9 +467,16 @@ void laio_attach_aio_context(void *s_, BlockDriverState *bs, AioContext *new_context) { QemuLaioState *qs = s_; - struct qemu_laio_state *s = laio_state_alloc(new_context); + LaioTrackedBs *tbs = g_malloc0(sizeof(*tbs)); + + if (aio_attach_aio_bs(new_context, bs)) { + new_context->opaque = qs->state = laio_state_alloc(new_context); + } else { + qs->state = new_context->opaque; + } - qs->state = s; + tbs->bs = bs; + QLIST_INSERT_HEAD(&qs->state->tracked_bs, tbs, list); } void *laio_init(void)