From nobody Tue Oct 22 23:34:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1684862047; cv=none; d=zohomail.com; s=zohoarc; b=JsN6dGuFusj4bkYmZwBw6Kz/REvDw/arvto83VZSJze2TJsD5CjuklOV2OKGJyKEp6SBIlC3FYN0aSByYC80Wj5EvVeEapGIctF66WsCkiXapP0JgmXgDtpWiUnh63DRzy+Sq1ezj1b4587E3o6FeV4RzHzJRQDn8bspx9UVTWc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684862047; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3FPGvS4E8XhJl458NpT+4AaqENtWEqDNIS9t7Nd8CmQ=; b=dBf94CNTJb08723oZjKse4AdVPDwisYCpNLJCLktpGxd5vGLUxAwN/xoAHFCxUVKx8Dp6xWQMfpiM/ualPmtumfQW1pOxjQd472afjo1Br2i/K66f5O2YwS36gsxdbkFmA02zA5zcHPVOss5puUTBkJtYYCT404jegBIezCtgYw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1684862046986932.8380693062257; Tue, 23 May 2023 10:14:06 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.538637.838795 (Exim 4.92) (envelope-from ) id 1q1VZa-0004bW-5g; Tue, 23 May 2023 17:13:22 +0000 Received: by outflank-mailman (output) from mailman id 538637.838795; Tue, 23 May 2023 17:13:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q1VZa-0004b5-16; Tue, 23 May 2023 17:13:22 +0000 Received: by outflank-mailman (input) for mailman id 538637; Tue, 23 May 2023 17:13:21 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q1VZY-0003JO-Tv for xen-devel@lists.xenproject.org; Tue, 23 May 2023 17:13:20 +0000 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 1c7d71b6-f98d-11ed-8611-37d641c3527e; Tue, 23 May 2023 19:13:19 +0200 (CEST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-179-gp84_tuxOQSN9WPS2-uenQ-1; Tue, 23 May 2023 13:13:16 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 60B711C08784; Tue, 23 May 2023 17:13:15 +0000 (UTC) Received: from localhost (unknown [10.39.195.107]) by smtp.corp.redhat.com (Postfix) with ESMTP id D1EC01121314; Tue, 23 May 2023 17:13:14 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 1c7d71b6-f98d-11ed-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684861998; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3FPGvS4E8XhJl458NpT+4AaqENtWEqDNIS9t7Nd8CmQ=; b=EesUVfQ6n503Cqx9uB61hT85qWlbV6147STBzL37tFf+/mOxvLmibMY1x6vbPgh0R7ANdr 7NXwvrQpTF8FvHXbiMb0R6furkNFjl+7ipDP3M2xEZb+FGboD/iVXuYpcfrkdxhceJkfVU 2LCUu3IiaR0N88ylnZo4bVHLnr7un94= X-MC-Unique: gp84_tuxOQSN9WPS2-uenQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Aarushi Mehta , "Michael S. Tsirkin" , Stefano Garzarella , Julia Suvorova , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefano Stabellini , Paul Durrant , Hanna Reitz , Kevin Wolf , Fam Zheng , Stefan Hajnoczi , xen-devel@lists.xenproject.org, eblake@redhat.com, Anthony Perard , qemu-block@nongnu.org Subject: [PATCH v2 5/6] block/linux-aio: convert to blk_io_plug_call() API Date: Tue, 23 May 2023 13:12:59 -0400 Message-Id: <20230523171300.132347-6-stefanha@redhat.com> In-Reply-To: <20230523171300.132347-1-stefanha@redhat.com> References: <20230523171300.132347-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1684862047394100004 Content-Type: text/plain; charset="utf-8" Stop using the .bdrv_co_io_plug() API because it is not multi-queue block layer friendly. Use the new blk_io_plug_call() API to batch I/O submission instead. Signed-off-by: Stefan Hajnoczi Reviewed-by: Eric Blake --- include/block/raw-aio.h | 7 ------- block/file-posix.c | 28 ---------------------------- block/linux-aio.c | 41 +++++++++++------------------------------ 3 files changed, 11 insertions(+), 65 deletions(-) diff --git a/include/block/raw-aio.h b/include/block/raw-aio.h index da60ca13ef..0f63c2800c 100644 --- a/include/block/raw-aio.h +++ b/include/block/raw-aio.h @@ -62,13 +62,6 @@ int coroutine_fn laio_co_submit(int fd, uint64_t offset,= QEMUIOVector *qiov, =20 void laio_detach_aio_context(LinuxAioState *s, AioContext *old_context); void laio_attach_aio_context(LinuxAioState *s, AioContext *new_context); - -/* - * laio_io_plug/unplug work in the thread's current AioContext, therefore = the - * caller must ensure that they are paired in the same IOThread. - */ -void laio_io_plug(void); -void laio_io_unplug(uint64_t dev_max_batch); #endif /* io_uring.c - Linux io_uring implementation */ #ifdef CONFIG_LINUX_IO_URING diff --git a/block/file-posix.c b/block/file-posix.c index 7baa8491dd..ac1ed54811 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2550,26 +2550,6 @@ static int coroutine_fn raw_co_pwritev(BlockDriverSt= ate *bs, int64_t offset, return raw_co_prw(bs, offset, bytes, qiov, QEMU_AIO_WRITE); } =20 -static void coroutine_fn raw_co_io_plug(BlockDriverState *bs) -{ - BDRVRawState __attribute__((unused)) *s =3D bs->opaque; -#ifdef CONFIG_LINUX_AIO - if (s->use_linux_aio) { - laio_io_plug(); - } -#endif -} - -static void coroutine_fn raw_co_io_unplug(BlockDriverState *bs) -{ - BDRVRawState __attribute__((unused)) *s =3D bs->opaque; -#ifdef CONFIG_LINUX_AIO - if (s->use_linux_aio) { - laio_io_unplug(s->aio_max_batch); - } -#endif -} - static int coroutine_fn raw_co_flush_to_disk(BlockDriverState *bs) { BDRVRawState *s =3D bs->opaque; @@ -3914,8 +3894,6 @@ BlockDriver bdrv_file =3D { .bdrv_co_copy_range_from =3D raw_co_copy_range_from, .bdrv_co_copy_range_to =3D raw_co_copy_range_to, .bdrv_refresh_limits =3D raw_refresh_limits, - .bdrv_co_io_plug =3D raw_co_io_plug, - .bdrv_co_io_unplug =3D raw_co_io_unplug, .bdrv_attach_aio_context =3D raw_aio_attach_aio_context, =20 .bdrv_co_truncate =3D raw_co_truncate, @@ -4286,8 +4264,6 @@ static BlockDriver bdrv_host_device =3D { .bdrv_co_copy_range_from =3D raw_co_copy_range_from, .bdrv_co_copy_range_to =3D raw_co_copy_range_to, .bdrv_refresh_limits =3D raw_refresh_limits, - .bdrv_co_io_plug =3D raw_co_io_plug, - .bdrv_co_io_unplug =3D raw_co_io_unplug, .bdrv_attach_aio_context =3D raw_aio_attach_aio_context, =20 .bdrv_co_truncate =3D raw_co_truncate, @@ -4424,8 +4400,6 @@ static BlockDriver bdrv_host_cdrom =3D { .bdrv_co_pwritev =3D raw_co_pwritev, .bdrv_co_flush_to_disk =3D raw_co_flush_to_disk, .bdrv_refresh_limits =3D cdrom_refresh_limits, - .bdrv_co_io_plug =3D raw_co_io_plug, - .bdrv_co_io_unplug =3D raw_co_io_unplug, .bdrv_attach_aio_context =3D raw_aio_attach_aio_context, =20 .bdrv_co_truncate =3D raw_co_truncate, @@ -4552,8 +4526,6 @@ static BlockDriver bdrv_host_cdrom =3D { .bdrv_co_pwritev =3D raw_co_pwritev, .bdrv_co_flush_to_disk =3D raw_co_flush_to_disk, .bdrv_refresh_limits =3D cdrom_refresh_limits, - .bdrv_co_io_plug =3D raw_co_io_plug, - .bdrv_co_io_unplug =3D raw_co_io_unplug, .bdrv_attach_aio_context =3D raw_aio_attach_aio_context, =20 .bdrv_co_truncate =3D raw_co_truncate, diff --git a/block/linux-aio.c b/block/linux-aio.c index 442c86209b..5021aed68f 100644 --- a/block/linux-aio.c +++ b/block/linux-aio.c @@ -15,6 +15,7 @@ #include "qemu/event_notifier.h" #include "qemu/coroutine.h" #include "qapi/error.h" +#include "sysemu/block-backend.h" =20 /* Only used for assertions. */ #include "qemu/coroutine_int.h" @@ -46,7 +47,6 @@ struct qemu_laiocb { }; =20 typedef struct { - int plugged; unsigned int in_queue; unsigned int in_flight; bool blocked; @@ -236,7 +236,7 @@ static void qemu_laio_process_completions_and_submit(Li= nuxAioState *s) { qemu_laio_process_completions(s); =20 - if (!s->io_q.plugged && !QSIMPLEQ_EMPTY(&s->io_q.pending)) { + if (!QSIMPLEQ_EMPTY(&s->io_q.pending)) { ioq_submit(s); } } @@ -277,7 +277,6 @@ static void qemu_laio_poll_ready(EventNotifier *opaque) static void ioq_init(LaioQueue *io_q) { QSIMPLEQ_INIT(&io_q->pending); - io_q->plugged =3D 0; io_q->in_queue =3D 0; io_q->in_flight =3D 0; io_q->blocked =3D false; @@ -354,31 +353,11 @@ static uint64_t laio_max_batch(LinuxAioState *s, uint= 64_t dev_max_batch) return max_batch; } =20 -void laio_io_plug(void) +static void laio_unplug_fn(void *opaque) { - AioContext *ctx =3D qemu_get_current_aio_context(); - LinuxAioState *s =3D aio_get_linux_aio(ctx); + LinuxAioState *s =3D opaque; =20 - s->io_q.plugged++; -} - -void laio_io_unplug(uint64_t dev_max_batch) -{ - AioContext *ctx =3D qemu_get_current_aio_context(); - LinuxAioState *s =3D aio_get_linux_aio(ctx); - - assert(s->io_q.plugged); - s->io_q.plugged--; - - /* - * Why max batch checking is performed here: - * Another BDS may have queued requests with a higher dev_max_batch and - * therefore in_queue could now exceed our dev_max_batch. Re-check the= max - * batch so we can honor our device's dev_max_batch. - */ - if (s->io_q.in_queue >=3D laio_max_batch(s, dev_max_batch) || - (!s->io_q.plugged && - !s->io_q.blocked && !QSIMPLEQ_EMPTY(&s->io_q.pending))) { + if (!s->io_q.blocked && !QSIMPLEQ_EMPTY(&s->io_q.pending)) { ioq_submit(s); } } @@ -410,10 +389,12 @@ static int laio_do_submit(int fd, struct qemu_laiocb = *laiocb, off_t offset, =20 QSIMPLEQ_INSERT_TAIL(&s->io_q.pending, laiocb, next); s->io_q.in_queue++; - if (!s->io_q.blocked && - (!s->io_q.plugged || - s->io_q.in_queue >=3D laio_max_batch(s, dev_max_batch))) { - ioq_submit(s); + if (!s->io_q.blocked) { + if (s->io_q.in_queue >=3D laio_max_batch(s, dev_max_batch)) { + ioq_submit(s); + } else { + blk_io_plug_call(laio_unplug_fn, s); + } } =20 return 0; --=20 2.40.1