* [Qemu-devel] [PATCH v2 0/2] block: make aio_poll(ctx, true) block with no fds
@ 2013-11-26 15:17 Stefan Hajnoczi
2013-11-26 15:18 ` [Qemu-devel] [PATCH v2 1/2] block: clean up bdrv_drain_all() throttling comments Stefan Hajnoczi
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Stefan Hajnoczi @ 2013-11-26 15:17 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, pingfank, alex, jan.kiszka, Stefan Hajnoczi, pbonzini
v2:
* Oops, this patch got lost. Rebased onto qemu.git/master for 1.8
Jan and Alex have expressed that aio_poll(ctx, blocking=true) should block even
when there are no file descriptors registered. This can be handy since other
threads may still kick the AioContext using aio_notify(ctx).
A concrete example is a thread that has only a timer in its AioContext.
aio_poll(ctx, true) should block until the timer expires or another thread
invokes aio_notify(ctx).
Alex and Paolo were concerned about bdrv_drain_all() which has the following
comment:
while (busy) {
/* FIXME: We do not have timer support here, so this is effectively
* a busy wait.
*/
QTAILQ_FOREACH(bs, &bdrv_states, list) {
if (bdrv_start_throttled_reqs(bs)) {
busy = true;
}
}
busy = bdrv_requests_pending_all();
busy |= aio_poll(qemu_get_aio_context(), busy);
}
Patch 1 drops this outdated comment. The new I/O throttling code already
eliminated the busy wait.
Patch 2 drops the special case which returns immediately from aio_poll(ctx,
true) when no file descriptors are registered.
Note that aio_notify(ctx) still causes aio_poll(ctx, true) to return false. I
don't see a need to change it so aio_poll(ctx, true) always returns true.
Stefan Hajnoczi (2):
block: clean up bdrv_drain_all() throttling comments
aio: make aio_poll(ctx, true) block with no fds
aio-posix.c | 5 -----
aio-win32.c | 5 -----
block.c | 7 +------
tests/test-aio.c | 1 -
4 files changed, 1 insertion(+), 17 deletions(-)
--
1.8.4.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH v2 1/2] block: clean up bdrv_drain_all() throttling comments
2013-11-26 15:17 [Qemu-devel] [PATCH v2 0/2] block: make aio_poll(ctx, true) block with no fds Stefan Hajnoczi
@ 2013-11-26 15:18 ` Stefan Hajnoczi
2013-11-26 15:18 ` [Qemu-devel] [PATCH v2 2/2] aio: make aio_poll(ctx, true) block with no fds Stefan Hajnoczi
2013-12-05 15:55 ` [Qemu-devel] [PATCH v2 0/2] block: " Stefan Hajnoczi
2 siblings, 0 replies; 4+ messages in thread
From: Stefan Hajnoczi @ 2013-11-26 15:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, pingfank, alex, jan.kiszka, Stefan Hajnoczi, pbonzini
Since cc0681c45430a1f1a4c2d06e9499b7775afc9a18 ("block: Enable the new
throttling code in the block layer.") bdrv_drain_all() no longer spins.
The code used to look as follows:
do {
busy = qemu_aio_wait();
/* FIXME: We do not have timer support here, so this is effectively
* a busy wait.
*/
QTAILQ_FOREACH(bs, &bdrv_states, list) {
while (qemu_co_enter_next(&bs->throttled_reqs)) {
busy = true;
}
}
} while (busy);
Note that throttle requests are kicked but I/O throttling limits are
still in effect. The loop spins until the vm_clock time allows the
request to make progress and complete.
The new throttling code introduced bdrv_start_throttled_reqs(). This
function not only kicks throttled requests but also temporarily disables
throttling so requests can run.
The outdated FIXME comment can be removed. Also drop the busy = true
assignment since we overwrite it immediately afterwards.
Reviewed-by: Alex Bligh <alex@alex.org.uk>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
block.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/block.c b/block.c
index 382ea71..13ad3fd 100644
--- a/block.c
+++ b/block.c
@@ -1559,13 +1559,8 @@ void bdrv_drain_all(void)
BlockDriverState *bs;
while (busy) {
- /* FIXME: We do not have timer support here, so this is effectively
- * a busy wait.
- */
QTAILQ_FOREACH(bs, &bdrv_states, list) {
- if (bdrv_start_throttled_reqs(bs)) {
- busy = true;
- }
+ bdrv_start_throttled_reqs(bs);
}
busy = bdrv_requests_pending_all();
--
1.8.4.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH v2 2/2] aio: make aio_poll(ctx, true) block with no fds
2013-11-26 15:17 [Qemu-devel] [PATCH v2 0/2] block: make aio_poll(ctx, true) block with no fds Stefan Hajnoczi
2013-11-26 15:18 ` [Qemu-devel] [PATCH v2 1/2] block: clean up bdrv_drain_all() throttling comments Stefan Hajnoczi
@ 2013-11-26 15:18 ` Stefan Hajnoczi
2013-12-05 15:55 ` [Qemu-devel] [PATCH v2 0/2] block: " Stefan Hajnoczi
2 siblings, 0 replies; 4+ messages in thread
From: Stefan Hajnoczi @ 2013-11-26 15:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, pingfank, alex, jan.kiszka, Stefan Hajnoczi, pbonzini
This patch drops a special case where aio_poll(ctx, true) returns false
instead of blocking if no file descriptors are waiting on I/O. Now it
is possible to block in aio_poll() to wait for aio_notify().
This change eliminates busy waiting. bdrv_drain_all() used to rely on
busy waiting to completed throttled I/O requests but this is no longer
required so we can simplify aio_poll().
Note that aio_poll() still returns false when aio_notify() was used. In
other words, stopping a blocking aio_poll() wait is not considered
making progress.
Adjust test-aio /aio/bh/callback-delete/one which assumed aio_poll(ctx,
true) would immediately return false instead of blocking.
Reviewed-by: Alex Bligh <alex@alex.org.uk>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
aio-posix.c | 5 -----
aio-win32.c | 5 -----
tests/test-aio.c | 1 -
3 files changed, 11 deletions(-)
diff --git a/aio-posix.c b/aio-posix.c
index bd06f33..f921d4f 100644
--- a/aio-posix.c
+++ b/aio-posix.c
@@ -217,11 +217,6 @@ bool aio_poll(AioContext *ctx, bool blocking)
ctx->walking_handlers--;
- /* early return if we only have the aio_notify() fd */
- if (ctx->pollfds->len == 1) {
- return progress;
- }
-
/* wait until next event */
ret = qemu_poll_ns((GPollFD *)ctx->pollfds->data,
ctx->pollfds->len,
diff --git a/aio-win32.c b/aio-win32.c
index f9cfbb7..23f4e5b 100644
--- a/aio-win32.c
+++ b/aio-win32.c
@@ -161,11 +161,6 @@ bool aio_poll(AioContext *ctx, bool blocking)
ctx->walking_handlers--;
- /* early return if we only have the aio_notify() fd */
- if (count == 1) {
- return progress;
- }
-
/* wait until next event */
while (count > 0) {
int ret;
diff --git a/tests/test-aio.c b/tests/test-aio.c
index c4fe0fc..592721e 100644
--- a/tests/test-aio.c
+++ b/tests/test-aio.c
@@ -195,7 +195,6 @@ static void test_bh_delete_from_cb(void)
g_assert(data1.bh == NULL);
g_assert(!aio_poll(ctx, false));
- g_assert(!aio_poll(ctx, true));
}
static void test_bh_delete_from_cb_many(void)
--
1.8.4.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH v2 0/2] block: make aio_poll(ctx, true) block with no fds
2013-11-26 15:17 [Qemu-devel] [PATCH v2 0/2] block: make aio_poll(ctx, true) block with no fds Stefan Hajnoczi
2013-11-26 15:18 ` [Qemu-devel] [PATCH v2 1/2] block: clean up bdrv_drain_all() throttling comments Stefan Hajnoczi
2013-11-26 15:18 ` [Qemu-devel] [PATCH v2 2/2] aio: make aio_poll(ctx, true) block with no fds Stefan Hajnoczi
@ 2013-12-05 15:55 ` Stefan Hajnoczi
2 siblings, 0 replies; 4+ messages in thread
From: Stefan Hajnoczi @ 2013-12-05 15:55 UTC (permalink / raw)
To: Stefan Hajnoczi
Cc: Kevin Wolf, pingfank, jan.kiszka, qemu-devel, alex, pbonzini
On Tue, Nov 26, 2013 at 04:17:59PM +0100, Stefan Hajnoczi wrote:
> v2:
> * Oops, this patch got lost. Rebased onto qemu.git/master for 1.8
>
> Jan and Alex have expressed that aio_poll(ctx, blocking=true) should block even
> when there are no file descriptors registered. This can be handy since other
> threads may still kick the AioContext using aio_notify(ctx).
>
> A concrete example is a thread that has only a timer in its AioContext.
> aio_poll(ctx, true) should block until the timer expires or another thread
> invokes aio_notify(ctx).
>
> Alex and Paolo were concerned about bdrv_drain_all() which has the following
> comment:
>
> while (busy) {
> /* FIXME: We do not have timer support here, so this is effectively
> * a busy wait.
> */
> QTAILQ_FOREACH(bs, &bdrv_states, list) {
> if (bdrv_start_throttled_reqs(bs)) {
> busy = true;
> }
> }
>
> busy = bdrv_requests_pending_all();
> busy |= aio_poll(qemu_get_aio_context(), busy);
> }
>
> Patch 1 drops this outdated comment. The new I/O throttling code already
> eliminated the busy wait.
>
> Patch 2 drops the special case which returns immediately from aio_poll(ctx,
> true) when no file descriptors are registered.
>
> Note that aio_notify(ctx) still causes aio_poll(ctx, true) to return false. I
> don't see a need to change it so aio_poll(ctx, true) always returns true.
>
> Stefan Hajnoczi (2):
> block: clean up bdrv_drain_all() throttling comments
> aio: make aio_poll(ctx, true) block with no fds
>
> aio-posix.c | 5 -----
> aio-win32.c | 5 -----
> block.c | 7 +------
> tests/test-aio.c | 1 -
> 4 files changed, 1 insertion(+), 17 deletions(-)
Applied to my block tree:
https://github.com/stefanha/qemu/commits/block
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-12-05 15:56 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-26 15:17 [Qemu-devel] [PATCH v2 0/2] block: make aio_poll(ctx, true) block with no fds Stefan Hajnoczi
2013-11-26 15:18 ` [Qemu-devel] [PATCH v2 1/2] block: clean up bdrv_drain_all() throttling comments Stefan Hajnoczi
2013-11-26 15:18 ` [Qemu-devel] [PATCH v2 2/2] aio: make aio_poll(ctx, true) block with no fds Stefan Hajnoczi
2013-12-05 15:55 ` [Qemu-devel] [PATCH v2 0/2] block: " Stefan Hajnoczi
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).