qtest: fix qtest_clock_warp() for no deadline case
PATCH 1/1 qtest: fix qtest_clock_warp() for no deadline case
If there is no deadline across all timerlists attached to the clock then qemu_clock_deadline_ns_all() returns -1. Cast it to unsinged so MIN() do not treat it as minimum.
--- cpus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
cpus.c +2 -2
@@ -346,8 +346,8 @@ void qtest_clock_warp(int64_t dest)int64_t clock =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );assert (qtest_enabled ());while (clock < dest) { -int64_t deadline =qemu_clock_deadline_ns_all (QEMU_CLOCK_VIRTUAL ); -int64_t warp =MIN (dest - clock, deadline); +uint64_t deadline =qemu_clock_deadline_ns_all (QEMU_CLOCK_VIRTUAL ); +uint64_t warp =MIN (dest - clock, deadline);seqlock_write_lock (&timers_state.vm_clock_seqlock); qemu_icount_bias += warp;seqlock_write_unlock (&timers_state.vm_clock_seqlock);
Signature · 1 line
1.9.1
Quoted 14 lines · Sergey Fedorov
If there is no deadline across all timerlists attached to the clock then
qemu_clock_deadline_ns_all()returns -1. Cast it to unsinged soMIN()do not treat it as minimum.Signed-off-by Sergey Fedorov <[email protected]>---
cpus.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)cpus.c +0
-0
cpus.c void qtest_clock_warp(int64_t dest) · line 350
Quoted 7 lines
cpus.c +2
-2@@ -346,8 +346,8 @@ void qtest_clock_warp(int64_t dest)int64_t clock =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );assert (qtest_enabled ());while (clock < dest) { -int64_t deadline =qemu_clock_deadline_ns_all (QEMU_CLOCK_VIRTUAL ); -int64_t warp =MIN (dest - clock, deadline); +uint64_t deadline =qemu_clock_deadline_ns_all (QEMU_CLOCK_VIRTUAL ); +uint64_t warp =MIN (dest - clock, deadline);
Please don't do that. It looks like a bug where you've not read the return type.
Instead, just do
int64_t warp = qemu_soonest_timeout(dest - clock, deadline);
which puts all the ugly casting stuff in one nicely documented inline function and will generate the same code.
Quoted 8 lines
cpus.c +0
-0seqlock_write_lock (&timers_state.vm_clock_seqlock); qemu_icount_bias += warp;seqlock_write_unlock (&timers_state.vm_clock_seqlock);Signature · 1 line
1.9.1
Signature · 1 line
Alex Bligh
Quoted 26 lines · Alex Bligh
Quoted 14 lines · Sergey Fedorov
If there is no deadline across all timerlists attached to the clock then
qemu_clock_deadline_ns_all()returns -1. Cast it to unsinged soMIN()do not treat it as minimum.Signed-off-by Sergey Fedorov <[email protected]>---
cpus.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)cpus.c +0
-0cpus.c void qtest_clock_warp(int64_t dest) · line 350
Quoted 7 lines
cpus.c +2
-2@@ -346,8 +346,8 @@ void qtest_clock_warp(int64_t dest)int64_t clock =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );assert (qtest_enabled ());while (clock < dest) { -int64_t deadline =qemu_clock_deadline_ns_all (QEMU_CLOCK_VIRTUAL ); -int64_t warp =MIN (dest - clock, deadline); +uint64_t deadline =qemu_clock_deadline_ns_all (QEMU_CLOCK_VIRTUAL ); +uint64_t warp =MIN (dest - clock, deadline);Please don't do that. It looks like a bug where you've not read the return type.
Quoted 6 lines
Instead, just do
int64_twarp =qemu_soonest_timeout(dest - clock, deadline);which puts all the ugly casting stuff in one nicely documented inline function and will generate the same code.
Thank you! I'm resubmitting the patch.
Quoted 9 lines
Quoted 9 lines
cpus.c +0
-0seqlock_write_lock (&timers_state.vm_clock_seqlock); qemu_icount_bias += warp;seqlock_write_unlock (&timers_state.vm_clock_seqlock);Signature · 1 line
1.9.1