From patchwork Mon Feb 22 02:40:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhanghailiang X-Patchwork-Id: 8370501 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 47865C0553 for ; Mon, 22 Feb 2016 02:47:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 49D6E20396 for ; Mon, 22 Feb 2016 02:47:18 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1B0B82038D for ; Mon, 22 Feb 2016 02:47:17 +0000 (UTC) Received: from localhost ([::1]:46097 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXgWq-0005A8-Fq for patchwork-qemu-devel@patchwork.kernel.org; Sun, 21 Feb 2016 21:47:16 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59604) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXgRA-0000k9-Mg for qemu-devel@nongnu.org; Sun, 21 Feb 2016 21:41:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aXgR8-0007PY-I2 for qemu-devel@nongnu.org; Sun, 21 Feb 2016 21:41:24 -0500 Received: from szxga02-in.huawei.com ([119.145.14.65]:8312) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXgR5-0007HX-RD for qemu-devel@nongnu.org; Sun, 21 Feb 2016 21:41:22 -0500 Received: from 172.24.1.51 (EHLO SZXEML429-HUB.china.huawei.com) ([172.24.1.51]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DBU14311; Mon, 22 Feb 2016 10:41:02 +0800 (CST) Received: from localhost (10.177.24.212) by SZXEML429-HUB.china.huawei.com (10.82.67.184) with Microsoft SMTP Server id 14.3.235.1; Mon, 22 Feb 2016 10:40:53 +0800 From: zhanghailiang To: Date: Mon, 22 Feb 2016 10:40:01 +0800 Message-ID: <1456108832-24212-8-git-send-email-zhang.zhanghailiang@huawei.com> X-Mailer: git-send-email 1.9.0.msysgit.0 In-Reply-To: <1456108832-24212-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1456108832-24212-1-git-send-email-zhang.zhanghailiang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.24.212] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090204.56CA753F.004C, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 1a77d1e00ab575d45dbfd1740d080da2 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.65 Cc: xiecl.fnst@cn.fujitsu.com, lizhijian@cn.fujitsu.com, quintela@redhat.com, armbru@redhat.com, yunhong.jiang@intel.com, eddie.dong@intel.com, peter.huangpeng@huawei.com, dgilbert@redhat.com, zhanghailiang , arei.gonglei@huawei.com, stefanha@redhat.com, amit.shah@redhat.com, zhangchen.fnst@cn.fujitsu.com, hongyang.yang@easystack.cn Subject: [Qemu-devel] [PATCH COLO-Frame v15 07/38] COLO: Implement colo checkpoint protocol X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We need communications protocol of user-defined to control the checkpoint process. The new checkpoint request is started by Primary VM, and the interactive process like below: Checkpoint synchronizing points: Primary Secondary initial work 'checkpoint-ready' <-------------------- @ 'checkpoint-request' @ --------------------> Suspend (Only in hybrid mode) 'checkpoint-reply' <-------------------- @ Suspend&Save state 'vmstate-send' @ --------------------> Send state Receive state 'vmstate-received' <-------------------- @ Release packets Load state 'vmstate-load' <-------------------- @ Resume Resume (Only in hybrid mode) Start Comparing (Only in hybrid mode) NOTE: 1) '@' who sends the message 2) Every sync-point is synchronized by two sides with only one handshake(single direction) for low-latency. If more strict synchronization is required, a opposite direction sync-point should be added. 3) Since sync-points are single direction, the remote side may go forward a lot when this side just receives the sync-point. 4) For now, we only support 'periodic' checkpoint, for which the Secondary VM is not running, later we will support 'hybrid' mode. Signed-off-by: zhanghailiang Signed-off-by: Li Zhijian Signed-off-by: Gonglei Cc: Eric Blake Cc: Markus Armbruster Cc: Dr. David Alan Gilbert Reviewed-by: Dr. David Alan Gilbert --- v14: - Rename 'COLOCommand' to 'COLOMessage'. (Markus's suggestion) - Add Reviewd-by tag v13: - Refactor colo command related helper functions, use 'Error **errp' parameter instead of return value to indicate success or failure. - Fix some other comments from Markus. v12: - Rename colo_ctl_put() to colo_put_cmd() - Rename colo_ctl_get() to colo_get_check_cmd() and drop the third parameter - Rename colo_ctl_get_cmd() to colo_get_cmd() - Remove useless 'invalid' member for COLOcommand enum. v11: - Add missing 'checkpoint-ready' communication in comment. - Use parameter to return 'value' for colo_ctl_get() (Dave's suggestion) - Fix trace for colo_ctl_get() to trace command and value both v10: - Rename enum COLOCmd to COLOCommand (Eric's suggestion). - Remove unused 'ram-steal' --- migration/colo.c | 201 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- qapi-schema.json | 25 +++++++ trace-events | 2 + 3 files changed, 226 insertions(+), 2 deletions(-) diff --git a/migration/colo.c b/migration/colo.c index 43e9890..c0ff088 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -10,6 +10,7 @@ * later. See the COPYING file in the top-level directory. */ +#include #include "sysemu/sysemu.h" #include "migration/colo.h" #include "trace.h" @@ -34,22 +35,147 @@ bool migration_incoming_in_colo_state(void) return mis && (mis->state == MIGRATION_STATUS_COLO); } +static void colo_put_cmd(QEMUFile *f, COLOMessage cmd, + Error **errp) +{ + int ret; + + if (cmd >= COLO_MESSAGE__MAX) { + error_setg(errp, "%s: Invalid cmd", __func__); + return; + } + qemu_put_be32(f, cmd); + qemu_fflush(f); + + ret = qemu_file_get_error(f); + if (ret < 0) { + error_setg_errno(errp, -ret, "Can't put COLO command"); + } + trace_colo_put_cmd(COLOMessage_lookup[cmd]); +} + +static COLOMessage colo_get_cmd(QEMUFile *f, Error **errp) +{ + COLOMessage cmd; + int ret; + + cmd = qemu_get_be32(f); + ret = qemu_file_get_error(f); + if (ret < 0) { + error_setg_errno(errp, -ret, "Can't get COLO command"); + return cmd; + } + if (cmd >= COLO_MESSAGE__MAX) { + error_setg(errp, "%s: Invalid cmd", __func__); + return cmd; + } + trace_colo_get_cmd(COLOMessage_lookup[cmd]); + return cmd; +} + +static void colo_get_check_cmd(QEMUFile *f, COLOMessage expect_cmd, + Error **errp) +{ + COLOMessage cmd; + Error *local_err = NULL; + + cmd = colo_get_cmd(f, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + if (cmd != expect_cmd) { + error_setg(errp, "Unexpected COLO command %d, expected %d", + expect_cmd, cmd); + } +} + +static int colo_do_checkpoint_transaction(MigrationState *s) +{ + Error *local_err = NULL; + + colo_put_cmd(s->to_dst_file, COLO_MESSAGE_CHECKPOINT_REQUEST, + &local_err); + if (local_err) { + goto out; + } + + colo_get_check_cmd(s->rp_state.from_dst_file, + COLO_MESSAGE_CHECKPOINT_REPLY, &local_err); + if (local_err) { + goto out; + } + + /* TODO: suspend and save vm state to colo buffer */ + + colo_put_cmd(s->to_dst_file, COLO_MESSAGE_VMSTATE_SEND, &local_err); + if (local_err) { + goto out; + } + + /* TODO: send vmstate to Secondary */ + + colo_get_check_cmd(s->rp_state.from_dst_file, + COLO_MESSAGE_VMSTATE_RECEIVED, &local_err); + if (local_err) { + goto out; + } + + colo_get_check_cmd(s->rp_state.from_dst_file, + COLO_MESSAGE_VMSTATE_LOADED, &local_err); + if (local_err) { + goto out; + } + + /* TODO: resume Primary */ + + return 0; +out: + if (local_err) { + error_report_err(local_err); + } + return -EINVAL; +} + static void colo_process_checkpoint(MigrationState *s) { + Error *local_err = NULL; + int ret; + s->rp_state.from_dst_file = qemu_file_get_return_path(s->to_dst_file); if (!s->rp_state.from_dst_file) { error_report("Open QEMUFile from_dst_file failed"); goto out; } + /* + * Wait for Secondary finish loading vm states and enter COLO + * restore. + */ + colo_get_check_cmd(s->rp_state.from_dst_file, + COLO_MESSAGE_CHECKPOINT_READY, &local_err); + if (local_err) { + goto out; + } + qemu_mutex_lock_iothread(); vm_start(); qemu_mutex_unlock_iothread(); trace_colo_vm_state_change("stop", "run"); - /*TODO: COLO checkpoint savevm loop*/ + while (s->state == MIGRATION_STATUS_COLO) { + /* start a colo checkpoint */ + ret = colo_do_checkpoint_transaction(s); + if (ret < 0) { + goto out; + } + } out: + /* Throw the unreported error message after exited from loop */ + if (local_err) { + error_report_err(local_err); + } migrate_set_state(&s->state, MIGRATION_STATUS_COLO, MIGRATION_STATUS_COMPLETED); @@ -67,9 +193,33 @@ void migrate_start_colo_process(MigrationState *s) qemu_mutex_lock_iothread(); } +static void colo_wait_handle_cmd(QEMUFile *f, int *checkpoint_request, + Error **errp) +{ + COLOMessage cmd; + Error *local_err = NULL; + + cmd = colo_get_cmd(f, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + switch (cmd) { + case COLO_MESSAGE_CHECKPOINT_REQUEST: + *checkpoint_request = 1; + break; + default: + *checkpoint_request = 0; + error_setg(errp, "Got unknown COLO command: %d", cmd); + break; + } +} + void *colo_process_incoming_thread(void *opaque) { MigrationIncomingState *mis = opaque; + Error *local_err = NULL; migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE, MIGRATION_STATUS_COLO); @@ -85,9 +235,56 @@ void *colo_process_incoming_thread(void *opaque) */ qemu_file_set_blocking(mis->from_src_file, true); - /* TODO: COLO checkpoint restore loop */ + colo_put_cmd(mis->to_src_file, COLO_MESSAGE_CHECKPOINT_READY, + &local_err); + if (local_err) { + goto out; + } + + while (mis->state == MIGRATION_STATUS_COLO) { + int request; + + colo_wait_handle_cmd(mis->from_src_file, &request, &local_err); + if (local_err) { + goto out; + } + assert(request); + /* FIXME: This is unnecessary for periodic checkpoint mode */ + colo_put_cmd(mis->to_src_file, COLO_MESSAGE_CHECKPOINT_REPLY, + &local_err); + if (local_err) { + goto out; + } + + colo_get_check_cmd(mis->from_src_file, + COLO_MESSAGE_VMSTATE_SEND, &local_err); + if (local_err) { + goto out; + } + + /* TODO: read migration data into colo buffer */ + + colo_put_cmd(mis->to_src_file, COLO_MESSAGE_VMSTATE_RECEIVED, + &local_err); + if (local_err) { + goto out; + } + + /* TODO: load vm state */ + + colo_put_cmd(mis->to_src_file, COLO_MESSAGE_VMSTATE_LOADED, + &local_err); + if (local_err) { + goto out; + } + } out: + /* Throw the unreported error message after exited from loop */ + if (local_err) { + error_report_err(local_err); + } + if (mis->to_src_file) { qemu_fclose(mis->to_src_file); } diff --git a/qapi-schema.json b/qapi-schema.json index 26a1d37..29afbb9 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -718,6 +718,31 @@ { 'command': 'migrate-start-postcopy' } ## +# @COLOMessage +# +# The message transmission between PVM and SVM +# +# @checkpoint-ready: SVM is ready for checkpointing +# +# @checkpoint-request: PVM tells SVM to prepare for new checkpointing +# +# @checkpoint-reply: SVM gets PVM's checkpoint request +# +# @vmstate-send: VM's state will be sent by PVM. +# +# @vmstate-size: The total size of VMstate. +# +# @vmstate-received: VM's state has been received by SVM. +# +# @vmstate-loaded: VM's state has been loaded by SVM. +# +# Since: 2.6 +## +{ 'enum': 'COLOMessage', + 'data': [ 'checkpoint-ready', 'checkpoint-request', 'checkpoint-reply', + 'vmstate-send', 'vmstate-size', 'vmstate-received', + 'vmstate-loaded' ] } + # @MouseInfo: # # Information about a mouse device. diff --git a/trace-events b/trace-events index 53714db..97807cd 100644 --- a/trace-events +++ b/trace-events @@ -1605,6 +1605,8 @@ postcopy_ram_incoming_cleanup_join(void) "" # migration/colo.c colo_vm_state_change(const char *old, const char *new) "Change '%s' => '%s'" +colo_put_cmd(const char *msg) "Send '%s' cmd" +colo_get_cmd(const char *msg) "Receive '%s' cmd" # kvm-all.c kvm_ioctl(int type, void *arg) "type 0x%x, arg %p"