Patchwork [08/10] Count nanoseconds with uint64_t not doubles

login
register
mail settings
Submitter Juan Quintela
Date Nov. 23, 2010, 11:03 p.m.
Message ID <d9aa9491982ed4cd5bdaa66d6ca09ede41e7d878.1290552026.git.quintela@redhat.com>
Download mbox | patch
Permalink /patch/72771/
State New
Headers show

Comments

Juan Quintela - Nov. 23, 2010, 11:03 p.m.
From: Juan Quintela <quintela@trasno.org>

Signed-off-by: Juan Quintela <quintela@trasno.org>
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 arch_init.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
Anthony Liguori - Nov. 30, 2010, 2:07 a.m.
On 11/23/2010 05:03 PM, Juan Quintela wrote:
> From: Juan Quintela<quintela@trasno.org>
>
> Signed-off-by: Juan Quintela<quintela@trasno.org>
> Signed-off-by: Juan Quintela<quintela@redhat.com>
>    

Why?

Regards,

Anthony Liguori

> ---
>   arch_init.c |    7 ++++---
>   1 files changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/arch_init.c b/arch_init.c
> index 9e941a0..d32aaae 100644
> --- a/arch_init.c
> +++ b/arch_init.c
> @@ -216,6 +216,7 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)
>   {
>       ram_addr_t addr;
>       uint64_t bytes_transferred_last;
> +    uint64_t t0;
>       double bwidth = 0;
>
>       if (stage<  0) {
> @@ -258,7 +259,7 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)
>       }
>
>       bytes_transferred_last = bytes_transferred;
> -    bwidth = qemu_get_clock_ns(rt_clock);
> +    t0 = qemu_get_clock_ns(rt_clock);
>
>       while (!qemu_file_rate_limit(f)) {
>           int bytes_sent;
> @@ -270,8 +271,8 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)
>           }
>       }
>
> -    bwidth = qemu_get_clock_ns(rt_clock) - bwidth;
> -    bwidth = (bytes_transferred - bytes_transferred_last) / bwidth;
> +    t0 = qemu_get_clock_ns(rt_clock) - t0;
> +    bwidth = (bytes_transferred - bytes_transferred_last) / t0;
>
>       /* if we haven't transferred anything this round, force expected_time to a
>        * a very high value, but without crashing */
>
Paolo Bonzini - Nov. 30, 2010, 7:17 a.m.
On 11/24/2010 12:03 AM, Juan Quintela wrote:
> -    bwidth = qemu_get_clock_ns(rt_clock) - bwidth;
> -    bwidth = (bytes_transferred - bytes_transferred_last) / bwidth;
> +    t0 = qemu_get_clock_ns(rt_clock) - t0;
> +    bwidth = (bytes_transferred - bytes_transferred_last) / t0;

The result here is integer too.  Is this desired?

Paolo
Juan Quintela - Nov. 30, 2010, 2:40 p.m.
Anthony Liguori <anthony@codemonkey.ws> wrote:
> On 11/23/2010 05:03 PM, Juan Quintela wrote:
>> From: Juan Quintela<quintela@trasno.org>
>>
>> Signed-off-by: Juan Quintela<quintela@trasno.org>
>> Signed-off-by: Juan Quintela<quintela@redhat.com>
>>    
>
> Why?

I needed the precision for the timestamp.  Nanoseconds is an "integer"
property, not a float value.  And ferther more, until last line, we are
using a variable named "bwidth" to measure times.

Later, Juan.

> Regards,
>
> Anthony Liguori
>
>> ---
>>   arch_init.c |    7 ++++---
>>   1 files changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/arch_init.c b/arch_init.c
>> index 9e941a0..d32aaae 100644
>> --- a/arch_init.c
>> +++ b/arch_init.c
>> @@ -216,6 +216,7 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)
>>   {
>>       ram_addr_t addr;
>>       uint64_t bytes_transferred_last;
>> +    uint64_t t0;
>>       double bwidth = 0;
>>
>>       if (stage<  0) {
>> @@ -258,7 +259,7 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)
>>       }
>>
>>       bytes_transferred_last = bytes_transferred;
>> -    bwidth = qemu_get_clock_ns(rt_clock);
>> +    t0 = qemu_get_clock_ns(rt_clock);
>>
>>       while (!qemu_file_rate_limit(f)) {
>>           int bytes_sent;
>> @@ -270,8 +271,8 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)
>>           }
>>       }
>>
>> -    bwidth = qemu_get_clock_ns(rt_clock) - bwidth;
>> -    bwidth = (bytes_transferred - bytes_transferred_last) / bwidth;
>> +    t0 = qemu_get_clock_ns(rt_clock) - t0;
>> +    bwidth = (bytes_transferred - bytes_transferred_last) / t0;
>>
>>       /* if we haven't transferred anything this round, force expected_time to a
>>        * a very high value, but without crashing */
>>

Patch

diff --git a/arch_init.c b/arch_init.c
index 9e941a0..d32aaae 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -216,6 +216,7 @@  int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)
 {
     ram_addr_t addr;
     uint64_t bytes_transferred_last;
+    uint64_t t0;
     double bwidth = 0;

     if (stage < 0) {
@@ -258,7 +259,7 @@  int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)
     }

     bytes_transferred_last = bytes_transferred;
-    bwidth = qemu_get_clock_ns(rt_clock);
+    t0 = qemu_get_clock_ns(rt_clock);

     while (!qemu_file_rate_limit(f)) {
         int bytes_sent;
@@ -270,8 +271,8 @@  int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)
         }
     }

-    bwidth = qemu_get_clock_ns(rt_clock) - bwidth;
-    bwidth = (bytes_transferred - bytes_transferred_last) / bwidth;
+    t0 = qemu_get_clock_ns(rt_clock) - t0;
+    bwidth = (bytes_transferred - bytes_transferred_last) / t0;

     /* if we haven't transferred anything this round, force expected_time to a
      * a very high value, but without crashing */