Skip to contentSkip to conversation

qtest: fix qtest_clock_warp() for no deadline case

PATCH In review Sergey Fedorov 2 participants 3 messages Jun 9, 2014 – Jun 10, 2014

lore
Share & tools
lore
#0 lore raw

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
index dd7ac13..3ec15cb 100644
@@ -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
#1 lore raw
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 so MIN() do not treat it as minimum.

---
cpus.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)
cpus.c +0 -0
index dd7ac13..3ec15cb 100644

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 -0
        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
Signature · 1 line
Alex Bligh
#2 lore raw
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 so MIN() do not treat it as minimum.

---
cpus.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)
cpus.c +0 -0
index dd7ac13..3ec15cb 100644

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.

Quoted 6 lines

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.

Thank you! I'm resubmitting the patch.

Quoted 9 lines
Quoted 9 lines
cpus.c +0 -0
        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