qtest: Fix deadloop by running main loop AIO context's timers
PATCH v2 1/1 qtest: Fix deadloop by running main loop AIO context's timers
qemu_clock_run_timers() only takes care of main_loop_tlg, we shouldn't forget aio timer list groups.
Currently, the qemu_clock_deadline_ns_all (a few lines above) counts all the timergroups of this clock type, including aio tlg, but we don't fire them, so they are never cleared, which makes a dead loop.
For example, this function hangs when trying to drive throttled block request queue with qtest clock_step.
---
v2: Only run QEMU_CLOCK_VIRTUAL events. (Paolo).
--- cpus.c | 4 ++++ 1 file changed, 4 insertions(+)
cpus.c +4 -0
@@ -378,15 +378,19 @@ static void icount_warp_rt(void *opaque)void qtest_clock_warp (int64_t dest) {int64_t clock =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); +AioContext *aio_context;assert (qtest_enabled ()); + aio_context =qemu_get_aio_context ();while (clock < dest) {int64_t deadline =qemu_clock_deadline_ns_all (QEMU_CLOCK_VIRTUAL );int64_t warp =qemu_soonest_timeout (dest - clock, deadline); +seqlock_write_lock (&timers_state.vm_clock_seqlock); timers_state.qemu_icount_bias += warp;seqlock_write_unlock (&timers_state.vm_clock_seqlock);qemu_clock_run_timers (QEMU_CLOCK_VIRTUAL ); +timerlist_run_timers (aio_context->tlg.tl[QEMU_CLOCK_VIRTUAL ]); clock =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); }qemu_clock_notify (QEMU_CLOCK_VIRTUAL );
Signature · 1 line
1.9.3
Quoted 33 lines · Fam Zheng
qemu_clock_run_timers()only takes care ofmain_loop_tlg, we shouldn't forget aio timer list groups.Currently, the
qemu_clock_deadline_ns_all(a few lines above) counts all the timergroups of this clock type, including aio tlg, but we don't fire them, so they are never cleared, which makes a dead loop.For example, this function hangs when trying to drive throttled block request queue with qtest
clock_step.Signed-off-by Fam Zheng <[email protected]>---
v2: Only runQEMU_CLOCK_VIRTUALevents. (Paolo).--- cpus.c | 4 ++++ 1 file changed, 4 insertions(+)cpus.c +2
-0@@ -378,15 +378,19 @@ static void icount_warp_rt(void *opaque)void qtest_clock_warp (int64_t dest) {int64_t clock =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); +AioContext *aio_context;assert (qtest_enabled ()); + aio_context =qemu_get_aio_context ();while (clock < dest) {int64_t deadline =qemu_clock_deadline_ns_all (QEMU_CLOCK_VIRTUAL );int64_t warp =qemu_soonest_timeout (dest - clock, deadline);
cpus.c static void icount_warp_rt(void *opaque) · line 396
Quoted 10 lines
cpus.c +2
-0+seqlock_write_lock (&timers_state.vm_clock_seqlock); timers_state.qemu_icount_bias += warp;seqlock_write_unlock (&timers_state.vm_clock_seqlock);qemu_clock_run_timers (QEMU_CLOCK_VIRTUAL ); +timerlist_run_timers (aio_context->tlg.tl[QEMU_CLOCK_VIRTUAL ]); clock =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); }qemu_clock_notify (QEMU_CLOCK_VIRTUAL );
Kevin/Stefan, can you apply it to the block branch together with Fam's qemu-iotests patches for throttling?
Paolo
Stefan Hajnoczi
AppliedQuoted 10 lines · Fam Zheng
qemu_clock_run_timers()only takes care ofmain_loop_tlg, we shouldn't forget aio timer list groups.Currently, the
qemu_clock_deadline_ns_all(a few lines above) counts all the timergroups of this clock type, including aio tlg, but we don't fire them, so they are never cleared, which makes a dead loop.For example, this function hangs when trying to drive throttled block request queue with qtest
clock_step.
Quoted 7 lines
Signed-off-by Fam Zheng <[email protected]>---
v2: Only runQEMU_CLOCK_VIRTUALevents. (Paolo).--- cpus.c | 4 ++++ 1 file changed, 4 insertions(+)
Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block
Stefan