From nobody Sat May 18 12:12:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1666959876; cv=none; d=zohomail.com; s=zohoarc; b=Mm2sSfzmPgkb1V2V9zjav3ejFsV65PuvXZ6et0ofnUrf2IpuduZUww+Y/sqYvgn4Owe37gwPhXPfZdp50sm5tORCbIUlLTJDj+OXhOZto3Atbjp2Gozz4/WgGpv1QnMKopNA8LjdmWLmnmivTzscQ7tdnB0deSJT3MlOTwKTJHY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666959876; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=g80FP4D8ugP/YCsna8FvlwK9It1bTW0WWcKqMvoYIe8=; b=ktY/QsuYlBFY89Y79wlH+R2lNMiOuEoYYDoziB/PT+PsSjK3tltLloSe508tITDLVJlnnIhrQ7pHjry4Qayz86sREGtkVZ4ADRD8tcSMZCmDQ/SRU31JApsm/mQ7Y2iwUYnhu7lb82elnJlStvOgyLom7ImdHQ5/fJd1MsOx/+8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1666959876172536.2871764634558; Fri, 28 Oct 2022 05:24:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ooONG-0004lt-Fq; Fri, 28 Oct 2022 08:22:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ooOME-0004FG-8k for qemu-devel@nongnu.org; Fri, 28 Oct 2022 08:21:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ooOM4-00025p-NK for qemu-devel@nongnu.org; Fri, 28 Oct 2022 08:20:59 -0400 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-537-q48yxflnPtO7sMfNqSTWVg-1; Fri, 28 Oct 2022 08:20:52 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E92FD381459E; Fri, 28 Oct 2022 12:20:51 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 94C5740C206B; Fri, 28 Oct 2022 12:20:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666959655; 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=g80FP4D8ugP/YCsna8FvlwK9It1bTW0WWcKqMvoYIe8=; b=h/vIbi7dE1+3Ogz+Z23nV4njQ+9UsC7V7usYvUp1QpGQLWZVcX8xHrCkNcE/qQJMwzfyzc Ap2nEbWykzpV4mv67O6j63XIPBL1DKP2fdBTOiWJtSc/S5mFLGpAaUCbZEjRk6SDP+LyoQ WkK/N2hFbmNIpZIAGMlIJKDMVm2EtWQ= X-MC-Unique: q48yxflnPtO7sMfNqSTWVg-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Hanna Reitz , Stefan Weil , Aarushi Mehta , Julia Suvorova , Stefan Hajnoczi , Stefano Garzarella , Fam Zheng , qemu-devel@nongnu.org, Paolo Bonzini , Emanuele Giuseppe Esposito Subject: [PATCH v3 1/3] linux-aio: use LinuxAioState from the running thread Date: Fri, 28 Oct 2022 08:20:46 -0400 Message-Id: <20221028122048.3101120-2-eesposit@redhat.com> In-Reply-To: <20221028122048.3101120-1-eesposit@redhat.com> References: <20221028122048.3101120-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.516, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666959877738100003 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Remove usage of aio_context_acquire by always submitting asynchronous AIO to the current thread's LinuxAioState. In order to prevent mistakes from the caller side, avoid passing LinuxAioSt= ate in laio_io_{plug/unplug} and laio_co_submit. Signed-off-by: Paolo Bonzini Signed-off-by: Emanuele Giuseppe Esposito --- block/file-posix.c | 10 +++------- block/linux-aio.c | 30 +++++++++++++++++------------- include/block/aio.h | 4 ---- include/block/raw-aio.h | 10 ++++------ 4 files changed, 24 insertions(+), 30 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 23acffb9a4..23fe98eb3e 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2099,10 +2099,8 @@ static int coroutine_fn raw_co_prw(BlockDriverState = *bs, uint64_t offset, #endif #ifdef CONFIG_LINUX_AIO } else if (s->use_linux_aio) { - LinuxAioState *aio =3D aio_get_linux_aio(bdrv_get_aio_context(bs)); assert(qiov->size =3D=3D bytes); - return laio_co_submit(bs, aio, s->fd, offset, qiov, type, - s->aio_max_batch); + return laio_co_submit(s->fd, offset, qiov, type, s->aio_max_batch); #endif } =20 @@ -2142,8 +2140,7 @@ static void raw_aio_plug(BlockDriverState *bs) BDRVRawState __attribute__((unused)) *s =3D bs->opaque; #ifdef CONFIG_LINUX_AIO if (s->use_linux_aio) { - LinuxAioState *aio =3D aio_get_linux_aio(bdrv_get_aio_context(bs)); - laio_io_plug(bs, aio); + laio_io_plug(); } #endif #ifdef CONFIG_LINUX_IO_URING @@ -2159,8 +2156,7 @@ static void raw_aio_unplug(BlockDriverState *bs) BDRVRawState __attribute__((unused)) *s =3D bs->opaque; #ifdef CONFIG_LINUX_AIO if (s->use_linux_aio) { - LinuxAioState *aio =3D aio_get_linux_aio(bdrv_get_aio_context(bs)); - laio_io_unplug(bs, aio, s->aio_max_batch); + laio_io_unplug(s->aio_max_batch); } #endif #ifdef CONFIG_LINUX_IO_URING diff --git a/block/linux-aio.c b/block/linux-aio.c index d2cfb7f523..ce41d19e1e 100644 --- a/block/linux-aio.c +++ b/block/linux-aio.c @@ -16,6 +16,9 @@ #include "qemu/coroutine.h" #include "qapi/error.h" =20 +/* Only used for assertions. */ +#include "qemu/coroutine_int.h" + #include =20 /* @@ -56,10 +59,8 @@ struct LinuxAioState { io_context_t ctx; EventNotifier e; =20 - /* io queue for submit at batch. Protected by AioContext lock. */ + /* All data is only used in one I/O thread. */ LaioQueue io_q; - - /* I/O completion processing. Only runs in I/O thread. */ QEMUBH *completion_bh; int event_idx; int event_max; @@ -102,6 +103,7 @@ static void qemu_laio_process_completion(struct qemu_la= iocb *laiocb) * later. Coroutines cannot be entered recursively so avoid doing * that! */ + assert(laiocb->co->ctx =3D=3D laiocb->ctx->aio_context); if (!qemu_coroutine_entered(laiocb->co)) { aio_co_wake(laiocb->co); } @@ -232,13 +234,11 @@ static void qemu_laio_process_completions(LinuxAioSta= te *s) =20 static void qemu_laio_process_completions_and_submit(LinuxAioState *s) { - aio_context_acquire(s->aio_context); qemu_laio_process_completions(s); =20 if (!s->io_q.plugged && !QSIMPLEQ_EMPTY(&s->io_q.pending)) { ioq_submit(s); } - aio_context_release(s->aio_context); } =20 static void qemu_laio_completion_bh(void *opaque) @@ -354,14 +354,18 @@ static uint64_t laio_max_batch(LinuxAioState *s, uint= 64_t dev_max_batch) return max_batch; } =20 -void laio_io_plug(BlockDriverState *bs, LinuxAioState *s) -{ +void laio_io_plug(void){ + AioContext *ctx =3D qemu_get_current_aio_context(); + LinuxAioState *s =3D aio_get_linux_aio(ctx); + s->io_q.plugged++; } =20 -void laio_io_unplug(BlockDriverState *bs, LinuxAioState *s, - uint64_t dev_max_batch) +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--; =20 @@ -411,15 +415,15 @@ static int laio_do_submit(int fd, struct qemu_laiocb = *laiocb, off_t offset, return 0; } =20 -int coroutine_fn laio_co_submit(BlockDriverState *bs, LinuxAioState *s, in= t fd, - uint64_t offset, QEMUIOVector *qiov, int t= ype, - uint64_t dev_max_batch) +int coroutine_fn laio_co_submit(int fd, uint64_t offset, QEMUIOVector *qio= v, + int type, uint64_t dev_max_batch) { int ret; + AioContext *ctx =3D qemu_get_current_aio_context(); struct qemu_laiocb laiocb =3D { .co =3D qemu_coroutine_self(), .nbytes =3D qiov->size, - .ctx =3D s, + .ctx =3D aio_get_linux_aio(ctx), .ret =3D -EINPROGRESS, .is_read =3D (type =3D=3D QEMU_AIO_READ), .qiov =3D qiov, diff --git a/include/block/aio.h b/include/block/aio.h index d128558f1d..8bb5eea4a9 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -200,10 +200,6 @@ struct AioContext { struct ThreadPool *thread_pool; =20 #ifdef CONFIG_LINUX_AIO - /* - * State for native Linux AIO. Uses aio_context_acquire/release for - * locking. - */ struct LinuxAioState *linux_aio; #endif #ifdef CONFIG_LINUX_IO_URING diff --git a/include/block/raw-aio.h b/include/block/raw-aio.h index 21fc10c4c9..f0f14f14f8 100644 --- a/include/block/raw-aio.h +++ b/include/block/raw-aio.h @@ -50,14 +50,12 @@ typedef struct LinuxAioState LinuxAioState; LinuxAioState *laio_init(Error **errp); void laio_cleanup(LinuxAioState *s); -int coroutine_fn laio_co_submit(BlockDriverState *bs, LinuxAioState *s, in= t fd, - uint64_t offset, QEMUIOVector *qiov, int t= ype, - uint64_t dev_max_batch); +int coroutine_fn laio_co_submit(int fd, uint64_t offset, QEMUIOVector *qio= v, + int type, uint64_t dev_max_batch); void laio_detach_aio_context(LinuxAioState *s, AioContext *old_context); void laio_attach_aio_context(LinuxAioState *s, AioContext *new_context); -void laio_io_plug(BlockDriverState *bs, LinuxAioState *s); -void laio_io_unplug(BlockDriverState *bs, LinuxAioState *s, - uint64_t dev_max_batch); +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 --=20 2.31.1 From nobody Sat May 18 12:12:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1666959880; cv=none; d=zohomail.com; s=zohoarc; b=j3Wg4hzSlKOCqPDW14nobVjUTeI3/cyebO92eR7L8rJgoLFNQsSTmhlXq29soacS+5abVWL5UbZ/BC+p5ZLqYJFowiatSw/PyTM0VZx98wmYy08pXWd0Re7dAY9VmYvrjuyzo2Hb3viR93Ad1SVvOChAn8ZJR9k1fbsrnQXfzks= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666959880; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SRKzARE86crNB/IkE//qDoRbvLcHgSkM1cN4gHuEkNY=; b=McSPS+kUD3Mv4KjJepHRjm+lBbEGTLUoEfIbaP2ZoJoCBN4jtMe5Ul4A66liapng/N5mub8wrS5qLD0lu6a3J0Sgt+XDgCTQy1CoI7M1so9pK4j6x4xqAcl+8IRiln3otwxBlDzIhR5MBinU8/QQCTfYEc4PmSdQR03YEqYTk7I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1666959880777724.1216863246725; Fri, 28 Oct 2022 05:24:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ooONH-0004nT-Nf; Fri, 28 Oct 2022 08:22:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ooOMJ-0004Fm-2Z for qemu-devel@nongnu.org; Fri, 28 Oct 2022 08:21:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ooOMD-00026h-RN for qemu-devel@nongnu.org; Fri, 28 Oct 2022 08:21:09 -0400 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-571-FATGxcJUML2Mk6UIh05V8w-1; Fri, 28 Oct 2022 08:20:52 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4E5873C0F243; Fri, 28 Oct 2022 12:20:52 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id F2AF040C206B; Fri, 28 Oct 2022 12:20:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666959660; 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=SRKzARE86crNB/IkE//qDoRbvLcHgSkM1cN4gHuEkNY=; b=OePuxIhsTCK0mYzVSBYvUW1XHhZHfu7YG/rUgnypS2qEY3JHgF4FTnrSW9KkmRbMSwlIIa h4mP53M3v7XUn6677cpJS2e8GnIB485Abyuv5g9tzS7yVt6O+2p2LnNMFiU94GhOaLfy7G jL969yuoa65x7mL3wBqA1wB2REuvGAA= X-MC-Unique: FATGxcJUML2Mk6UIh05V8w-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Hanna Reitz , Stefan Weil , Aarushi Mehta , Julia Suvorova , Stefan Hajnoczi , Stefano Garzarella , Fam Zheng , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito Subject: [PATCH v3 2/3] io_uring: use LuringState from the running thread Date: Fri, 28 Oct 2022 08:20:47 -0400 Message-Id: <20221028122048.3101120-3-eesposit@redhat.com> In-Reply-To: <20221028122048.3101120-1-eesposit@redhat.com> References: <20221028122048.3101120-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.516, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666959881596100001 Content-Type: text/plain; charset="utf-8" Remove usage of aio_context_acquire by always submitting asynchronous AIO to the current thread's LuringState. In order to prevent mistakes from the caller side, avoid passing LuringState in luring_io_{plug/unplug} and luring_co_submit. Signed-off-by: Emanuele Giuseppe Esposito --- block/file-posix.c | 12 ++++-------- block/io_uring.c | 22 ++++++++++++++-------- include/block/aio.h | 4 ---- include/block/raw-aio.h | 8 ++++---- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 23fe98eb3e..3800dbd222 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2093,9 +2093,8 @@ static int coroutine_fn raw_co_prw(BlockDriverState *= bs, uint64_t offset, type |=3D QEMU_AIO_MISALIGNED; #ifdef CONFIG_LINUX_IO_URING } else if (s->use_linux_io_uring) { - LuringState *aio =3D aio_get_linux_io_uring(bdrv_get_aio_context(b= s)); assert(qiov->size =3D=3D bytes); - return luring_co_submit(bs, aio, s->fd, offset, qiov, type); + return luring_co_submit(bs, s->fd, offset, qiov, type); #endif #ifdef CONFIG_LINUX_AIO } else if (s->use_linux_aio) { @@ -2145,8 +2144,7 @@ static void raw_aio_plug(BlockDriverState *bs) #endif #ifdef CONFIG_LINUX_IO_URING if (s->use_linux_io_uring) { - LuringState *aio =3D aio_get_linux_io_uring(bdrv_get_aio_context(b= s)); - luring_io_plug(bs, aio); + luring_io_plug(); } #endif } @@ -2161,8 +2159,7 @@ static void raw_aio_unplug(BlockDriverState *bs) #endif #ifdef CONFIG_LINUX_IO_URING if (s->use_linux_io_uring) { - LuringState *aio =3D aio_get_linux_io_uring(bdrv_get_aio_context(b= s)); - luring_io_unplug(bs, aio); + luring_io_unplug(); } #endif } @@ -2186,8 +2183,7 @@ static int coroutine_fn raw_co_flush_to_disk(BlockDri= verState *bs) =20 #ifdef CONFIG_LINUX_IO_URING if (s->use_linux_io_uring) { - LuringState *aio =3D aio_get_linux_io_uring(bdrv_get_aio_context(b= s)); - return luring_co_submit(bs, aio, s->fd, 0, NULL, QEMU_AIO_FLUSH); + return luring_co_submit(bs, s->fd, 0, NULL, QEMU_AIO_FLUSH); } #endif return raw_thread_pool_submit(bs, handle_aiocb_flush, &acb); diff --git a/block/io_uring.c b/block/io_uring.c index a1760152e0..df1f076cb9 100644 --- a/block/io_uring.c +++ b/block/io_uring.c @@ -19,6 +19,8 @@ #include "qapi/error.h" #include "trace.h" =20 +/* Only used for assertions. */ +#include "qemu/coroutine_int.h" =20 /* io_uring ring size */ #define MAX_ENTRIES 128 @@ -52,10 +54,9 @@ typedef struct LuringState { =20 struct io_uring ring; =20 - /* io queue for submit at batch. Protected by AioContext lock. */ + /* All data is only used in one I/O thread. */ LuringQueue io_q; =20 - /* I/O completion processing. Only runs in I/O thread. */ QEMUBH *completion_bh; } LuringState; =20 @@ -211,6 +212,7 @@ end: * eventually runs later. Coroutines cannot be entered recursively * so avoid doing that! */ + assert(luringcb->co->ctx =3D=3D luringcb->aio_context); if (!qemu_coroutine_entered(luringcb->co)) { aio_co_wake(luringcb->co); } @@ -264,13 +266,11 @@ static int ioq_submit(LuringState *s) =20 static void luring_process_completions_and_submit(LuringState *s) { - aio_context_acquire(s->aio_context); luring_process_completions(s); =20 if (!s->io_q.plugged && s->io_q.in_queue > 0) { ioq_submit(s); } - aio_context_release(s->aio_context); } =20 static void qemu_luring_completion_bh(void *opaque) @@ -308,14 +308,18 @@ static void ioq_init(LuringQueue *io_q) io_q->blocked =3D false; } =20 -void luring_io_plug(BlockDriverState *bs, LuringState *s) +void luring_io_plug(void) { + AioContext *ctx =3D qemu_get_current_aio_context(); + LuringState *s =3D aio_get_linux_io_uring(ctx); trace_luring_io_plug(s); s->io_q.plugged++; } =20 -void luring_io_unplug(BlockDriverState *bs, LuringState *s) +void luring_io_unplug(void) { + AioContext *ctx =3D qemu_get_current_aio_context(); + LuringState *s =3D aio_get_linux_io_uring(ctx); assert(s->io_q.plugged); trace_luring_io_unplug(s, s->io_q.blocked, s->io_q.plugged, s->io_q.in_queue, s->io_q.in_flight); @@ -375,10 +379,12 @@ static int luring_do_submit(int fd, LuringAIOCB *luri= ngcb, LuringState *s, return 0; } =20 -int coroutine_fn luring_co_submit(BlockDriverState *bs, LuringState *s, in= t fd, - uint64_t offset, QEMUIOVector *qiov, int= type) +int coroutine_fn luring_co_submit(BlockDriverState *bs, int fd, uint64_t o= ffset, + QEMUIOVector *qiov, int type) { int ret; + AioContext *ctx =3D qemu_get_current_aio_context(); + LuringState *s =3D aio_get_linux_io_uring(ctx); LuringAIOCB luringcb =3D { .co =3D qemu_coroutine_self(), .ret =3D -EINPROGRESS, diff --git a/include/block/aio.h b/include/block/aio.h index 8bb5eea4a9..15375ff63a 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -203,10 +203,6 @@ struct AioContext { struct LinuxAioState *linux_aio; #endif #ifdef CONFIG_LINUX_IO_URING - /* - * State for Linux io_uring. Uses aio_context_acquire/release for - * locking. - */ struct LuringState *linux_io_uring; =20 /* State for file descriptor monitoring using Linux io_uring */ diff --git a/include/block/raw-aio.h b/include/block/raw-aio.h index f0f14f14f8..4d6b0ee125 100644 --- a/include/block/raw-aio.h +++ b/include/block/raw-aio.h @@ -62,12 +62,12 @@ void laio_io_unplug(uint64_t dev_max_batch); typedef struct LuringState LuringState; LuringState *luring_init(Error **errp); void luring_cleanup(LuringState *s); -int coroutine_fn luring_co_submit(BlockDriverState *bs, LuringState *s, in= t fd, - uint64_t offset, QEMUIOVector *qiov, int t= ype); +int coroutine_fn luring_co_submit(BlockDriverState *bs, int fd, uint64_t o= ffset, + QEMUIOVector *qiov, int type); void luring_detach_aio_context(LuringState *s, AioContext *old_context); void luring_attach_aio_context(LuringState *s, AioContext *new_context); -void luring_io_plug(BlockDriverState *bs, LuringState *s); -void luring_io_unplug(BlockDriverState *bs, LuringState *s); +void luring_io_plug(void); +void luring_io_unplug(void); #endif =20 #ifdef _WIN32 --=20 2.31.1 From nobody Sat May 18 12:12:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1666959766; cv=none; d=zohomail.com; s=zohoarc; b=cFN7ULSELPuPZPJEAlKpXHemzmJLH3EguThvDGfxSEqitS+cxAxkoeSdi+zzT8oaXTwsZwFMAem4iQYb7jRMbVP0bxmvGnzqiv5LDfjvywK7iPcuhEOni4W/CfmCobTG9kdNmMWgSdUq6b4icUCti4oaK5m2kob6lez23VUdmcw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666959766; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NLcp73qS3RmgNAXILQcYi1WrtOmOr7UzTAs5jc0u+ro=; b=QdMYpt0u8qc+ojocsm0gJcMb814VtzkDcO9EgMNc+KeERW0UXUN2ZTRlr38REf4pGDAaJy24WXZMYIlh3T/3dtgPGyAFjEipt5Gdx61HOoX+VsRemUccGgMmaup0m1bEp+Kq9bSgSHKC8KHMvlUhVqhjLp9oIPgppdIOf4/6/D8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1666959766757975.9000218649246; Fri, 28 Oct 2022 05:22:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ooONA-0004dC-7y; Fri, 28 Oct 2022 08:22:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ooOME-0004FF-AW for qemu-devel@nongnu.org; Fri, 28 Oct 2022 08:21:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ooOM6-000262-9D for qemu-devel@nongnu.org; Fri, 28 Oct 2022 08:20:59 -0400 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-470-aCNEV_E6PzqhVnHmE1lQ-w-1; Fri, 28 Oct 2022 08:20:53 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AD3C129ABA36; Fri, 28 Oct 2022 12:20:52 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57C5140C206B; Fri, 28 Oct 2022 12:20:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666959656; 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=NLcp73qS3RmgNAXILQcYi1WrtOmOr7UzTAs5jc0u+ro=; b=SsUfS9L65b10qvvFNAR5RfRrb+trNV2VeUNaF85Q7xsh0TbINh8NKdY5e4Iy8eEzTo6Xl4 ONTl9x9OV+z7d2D/TaKGqkBeE49x0kJZbO5hOOh7pNR1KG7ahHAFXrVhF26UJdltkuLlWA Jiv3eYAes2zxx74XYuodcFOyclmG7W8= X-MC-Unique: aCNEV_E6PzqhVnHmE1lQ-w-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Hanna Reitz , Stefan Weil , Aarushi Mehta , Julia Suvorova , Stefan Hajnoczi , Stefano Garzarella , Fam Zheng , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito , Paolo Bonzini Subject: [PATCH v3 3/3] thread-pool: use ThreadPool from the running thread Date: Fri, 28 Oct 2022 08:20:48 -0400 Message-Id: <20221028122048.3101120-4-eesposit@redhat.com> In-Reply-To: <20221028122048.3101120-1-eesposit@redhat.com> References: <20221028122048.3101120-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.516, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666959767047100001 Content-Type: text/plain; charset="utf-8" Use qemu_get_current_aio_context() where possible, since we always submit work to the current thread anyways. We want to also be sure that the thread submitting the work is the same as the one processing the pool, to avoid adding synchronization to the pool list. Signed-off-by: Paolo Bonzini Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Paolo Bonzini --- block/file-posix.c | 21 ++++++++++----------- block/file-win32.c | 2 +- block/qcow2-threads.c | 2 +- util/thread-pool.c | 5 ++++- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 3800dbd222..28f12b08c8 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2044,11 +2044,10 @@ out: return result; } =20 -static int coroutine_fn raw_thread_pool_submit(BlockDriverState *bs, - ThreadPoolFunc func, void *= arg) +static int coroutine_fn raw_thread_pool_submit(ThreadPoolFunc func, void *= arg) { /* @bs can be NULL, bdrv_get_aio_context() returns the main context th= en */ - ThreadPool *pool =3D aio_get_thread_pool(bdrv_get_aio_context(bs)); + ThreadPool *pool =3D aio_get_thread_pool(qemu_get_current_aio_context(= )); return thread_pool_submit_co(pool, func, arg); } =20 @@ -2116,7 +2115,7 @@ static int coroutine_fn raw_co_prw(BlockDriverState *= bs, uint64_t offset, }; =20 assert(qiov->size =3D=3D bytes); - return raw_thread_pool_submit(bs, handle_aiocb_rw, &acb); + return raw_thread_pool_submit(handle_aiocb_rw, &acb); } =20 static int coroutine_fn raw_co_preadv(BlockDriverState *bs, int64_t offset, @@ -2186,7 +2185,7 @@ static int coroutine_fn raw_co_flush_to_disk(BlockDri= verState *bs) return luring_co_submit(bs, s->fd, 0, NULL, QEMU_AIO_FLUSH); } #endif - return raw_thread_pool_submit(bs, handle_aiocb_flush, &acb); + return raw_thread_pool_submit(handle_aiocb_flush, &acb); } =20 static void raw_aio_attach_aio_context(BlockDriverState *bs, @@ -2248,7 +2247,7 @@ raw_regular_truncate(BlockDriverState *bs, int fd, in= t64_t offset, }, }; =20 - return raw_thread_pool_submit(bs, handle_aiocb_truncate, &acb); + return raw_thread_pool_submit(handle_aiocb_truncate, &acb); } =20 static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offs= et, @@ -2998,7 +2997,7 @@ raw_do_pdiscard(BlockDriverState *bs, int64_t offset,= int64_t bytes, acb.aio_type |=3D QEMU_AIO_BLKDEV; } =20 - ret =3D raw_thread_pool_submit(bs, handle_aiocb_discard, &acb); + ret =3D raw_thread_pool_submit(handle_aiocb_discard, &acb); raw_account_discard(s, bytes, ret); return ret; } @@ -3073,7 +3072,7 @@ raw_do_pwrite_zeroes(BlockDriverState *bs, int64_t of= fset, int64_t bytes, handler =3D handle_aiocb_write_zeroes; } =20 - return raw_thread_pool_submit(bs, handler, &acb); + return raw_thread_pool_submit(handler, &acb); } =20 static int coroutine_fn raw_co_pwrite_zeroes( @@ -3284,7 +3283,7 @@ static int coroutine_fn raw_co_copy_range_to(BlockDri= verState *bs, }, }; =20 - return raw_thread_pool_submit(bs, handle_aiocb_copy_range, &acb); + return raw_thread_pool_submit(handle_aiocb_copy_range, &acb); } =20 BlockDriver bdrv_file =3D { @@ -3614,7 +3613,7 @@ hdev_co_ioctl(BlockDriverState *bs, unsigned long int= req, void *buf) struct sg_io_hdr *io_hdr =3D buf; if (io_hdr->cmdp[0] =3D=3D PERSISTENT_RESERVE_OUT || io_hdr->cmdp[0] =3D=3D PERSISTENT_RESERVE_IN) { - return pr_manager_execute(s->pr_mgr, bdrv_get_aio_context(bs), + return pr_manager_execute(s->pr_mgr, qemu_get_current_aio_cont= ext(), s->fd, io_hdr); } } @@ -3630,7 +3629,7 @@ hdev_co_ioctl(BlockDriverState *bs, unsigned long int= req, void *buf) }, }; =20 - return raw_thread_pool_submit(bs, handle_aiocb_ioctl, &acb); + return raw_thread_pool_submit(handle_aiocb_ioctl, &acb); } #endif /* linux */ =20 diff --git a/block/file-win32.c b/block/file-win32.c index ec9d64d0e4..3d7f59a592 100644 --- a/block/file-win32.c +++ b/block/file-win32.c @@ -167,7 +167,7 @@ static BlockAIOCB *paio_submit(BlockDriverState *bs, HA= NDLE hfile, acb->aio_offset =3D offset; =20 trace_file_paio_submit(acb, opaque, offset, count, type); - pool =3D aio_get_thread_pool(bdrv_get_aio_context(bs)); + pool =3D aio_get_thread_pool(qemu_get_current_aio_context()); return thread_pool_submit_aio(pool, aio_worker, acb, cb, opaque); } =20 diff --git a/block/qcow2-threads.c b/block/qcow2-threads.c index 1914baf456..9e370acbb3 100644 --- a/block/qcow2-threads.c +++ b/block/qcow2-threads.c @@ -42,7 +42,7 @@ qcow2_co_process(BlockDriverState *bs, ThreadPoolFunc *fu= nc, void *arg) { int ret; BDRVQcow2State *s =3D bs->opaque; - ThreadPool *pool =3D aio_get_thread_pool(bdrv_get_aio_context(bs)); + ThreadPool *pool =3D aio_get_thread_pool(qemu_get_current_aio_context(= )); =20 qemu_co_mutex_lock(&s->lock); while (s->nb_threads >=3D QCOW2_MAX_THREADS) { diff --git a/util/thread-pool.c b/util/thread-pool.c index 31113b5860..0e26687e97 100644 --- a/util/thread-pool.c +++ b/util/thread-pool.c @@ -48,7 +48,7 @@ struct ThreadPoolElement { /* Access to this list is protected by lock. */ QTAILQ_ENTRY(ThreadPoolElement) reqs; =20 - /* Access to this list is protected by the global mutex. */ + /* This list is only written by the thread pool's mother thread. */ QLIST_ENTRY(ThreadPoolElement) all; }; =20 @@ -251,6 +251,9 @@ BlockAIOCB *thread_pool_submit_aio(ThreadPool *pool, { ThreadPoolElement *req; =20 + /* Assert that the thread submitting work is the same running the pool= */ + assert(pool->ctx =3D=3D qemu_get_current_aio_context()); + req =3D qemu_aio_get(&thread_pool_aiocb_info, NULL, cb, opaque); req->func =3D func; req->arg =3D arg; --=20 2.31.1