From patchwork Wed May 24 18:05:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlad Yasevich X-Patchwork-Id: 9746739 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D22DA601C2 for ; Wed, 24 May 2017 18:13:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C938C2834A for ; Wed, 24 May 2017 18:13:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BAE4828462; Wed, 24 May 2017 18:13:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 5BAD72834A for ; Wed, 24 May 2017 18:13:33 +0000 (UTC) Received: from localhost ([::1]:56217 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDamq-0001sm-JH for patchwork-qemu-devel@patchwork.kernel.org; Wed, 24 May 2017 14:13:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52261) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDafd-0003zj-D1 for qemu-devel@nongnu.org; Wed, 24 May 2017 14:06:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dDafc-0001PD-F9 for qemu-devel@nongnu.org; Wed, 24 May 2017 14:06:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35460) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dDafc-0001P0-6F for qemu-devel@nongnu.org; Wed, 24 May 2017 14:06:04 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2DB29448D68 for ; Wed, 24 May 2017 18:06:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2DB29448D68 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=vyasevic@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 2DB29448D68 Received: from flash.redhat.com (ovpn-116-215.phx2.redhat.com [10.3.116.215]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3FF7B77DC4; Wed, 24 May 2017 18:05:55 +0000 (UTC) From: Vladislav Yasevich To: qemu-devel@nongnu.org, dgilbert@redhat.com, quintela@redhat.com Date: Wed, 24 May 2017 14:05:24 -0400 Message-Id: <1495649128-10529-9-git-send-email-vyasevic@redhat.com> In-Reply-To: <1495649128-10529-1-git-send-email-vyasevic@redhat.com> References: <1495649128-10529-1-git-send-email-vyasevic@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 24 May 2017 18:06:03 +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] [PATCH 08/12] announce_timer: Add ability to reset an existing 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: germano@redhat.com, lvivier@redhat.com, mst@redhat.com, jasowang@redhat.com, Vladislav Yasevich , armbru@redhat.com, kashyap@redhat.com, jdenemar@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP It is now potentially possible to issue annouce-self command in a tight loop. Instead of doing nother, we can reset the timeout pararameters, especially since each instance may provide it's own values. This allows the user to extend or cut short currently runnig timer. Signed-off-by: Vladislav Yasevich --- include/migration/vmstate.h | 1 + migration/savevm.c | 41 +++++++++++++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 689b685..6dfdac3 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -1057,6 +1057,7 @@ void vmstate_register_ram_global(struct MemoryRegion *memory); typedef struct AnnounceTimer { QEMUTimer *tm; + QemuMutex active_lock; struct AnnounceTimer **entry; AnnounceParameters params; QEMUClockType type; diff --git a/migration/savevm.c b/migration/savevm.c index dcba8bd..e43658f 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -220,20 +220,29 @@ static void qemu_announce_self_iter(NICState *nic, void *opaque) AnnounceTimer *announce_timers[QEMU_ANNOUNCE__MAX]; +static void qemu_announce_timer_destroy(AnnounceTimer *timer) +{ + timer_del(timer->tm); + timer_free(timer->tm); + qemu_mutex_destroy(&timer->active_lock); + g_free(timer); +} + static void qemu_announce_self_once(void *opaque) { AnnounceTimer *timer = (AnnounceTimer *)opaque; + qemu_mutex_lock(&timer->active_lock); qemu_foreach_nic(qemu_announce_self_iter, NULL); - if (--timer->round) { + if (--timer->round ) { timer_mod(timer->tm, qemu_clock_get_ms(timer->type) + self_announce_delay(timer)); + qemu_mutex_unlock(&timer->active_lock); } else { - *(timer->entry) = NULL; - timer_del(timer->tm); - timer_free(timer->tm); - g_free(timer); + *(timer->entry) = NULL; + qemu_mutex_unlock(&timer->active_lock); + qemu_announce_timer_destroy(timer); } } @@ -242,6 +251,7 @@ AnnounceTimer *qemu_announce_timer_new(AnnounceParameters *params, { AnnounceTimer *timer = g_new(AnnounceTimer, 1); + qemu_mutex_init(&timer->active_lock); timer->params = *params; timer->round = params->rounds; timer->type = type; @@ -259,6 +269,21 @@ AnnounceTimer *qemu_announce_timer_create(AnnounceParameters *params, return timer; } +static void qemu_announce_timer_update(AnnounceTimer *timer, + AnnounceParameters *params) +{ + qemu_mutex_lock(&timer->active_lock); + + /* Update timer paramenter with any new values. + * Reset the number of rounds to run, and stop the current timer. + */ + timer->params = *params; + timer->round = params->rounds; + timer_del(timer->tm); + + qemu_mutex_unlock(&timer->active_lock); +} + void qemu_announce_self(AnnounceParameters *params, AnnounceType type) { AnnounceTimer *timer; @@ -270,11 +295,7 @@ void qemu_announce_self(AnnounceParameters *params, AnnounceType type) announce_timers[type] = timer; timer->entry = &announce_timers[type]; } else { - /* For now, don't do anything. If we want to reset the timer, - * we'll need to add locking to each announce timer to prevent - * races between timeout handling and a reset. - */ - return; + qemu_announce_timer_update(timer, params); } qemu_announce_self_once(timer); }