thread-pool: add missing qemu_bh_cancel in completion function
PATCH 1/1 thread-pool: add missing qemu_bh_cancel in completion function
commit 3c80ca15 fixed a deadlock scenarion with nested aio_poll invocations.
However, the rescheduling of the completion BH introcuded unnecessary spinning in the main-loop. On very fast file backends this can even lead to the "WARNING: I/O thread spun for 1000 iterations" message popping up.
Callgrind reports about 3-4% less instructions with this patch running qemu-img bench on a ramdisk based VMDK file.
--- util/thread-pool.c | 7 +++++++ 1 file changed, 7 insertions(+)
util/thread-pool.c +7 -0
@@ -188,6 +188,13 @@ restart:aio_context_release (pool->ctx); elem->common.cb (elem->common.opaque, elem->ret);aio_context_acquire (pool->ctx); + +/* We can safely cancel the completion_bh here regardless of someone +* else having scheduled it meanwhile because we reenter the +* completion function anyway (goto restart). +*/ +qemu_bh_cancel (pool->completion_bh); +qemu_aio_unref (elem); goto restart; }else {
Signature · 1 line
1.9.1
Quoted 25 lines · Peter Lieven
commit
3c80ca15fixed a deadlock scenarion with nestedaio_pollinvocations.However, the rescheduling of the completion BH introcuded unnecessary spinning in the main-loop. On very fast file backends this can even lead to the "WARNING: I/O thread spun for 1000 iterations" message popping up.
Callgrind reports about 3-4% less instructions with this patch running qemu-img bench on a ramdisk based VMDK file.
Fixes 3c80ca158c96ff902a30883a8933e755988948b1Signed-off-by Peter Lieven <[email protected]>--- util/thread-pool.c | 7 +++++++ 1 file changed, 7 insertions(+)util/thread-pool.c +0
-0@@ -188,6 +188,13 @@ restart:aio_context_release (pool->ctx); elem->common.cb (elem->common.opaque, elem->ret);aio_context_acquire (pool->ctx);
util/thread-pool.c restart: · line 200
Quoted 10 lines
util/thread-pool.c +7
-0+ +/* We can safely cancel the completion_bh here regardless of someone +* else having scheduled it meanwhile because we reenter the +* completion function anyway (goto restart). +*/ +qemu_bh_cancel (pool->completion_bh); +qemu_aio_unref (elem); goto restart; }else {
Right, this is the same thing that block/linux-aio.c does.
Paolo
Quoted 35 lines
Am 16.03.2017 um 17:18 schrieb Paolo Bonzini <[email protected]>:
Quoted 29 lines · Peter Lieven
commit
3c80ca15fixed a deadlock scenarion with nestedaio_pollinvocations.However, the rescheduling of the completion BH introcuded unnecessary spinning in the main-loop. On very fast file backends this can even lead to the "WARNING: I/O thread spun for 1000 iterations" message popping up.
Callgrind reports about 3-4% less instructions with this patch running qemu-img bench on a ramdisk based VMDK file.
Fixes 3c80ca158c96ff902a30883a8933e755988948b1Signed-off-by Peter Lieven <[email protected]>---
util/thread-pool.c| 7 +++++++1 file changed, 7 insertions(+)util/thread-pool.c +5
-0@@ -188,6 +188,13 @@ restart:aio_context_release (pool->ctx); elem->common.cb (elem->common.opaque, elem->ret);aio_context_acquire (pool->ctx); + +/* We can safely cancel the completion_bh here regardless of someone +* else having scheduled it meanwhile because we reenter the +* completion function anyway (goto restart). +*/
Quoted 8 lines
util/thread-pool.c restart: · line 200
Quoted 6 lines
util/thread-pool.c +2
-0+qemu_bh_cancel (pool->completion_bh); +qemu_aio_unref (elem); goto restart; }else {Right, this is the same thing that
block/linux-aio.cdoes.
Okay, so you also think its safe to do this? As far as I have seen you have been working a lot on the aio code recently.
Thanks,
Peter
Kevin Wolf
AppliedAm 16.03.2017 um 17:02 hat Peter Lieven geschrieben:
Quoted 6 lines
commit
3c80ca15fixed a deadlock scenarion with nestedaio_pollinvocations.However, the rescheduling of the completion BH introcuded unnecessary spinning in the main-loop. On very fast file backends this can even lead to the "WARNING: I/O thread spun for 1000 iterations" message popping up.
Quoted 6 lines
Callgrind reports about 3-4% less instructions with this patch running qemu-img bench on a ramdisk based VMDK file.
Fixes 3c80ca158c96ff902a30883a8933e755988948b1Signed-off-by Peter Lieven <[email protected]>
Thanks, applied to the block branch.
Kevin