diff mbox

[6/8] Exit loop if we have been there too long

Message ID e957b4e7af8e1854e2a26e3f670c90687ed986a4.1340371865.git.quintela@redhat.com
State New
Headers show

Commit Message

Juan Quintela June 22, 2012, 1:46 p.m. UTC
Checking each 64 pages is a random magic number as good as any other.
We don't want to test too many times, but on the other hand,
qemu_get_clock_ns() is not so expensive either.  We want to be sure
that we spent less than 50ms (half of buffered_file timer), if we
spent more than 100ms, all the accounting got wrong.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 arch_init.c |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Comments

Orit Wasserman June 25, 2012, 6:26 a.m. UTC | #1
On 06/22/2012 04:46 PM, Juan Quintela wrote:
> Checking each 64 pages is a random magic number as good as any other.
> We don't want to test too many times, but on the other hand,
> qemu_get_clock_ns() is not so expensive either.  We want to be sure
> that we spent less than 50ms (half of buffered_file timer), if we
> spent more than 100ms, all the accounting got wrong.
> 
> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
>  arch_init.c |   17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/arch_init.c b/arch_init.c
> index 424efe7..7de1abf 100644
> --- a/arch_init.c
> +++ b/arch_init.c
> @@ -294,12 +294,15 @@ static void sort_ram_list(void)
>      g_free(blocks);
>  }
> 
> +#define MAX_WAIT 50 /* ms, half buffered_file limit */
> +
>  int ram_save_live(QEMUFile *f, int stage, void *opaque)
>  {
>      ram_addr_t addr;
>      uint64_t bytes_transferred_last;
>      double bwidth = 0;
>      int ret;
> +    int i;
> 
>      if (stage < 0) {
>          memory_global_dirty_log_stop();
> @@ -339,6 +342,7 @@ int ram_save_live(QEMUFile *f, int stage, void *opaque)
>      bytes_transferred_last = bytes_transferred;
>      bwidth = qemu_get_clock_ns(rt_clock);
> 
> +    i = 0;
>      while ((ret = qemu_file_rate_limit(f)) == 0) {
>          int bytes_sent;
> 
> @@ -347,6 +351,19 @@ int ram_save_live(QEMUFile *f, int stage, void *opaque)
>          if (bytes_sent == 0) { /* no more blocks */
>              break;
>          }
> +        /* we want to check in the 1st loop, just in case it was the 1st time
> +           and we had to sync the dirty bitmap.
> +           qemu_get_clock_ns() is a bit expensive, so we only check each some
> +           iterations
> +        */
> +        if ((i & 63) == 0) {
> +            uint64_t t1 = (qemu_get_clock_ns(rt_clock) - bwidth) / 1000000;
> +            if (t1 > MAX_WAIT) {
> +                DPRINTF("big wait: %ld milliseconds, %d iterations\n", t1, i);
> +                break;
> +            }
> +        }
> +        i++;
>      }
> 
>      if (ret < 0) {

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
diff mbox

Patch

diff --git a/arch_init.c b/arch_init.c
index 424efe7..7de1abf 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -294,12 +294,15 @@  static void sort_ram_list(void)
     g_free(blocks);
 }

+#define MAX_WAIT 50 /* ms, half buffered_file limit */
+
 int ram_save_live(QEMUFile *f, int stage, void *opaque)
 {
     ram_addr_t addr;
     uint64_t bytes_transferred_last;
     double bwidth = 0;
     int ret;
+    int i;

     if (stage < 0) {
         memory_global_dirty_log_stop();
@@ -339,6 +342,7 @@  int ram_save_live(QEMUFile *f, int stage, void *opaque)
     bytes_transferred_last = bytes_transferred;
     bwidth = qemu_get_clock_ns(rt_clock);

+    i = 0;
     while ((ret = qemu_file_rate_limit(f)) == 0) {
         int bytes_sent;

@@ -347,6 +351,19 @@  int ram_save_live(QEMUFile *f, int stage, void *opaque)
         if (bytes_sent == 0) { /* no more blocks */
             break;
         }
+        /* we want to check in the 1st loop, just in case it was the 1st time
+           and we had to sync the dirty bitmap.
+           qemu_get_clock_ns() is a bit expensive, so we only check each some
+           iterations
+        */
+        if ((i & 63) == 0) {
+            uint64_t t1 = (qemu_get_clock_ns(rt_clock) - bwidth) / 1000000;
+            if (t1 > MAX_WAIT) {
+                DPRINTF("big wait: %ld milliseconds, %d iterations\n", t1, i);
+                break;
+            }
+        }
+        i++;
     }

     if (ret < 0) {