From nobody Sun Feb 8 22:34:05 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487010426380189.21669940788536; Mon, 13 Feb 2017 10:27:06 -0800 (PST) Received: from localhost ([::1]:58756 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdLL6-00041b-Pw for importer@patchew.org; Mon, 13 Feb 2017 13:27:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39112) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdKm4-0003aV-3N for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdKm2-0005xH-Il for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36974) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cdKm2-0005x3-9k for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:50 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 553CE7E9F1; Mon, 13 Feb 2017 17:50:50 +0000 (UTC) Received: from dgilbert-t530.redhat.com (ovpn-117-140.ams2.redhat.com [10.36.117.140]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1DHoYkH007824; Mon, 13 Feb 2017 12:50:48 -0500 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Mon, 13 Feb 2017 17:50:27 +0000 Message-Id: <20170213175033.7314-9-dgilbert@redhat.com> In-Reply-To: <20170213175033.7314-1-dgilbert@redhat.com> References: <20170213175033.7314-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 13 Feb 2017 17:50:50 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 08/14] COLO: fix setting checkpoint-delay not working properly X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbutsykin@virtuozzo.com, amit@kernel.org, zhang.zhanghailiang@huawei.com, ashijeetacharya@gmail.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: zhanghailiang If we set checkpoint-delay through command 'migrate-set-parameters', It will not take effect until we finish last sleep chekpoint-delay, That's will be offensive espeically when we want to change its value from an extreme big one to a proper value. Fix it by using timer to realize checkpoint-delay. Signed-off-by: zhanghailiang Message-Id: <1484657864-21708-2-git-send-email-zhang.zhanghailiang@huawei.c= om> Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Dr. David Alan Gilbert --- include/migration/colo.h | 2 ++ include/migration/migration.h | 5 +++++ migration/colo.c | 33 +++++++++++++++++++++++---------- migration/migration.c | 3 +++ 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/include/migration/colo.h b/include/migration/colo.h index e32eef4..2bbff9e 100644 --- a/include/migration/colo.h +++ b/include/migration/colo.h @@ -35,4 +35,6 @@ COLOMode get_colo_mode(void); =20 /* failover */ void colo_do_failover(MigrationState *s); + +void colo_checkpoint_notify(void *opaque); #endif diff --git a/include/migration/migration.h b/include/migration/migration.h index 71ce190..cb83f16 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -188,6 +188,11 @@ struct MigrationState /* The RAMBlock used in the last src_page_request */ RAMBlock *last_req_rb; =20 + /* The semaphore is used to notify COLO thread to do checkpoint */ + QemuSemaphore colo_checkpoint_sem; + int64_t colo_checkpoint_time; + QEMUTimer *colo_delay_timer; + /* The last error that occurred */ Error *error; }; diff --git a/migration/colo.c b/migration/colo.c index 93c85c5..08b2e46 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -302,7 +302,7 @@ static void colo_process_checkpoint(MigrationState *s) { QIOChannelBuffer *bioc; QEMUFile *fb =3D NULL; - int64_t current_time, checkpoint_time =3D qemu_clock_get_ms(QEMU_CLOCK= _HOST); + int64_t current_time =3D qemu_clock_get_ms(QEMU_CLOCK_HOST); Error *local_err =3D NULL; int ret; =20 @@ -332,26 +332,21 @@ static void colo_process_checkpoint(MigrationState *s) qemu_mutex_unlock_iothread(); trace_colo_vm_state_change("stop", "run"); =20 + timer_mod(s->colo_delay_timer, + current_time + s->parameters.x_checkpoint_delay); + while (s->state =3D=3D MIGRATION_STATUS_COLO) { if (failover_get_state() !=3D FAILOVER_STATUS_NONE) { error_report("failover request"); goto out; } =20 - current_time =3D qemu_clock_get_ms(QEMU_CLOCK_HOST); - if (current_time - checkpoint_time < - s->parameters.x_checkpoint_delay) { - int64_t delay_ms; + qemu_sem_wait(&s->colo_checkpoint_sem); =20 - delay_ms =3D s->parameters.x_checkpoint_delay - - (current_time - checkpoint_time); - g_usleep(delay_ms * 1000); - } ret =3D colo_do_checkpoint_transaction(s, bioc, fb); if (ret < 0) { goto out; } - checkpoint_time =3D qemu_clock_get_ms(QEMU_CLOCK_HOST); } =20 out: @@ -364,14 +359,32 @@ out: qemu_fclose(fb); } =20 + timer_del(s->colo_delay_timer); + if (s->rp_state.from_dst_file) { qemu_fclose(s->rp_state.from_dst_file); } } =20 +void colo_checkpoint_notify(void *opaque) +{ + MigrationState *s =3D opaque; + int64_t next_notify_time; + + qemu_sem_post(&s->colo_checkpoint_sem); + s->colo_checkpoint_time =3D qemu_clock_get_ms(QEMU_CLOCK_HOST); + next_notify_time =3D s->colo_checkpoint_time + + s->parameters.x_checkpoint_delay; + timer_mod(s->colo_delay_timer, next_notify_time); +} + void migrate_start_colo_process(MigrationState *s) { qemu_mutex_unlock_iothread(); + qemu_sem_init(&s->colo_checkpoint_sem, 0); + s->colo_delay_timer =3D timer_new_ms(QEMU_CLOCK_HOST, + colo_checkpoint_notify, s); + migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE, MIGRATION_STATUS_COLO); colo_process_checkpoint(s); diff --git a/migration/migration.c b/migration/migration.c index 2a26a20..c6ae69d 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -891,6 +891,9 @@ void qmp_migrate_set_parameters(MigrationParameters *pa= rams, Error **errp) =20 if (params->has_x_checkpoint_delay) { s->parameters.x_checkpoint_delay =3D params->x_checkpoint_delay; + if (migration_in_colo_state()) { + colo_checkpoint_notify(s); + } } } =20 --=20 2.9.3