From nobody Fri May 3 06:34:49 2024 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.zohomail.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 1500963557441800.9895590852286; Mon, 24 Jul 2017 23:19:17 -0700 (PDT) Received: from localhost ([::1]:58653 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dZtBb-00008O-Dz for importer@patchew.org; Tue, 25 Jul 2017 02:19:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56397) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dZtAl-0008Cx-97 for qemu-devel@nongnu.org; Tue, 25 Jul 2017 02:18:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dZtAi-0002w1-3q for qemu-devel@nongnu.org; Tue, 25 Jul 2017 02:18:23 -0400 Received: from out1.zte.com.cn ([202.103.147.172]:40897) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dZtAh-0002rB-Gy for qemu-devel@nongnu.org; Tue, 25 Jul 2017 02:18:20 -0400 Received: from unknown (HELO mse01.zte.com.cn) (10.30.3.20) by localhost with (AES256-SHA encrypted) SMTP; 25 Jul 2017 06:16:24 -0000 Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id v6P6HYtx067175; Tue, 25 Jul 2017 14:17:34 +0800 (GMT-8) (envelope-from wang.guang55@zte.com.cn) Received: from localhost.localdomain ([10.74.120.79]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2017072514173717-4799920 ; Tue, 25 Jul 2017 14:17:37 +0800 X-scanvirus: By SEG_CYREN AntiVirus Engine X-scanresult: CLEAN X-MAILFROM: X-RCPTTO: X-FROMIP: 10.30.3.20 X-SEG-Scaned: 1 X-Received: unknown,10.30.3.20,20170725141624 From: Wang guang To: zhang.zhanghailiang@huawei.com Date: Wed, 26 Jul 2017 06:36:57 +0800 Message-Id: <1501022217-2783-1-git-send-email-wang.guang55@zte.com.cn> X-Mailer: git-send-email 1.8.3.1 X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2017-07-25 14:17:37, Serialize by Router on notes_smtp/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2017-07-25 14:17:30, Serialize complete at 2017-07-25 14:17:30 X-MAIL: mse01.zte.com.cn v6P6HYtx067175 X-HQIP: 127.0.0.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x [fuzzy] X-Received-From: 202.103.147.172 Subject: [Qemu-devel] [PATCH] COLO: use condtion variable instead of semaphore in colo_checkpoint_notify 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: Wang Yong , zhangchen.fnst@cn.fujitsu.com, Wang guang , quintela@redhat.com, qemu-devel@nongnu.org, dgilbert@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" Colo_checkpoint_notify use semaphore to notify COLO thread to do checkpoint. If x-checkpoint-delay is set to be a very small value,The semaphore will be accumulated.Even we change x-checkpoint-delay to be a big one,the checkp= oint will continue work for a long time.So we use condtion variable instead. Signed-off-by: Wang Guang Signed-off-by: Wang Yong --- migration/colo.c | 19 ++++++++++++++++--- migration/migration.h | 7 +++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/migration/colo.c b/migration/colo.c index a425543..617ef23 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -442,7 +442,13 @@ static void colo_process_checkpoint(MigrationState *s) goto out; } =20 - qemu_sem_wait(&s->colo_checkpoint_sem); + qemu_mutex_lock(&s->colo_checkpoint_mutex); + while (!s->colo_checkpoint_is_signaled) { + qemu_cond_wait(&s->colo_checkpoint_cond, + &s->colo_checkpoint_mutex); + } + s->colo_checkpoint_is_signaled =3D false; + qemu_mutex_unlock(&s->colo_checkpoint_mutex); =20 ret =3D colo_do_checkpoint_transaction(s, bioc, fb); if (ret < 0) { @@ -465,6 +471,8 @@ out: /* Hope this not to be too long to wait here */ qemu_sem_wait(&s->colo_exit_sem); qemu_sem_destroy(&s->colo_exit_sem); + qemu_cond_destroy(&s->colo_checkpoint_cond); + qemu_mutex_destroy(&s->colo_checkpoint_mutex); /* * Must be called after failover BH is completed, * Or the failover BH may shutdown the wrong fd that @@ -480,7 +488,10 @@ void colo_checkpoint_notify(void *opaque) MigrationState *s =3D opaque; int64_t next_notify_time; =20 - qemu_sem_post(&s->colo_checkpoint_sem); + qemu_mutex_lock(&s->colo_checkpoint_mutex); + s->colo_checkpoint_is_signaled =3D true; + qemu_cond_signal(&s->colo_checkpoint_cond); + qemu_mutex_unlock(&s->colo_checkpoint_mutex); 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; @@ -490,10 +501,12 @@ void colo_checkpoint_notify(void *opaque) 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); =20 + qemu_cond_init(&s->colo_checkpoint_cond); + qemu_mutex_init(&s->colo_checkpoint_mutex); + s->colo_checkpoint_is_signaled =3D false; qemu_sem_init(&s->colo_exit_sem, 0); migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE, MIGRATION_STATUS_COLO); diff --git a/migration/migration.h b/migration/migration.h index 148c9fa..9cdfedb 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -123,8 +123,11 @@ struct MigrationState /* The semaphore is used to notify COLO thread that failover is finish= ed */ QemuSemaphore colo_exit_sem; =20 - /* The semaphore is used to notify COLO thread to do checkpoint */ - QemuSemaphore colo_checkpoint_sem; + /* The Condtion Variable is used to notify COLO thread to do checkpoin= t */ + QemuMutex colo_checkpoint_mutex; + QemuCond colo_checkpoint_cond; + bool colo_checkpoint_is_signaled; + int64_t colo_checkpoint_time; QEMUTimer *colo_delay_timer; =20 --=20 1.8.3.1