diff mbox

[COLO-Frame,v9,25/32] COLO: Control the checkpoint delay time by migrate-set-parameters command

Message ID 1441182199-8328-26-git-send-email-zhang.zhanghailiang@huawei.com
State New
Headers show

Commit Message

Zhanghailiang Sept. 2, 2015, 8:23 a.m. UTC
Add checkpoint-delay parameter for migrate-set-parameters, so that
we can control the checkpoint frequency when COLO is in periodic mode.

Cc: Luiz Capitulino <lcapitulino@redhat.com>
Cc: Eric Blake <eblake@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>
Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
---
 hmp.c                 |  8 ++++++++
 migration/colo.c      | 12 +++++-------
 migration/migration.c | 27 ++++++++++++++++++++++++++-
 qapi-schema.json      | 17 ++++++++++++++---
 4 files changed, 53 insertions(+), 11 deletions(-)
diff mbox

Patch

diff --git a/hmp.c b/hmp.c
index 94b0149..2f78666 100644
--- a/hmp.c
+++ b/hmp.c
@@ -273,6 +273,9 @@  void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
         monitor_printf(mon, " %s: %" PRId64,
             MigrationParameter_lookup[MIGRATION_PARAMETER_DECOMPRESS_THREADS],
             params->decompress_threads);
+        monitor_printf(mon, " %s: %" PRId64,
+            MigrationParameter_lookup[MIGRATION_PARAMETER_CHECKPOINT_DELAY],
+            params->checkpoint_delay);
         monitor_printf(mon, "\n");
     }
 
@@ -1222,6 +1225,7 @@  void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
     bool has_compress_level = false;
     bool has_compress_threads = false;
     bool has_decompress_threads = false;
+    bool has_checkpoint_delay = false;
     int i;
 
     for (i = 0; i < MIGRATION_PARAMETER_MAX; i++) {
@@ -1236,10 +1240,14 @@  void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
             case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
                 has_decompress_threads = true;
                 break;
+            case MIGRATION_PARAMETER_CHECKPOINT_DELAY:
+                has_checkpoint_delay = true;
+                break;
             }
             qmp_migrate_set_parameters(has_compress_level, value,
                                        has_compress_threads, value,
                                        has_decompress_threads, value,
+                                       has_checkpoint_delay, value,
                                        &err);
             break;
         }
diff --git a/migration/colo.c b/migration/colo.c
index 6bfebd1..0113e1b 100644
--- a/migration/colo.c
+++ b/migration/colo.c
@@ -19,12 +19,8 @@ 
 #include "qemu/sockets.h"
 #include "migration/failover.h"
 #include "qapi-event.h"
-
-/*
- * checkpoint interval: unit ms
- * Note: Please change this default value to 10000 when we support hybrid mode.
- */
-#define CHECKPOINT_MAX_PEROID 200
+#include "qmp-commands.h"
+#include "qapi-types.h"
 
 /*
  * The delay time before qemu begin the procedure of default failover treatment.
@@ -36,6 +32,7 @@ 
 
 static QEMUBH *colo_bh;
 static bool vmstate_loading;
+
 /* colo buffer */
 #define COLO_BUFFER_BASE_SIZE (4 * 1024 * 1024)
 
@@ -360,7 +357,8 @@  static void *colo_thread(void *opaque)
         }
 
         current_time = qemu_clock_get_ms(QEMU_CLOCK_HOST);
-        if (current_time - checkpoint_time < CHECKPOINT_MAX_PEROID) {
+        if (current_time - checkpoint_time <
+            s->parameters[MIGRATION_PARAMETER_CHECKPOINT_DELAY]) {
             g_usleep(100000);
             continue;
         }
diff --git a/migration/migration.c b/migration/migration.c
index f7ca2c4..b140678 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -49,6 +49,11 @@ 
 /* Migration XBZRLE default cache size */
 #define DEFAULT_MIGRATE_CACHE_SIZE (64 * 1024 * 1024)
 
+/* The delay time (in ms) between two COLO checkpoints
+ * Note: Please change this default value to 10000 when we support hybrid mode.
+ */
+#define DEFAULT_MIGRATE_CHECKPOINT_DELAY 200
+
 static NotifierList migration_state_notifiers =
     NOTIFIER_LIST_INITIALIZER(migration_state_notifiers);
 
@@ -72,6 +77,8 @@  MigrationState *migrate_get_current(void)
                 DEFAULT_MIGRATE_COMPRESS_THREAD_COUNT,
         .parameters[MIGRATION_PARAMETER_DECOMPRESS_THREADS] =
                 DEFAULT_MIGRATE_DECOMPRESS_THREAD_COUNT,
+        .parameters[MIGRATION_PARAMETER_CHECKPOINT_DELAY] =
+                DEFAULT_MIGRATE_CHECKPOINT_DELAY,
     };
 
     return &current_migration;
