From patchwork Mon Jun 4 09:55:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 10446231 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 AA33C603D7 for ; Mon, 4 Jun 2018 10:02:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C0FE28BCF for ; Mon, 4 Jun 2018 10:02:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 90EF628BE5; Mon, 4 Jun 2018 10:02:51 +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=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=unavailable 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 2A8A228BCF for ; Mon, 4 Jun 2018 10:02:51 +0000 (UTC) Received: from localhost ([::1]:38640 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPmK9-0003zS-3Q for patchwork-qemu-devel@patchwork.kernel.org; Mon, 04 Jun 2018 06:02:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46531) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPmDu-0007Yw-6Q for qemu-devel@nongnu.org; Mon, 04 Jun 2018 05:56:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fPmDp-00019b-Ce for qemu-devel@nongnu.org; Mon, 04 Jun 2018 05:56:22 -0400 Received: from mail-pg0-x233.google.com ([2607:f8b0:400e:c05::233]:42116) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fPmDp-00019H-66 for qemu-devel@nongnu.org; Mon, 04 Jun 2018 05:56:17 -0400 Received: by mail-pg0-x233.google.com with SMTP id p9-v6so14239988pgc.9 for ; Mon, 04 Jun 2018 02:56:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rFUOcxpoIl7y/fY0ndasP+psXK2ovkE6HqfEdl19mjE=; b=GaqS63asSa6vTreBBOwH/jmN57rgIL+ibWSFAXJZTia/9O1qP1cbgZ+y+eZSVApKDP b/AkVzebpiEsKk2vCz84iSthQHzexy4JAma8u/miO/CAPbgE59KD4HV457qgY9jmp7t5 5le1U/th4r8jVwy8W9DsAKHAt4Oa9/b4+hVN9ZohOrLyPMof3Pe/g3mFcYu35q4FdURI ma1OQS03dDwwh/ezShfGjB7Ej7OM42FS7sIOLCDyi/H9y9PTbwdlIHfKW35fBBu52ajP JjCRIh1ZZeUvj3oIoX+hPNSyRLdkY4Que3ndgzLl8YPZrjGEQGRpGwdAp95+CyqZpgHE NWoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=rFUOcxpoIl7y/fY0ndasP+psXK2ovkE6HqfEdl19mjE=; b=pIK9lLAh/sWWJzsYXUmnmEDCbon9Yh6k+cidbexUswb8PCJVHzcmToUlbodZm0jOR0 mnJ3np/OJLNUDicAzFz4vpn9f8+hKCuMMvOJfWR5Nglx1yVhttqdIlzHiPtER6Cu69+6 sOftyEIHTI5KcXmyjUVcaxaetSJyYrC0ydgXp8hrYDmLS6500aHKE1p7GPWj/8tsHOkk tCruOowEUTiBhXG67OPQZzNlo8BGx2sW5dZIO6CCQ86zrH3mGtM8SSKuQcI4uy8FpaW+ aghvgrTT60wEMnbeWiO97ITrhSqGAAgiFgQz4etIaO1zaH1gD+WFRSalvUttp/nVNpJX rc/A== X-Gm-Message-State: ALKqPwca4x1r/YuBrnjykoVYS5+KVQqer+MMVbqy5xzkroRdD+6R3NJk rwIAdZo5a0k0mgxBRC9gQxE= X-Google-Smtp-Source: ADUXVKIsSoERgKOm+tFHUYP+1VZBGvGsU8431lYlMO3rqUabtWEec4d8QKQ+rbGTNSw5ev7OvC0Btw== X-Received: by 2002:a63:778b:: with SMTP id s133-v6mr16204691pgc.400.1528106176279; Mon, 04 Jun 2018 02:56:16 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.35]) by smtp.gmail.com with ESMTPSA id h130-v6sm124502105pfc.98.2018.06.04.02.56.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Jun 2018 02:56:15 -0700 (PDT) From: guangrong.xiao@gmail.com X-Google-Original-From: xiaoguangrong@tencent.com To: pbonzini@redhat.com, mst@redhat.com, mtosatti@redhat.com Date: Mon, 4 Jun 2018 17:55:12 +0800 Message-Id: <20180604095520.8563-5-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180604095520.8563-1-xiaoguangrong@tencent.com> References: <20180604095520.8563-1-xiaoguangrong@tencent.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::233 Subject: [Qemu-devel] [PATCH 04/12] migration: introduce migration_update_rates 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: kvm@vger.kernel.org, Xiao Guangrong , qemu-devel@nongnu.org, peterx@redhat.com, dgilbert@redhat.com, wei.w.wang@intel.com, jiang.biao2@zte.com.cn Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Xiao Guangrong It is used to slightly clean the code up, no logic is changed Signed-off-by: Xiao Guangrong Reviewed-by: Dr. David Alan Gilbert --- migration/ram.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index dd1283dd45..ee03b28435 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1130,6 +1130,25 @@ uint64_t ram_pagesize_summary(void) return summary; } +static void migration_update_rates(RAMState *rs, int64_t end_time) +{ + uint64_t iter_count = rs->iterations - rs->iterations_prev; + + /* calculate period counters */ + ram_counters.dirty_pages_rate = rs->num_dirty_pages_period * 1000 + / (end_time - rs->time_last_bitmap_sync); + + if (!iter_count) { + return; + } + + if (migrate_use_xbzrle()) { + xbzrle_counters.cache_miss_rate = (double)(xbzrle_counters.cache_miss - + rs->xbzrle_cache_miss_prev) / iter_count; + rs->xbzrle_cache_miss_prev = xbzrle_counters.cache_miss; + } +} + static void migration_bitmap_sync(RAMState *rs) { RAMBlock *block; @@ -1159,9 +1178,6 @@ static void migration_bitmap_sync(RAMState *rs) /* more than 1 second = 1000 millisecons */ if (end_time > rs->time_last_bitmap_sync + 1000) { - /* calculate period counters */ - ram_counters.dirty_pages_rate = rs->num_dirty_pages_period * 1000 - / (end_time - rs->time_last_bitmap_sync); bytes_xfer_now = ram_counters.transferred; /* During block migration the auto-converge logic incorrectly detects @@ -1183,16 +1199,9 @@ static void migration_bitmap_sync(RAMState *rs) } } - if (migrate_use_xbzrle()) { - if (rs->iterations_prev != rs->iterations) { - xbzrle_counters.cache_miss_rate = - (double)(xbzrle_counters.cache_miss - - rs->xbzrle_cache_miss_prev) / - (rs->iterations - rs->iterations_prev); - rs->xbzrle_cache_miss_prev = xbzrle_counters.cache_miss; - } - rs->iterations_prev = rs->iterations; - } + migration_update_rates(rs, end_time); + + rs->iterations_prev = rs->iterations; /* reset period counters */ rs->time_last_bitmap_sync = end_time;