9ae3a8
From ab8cff98f973031b20d7f1971b4fe42d8bf6488c Mon Sep 17 00:00:00 2001
9ae3a8
Message-Id: <ab8cff98f973031b20d7f1971b4fe42d8bf6488c.1387382496.git.minovotn@redhat.com>
9ae3a8
In-Reply-To: <c5386144fbf09f628148101bc674e2421cdd16e3.1387382496.git.minovotn@redhat.com>
9ae3a8
References: <c5386144fbf09f628148101bc674e2421cdd16e3.1387382496.git.minovotn@redhat.com>
9ae3a8
From: Nigel Croxon <ncroxon@redhat.com>
9ae3a8
Date: Thu, 14 Nov 2013 22:52:52 +0100
9ae3a8
Subject: [PATCH 16/46] rdma: send pc.ram
9ae3a8
9ae3a8
RH-Author: Nigel Croxon <ncroxon@redhat.com>
9ae3a8
Message-id: <1384469598-13137-17-git-send-email-ncroxon@redhat.com>
9ae3a8
Patchwork-id: 55700
9ae3a8
O-Subject: [RHEL7.0 PATCH 16/42] rdma: send pc.ram
9ae3a8
Bugzilla: 1011720
9ae3a8
RH-Acked-by: Orit Wasserman <owasserm@redhat.com>
9ae3a8
RH-Acked-by: Amit Shah <amit.shah@redhat.com>
9ae3a8
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
9ae3a8
Bugzilla: 1011720
9ae3a8
https://bugzilla.redhat.com/show_bug.cgi?id=1011720
9ae3a8
9ae3a8
>From commit ID:
9ae3a8
commit 0033b8b42a1cc2a9350619ea19e11954b12fb819
9ae3a8
Author: Michael R. Hines <mrhines@us.ibm.com>
9ae3a8
Date:   Mon Jul 22 10:01:55 2013 -0400
9ae3a8
9ae3a8
    rdma: send pc.ram
9ae3a8
9ae3a8
    This takes advantages of the previous patches:
9ae3a8
9ae3a8
    1. use the new QEMUFileOps hook 'save_page'
9ae3a8
9ae3a8
    2. call out to the right accessor methods to invoke
9ae3a8
       the iteration hooks defined in QEMUFileOps
9ae3a8
9ae3a8
    Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
    Reviewed-by: Chegu Vinod <chegu_vinod@hp.com>
9ae3a8
    Tested-by: Chegu Vinod <chegu_vinod@hp.com>
9ae3a8
    Tested-by: Michael R. Hines <mrhines@us.ibm.com>
9ae3a8
    Signed-off-by: Michael R. Hines <mrhines@us.ibm.com>
9ae3a8
    Signed-off-by: Juan Quintela <quintela@redhat.com>
9ae3a8
---
9ae3a8
 arch_init.c |   33 ++++++++++++++++++++++++++++++++-
9ae3a8
 1 files changed, 32 insertions(+), 1 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Michal Novotny <minovotn@redhat.com>
9ae3a8
---
9ae3a8
 arch_init.c | 33 ++++++++++++++++++++++++++++++++-
9ae3a8
 1 file changed, 32 insertions(+), 1 deletion(-)
9ae3a8
9ae3a8
diff --git a/arch_init.c b/arch_init.c
9ae3a8
index e7da520..034341c 100644
9ae3a8
--- a/arch_init.c
9ae3a8
+++ b/arch_init.c
9ae3a8
@@ -118,6 +118,7 @@ static void check_guest_throttling(void);
9ae3a8
 #define RAM_SAVE_FLAG_EOS      0x10
9ae3a8
 #define RAM_SAVE_FLAG_CONTINUE 0x20
9ae3a8
 #define RAM_SAVE_FLAG_XBZRLE   0x40
9ae3a8
+/* 0x80 is reserved in migration.h start with 0x100 next */
9ae3a8
 
9ae3a8
 
9ae3a8
 static struct defconfig_file {
9ae3a8
@@ -476,6 +477,7 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
9ae3a8
                 ram_bulk_stage = false;
9ae3a8
             }