@@ -393,6 +400,8 @@  MigrationParameters *qmp_query_migrate_parameters(Error **errp)
             s->parameters[MIGRATION_PARAMETER_COMPRESS_THREADS];
     params->decompress_threads =
             s->parameters[MIGRATION_PARAMETER_DECOMPRESS_THREADS];
+    params->checkpoint_delay =
+            s->parameters[MIGRATION_PARAMETER_CHECKPOINT_DELAY];
 
     return params;
 }
@@ -526,7 +535,10 @@  void qmp_migrate_set_parameters(bool has_compress_level,
                                 bool has_compress_threads,
                                 int64_t compress_threads,
                                 bool has_decompress_threads,
-                                int64_t decompress_threads, Error **errp)
+                                int64_t decompress_threads,
+                                bool has_checkpoint_delay,
+                                int64_t checkpoint_delay,
+                                Error **errp)
 {
     MigrationState *s = migrate_get_current();
 
@@ -549,6 +561,11 @@  void qmp_migrate_set_parameters(bool has_compress_level,
                    "is invalid, it should be in the range of 1 to 255");
         return;
     }
+    if (has_checkpoint_delay && (checkpoint_delay < 0)) {
+        error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
+                    "checkpoint_delay",
+                    "is invalid, it should be positive");
+    }
 
     if (has_compress_level) {
         s->parameters[MIGRATION_PARAMETER_COMPRESS_LEVEL] = compress_level;
@@ -560,6 +577,9 @@  void qmp_migrate_set_parameters(bool has_compress_level,
         s->parameters[MIGRATION_PARAMETER_DECOMPRESS_THREADS] =
                                                     decompress_threads;
     }
+    if (has_checkpoint_delay) {
+        s->parameters[MIGRATION_PARAMETER_CHECKPOINT_DELAY] = checkpoint_delay;
+    }
 }
 
 /* shared migration helpers */
@@ -676,6 +696,8 @@  static MigrationState *migrate_init(const MigrationParams *params)
             s->parameters[MIGRATION_PARAMETER_COMPRESS_THREADS];
     int decompress_thread_count =
             s->parameters[MIGRATION_PARAMETER_DECOMPRESS_THREADS];
+    int checkpoint_delay =
+            s->parameters[MIGRATION_PARAMETER_CHECKPOINT_DELAY];
 
     memcpy(enabled_capabilities, s->enabled_capabilities,
            sizeof(enabled_capabilities));
@@ -691,6 +713,9 @@  static MigrationState *migrate_init(const MigrationParams *params)
                compress_thread_count;
     s->parameters[MIGRATION_PARAMETER_DECOMPRESS_THREADS] =
                decompress_thread_count;
+    s->parameters[MIGRATION_PARAMETER_CHECKPOINT_DELAY] =
+                checkpoint_delay;
+
     s->bandwidth_limit = bandwidth_limit;
     migrate_set_state(&s->state, MIGRATION_STATUS_NONE, MIGRATION_STATUS_SETUP);
 
diff --git a/qapi-schema.json b/qapi-schema.json
index f75e96b..75e1770 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -599,10 +599,14 @@ 
 #          compression, so set the decompress-threads to the number about 1/4
 #          of compress-threads is adequate.
 #
+# @checkpoint-delay: The delay time (in ms) between two COLO checkpoints in
+#          periodic mode.
+#
 # Since: 2.4
 ##
 { 'enum': 'MigrationParameter',
-  'data': ['compress-level', 'compress-threads', 'decompress-threads'] }
+  'data': ['compress-level', 'compress-threads', 'decompress-threads',
+           'checkpoint-delay' ] }
 
 #
 # @migrate-set-parameters
@@ -615,12 +619,15 @@ 
 #
 # @decompress-threads: decompression thread count
 #
+# @checkpoint-delay: the delay time between two checkpoints
+#
 # Since: 2.4
 ##
 { 'command': 'migrate-set-parameters',
   'data': { '*compress-level': 'int',
             '*compress-threads': 'int',
-            '*decompress-threads': 'int'} }
+            '*decompress-threads': 'int',
+            '*checkpoint-delay': 'int' } }
 
 #
 # @MigrationParameters
@@ -631,12 +638,16 @@ 
 #
 # @decompress-threads: decompression thread count
 #
+# @checkpoint-delay: the delay time between two COLO checkpoints
+#
 # Since: 2.4
 ##
 { 'struct': 'MigrationParameters',
   'data': { 'compress-level': 'int',
             'compress-threads': 'int',
-            'decompress-threads': 'int'} }
+            'decompress-threads': 'int',
+            'checkpoint-delay': 'int'} }
+
 ##
 # @query-migrate-parameters
 #