diff options
author | Stefan Hajnoczi <stefanha@redhat.com> | 2020-02-21 09:39:51 +0000 |
---|---|---|
committer | Stefan Hajnoczi <stefanha@redhat.com> | 2020-02-22 08:26:47 +0000 |
commit | 8c6b0356b53977bcfdea5299db07884915425b0c (patch) | |
tree | d309eb193c9a185cd2c9a58bcc769ffb73b108c7 /tests/test-aio.c | |
parent | 8c3570e33954d26675ec6fd224ede02763dfbd1d (diff) | |
download | qemu-8c6b0356b53977bcfdea5299db07884915425b0c.zip qemu-8c6b0356b53977bcfdea5299db07884915425b0c.tar.gz qemu-8c6b0356b53977bcfdea5299db07884915425b0c.tar.bz2 |
util/async: make bh_aio_poll() O(1)
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 <stefanha@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-id: 20200221093951.1414693-1-stefanha@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'tests/test-aio.c')
-rw-r--r-- | tests/test-aio.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/tests/test-aio.c b/tests/test-aio.c index 86fb73b..8a46078 100644 --- a/tests/test-aio.c +++ b/tests/test-aio.c @@ -615,7 +615,8 @@ static void test_source_bh_delete_from_cb(void) g_assert_cmpint(data1.n, ==, data1.max); g_assert(data1.bh == NULL); - g_assert(!g_main_context_iteration(NULL, false)); + assert(g_main_context_iteration(NULL, false)); + assert(!g_main_context_iteration(NULL, false)); } static void test_source_bh_delete_from_cb_many(void) |