9ae3a8
         } else {
9ae3a8
+            int ret;
9ae3a8
             uint8_t *p;
9ae3a8
             int cont = (block == last_sent_block) ?
9ae3a8
                 RAM_SAVE_FLAG_CONTINUE : 0;
9ae3a8
@@ -484,7 +486,18 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
9ae3a8
 
9ae3a8
             /* In doubt sent page as normal */
9ae3a8
             bytes_sent = -1;
9ae3a8
-            if (is_zero_page(p)) {
9ae3a8
+            ret = ram_control_save_page(f, block->offset,
9ae3a8
+                               offset, TARGET_PAGE_SIZE, &bytes_sent);
9ae3a8
+
9ae3a8
+            if (ret != RAM_SAVE_CONTROL_NOT_SUPP) {
9ae3a8
+                if (ret != RAM_SAVE_CONTROL_DELAYED) {
9ae3a8
+                    if (bytes_sent > 0) {
9ae3a8
+                        acct_info.norm_pages++;
9ae3a8
+                    } else if (bytes_sent == 0) {
9ae3a8
+                        acct_info.dup_pages++;
9ae3a8
+                    }
9ae3a8
+                }
9ae3a8
+            } else if (is_zero_page(p)) {
9ae3a8
                 acct_info.dup_pages++;
9ae3a8
                 bytes_sent = save_block_hdr(f, block, offset, cont,
9ae3a8
                                             RAM_SAVE_FLAG_COMPRESS);
9ae3a8
@@ -636,6 +649,10 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
9ae3a8
     }
9ae3a8
 
9ae3a8
     qemu_mutex_unlock_ramlist();
9ae3a8
+
9ae3a8
+    ram_control_before_iterate(f, RAM_CONTROL_SETUP);
9ae3a8
+    ram_control_after_iterate(f, RAM_CONTROL_SETUP);
9ae3a8
+
9ae3a8
     qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
9ae3a8
 
9ae3a8
     return 0;
9ae3a8
@@ -654,6 +671,8 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
9ae3a8
         reset_ram_globals();
9ae3a8
     }
9ae3a8
 
9ae3a8
+    ram_control_before_iterate(f, RAM_CONTROL_ROUND);
9ae3a8
+
9ae3a8
     t0 = qemu_get_clock_ns(rt_clock);
9ae3a8
     i = 0;
9ae3a8
     while ((ret = qemu_file_rate_limit(f)) == 0) {
9ae3a8
@@ -685,6 +704,12 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
9ae3a8
 
9ae3a8
     qemu_mutex_unlock_ramlist();
9ae3a8
 
9ae3a8
+    /*
9ae3a8
+     * Must occur before EOS (or any QEMUFile operation)
9ae3a8
+     * because of RDMA protocol.
9ae3a8
+     */
9ae3a8
+    ram_control_after_iterate(f, RAM_CONTROL_ROUND);
9ae3a8
+
9ae3a8
     if (ret < 0) {
9ae3a8
         bytes_transferred += total_sent;
9ae3a8
         return ret;
9ae3a8
@@ -702,6 +727,8 @@ static int ram_save_complete(QEMUFile *f, void *opaque)
9ae3a8
     qemu_mutex_lock_ramlist();
9ae3a8
     migration_bitmap_sync();
9ae3a8
 
9ae3a8
+    ram_control_before_iterate(f, RAM_CONTROL_FINISH);
9ae3a8
+
9ae3a8
     /* try transferring iterative blocks of memory */
9ae3a8
 
9ae3a8
     /* flush all remaining blocks regardless of rate limiting */
9ae3a8
@@ -715,6 +742,8 @@ static int ram_save_complete(QEMUFile *f, void *opaque)
9ae3a8
         }
9ae3a8
         bytes_transferred += bytes_sent;
9ae3a8
     }
9ae3a8
+
9ae3a8
+    ram_control_after_iterate(f, RAM_CONTROL_FINISH);
9ae3a8
     migration_end();
9ae3a8
 
9ae3a8
     qemu_mutex_unlock_ramlist();
9ae3a8
@@ -914,6 +943,8 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
9ae3a8
                 ret = -EINVAL;
9ae3a8
                 goto done;
9ae3a8
             }
9ae3a8
+        } else if (flags & RAM_SAVE_FLAG_HOOK) {
9ae3a8
+            ram_control_load_hook(f, flags);
9ae3a8
         }
9ae3a8
         error = qemu_file_get_error(f);
9ae3a8
         if (error) {
9ae3a8
-- 
9ae3a8
1.7.11.7
9ae3a8