From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35995) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLkIn-0003PO-SM for qemu-devel@nongnu.org; Wed, 11 Feb 2015 22:18:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YLkIi-0005km-OI for qemu-devel@nongnu.org; Wed, 11 Feb 2015 22:18:53 -0500 Received: from szxga03-in.huawei.com ([119.145.14.66]:44379) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLkIi-0005kP-5u for qemu-devel@nongnu.org; Wed, 11 Feb 2015 22:18:48 -0500 From: zhanghailiang Date: Thu, 12 Feb 2015 11:17:09 +0800 Message-ID: <1423711034-5340-23-git-send-email-zhang.zhanghailiang@huawei.com> In-Reply-To: <1423711034-5340-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1423711034-5340-1-git-send-email-zhang.zhanghailiang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH RFC v3 22/27] COLO: Do checkpoint according to the result of net packets comparing List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: zhanghailiang , yunhong.jiang@intel.com, eddie.dong@intel.com, dgilbert@redhat.com, peter.huangpeng@huawei.com, Gao feng , stefanha@redhat.com, pbonzini@redhat.com Only do checkpoint, when the VMs' output net packets are inconsistent. Signed-off-by: zhanghailiang Signed-off-by: Gao feng --- include/net/colo-nic.h | 2 ++ migration/colo.c | 23 +++++++++++++++++++++++ net/colo-nic.c | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) diff --git a/include/net/colo-nic.h b/include/net/colo-nic.h index 40dbcfb..67c9807 100644 --- a/include/net/colo-nic.h +++ b/include/net/colo-nic.h @@ -19,4 +19,6 @@ void colo_proxy_destroy(int side); void colo_add_nic_devices(NetClientState *nc); void colo_remove_nic_devices(NetClientState *nc); +int colo_proxy_compare(void); + #endif diff --git a/migration/colo.c b/migration/colo.c index 9f8a873..3e13611 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -24,6 +24,12 @@ do { fprintf(stdout, "colo: " fmt , ## __VA_ARGS__); } while (0) #else #define DPRINTF(fmt, ...) do {} while (0) #endif +/* + * force checkpoint timer: unit ms + * this is large because COLO checkpoint will mostly depend on + * COLO compare module. + */ +#define CHKPOINT_TIMER 10000 enum { COLO_READY = 0x46, @@ -321,6 +327,23 @@ static void *colo_thread(void *opaque) DPRINTF("vm resume to run\n"); while (s->state == MIG_STATE_COLO) { + int proxy_checkpoint_req; + + /* 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 + */ + usleep(1000); + continue; + } else { + DPRINTF("Net packets is not consistent!!!\n"); + } + /* start a colo checkpoint */ if (do_colo_transaction(s, colo_control)) { goto out; diff --git a/net/colo-nic.c b/net/colo-nic.c index 38d9bf5..563d661 100644 --- a/net/colo-nic.c +++ b/net/colo-nic.c @@ -37,6 +37,9 @@ typedef struct nic_device { bool is_up; } nic_device; +typedef struct colo_msg { + bool is_checkpoint; +} colo_msg; typedef struct colo_proxy { int sockfd; @@ -376,3 +379,41 @@ void colo_proxy_destroy(int side) cp_info.index = -1; colo_nic_side = -1; } +/* +do checkpoint: return 1 +error: return -1 +do not checkpoint: return 0 +*/ +int colo_proxy_compare(void) +{ + uint8_t *buff; + int64_t size; + struct nlmsghdr *h; + struct colo_msg *m; + int ret = -1; + + size = colo_proxy_recv(&buff, MSG_DONTWAIT); + + /* timeout, return no checkpoint message. */ + if (size <= 0) { + return 0; + } + + h = (struct nlmsghdr *) buff; + + if (h->nlmsg_type == NLMSG_ERROR) { + goto out; + } + + if (h->nlmsg_len < NLMSG_LENGTH(sizeof(*m))) { + goto out; + } + + m = NLMSG_DATA(h); + + ret = m->is_checkpoint ? 1 : 0; + +out: + g_free(buff); + return ret; +} -- 1.7.12.4