On Fri, Feb 21, 2020 at 09:39:51AM +0000, Stefan Hajnoczi wrote: > The ctx->first_bh list contains all created BHs, including those that > are not scheduled. The list is iterated by the event loop and therefore > has O(n) time complexity with respected to the number of created BHs. > > Rewrite BHs so that only scheduled or deleted BHs are enqueued. > Only BHs that actually require action will be iterated. > > One semantic change is required: qemu_bh_delete() enqueues the BH and > therefore invokes aio_notify(). The > tests/test-aio.c:test_source_bh_delete_from_cb() test case assumed that > g_main_context_iteration(NULL, false) returns false after > qemu_bh_delete() but it now returns true for one iteration. Fix up the > test case. > > This patch makes aio_compute_timeout() and aio_bh_poll() drop from a CPU > profile reported by perf-top(1). Previously they combined to 9% CPU > utilization when AioContext polling is commented out and the guest has 2 > virtio-blk,num-queues=1 and 99 virtio-blk,num-queues=32 devices. > > Signed-off-by: Stefan Hajnoczi > --- > v3: > * Use QSLIST_FOREACH_RCU() and QSLIST_FIRST_RCU() [Paolo] > v2: > * Use QSLIST for BHs and QSIMPLEQ for BHListSlices [Paolo] > (Note that I replaced bh = atomic_rcu_read(&first_bh) with > QSLIST_FOREACH(&bh_list) so there is no memory ordering but I think > this is safe.) > * Comment clarifications [Paolo] > > Based-on: 20200220103828.24525-1-pbonzini@redhat.com > ("[PATCH] rcu_queue: add QSLIST functions") > --- > include/block/aio.h | 20 +++- > tests/test-aio.c | 3 +- > util/async.c | 237 ++++++++++++++++++++++++++------------------ > 3 files changed, 158 insertions(+), 102 deletions(-) Thanks, applied to my block tree: https://github.com/stefanha/qemu/commits/block Stefan