diff mbox

qtest: fix qtest_clock_warp() for no deadline case

Message ID 1402332171-7159-1-git-send-email-serge.fdrv@gmail.com
State New
Headers show

Commit Message

Sergey Fedorov June 9, 2014, 4:42 p.m. UTC
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.

Signed-off-by: Sergey Fedorov <serge.fdrv@gmail.com>
---
 cpus.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Alex Bligh June 9, 2014, 5:36 p.m. UTC | #1
On 9 Jun 2014, at 17:42, Sergey Fedorov wrote:

> 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.
> 
> Signed-off-by: Sergey Fedorov <serge.fdrv@gmail.com>
> ---
> cpus.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/cpus.c b/cpus.c
> index dd7ac13..3ec15cb 100644
> --- a/cpus.c
> +++ b/cpus.c
> @@ -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.

>         seqlock_write_lock(&timers_state.vm_clock_seqlock);
>         qemu_icount_bias += warp;
>         seqlock_write_unlock(&timers_state.vm_clock_seqlock);
> -- 
> 1.9.1
> 
> 
>
Sergey Fedorov June 10, 2014, 9:08 a.m. UTC | #2
On 09.06.2014 21:36, Alex Bligh wrote:
> On 9 Jun 2014, at 17:42, Sergey Fedorov wrote:
>
>> 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.
>>
>> Signed-off-by: Sergey Fedorov <serge.fdrv@gmail.com>
>> ---
>> cpus.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/cpus.c b/cpus.c
>> index dd7ac13..3ec15cb 100644
>> --- a/cpus.c
>> +++ b/cpus.c
>> @@ -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.

Thank you! I'm resubmitting the patch.

>
>>         seqlock_write_lock(&timers_state.vm_clock_seqlock);
>>         qemu_icount_bias += warp;
>>         seqlock_write_unlock(&timers_state.vm_clock_seqlock);
>> -- 
>> 1.9.1
>>
>>
>>
diff mbox

Patch

diff --git a/cpus.c b/cpus.c
index dd7ac13..3ec15cb 100644
--- a/cpus.c
+++ b/cpus.c
@@ -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);