From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
To: qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>,
Stefan Weil <sw@weilnetz.de>,
Stefan Hajnoczi <stefanha@redhat.com>, Fam Zheng <fam@euphon.net>,
Paolo Bonzini <pbonzini@redhat.com>,
qemu-devel@nongnu.org,
Emanuele Giuseppe Esposito <eesposit@redhat.com>
Subject: [PATCH 1/2] linux-aio: use LinuxAioState from the running thread
Date: Thu, 9 Jun 2022 09:44:51 -0400 [thread overview]
Message-ID: <20220609134452.1146309-2-eesposit@redhat.com> (raw)
In-Reply-To: <20220609134452.1146309-1-eesposit@redhat.com>
From: Paolo Bonzini <pbonzini@redhat.com>
Remove usage of aio_context_acquire by always submitting asynchronous
AIO to the current thread's LinuxAioState.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
block/file-posix.c | 3 ++-
block/linux-aio.c | 13 ++++++-------
include/block/aio.h | 4 ----
3 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/block/file-posix.c b/block/file-posix.c
index 48cd096624..33f92f004a 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -2086,7 +2086,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 = aio_get_linux_aio(bdrv_get_aio_context(bs));
+ AioContext *ctx = qemu_get_current_aio_context();
+ LinuxAioState *aio = aio_get_linux_aio(ctx);
assert(qiov->size == bytes);
return laio_co_submit(bs, aio, s->fd, offset, qiov, type,
s->aio_max_batch);
diff --git a/block/linux-aio.c b/block/linux-aio.c
index 4c423fcccf..1d3cc767d1 100644
--- a/block/linux-aio.c
+++ b/block/linux-aio.c
@@ -16,6 +16,9 @@
#include "qemu/coroutine.h"
#include "qapi/error.h"
+/* Only used for assertions. */
+#include "qemu/coroutine_int.h"
+
#include <libaio.h>
/*
@@ -56,10 +59,8 @@ struct LinuxAioState {
io_context_t ctx;
EventNotifier e;
- /* 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,9 +103,8 @@ static void qemu_laio_process_completion(struct qemu_laiocb *laiocb)
* later. Coroutines cannot be entered recursively so avoid doing
* that!
*/
- if (!qemu_coroutine_entered(laiocb->co)) {
- aio_co_wake(laiocb->co);
- }
+ assert(laiocb->co->ctx == laiocb->ctx->aio_context);
+ qemu_coroutine_enter_if_inactive(laiocb->co);
}
/**
@@ -238,7 +238,6 @@ static void qemu_laio_process_completions_and_submit(LinuxAioState *s)
if (!s->io_q.plugged && !QSIMPLEQ_EMPTY(&s->io_q.pending)) {
ioq_submit(s);
}
- aio_context_release(s->aio_context);
}
static void qemu_laio_completion_bh(void *opaque)
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;
#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
--
2.31.1
next prev parent reply other threads:[~2022-06-09 15:14 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-09 13:44 [PATCH 0/2] AioContext removal: LinuxAioState and ThreadPool Emanuele Giuseppe Esposito
2022-06-09 13:44 ` Emanuele Giuseppe Esposito [this message]
2022-09-29 14:52 ` [PATCH 1/2] linux-aio: use LinuxAioState from the running thread Kevin Wolf
2022-09-30 10:00 ` Emanuele Giuseppe Esposito
2022-09-30 15:32 ` Kevin Wolf
2022-10-03 9:18 ` Emanuele Giuseppe Esposito
2022-06-09 13:44 ` [PATCH 2/2] thread-pool: use ThreadPool " Emanuele Giuseppe Esposito
2022-09-29 15:30 ` Kevin Wolf
2022-09-30 12:17 ` Emanuele Giuseppe Esposito
2022-09-30 14:46 ` Emanuele Giuseppe Esposito
2022-09-30 15:45 ` Kevin Wolf
2022-10-03 8:52 ` Emanuele Giuseppe Esposito
2022-10-20 15:39 ` Stefan Hajnoczi
2022-10-20 16:22 ` Dr. David Alan Gilbert
2022-10-24 18:49 ` Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220609134452.1146309-2-eesposit@redhat.com \
--to=eesposit@redhat.com \
--cc=fam@euphon.net \
--cc=hreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=sw@weilnetz.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).