From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59109) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZKN0x-0002Lz-Ad for qemu-devel@nongnu.org; Wed, 29 Jul 2015 04:47:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZKN0v-0006Go-TO for qemu-devel@nongnu.org; Wed, 29 Jul 2015 04:47:03 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:61884) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZKN0v-0006Fm-52 for qemu-devel@nongnu.org; Wed, 29 Jul 2015 04:47:01 -0400 From: zhanghailiang Date: Wed, 29 Jul 2015 16:45:39 +0800 Message-ID: <1438159544-6224-30-git-send-email-zhang.zhanghailiang@huawei.com> In-Reply-To: <1438159544-6224-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1438159544-6224-1-git-send-email-zhang.zhanghailiang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH COLO-Frame v8 29/34] COLO: Do checkpoint according to the result of packets comparation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: lizhijian@cn.fujitsu.com, quintela@redhat.com, yunhong.jiang@intel.com, eddie.dong@intel.com, peter.huangpeng@huawei.com, dgilbert@redhat.com, arei.gonglei@huawei.com, amit.shah@redhat.com, zhanghailiang Only do checkpoint, when the PVM's and SVM's output net packets are inconsistent, We also limit the min time between two continuous checkpoint action, to give VM a change to run. Signed-off-by: zhanghailiang Signed-off-by: Li Zhijian --- include/net/colo-nic.h | 2 ++ migration/colo.c | 32 ++++++++++++++++++++++++++++++++ net/colo-nic.c | 5 +++++ 3 files changed, 39 insertions(+) diff --git a/include/net/colo-nic.h b/include/net/colo-nic.h index 7b8ff57..271ab8b 100644 --- a/include/net/colo-nic.h +++ b/include/net/colo-nic.h @@ -30,4 +30,6 @@ void colo_remove_nic_devices(COLONicState *cns); int colo_proxy_init(enum COLOMode mode); void colo_proxy_destroy(enum COLOMode mode); +int colo_proxy_compare(void); + #endif diff --git a/migration/colo.c b/migration/colo.c index c286152..f9f2156 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -19,6 +19,13 @@ #include "qapi-event.h" #include "net/colo-nic.h" +/* +* We should not do checkpoint one after another without any time interval, +* Because this will lead continuous 'stop' status for VM. +* CHECKPOINT_MIN_PERIOD is the min time limit between two checkpoint action. +*/ +#define CHECKPOINT_MIN_PERIOD 100 /* unit: ms */ + /* Fix me: Convert to use QAPI */ typedef enum COLOCommand { COLO_CHECPOINT_READY = 0x46, @@ -341,6 +348,7 @@ static void *colo_thread(void *opaque) { MigrationState *s = opaque; QEMUFile *colo_control = NULL; + int64_t current_time, checkpoint_time = qemu_clock_get_ms(QEMU_CLOCK_HOST); int i, ret; failover_init_state(); @@ -376,15 +384,39 @@ static void *colo_thread(void *opaque) trace_colo_vm_state_change("stop", "run"); while (s->state == MIGRATION_STATUS_COLO) { + int proxy_checkpoint_req; + if (failover_request_is_active()) { error_report("failover request"); goto out; } + /* wait for a colo checkpoint */ + proxy_checkpoint_req = colo_proxy_compare(); + if (proxy_checkpoint_req < 0) { + goto out; + } else if (!proxy_checkpoint_req) { + /* + * No checkpoint is needed, wait for 1ms and then + * check if we need checkpoint again + */ + g_usleep(1000); + continue; + } else { + int64_t interval; + + current_time = qemu_clock_get_ms(QEMU_CLOCK_HOST); + interval = current_time - checkpoint_time; + if (interval < CHECKPOINT_MIN_PERIOD) { + /* Limit the min time between two checkpoint */ + g_usleep((1000*(CHECKPOINT_MIN_PERIOD - interval))); + } + } /* start a colo checkpoint */ if (colo_do_checkpoint_transaction(s, colo_control)) { goto out; } + checkpoint_time = qemu_clock_get_ms(QEMU_CLOCK_HOST); } out: diff --git a/net/colo-nic.c b/net/colo-nic.c index 49380ce..d2073b8 100644 --- a/net/colo-nic.c +++ b/net/colo-nic.c @@ -427,3 +427,8 @@ void colo_proxy_destroy(enum COLOMode mode) } teardown_nic(mode, getpid()); } + +int colo_proxy_compare(void) +{ + return atomic_xchg(&packet_compare_different, 0); +} -- 1.8.3.1