block: make aio_poll(ctx, true) block with no fds
cover block: make aio_poll(ctx, true) block with no fds
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(-)
Signature · 1 line
1.8.3.1
PATCH 1/2 block: clean up bdrv_drain_all() throttling comments
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.
--- block.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
block.c +1 -6
@@ -1558,13 +1558,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 ();
Signature · 1 line
1.8.3.1
PATCH 2/2 aio: make aio_poll(ctx, true) block with no fds
In reply to Stefan HajnocziThis 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.
--- aio-posix.c | 5 ----- aio-win32.c | 5 ----- tests/test-aio.c | 1 - 3 files changed, 11 deletions(-)
aio-posix.c +0 -5
@@ -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,
aio-win32.c +0 -5
@@ -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;
tests/test-aio.c +0 -1
@@ -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 )
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 1/2] block: clean up bdrv_drain_all() throttling comments
In reply to Stefan HajnocziQuoted 21 lines · Stefan Hajnoczi
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_clocktime allows the request to make progress and complete.
Quoted 8 lines
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.
Signed-off-by Stefan Hajnoczi <[email protected]>
(if I meant 'Reviewed-By:' please change it!)
Quoted 28 lines
---
block.c| 7 +------1 file changed, 1 insertion(+), 6 deletions(-)block.c +1
-6@@ -1558,13 +1558,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 ();Signature · 1 line
1.8.3.1
Signature · 1 line
Alex Bligh
Re: [Qemu-devel] [PATCH 2/2] aio: make aio_poll(ctx, true) block with no fds
In reply to Stefan HajnocziQuoted 8 lines · Stefan Hajnoczi
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 inaio_poll()to wait foraio_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 simplifyaio_poll().
Quoted 8 lines
Note that
aio_poll()still returns false whenaio_notify()was used. In other words, stopping a blockingaio_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.Signed-off-by Stefan Hajnoczi <[email protected]>
(if I meant 'Reviewed-By:' please change it!)
Quoted 55 lines
---
aio-posix.c | 5 ----- aio-win32.c | 5 ----- tests/test-aio.c | 1 - 3 files changed, 11 deletions(-)aio-posix.c +0
-5@@ -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,aio-win32.c +0
-5@@ -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;tests/test-aio.c +0
-1@@ -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 )Signature · 1 line
1.8.3.1
Signature · 1 line
Alex Bligh