Patchwork [2/3] Correct alarm deadline computation

login
register
mail settings
Submitter Paolo Bonzini
Date Jan. 31, 2011, 9:51 p.m.
Message ID <1296510679-12268-3-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/81246/
State New
Headers show

Comments

Paolo Bonzini - Jan. 31, 2011, 9:51 p.m.
When the QEMU_CLOCK_HOST clock was added, computation of its
deadline was added to qemu_next_deadline, which is correct but
incomplete.

I noticed this by reading the very convoluted rules whereby
qemu_next_deadline_dyntick is computed, which miss QEMU_CLOCK_HOST
when use_icount is true.  This patch inlines qemu_next_deadline
into qemu_next_deadline_dyntick, and then corrects the logic to skip
only QEMU_CLOCK_VIRTUAL when use_icount is true.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Cc: Jan Kiszka <jan.kiszka@siemens.com>
---
 qemu-timer.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)
Jan Kiszka - Feb. 1, 2011, 1:01 p.m.
On 2011-01-31 22:51, Paolo Bonzini wrote:
> When the QEMU_CLOCK_HOST clock was added, computation of its
> deadline was added to qemu_next_deadline, which is correct but
> incomplete.
> 
> I noticed this by reading the very convoluted rules whereby
> qemu_next_deadline_dyntick is computed, which miss QEMU_CLOCK_HOST
> when use_icount is true.  This patch inlines qemu_next_deadline
> into qemu_next_deadline_dyntick, and then corrects the logic to skip
> only QEMU_CLOCK_VIRTUAL when use_icount is true.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Jan Kiszka <jan.kiszka@siemens.com>
> ---
>  qemu-timer.c |   15 +++++++++++----
>  1 files changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/qemu-timer.c b/qemu-timer.c
> index 60283a8..c19d0a2 100644
> --- a/qemu-timer.c
> +++ b/qemu-timer.c
> @@ -724,11 +724,18 @@ static uint64_t qemu_next_deadline_dyntick(void)
>      int64_t delta;
>      int64_t rtdelta;
>  
> -    if (use_icount)
> +    if (!use_icount && active_timers[QEMU_CLOCK_VIRTUAL]) {
> +        delta = active_timers[QEMU_CLOCK_VIRTUAL]->expire_time -
> +                     qemu_get_clock(vm_clock);
> +    } else {
>          delta = INT32_MAX;
> -    else
> -        delta = qemu_next_deadline();
> -
> +    }
> +    if (active_timers[QEMU_CLOCK_HOST]) {
> +        int64_t hdelta = active_timers[QEMU_CLOCK_HOST]->expire_time -
> +                 qemu_get_clock(host_clock);
> +        if (hdelta < delta)
> +            delta = hdelta;
> +    }
>      if (active_timers[QEMU_CLOCK_REALTIME]) {
>          rtdelta = (active_timers[QEMU_CLOCK_REALTIME]->expire_time -
>                   qemu_get_clock_ns(rt_clock));

Looks good to me. I guess this applies without the first patch? Then it
should go in (unless you are working on a new version for 1/3).

Thanks for fixing this.

Jan
Paolo Bonzini - Feb. 1, 2011, 1:04 p.m.
On 02/01/2011 02:01 PM, Jan Kiszka wrote:
> Looks good to me. I guess this applies without the first patch? Then it
> should go in (unless you are working on a new version for 1/3).

It's wrong without the first patch (micro instead of nanoseconds). 
However, I read Anthony's message as a suggestion rather than a rejection.

Paolo
Jan Kiszka - Feb. 1, 2011, 1:07 p.m.
On 2011-02-01 14:04, Paolo Bonzini wrote:
> On 02/01/2011 02:01 PM, Jan Kiszka wrote:
>> Looks good to me. I guess this applies without the first patch? Then it
>> should go in (unless you are working on a new version for 1/3).
> 
> It's wrong without the first patch (micro instead of nanoseconds). 
> However, I read Anthony's message as a suggestion rather than a rejection.
> 

Yes, it's probably a better idea anyway to do this stepwise.

Jan

Patch

diff --git a/qemu-timer.c b/qemu-timer.c
index 60283a8..c19d0a2 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -724,11 +724,18 @@  static uint64_t qemu_next_deadline_dyntick(void)
     int64_t delta;
     int64_t rtdelta;
 
-    if (use_icount)
+    if (!use_icount && active_timers[QEMU_CLOCK_VIRTUAL]) {
+        delta = active_timers[QEMU_CLOCK_VIRTUAL]->expire_time -
+                     qemu_get_clock(vm_clock);
+    } else {
         delta = INT32_MAX;
-    else
-        delta = qemu_next_deadline();
-
+    }
+    if (active_timers[QEMU_CLOCK_HOST]) {
+        int64_t hdelta = active_timers[QEMU_CLOCK_HOST]->expire_time -
+                 qemu_get_clock(host_clock);
+        if (hdelta < delta)
+            delta = hdelta;
+    }
     if (active_timers[QEMU_CLOCK_REALTIME]) {
         rtdelta = (active_timers[QEMU_CLOCK_REALTIME]->expire_time -
                  qemu_get_clock_ns(rt_clock));