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: 10446175 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 E2E9660284 for ; Mon, 4 Jun 2018 09:56:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D2CC528BC6 for ; Mon, 4 Jun 2018 09:56:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C6E2928BD0; Mon, 4 Jun 2018 09:56:22 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 737B128BC6 for ; Mon, 4 Jun 2018 09:56:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752399AbeFDJ4T (ORCPT ); Mon, 4 Jun 2018 05:56:19 -0400 Received: from mail-pg0-f44.google.com ([74.125.83.44]:45107 "EHLO mail-pg0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752293AbeFDJ4Q (ORCPT ); Mon, 4 Jun 2018 05:56:16 -0400 Received: by mail-pg0-f44.google.com with SMTP id z1-v6so7322706pgv.12 for ; Mon, 04 Jun 2018 02:56:16 -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=icTe9CJtD7S2PqmXfKS75gtcG9XcZAxsSt4x4rUS0ijkMkGd/MicOzmGNTKRC4ZP3Y /TIoFbnbKYyGPDribfgxUqZvf73Mu9bJtEQcNGTuFMSrYDtNSFmQv3lfaouv/uXbtx75 TIQl5ThOYnqXhFjvYEXPBJjKJ7xQkMggEub05yS//z3/AhyYD/YjgmVMcpk9bJZlEKHd 2xM/9xmZhLA9L6ifweEW943pbi1HXxIQBLDTvx+TLW2TZEaHHJ9TIKNKnpBtZ98tJ1tH TeP72kpSUuJOiV3xP0Ki3VC8tVnqIOTm+tUOitkZDsxUcm7iXO+dPnjZL0dxjIHd5YAG Oqmw== X-Gm-Message-State: ALKqPwfkSJ9IcOB1Hw4XxX5477mmqKwRSNJ55Ltoxo6S77jbCzxgRzBy j77jpcYzu6KCLmEGhdlOJXQ= 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 Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, dgilbert@redhat.com, peterx@redhat.com, jiang.biao2@zte.com.cn, wei.w.wang@intel.com, Xiao Guangrong Subject: [PATCH 04/12] migration: introduce migration_update_rates 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> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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;