From nobody Sun May 5 11:47:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1600073616; cv=none; d=zohomail.com; s=zohoarc; b=h6iD8eP0MLQ34QFatoGWKsIJHGTxbhUo5AWb/xgbKjnC86pTDsnWR22fSCGhezdzaQS9emRUgnjeMOp3EOzOTu7QlN9nMWT6q+dZL5BoFeaqEGPnkkcXBkDbwJW1IMlVMjpgo3OEEXoRzyw5c5XlO5zl6kNjvpJjCUqSs2TdbTc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600073616; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4Tqb6pfo8yw61hFfu7XbX7Ee25gDzimOTXAd5+BVGRQ=; b=SkQ5vCIHzw3faoLG0sN5KC6LaP/Xr753WM9/LKPE9IDOJjE6sE7uKsA0VBpMpmJ2+9QyKoGSTH1WWQ5sc98X2xihXJORLI1nQBbb2Qdy1NRBDPW+PepvFUEeJqoMnQ3HoWICd8eUBmXfoN9sXHMwPCRj9GVrykk8Y5oP54S0Tpg= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600073616664493.460813734859; Mon, 14 Sep 2020 01:53:36 -0700 (PDT) Received: from localhost ([::1]:50152 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHkEx-0007WS-IX for importer@patchew.org; Mon, 14 Sep 2020 04:53:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42200) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHkDx-0005uS-PQ for qemu-devel@nongnu.org; Mon, 14 Sep 2020 04:52:33 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:60934 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHkDv-0005kj-EE for qemu-devel@nongnu.org; Mon, 14 Sep 2020 04:52:33 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 5E9DD70E5A6975BCA9D2; Mon, 14 Sep 2020 16:52:26 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.487.0; Mon, 14 Sep 2020 16:52:16 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v8 01/12] migration/dirtyrate: setup up query-dirtyrate framwork Date: Mon, 14 Sep 2020 17:02:54 +0800 Message-ID: <1600074185-91624-2-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600074185-91624-1-git-send-email-zhengchuan@huawei.com> References: <1600074185-91624-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.32; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/14 04:52:27 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: zhengchuan@huawei.com, zhang.zhanghailiang@huawei.com, yuxiating@huawei.com, liq3ea@gmail.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@huawei.com, jinyan12@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add get_dirtyrate_thread() functions to setup query-dirtyrate framework. Signed-off-by: Chuan Zheng Signed-off-by: YanYing Zhuang Reviewed-by: Dr. David Alan Gilbert Reviewed-by: David Edmondson --- migration/dirtyrate.c | 38 ++++++++++++++++++++++++++++++++++++++ migration/dirtyrate.h | 29 +++++++++++++++++++++++++++++ migration/meson.build | 2 +- 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 migration/dirtyrate.c create mode 100644 migration/dirtyrate.h diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c new file mode 100644 index 0000000..bf7fd24 --- /dev/null +++ b/migration/dirtyrate.c @@ -0,0 +1,38 @@ +/* + * Dirtyrate implement code + * + * Copyright (c) 2020 HUAWEI TECHNOLOGIES CO.,LTD. + * + * Authors: + * Chuan Zheng + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "cpu.h" +#include "qemu/config-file.h" +#include "exec/memory.h" +#include "exec/ramblock.h" +#include "exec/target_page.h" +#include "qemu/rcu_queue.h" +#include "qapi/qapi-commands-migration.h" +#include "migration.h" +#include "dirtyrate.h" + +static void calculate_dirtyrate(struct DirtyRateConfig config) +{ + /* todo */ + return; +} + +void *get_dirtyrate_thread(void *arg) +{ + struct DirtyRateConfig config =3D *(struct DirtyRateConfig *)arg; + + calculate_dirtyrate(config); + + return NULL; +} diff --git a/migration/dirtyrate.h b/migration/dirtyrate.h new file mode 100644 index 0000000..5be9714 --- /dev/null +++ b/migration/dirtyrate.h @@ -0,0 +1,29 @@ +/* + * Dirtyrate common functions + * + * Copyright (c) 2020 HUAWEI TECHNOLOGIES CO., LTD. + * + * Authors: + * Chuan Zheng + * + * This work is licensed under the terms of the GNU GPL, version 2 or lat= er. + * See the COPYING file in the top-level directory. + */ + +#ifndef QEMU_MIGRATION_DIRTYRATE_H +#define QEMU_MIGRATION_DIRTYRATE_H + +/* + * Sample 512 pages per GB as default. + * TODO: Make it configurable. + */ +#define DIRTYRATE_DEFAULT_SAMPLE_PAGES 512 + +struct DirtyRateConfig { + uint64_t sample_pages_per_gigabytes; /* sample pages per GB */ + int64_t sample_period_seconds; /* time duration between two sampling */ +}; + +void *get_dirtyrate_thread(void *arg); +#endif + diff --git a/migration/meson.build b/migration/meson.build index ac8ff14..b5b71c8 100644 --- a/migration/meson.build +++ b/migration/meson.build @@ -37,4 +37,4 @@ softmmu_ss.add(when: ['CONFIG_RDMA', rdma], if_true: file= s('rdma.c')) softmmu_ss.add(when: 'CONFIG_LIVE_BLOCK_MIGRATION', if_true: files('block.= c')) softmmu_ss.add(when: 'CONFIG_ZSTD', if_true: [files('multifd-zstd.c'), zst= d]) =20 -specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: files('ram.c')) +specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: files('dirtyrate.c', 'ram= .c')) --=20 1.8.3.1 From nobody Sun May 5 11:47:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1600073723; cv=none; d=zohomail.com; s=zohoarc; b=E7q9x60gGrOR3SHXNP6UQhYSKYiIfdLQpHCN6/djVrdB1pgQOh1cgOc3NWrGKA/Hcb/bUmjbp3AfYTSFx1Jpgpd3MxyXniOWpKP23T5GCbQpXl8mWKntEUuWKDc02wbelpCOQIMsQ6Is874OmZNKfklYG0aJ/CprSonoKoqVVRQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600073723; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NRMlI14VEof/MjecyC8XE9kViLvFtU05AfGx30GsgwM=; b=U8W/WN8VcAmOeQf1+sKzKVaKV2VBuFGRJuFrU+2mo1uwhjMGMWzEUOn26PVl5Gu5AIPV0q76EM0Dcup/KNR4WuGeBN779bEoyuzNBLPEZk+ZtU5xxImp21Z5+CN7kmPsWv1+BCWt+7w3Uu+LHBsOVh45mrJBhaIXnq/ujOyQoa4= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600073723199594.0952179057806; Mon, 14 Sep 2020 01:55:23 -0700 (PDT) Received: from localhost ([::1]:60286 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHkGg-0003BY-2C for importer@patchew.org; Mon, 14 Sep 2020 04:55:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42236) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHkDy-0005w9-OL for qemu-devel@nongnu.org; Mon, 14 Sep 2020 04:52:34 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:60936 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHkDv-0005ki-Fv for qemu-devel@nongnu.org; Mon, 14 Sep 2020 04:52:34 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 5959E55592CF91FB95E1; Mon, 14 Sep 2020 16:52:26 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.487.0; Mon, 14 Sep 2020 16:52:17 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v8 02/12] migration/dirtyrate: add DirtyRateStatus to denote calculation status Date: Mon, 14 Sep 2020 17:02:55 +0800 Message-ID: <1600074185-91624-3-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600074185-91624-1-git-send-email-zhengchuan@huawei.com> References: <1600074185-91624-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.32; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/14 04:52:27 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: zhengchuan@huawei.com, zhang.zhanghailiang@huawei.com, yuxiating@huawei.com, liq3ea@gmail.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@huawei.com, jinyan12@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" add DirtyRateStatus to denote calculating status. Signed-off-by: Chuan Zheng Reviewed-by: Dr. David Alan Gilbert --- migration/dirtyrate.c | 26 ++++++++++++++++++++++++++ qapi/migration.json | 17 +++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index bf7fd24..7bea8ff 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -22,6 +22,19 @@ #include "migration.h" #include "dirtyrate.h" =20 +static int CalculatingState =3D DIRTY_RATE_STATUS_UNSTARTED; + +static int dirtyrate_set_state(int *state, int old_state, int new_state) +{ + assert(new_state < DIRTY_RATE_STATUS__MAX); + if (atomic_cmpxchg(state, old_state, new_state) =3D=3D old_state) { + return 0; + } else { + return -1; + } +} + + static void calculate_dirtyrate(struct DirtyRateConfig config) { /* todo */ @@ -31,8 +44,21 @@ static void calculate_dirtyrate(struct DirtyRateConfig c= onfig) void *get_dirtyrate_thread(void *arg) { struct DirtyRateConfig config =3D *(struct DirtyRateConfig *)arg; + int ret; + + ret =3D dirtyrate_set_state(&CalculatingState, DIRTY_RATE_STATUS_UNSTA= RTED, + DIRTY_RATE_STATUS_MEASURING); + if (ret =3D=3D -1) { + error_report("change dirtyrate state failed."); + return NULL; + } =20 calculate_dirtyrate(config); =20 + ret =3D dirtyrate_set_state(&CalculatingState, DIRTY_RATE_STATUS_MEASU= RING, + DIRTY_RATE_STATUS_MEASURED); + if (ret =3D=3D -1) { + error_report("change dirtyrate state failed."); + } return NULL; } diff --git a/qapi/migration.json b/qapi/migration.json index 5f6b061..061ff25 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -1720,3 +1720,20 @@ ## { 'event': 'UNPLUG_PRIMARY', 'data': { 'device-id': 'str' } } + +## +# @DirtyRateStatus: +# +# An enumeration of dirtyrate status. +# +# @unstarted: the dirtyrate thread has not been started. +# +# @measuring: the dirtyrate thread is measuring. +# +# @measured: the dirtyrate thread has measured and results are available. +# +# Since: 5.2 +# +## +{ 'enum': 'DirtyRateStatus', + 'data': [ 'unstarted', 'measuring', 'measured'] } --=20 1.8.3.1 From nobody Sun May 5 11:47:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1600073705; cv=none; d=zohomail.com; s=zohoarc; b=hqOk4jy3xRiIZYwwlEXrnSBxXc7kYLFfywN36k7QVe1g+IagnFYXMAoLPwAYGi9kEaf70U4nJCNr8LQJbJpHLvmo+Q4VeYeN4lGmJYD0ARyA/5OFSISyJvoCrSUq1sJhdFJg0vNxoPRQV4Y6EhLmwEWUkaSPnxxZY3iQnf8udxc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600073705; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Cnu4twx4mXhZoz8TXcbaSKW/K3O9AAAGXvwVgj0E1qw=; b=DUZ7McqlNIHMLA4aRqRqHL7P3dwbM7yNitCLDsvAoh7d+Lyu5G3Jocjk89CNQfbAkyXIJ9CgVsaDmEtZQshW17xW8+f7eOGX24qHKAKe1dMCBiZxC/YaDKN8BkmTmVrNKdxxnzaNOWZlgFMW6lcDZuamLp5KFU0CpM2TwSbojeI= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600073705199896.1629757948351; Mon, 14 Sep 2020 01:55:05 -0700 (PDT) Received: from localhost ([::1]:58348 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHkGN-0002Oa-Nl for importer@patchew.org; Mon, 14 Sep 2020 04:55:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42256) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHkDz-0005yQ-P6 for qemu-devel@nongnu.org; Mon, 14 Sep 2020 04:52:35 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4691 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHkDw-0005ke-CM for qemu-devel@nongnu.org; Mon, 14 Sep 2020 04:52:35 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 320A2A5821597BBB697A; Mon, 14 Sep 2020 16:52:26 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.487.0; Mon, 14 Sep 2020 16:52:17 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v8 03/12] migration/dirtyrate: Add RamblockDirtyInfo to store sampled page info Date: Mon, 14 Sep 2020 17:02:56 +0800 Message-ID: <1600074185-91624-4-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600074185-91624-1-git-send-email-zhengchuan@huawei.com> References: <1600074185-91624-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.190; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/14 04:52:27 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: zhengchuan@huawei.com, zhang.zhanghailiang@huawei.com, yuxiating@huawei.com, liq3ea@gmail.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@huawei.com, jinyan12@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add RamblockDirtyInfo to store sampled page info of each ramblock. Signed-off-by: Chuan Zheng Reviewed-by: Dr. David Alan Gilbert Reviewed-by: David Edmondson --- migration/dirtyrate.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/migration/dirtyrate.h b/migration/dirtyrate.h index 5be9714..479e222 100644 --- a/migration/dirtyrate.h +++ b/migration/dirtyrate.h @@ -19,11 +19,29 @@ */ #define DIRTYRATE_DEFAULT_SAMPLE_PAGES 512 =20 +/* + * Record ramblock idstr + */ +#define RAMBLOCK_INFO_MAX_LEN 256 + struct DirtyRateConfig { uint64_t sample_pages_per_gigabytes; /* sample pages per GB */ int64_t sample_period_seconds; /* time duration between two sampling */ }; =20 +/* + * Store dirtypage info for each ramblock. + */ +struct RamblockDirtyInfo { + char idstr[RAMBLOCK_INFO_MAX_LEN]; /* idstr for each ramblock */ + uint8_t *ramblock_addr; /* base address of ramblock we measure */ + uint64_t ramblock_pages; /* ramblock size in TARGET_PAGE_SIZE */ + uint64_t *sample_page_vfn; /* relative offset address for sampled page= */ + uint64_t sample_pages_count; /* count of sampled pages */ + uint64_t sample_dirty_count; /* count of dirty pages we measure */ + uint32_t *hash_result; /* array of hash result for sampled pages */ +}; + void *get_dirtyrate_thread(void *arg); #endif =20 --=20 1.8.3.1 From nobody Sun May 5 11:47:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1600073835; cv=none; d=zohomail.com; s=zohoarc; b=YJCtJAiz1zSmw+Mx5Y05XX0z6/ZR4Kvbi3pzzTsbEupRUyn5QGprCqYWRlIYAUXdvaQ5G1iojYwYUxL3/eJrhaJOzRW5mP98KV4R8FMLdHT66p6Ts/Z42g+cPgkbWCYRS5bl+wu1GEGLfEujIUKBw+hub5esd6ccE0KsaePxH+c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600073835; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AZx6m2GyeNx1QoX9ZxXsVuY1k2OJmxNJ80HbZDT3rmY=; b=YaxeXFY3gw/jTI0cvqOQsDyiFmefej22QQGRkENWwQrMz4Bxin4c7SEqr3Aa1V6PLaW866Q6Keedz3JAhVmrHcFD6VkWsAaNbZ4f8um6HpIl2bxliXSqTZ6d8zRW8E+xDLlCDzPA3avfyLhuvrLNunBN5k/j/EHAjQAmZ5ZkLQw= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600073835742706.1599862182258; Mon, 14 Sep 2020 01:57:15 -0700 (PDT) Received: from localhost ([::1]:40416 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHkIU-0006cT-Fl for importer@patchew.org; Mon, 14 Sep 2020 04:57:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42240) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHkDz-0005wh-1D for qemu-devel@nongnu.org; Mon, 14 Sep 2020 04:52:35 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:60932 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHkDw-0005kh-Bd for qemu-devel@nongnu.org; Mon, 14 Sep 2020 04:52:34 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 53CB8FE157BD4E2774C6; Mon, 14 Sep 2020 16:52:26 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.487.0; Mon, 14 Sep 2020 16:52:18 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v8 04/12] migration/dirtyrate: Add dirtyrate statistics series functions Date: Mon, 14 Sep 2020 17:02:57 +0800 Message-ID: <1600074185-91624-5-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600074185-91624-1-git-send-email-zhengchuan@huawei.com> References: <1600074185-91624-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.32; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/14 04:52:27 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: zhengchuan@huawei.com, zhang.zhanghailiang@huawei.com, yuxiating@huawei.com, liq3ea@gmail.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@huawei.com, jinyan12@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add dirtyrate statistics functions to record/update dirtyrate info. Signed-off-by: Chuan Zheng Reviewed-by: Dr. David Alan Gilbert --- migration/dirtyrate.c | 32 ++++++++++++++++++++++++++++++++ migration/dirtyrate.h | 12 ++++++++++++ 2 files changed, 44 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 7bea8ff..dca74e9 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -23,6 +23,7 @@ #include "dirtyrate.h" =20 static int CalculatingState =3D DIRTY_RATE_STATUS_UNSTARTED; +static struct DirtyRateStat DirtyStat; =20 static int dirtyrate_set_state(int *state, int old_state, int new_state) { @@ -34,6 +35,37 @@ static int dirtyrate_set_state(int *state, int old_state= , int new_state) } } =20 +static void reset_dirtyrate_stat(void) +{ + DirtyStat.total_dirty_samples =3D 0; + DirtyStat.total_sample_count =3D 0; + DirtyStat.total_block_mem_MB =3D 0; + DirtyStat.dirty_rate =3D 0; + DirtyStat.start_time =3D 0; + DirtyStat.calc_time =3D 0; +} + +static void update_dirtyrate_stat(struct RamblockDirtyInfo *info) +{ + DirtyStat.total_dirty_samples +=3D info->sample_dirty_count; + DirtyStat.total_sample_count +=3D info->sample_pages_count; + /* size of total pages in MB */ + DirtyStat.total_block_mem_MB +=3D (info->ramblock_pages * + TARGET_PAGE_SIZE) >> 20; +} + +static void update_dirtyrate(uint64_t msec) +{ + uint64_t dirtyrate; + uint64_t total_dirty_samples =3D DirtyStat.total_dirty_samples; + uint64_t total_sample_count =3D DirtyStat.total_sample_count; + uint64_t total_block_mem_MB =3D DirtyStat.total_block_mem_MB; + + dirtyrate =3D total_dirty_samples * total_block_mem_MB * + 1000 / (total_sample_count * msec); + + DirtyStat.dirty_rate =3D dirtyrate; +} =20 static void calculate_dirtyrate(struct DirtyRateConfig config) { diff --git a/migration/dirtyrate.h b/migration/dirtyrate.h index 479e222..a3ee305 100644 --- a/migration/dirtyrate.h +++ b/migration/dirtyrate.h @@ -42,6 +42,18 @@ struct RamblockDirtyInfo { uint32_t *hash_result; /* array of hash result for sampled pages */ }; =20 +/* + * Store calculation statistics for each measure. + */ +struct DirtyRateStat { + uint64_t total_dirty_samples; /* total dirty sampled page */ + uint64_t total_sample_count; /* total sampled pages */ + uint64_t total_block_mem_MB; /* size of total sampled pages in MB */ + int64_t dirty_rate; /* dirty rate in MB/s */ + int64_t start_time; /* calculation start time in units of second */ + int64_t calc_time; /* time duration of two sampling in units of second= */ +}; + void *get_dirtyrate_thread(void *arg); #endif =20 --=20 1.8.3.1 From nobody Sun May 5 11:47:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1600073707; cv=none; d=zohomail.com; s=zohoarc; b=YucAJ1jrLEbZizWk4XJIr9DSaUnfFAFWwc0tNQHDpG9Car6QFOFY4KMtWWKdC81wFx8fVmr5az+r16lLkxx6i+rTWhlT8Ua8oZq1o7UQ4mrWyDt4myZ/1NSvsGRgsToKYQRTg0Pj6DrRbKq1bbdr9U8DZtyHZrJSJ38DqDN+LPE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600073707; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2c6MVsJx9u+vP0EQdt0ZKc5gTe+QlFwdAXB0u6jfZAg=; b=KBsCiZLx9W6bWCzxk0ZalrFEeA+k5dclnfypnkrQQCK1HhSzkdvLaQaCkv0VzKaCueOBE8MKCBXd1Kll22+g1x7jNM5KKijFZADJV0OmHpS5jckGw8IgUWVblAtkIo8qU40+1LS/1TgLO14WF5UsrFsscL5IU7eT3OeZ2R+Rs8Q= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600073707299506.0951272820437; Mon, 14 Sep 2020 01:55:07 -0700 (PDT) Received: from localhost ([::1]:58536 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHkGQ-0002UG-5x for importer@patchew.org; Mon, 14 Sep 2020 04:55:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42294) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHkE1-00062u-I0 for qemu-devel@nongnu.org; Mon, 14 Sep 2020 04:52:37 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4690 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHkDw-0005kg-CH for qemu-devel@nongnu.org; Mon, 14 Sep 2020 04:52:37 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 2C7776C525B281A2F83F; Mon, 14 Sep 2020 16:52:26 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.487.0; Mon, 14 Sep 2020 16:52:19 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v8 05/12] migration/dirtyrate: move RAMBLOCK_FOREACH_MIGRATABLE into ram.h Date: Mon, 14 Sep 2020 17:02:58 +0800 Message-ID: <1600074185-91624-6-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600074185-91624-1-git-send-email-zhengchuan@huawei.com> References: <1600074185-91624-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.190; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/14 04:52:27 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: zhengchuan@huawei.com, zhang.zhanghailiang@huawei.com, yuxiating@huawei.com, liq3ea@gmail.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@huawei.com, jinyan12@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" RAMBLOCK_FOREACH_MIGRATABLE is need in dirtyrate measure, move the existing definition up into migration/ram.h Signed-off-by: Chuan Zheng Reviewed-by: Dr. David Alan Gilbert Reviewed-by: David Edmondson --- migration/dirtyrate.c | 1 + migration/ram.c | 11 +---------- migration/ram.h | 10 ++++++++++ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index dca74e9..cf2d560 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -20,6 +20,7 @@ #include "qemu/rcu_queue.h" #include "qapi/qapi-commands-migration.h" #include "migration.h" +#include "ram.h" #include "dirtyrate.h" =20 static int CalculatingState =3D DIRTY_RATE_STATUS_UNSTARTED; diff --git a/migration/ram.c b/migration/ram.c index 76d4fee..37ef0da 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -158,21 +158,12 @@ out: return ret; } =20 -static bool ramblock_is_ignored(RAMBlock *block) +bool ramblock_is_ignored(RAMBlock *block) { return !qemu_ram_is_migratable(block) || (migrate_ignore_shared() && qemu_ram_is_shared(block)); } =20 -/* Should be holding either ram_list.mutex, or the RCU lock. */ -#define RAMBLOCK_FOREACH_NOT_IGNORED(block) \ - INTERNAL_RAMBLOCK_FOREACH(block) \ - if (ramblock_is_ignored(block)) {} else - -#define RAMBLOCK_FOREACH_MIGRATABLE(block) \ - INTERNAL_RAMBLOCK_FOREACH(block) \ - if (!qemu_ram_is_migratable(block)) {} else - #undef RAMBLOCK_FOREACH =20 int foreach_not_ignored_block(RAMBlockIterFunc func, void *opaque) diff --git a/migration/ram.h b/migration/ram.h index 2eeaacf..011e854 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -37,6 +37,16 @@ extern MigrationStats ram_counters; extern XBZRLECacheStats xbzrle_counters; extern CompressionStats compression_counters; =20 +bool ramblock_is_ignored(RAMBlock *block); +/* Should be holding either ram_list.mutex, or the RCU lock. */ +#define RAMBLOCK_FOREACH_NOT_IGNORED(block) \ + INTERNAL_RAMBLOCK_FOREACH(block) \ + if (ramblock_is_ignored(block)) {} else + +#define RAMBLOCK_FOREACH_MIGRATABLE(block) \ + INTERNAL_RAMBLOCK_FOREACH(block) \ + if (!qemu_ram_is_migratable(block)) {} else + int xbzrle_cache_resize(int64_t new_size, Error **errp); uint64_t ram_bytes_remaining(void); uint64_t ram_bytes_total(void); --=20 1.8.3.1 From nobody Sun May 5 11:47:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1600073922; cv=none; d=zohomail.com; s=zohoarc; b=XAjpppG9GrMXs51b96YfArO3wWFfwSpeW3C2C2DNS7cpsm2vPFdSvakvATqC5KUtesRJPTja+5UAgpTQgGNLjX7/j5gBQfmVlNi/fUB6i/0ZM3icL47aetCoQpnuGyE6Id5ywElSziQDsxoGVVQOurDoYMN/p5kcTC1ODxL07hs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600073922; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OSYsPTnINCEIWvf+D7iISovu/K/phFUpmQSPwonOjrE=; b=E+XsSNA1ESom781p7bc3iBucGVGdfx41cFoibsf8JMQXDHiRPPkSRJlscPYgaB352DSj+i5nQa1uxbPasgBxYDXKab6p+jZ7r8lcnBetuUm13FuZlWQ9pTjEO0LIamWOedshlmZ0x5CTHHpU3X6i8WS2EWzRuE/vALFGFW+UiZI= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600073922340360.84500388231754; Mon, 14 Sep 2020 01:58:42 -0700 (PDT) Received: from localhost ([::1]:46602 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHkJt-0000fN-6q for importer@patchew.org; Mon, 14 Sep 2020 04:58:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42312) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHkE2-00064i-PO for qemu-devel@nongnu.org; Mon, 14 Sep 2020 04:52:38 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4689 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHkDw-0005kd-DA for qemu-devel@nongnu.org; Mon, 14 Sep 2020 04:52:38 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 3730F9C1835DB7782715; Mon, 14 Sep 2020 16:52:26 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.487.0; Mon, 14 Sep 2020 16:52:19 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v8 06/12] migration/dirtyrate: Record hash results for each sampled page Date: Mon, 14 Sep 2020 17:02:59 +0800 Message-ID: <1600074185-91624-7-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600074185-91624-1-git-send-email-zhengchuan@huawei.com> References: <1600074185-91624-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.190; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/14 04:52:27 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: zhengchuan@huawei.com, zhang.zhanghailiang@huawei.com, yuxiating@huawei.com, liq3ea@gmail.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@huawei.com, jinyan12@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Record hash results for each sampled page, crc32 is taken to calculate hash results for each sampled length in TARGET_PAGE_SIZE. Signed-off-by: Chuan Zheng Signed-off-by: YanYing Zhuang Reviewed-by: David Edmondson --- migration/dirtyrate.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 111 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index cf2d560..beb18cb 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -10,6 +10,7 @@ * See the COPYING file in the top-level directory. */ =20 +#include #include "qemu/osdep.h" #include "qapi/error.h" #include "cpu.h" @@ -68,6 +69,116 @@ static void update_dirtyrate(uint64_t msec) DirtyStat.dirty_rate =3D dirtyrate; } =20 +/* + * get hash result for the sampled memory with length of TARGET_PAGE_SIZE + * in ramblock, which starts from ramblock base address. + */ +static uint32_t get_ramblock_vfn_hash(struct RamblockDirtyInfo *info, + uint64_t vfn) +{ + uint32_t crc; + + crc =3D crc32(0, (info->ramblock_addr + + vfn * TARGET_PAGE_SIZE), TARGET_PAGE_SIZE); + + return crc; +} + +static bool save_ramblock_hash(struct RamblockDirtyInfo *info) +{ + unsigned int sample_pages_count; + int i; + GRand *rand; + + sample_pages_count =3D info->sample_pages_count; + + /* ramblock size less than one page, return success to skip this rambl= ock */ + if (unlikely(info->ramblock_pages =3D=3D 0 || sample_pages_count =3D= =3D 0)) { + return true; + } + + info->hash_result =3D g_try_malloc0_n(sample_pages_count, + sizeof(uint32_t)); + if (!info->hash_result) { + return false; + } + + info->sample_page_vfn =3D g_try_malloc0_n(sample_pages_count, + sizeof(uint64_t)); + if (!info->sample_page_vfn) { + g_free(info->hash_result); + return false; + } + + rand =3D g_rand_new(); + for (i =3D 0; i < sample_pages_count; i++) { + info->sample_page_vfn[i] =3D g_rand_int_range(rand, 0, + info->ramblock_pages -= 1); + info->hash_result[i] =3D get_ramblock_vfn_hash(info, + info->sample_page_vfn= [i]); + } + g_rand_free(rand); + + return true; +} + +static void get_ramblock_dirty_info(RAMBlock *block, + struct RamblockDirtyInfo *info, + struct DirtyRateConfig *config) +{ + uint64_t sample_pages_per_gigabytes =3D config->sample_pages_per_gigab= ytes; + + /* Right shift 30 bits to calc ramblock size in GB */ + info->sample_pages_count =3D (qemu_ram_get_used_length(block) * + sample_pages_per_gigabytes) >> 30; + /* Right shift TARGET_PAGE_BITS to calc page count */ + info->ramblock_pages =3D qemu_ram_get_used_length(block) >> + TARGET_PAGE_BITS; + info->ramblock_addr =3D qemu_ram_get_host_addr(block); + strcpy(info->idstr, qemu_ram_get_idstr(block)); +} + +static bool record_ramblock_hash_info(struct RamblockDirtyInfo **block_din= fo, + struct DirtyRateConfig config, + int *block_index) +{ + struct RamblockDirtyInfo *info =3D NULL; + struct RamblockDirtyInfo *dinfo =3D NULL; + RAMBlock *block =3D NULL; + int total_index =3D 0; + int index =3D 0; + bool ret =3D true; + + RAMBLOCK_FOREACH_MIGRATABLE(block) { + total_index++; + } + + dinfo =3D g_try_malloc0_n(total_index, sizeof(struct RamblockDirtyInfo= )); + if (dinfo =3D=3D NULL) { + total_index =3D 0; + ret =3D false; + goto out; + } + + RAMBLOCK_FOREACH_MIGRATABLE(block) { + if (index >=3D total_index) { + break; + } + info =3D &dinfo[index]; + get_ramblock_dirty_info(block, info, &config); + if (!save_ramblock_hash(info)) { + ret =3D false; + goto out; + } + index++; + } + +out: + *block_index =3D total_index; + *block_dinfo =3D dinfo; + return ret; +} + static void calculate_dirtyrate(struct DirtyRateConfig config) { /* todo */ --=20 1.8.3.1 From nobody Sun May 5 11:47:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1600073809; cv=none; d=zohomail.com; s=zohoarc; b=kzoy4LcAMe8GCvJUyRYZqRnv8ijG1AYsRXaeVuorCGMvrQpxHjSENFB8qyR1rbcZ7aZizs8Ows1n6TMF3apxnxO+R0h7dt3tx799adK5XvpzyhmohSvSGWSF7UvrXWj+Drs9wtnkReOTs1vJW+GWD7Q+21nl8E7HccadYyX7ycg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600073809; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=c5CsTkvdxDDtJ6DU2iWC7Gy9RImJPZP8bvpZ3XKnieI=; b=KCHCk/FtnsWCuZlfDQQ/DbsV+RxKweoTqGZIw2VJveX2aS8FWiVzDwhV+b8VsmhcI9oVV8XJDpGw5TSLb0u5Wl814X/locgmRvbdccRs9Fjx+Vz1mI/r1N/9D+2HdYYNGDkUPp77wnf8KVSGLodI9Us/21bdSJFdO95Ht4pBsh0= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600073809638634.0360148543101; Mon, 14 Sep 2020 01:56:49 -0700 (PDT) Received: from localhost ([::1]:38404 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHkI4-0005oX-Gz for importer@patchew.org; Mon, 14 Sep 2020 04:56:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42264) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHkE0-0005zE-3q for qemu-devel@nongnu.org; Mon, 14 Sep 2020 04:52:36 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4692 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHkDw-0005kf-EP for qemu-devel@nongnu.org; Mon, 14 Sep 2020 04:52:35 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 26B9C3C84E024BB45023; Mon, 14 Sep 2020 16:52:26 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.487.0; Mon, 14 Sep 2020 16:52:20 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v8 07/12] migration/dirtyrate: Compare page hash results for recorded sampled page Date: Mon, 14 Sep 2020 17:03:00 +0800 Message-ID: <1600074185-91624-8-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600074185-91624-1-git-send-email-zhengchuan@huawei.com> References: <1600074185-91624-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.190; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/14 04:52:27 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: zhengchuan@huawei.com, zhang.zhanghailiang@huawei.com, yuxiating@huawei.com, liq3ea@gmail.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@huawei.com, jinyan12@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Compare page hash results for recorded sampled page. Signed-off-by: Chuan Zheng Signed-off-by: YanYing Zhuang Reviewed-by: Dr. David Alan Gilbert --- migration/dirtyrate.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 63 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index beb18cb..e836474 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -179,6 +179,69 @@ out: return ret; } =20 +static void calc_page_dirty_rate(struct RamblockDirtyInfo *info) +{ + uint32_t crc; + int i; + + for (i =3D 0; i < info->sample_pages_count; i++) { + crc =3D get_ramblock_vfn_hash(info, info->sample_page_vfn[i]); + if (crc !=3D info->hash_result[i]) { + info->sample_dirty_count++; + } + } +} + +static struct RamblockDirtyInfo * +find_page_matched(RAMBlock *block, int count, + struct RamblockDirtyInfo *infos) +{ + int i; + struct RamblockDirtyInfo *matched; + + for (i =3D 0; i < count; i++) { + if (!strcmp(infos[i].idstr, qemu_ram_get_idstr(block))) { + break; + } + } + + if (i =3D=3D count) { + return NULL; + } + + if (infos[i].ramblock_addr !=3D qemu_ram_get_host_addr(block) || + infos[i].ramblock_pages !=3D + (qemu_ram_get_used_length(block) >> TARGET_PAGE_BITS)) { + return NULL; + } + + matched =3D &infos[i]; + + return matched; +} + +static int compare_page_hash_info(struct RamblockDirtyInfo *info, + int block_index) +{ + struct RamblockDirtyInfo *block_dinfo =3D NULL; + RAMBlock *block =3D NULL; + + RAMBLOCK_FOREACH_MIGRATABLE(block) { + block_dinfo =3D find_page_matched(block, block_index + 1, info); + if (block_dinfo =3D=3D NULL) { + continue; + } + calc_page_dirty_rate(block_dinfo); + update_dirtyrate_stat(block_dinfo); + } + + if (DirtyStat.total_sample_count =3D=3D 0) { + return -1; + } + + return 0; +} + static void calculate_dirtyrate(struct DirtyRateConfig config) { /* todo */ --=20 1.8.3.1 From nobody Sun May 5 11:47:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1600073915; cv=none; d=zohomail.com; s=zohoarc; b=RK9ur94Ys9lBtSSxnjmcjGVCYyjBtfAg++mLWWe+WWcIOPTYWotJ7hELfb5H+Ud/U1VSixLupOWM7XAGy7g3ggZ3PoQIbFluhBP6VVbq6lDtiELXtmFIRyZnOeEZmphJHlZC1+1TEkMVJpB7Jw8ehudDU4TCVQ1TTXrae91HyNc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600073915; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Flei+UYF73jDuNKvE6FWlrgxWnu8iUg+Q+oj58wfSvI=; b=M/sDP9Lip7pIgwm841Yc6SclzXHPIVrwwCwTPmR6iYSuBzvcCkcTmr36Df9BQsOThSok/Ye0Dg54wPA02Cs+adX0q0WATLT6lXShfZILTu2icYAhb1mxSiiHxZs4XA4PsULqMkxmPbtLsCKPJmHZvYcQENNJkIKCRDOKBAJgpMQ= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600073915021540.8857056798485; Mon, 14 Sep 2020 01:58:35 -0700 (PDT) Received: from localhost ([::1]:46320 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHkJl-0000YC-U1 for importer@patchew.org; Mon, 14 Sep 2020 04:58:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42272) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHkE0-0005zm-Av for qemu-devel@nongnu.org; Mon, 14 Sep 2020 04:52:36 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:32798 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHkDx-0005lD-E9 for qemu-devel@nongnu.org; Mon, 14 Sep 2020 04:52:36 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 3ABC37E6DC6F85406A54; Mon, 14 Sep 2020 16:52:31 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.487.0; Mon, 14 Sep 2020 16:52:20 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v8 08/12] migration/dirtyrate: skip sampling ramblock with size below MIN_RAMBLOCK_SIZE Date: Mon, 14 Sep 2020 17:03:01 +0800 Message-ID: <1600074185-91624-9-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600074185-91624-1-git-send-email-zhengchuan@huawei.com> References: <1600074185-91624-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.32; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/14 04:52:27 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: zhengchuan@huawei.com, zhang.zhanghailiang@huawei.com, yuxiating@huawei.com, liq3ea@gmail.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@huawei.com, jinyan12@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In order to sample real RAM, skip ramblock with size below MIN_RAMBLOCK_SIZE which is set as 128M. Signed-off-by: Chuan Zheng Reviewed-by: David Edmondson Reviewed-by: Dr. David Alan Gilbert --- migration/dirtyrate.c | 21 +++++++++++++++++++++ migration/dirtyrate.h | 5 +++++ 2 files changed, 26 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index e836474..e68af6f 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -138,6 +138,18 @@ static void get_ramblock_dirty_info(RAMBlock *block, strcpy(info->idstr, qemu_ram_get_idstr(block)); } =20 +static bool skip_sample_ramblock(RAMBlock *block) +{ + /* + * Sample only blocks larger than MIN_RAMBLOCK_SIZE. + */ + if (qemu_ram_get_used_length(block) < (MIN_RAMBLOCK_SIZE << 10)) { + return true; + } + + return false; +} + static bool record_ramblock_hash_info(struct RamblockDirtyInfo **block_din= fo, struct DirtyRateConfig config, int *block_index) @@ -150,6 +162,9 @@ static bool record_ramblock_hash_info(struct RamblockDi= rtyInfo **block_dinfo, bool ret =3D true; =20 RAMBLOCK_FOREACH_MIGRATABLE(block) { + if (skip_sample_ramblock(block)) { + continue; + } total_index++; } =20 @@ -161,6 +176,9 @@ static bool record_ramblock_hash_info(struct RamblockDi= rtyInfo **block_dinfo, } =20 RAMBLOCK_FOREACH_MIGRATABLE(block) { + if (skip_sample_ramblock(block)) { + continue; + } if (index >=3D total_index) { break; } @@ -227,6 +245,9 @@ static int compare_page_hash_info(struct RamblockDirtyI= nfo *info, RAMBlock *block =3D NULL; =20 RAMBLOCK_FOREACH_MIGRATABLE(block) { + if (skip_sample_ramblock(block)) { + continue; + } block_dinfo =3D find_page_matched(block, block_index + 1, info); if (block_dinfo =3D=3D NULL) { continue; diff --git a/migration/dirtyrate.h b/migration/dirtyrate.h index a3ee305..faaf9da 100644 --- a/migration/dirtyrate.h +++ b/migration/dirtyrate.h @@ -24,6 +24,11 @@ */ #define RAMBLOCK_INFO_MAX_LEN 256 =20 +/* + * Minimum RAMBlock size to sample, in megabytes. + */ +#define MIN_RAMBLOCK_SIZE 128 + struct DirtyRateConfig { uint64_t sample_pages_per_gigabytes; /* sample pages per GB */ int64_t sample_period_seconds; /* time duration between two sampling */ --=20 1.8.3.1 From nobody Sun May 5 11:47:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1600073811; cv=none; d=zohomail.com; s=zohoarc; b=C5kA6AVhoUT3jozL5fEUJqRgH4W7NAhmB/KR+oBzpEUaOTsk264IijUrQDnVX+H9EUYC4c8kLz201oDEv8Oj50Pkq9bLIyT2vU7QY1hn5PNlpYp2jWgM66RpcI0z791EudeMB1PmThwhY0RmZOLVacx05AoIp36xLNS0+AvLvtM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600073811; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1e/7th1EMgS+Zd/zI5hzIrmROwXNWcgAbJ0o5b/7HY4=; b=arJ4m2LPE+aLQ9rKpKM6z8pyuZ/9qdHFQHhjhYlKxeAVbLN0+vQtN021zzpVOiqwQrzk235bcsvvHpllM3sh7cFIJFWH0B0oCLtnCqPz9gXAxkGSlLZQ0tjGaYYE1yyFsXucB0d0s/qnMT6kcFQobcgBwF/5Jaq6cUoZk7gb7OY= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600073811179566.2302223715017; Mon, 14 Sep 2020 01:56:51 -0700 (PDT) Received: from localhost ([::1]:38636 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHkI6-0005uf-22 for importer@patchew.org; Mon, 14 Sep 2020 04:56:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42300) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHkE1-00063Q-Ni for qemu-devel@nongnu.org; Mon, 14 Sep 2020 04:52:37 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:32888 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHkDz-0005lc-Tx for qemu-devel@nongnu.org; Mon, 14 Sep 2020 04:52:37 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 687CE133575316146C63; Mon, 14 Sep 2020 16:52:31 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.487.0; Mon, 14 Sep 2020 16:52:21 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v8 09/12] migration/dirtyrate: Implement set_sample_page_period() and is_sample_period_valid() Date: Mon, 14 Sep 2020 17:03:02 +0800 Message-ID: <1600074185-91624-10-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600074185-91624-1-git-send-email-zhengchuan@huawei.com> References: <1600074185-91624-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.32; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/14 04:52:27 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: zhengchuan@huawei.com, zhang.zhanghailiang@huawei.com, yuxiating@huawei.com, liq3ea@gmail.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@huawei.com, jinyan12@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Implement is_sample_period_valid() to check if the sample period is vaild a= nd do set_sample_page_period() to sleep specific time between sample actions. Signed-off-by: Chuan Zheng Reviewed-by: Dr. David Alan Gilbert Reviewed-by: David Edmondson --- migration/dirtyrate.c | 24 ++++++++++++++++++++++++ migration/dirtyrate.h | 6 ++++++ 2 files changed, 30 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index e68af6f..6add846 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -27,6 +27,30 @@ static int CalculatingState =3D DIRTY_RATE_STATUS_UNSTARTED; static struct DirtyRateStat DirtyStat; =20 +static int64_t set_sample_page_period(int64_t msec, int64_t initial_time) +{ + int64_t current_time; + + current_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); + if ((current_time - initial_time) >=3D msec) { + msec =3D current_time - initial_time; + } else { + g_usleep((msec + initial_time - current_time) * 1000); + } + + return msec; +} + +static bool is_sample_period_valid(int64_t sec) +{ + if (sec < MIN_FETCH_DIRTYRATE_TIME_SEC || + sec > MAX_FETCH_DIRTYRATE_TIME_SEC) { + return false; + } + + return true; +} + static int dirtyrate_set_state(int *state, int old_state, int new_state) { assert(new_state < DIRTY_RATE_STATUS__MAX); diff --git a/migration/dirtyrate.h b/migration/dirtyrate.h index faaf9da..8f9bc80 100644 --- a/migration/dirtyrate.h +++ b/migration/dirtyrate.h @@ -29,6 +29,12 @@ */ #define MIN_RAMBLOCK_SIZE 128 =20 +/* + * Take 1s as minimum time for calculation duration + */ +#define MIN_FETCH_DIRTYRATE_TIME_SEC 1 +#define MAX_FETCH_DIRTYRATE_TIME_SEC 60 + struct DirtyRateConfig { uint64_t sample_pages_per_gigabytes; /* sample pages per GB */ int64_t sample_period_seconds; /* time duration between two sampling */ --=20 1.8.3.1 From nobody Sun May 5 11:47:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1600073619; cv=none; d=zohomail.com; s=zohoarc; b=mb5cB3hdKdYEAetmxRMsjII9OcLTYxnO2rzky6rW5dL6kDlotil4mG29ArN+5+uerGQfLqQz41XdL1Tccj9+GIB8mLZWJxhFVD2rca/bxFOl56svlQ/IRusmmHnLz+8y+Gb5VhmkCW1OmXJRtcCtU0z199W79qvowsycBUw0QGY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600073619; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KcuJCPuHEo5xEl1w5g3W2WWpu9hX2bqT4W4eh5YeZYM=; b=Z5vvCDoKtpwvd6J1RiXLQlghEZ7X+AM3JP7XCeF7HEh0NwAr+/wBPsDaJr7Y15ChzVzIFPxCi+AlU+IkGmPcpHKHXWSr/wtqFV6gjaAFrjTnYVDZuOXWHjHdSsJUM5Zy+K7Uwr7QL83hvflYnRFPshFVPMTcpTJa8LXJzUOgqU0= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600073619139908.2030163272867; Mon, 14 Sep 2020 01:53:39 -0700 (PDT) Received: from localhost ([::1]:50492 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHkEz-0007ej-Vi for importer@patchew.org; Mon, 14 Sep 2020 04:53:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42290) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHkE1-00061k-2v for qemu-devel@nongnu.org; Mon, 14 Sep 2020 04:52:37 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:32822 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHkDx-0005lF-E5 for qemu-devel@nongnu.org; Mon, 14 Sep 2020 04:52:36 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 4010E8D5A6AC9C0FC7D6; Mon, 14 Sep 2020 16:52:31 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.487.0; Mon, 14 Sep 2020 16:52:22 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v8 10/12] migration/dirtyrate: Implement calculate_dirtyrate() function Date: Mon, 14 Sep 2020 17:03:03 +0800 Message-ID: <1600074185-91624-11-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600074185-91624-1-git-send-email-zhengchuan@huawei.com> References: <1600074185-91624-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.32; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/14 04:52:27 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: zhengchuan@huawei.com, zhang.zhanghailiang@huawei.com, yuxiating@huawei.com, liq3ea@gmail.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@huawei.com, jinyan12@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Implement calculate_dirtyrate() function. Signed-off-by: Chuan Zheng Signed-off-by: YanYing Zhuang Reviewed-by: Dr. David Alan Gilbert --- migration/dirtyrate.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 6add846..cc31bd1 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -162,6 +162,21 @@ static void get_ramblock_dirty_info(RAMBlock *block, strcpy(info->idstr, qemu_ram_get_idstr(block)); } =20 +static void free_ramblock_dirty_info(struct RamblockDirtyInfo *infos, int = count) +{ + int i; + + if (!infos) { + return; + } + + for (i =3D 0; i < count; i++) { + g_free(infos[i].sample_page_vfn); + g_free(infos[i].hash_result); + } + g_free(infos); +} + static bool skip_sample_ramblock(RAMBlock *block) { /* @@ -289,8 +304,34 @@ static int compare_page_hash_info(struct RamblockDirty= Info *info, =20 static void calculate_dirtyrate(struct DirtyRateConfig config) { - /* todo */ - return; + struct RamblockDirtyInfo *block_dinfo =3D NULL; + int block_index =3D 0; + int64_t msec =3D 0; + int64_t initial_time; + + rcu_register_thread(); + reset_dirtyrate_stat(); + rcu_read_lock(); + initial_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); + if (!record_ramblock_hash_info(&block_dinfo, config, &block_index)) { + goto out; + } + rcu_read_unlock(); + + msec =3D config.sample_period_seconds * 1000; + msec =3D set_sample_page_period(msec, initial_time); + + rcu_read_lock(); + if (compare_page_hash_info(block_dinfo, block_index) < 0) { + goto out; + } + + update_dirtyrate(msec); + +out: + rcu_read_unlock(); + free_ramblock_dirty_info(block_dinfo, block_index); + rcu_unregister_thread(); } =20 void *get_dirtyrate_thread(void *arg) --=20 1.8.3.1 From nobody Sun May 5 11:47:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1600073968; cv=none; d=zohomail.com; s=zohoarc; b=JtvM7+yx+rXTMrmXN8r3z8LiuaKrHA+FXlGNdbD+PgbfhQ+4NDSz3Pdhpsuk8FYeP8qrCaIbZQX2PIe2E8NrlwKOqroNfjlkBU/XCJy0yXJ+7zJeyljgcEoHbDc4EwRne43EV7Z7bDPdXFFvjF0/QGPbxtzyAyQ3fsLLFConRfM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600073968; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=oeUH+7Wu0q7778Z8OmS+np9iWQm8AR9S7iqZVFleF7A=; b=SC9DykwZPZQi5sJLj3VvPBlPL9ZY6Rx786YXJH1TkEJW+d3irXv0QaAbf+rgGnJIgBvZfYq2ugqLVHnfjRCAcT6zjxNdf0g4BvB4zd6nfPFdCALQ/r/XAZm8CnJ3EMj5TdIfcIH/BEVUUkQZhz8LVcQR3q5Qm3Gj1L//Zd/rpVU= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600073968531455.37707814650616; Mon, 14 Sep 2020 01:59:28 -0700 (PDT) Received: from localhost ([::1]:50092 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHkKd-00026M-B8 for importer@patchew.org; Mon, 14 Sep 2020 04:59:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42316) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHkE4-00066l-52 for qemu-devel@nongnu.org; Mon, 14 Sep 2020 04:52:41 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:32894 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHkE0-0005ln-Nc for qemu-devel@nongnu.org; Mon, 14 Sep 2020 04:52:39 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 6DA4B51D4ABF6CCEAF04; Mon, 14 Sep 2020 16:52:31 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.487.0; Mon, 14 Sep 2020 16:52:22 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v8 11/12] migration/dirtyrate: Implement qmp_cal_dirty_rate()/qmp_get_dirty_rate() function Date: Mon, 14 Sep 2020 17:03:04 +0800 Message-ID: <1600074185-91624-12-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600074185-91624-1-git-send-email-zhengchuan@huawei.com> References: <1600074185-91624-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.32; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/14 04:52:27 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: zhengchuan@huawei.com, zhang.zhanghailiang@huawei.com, yuxiating@huawei.com, liq3ea@gmail.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@huawei.com, jinyan12@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Implement qmp_cal_dirty_rate()/qmp_get_dirty_rate() function which could be= called Signed-off-by: Chuan Zheng --- migration/dirtyrate.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ qapi/migration.json | 50 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index cc31bd1..917edef 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -61,6 +61,24 @@ static int dirtyrate_set_state(int *state, int old_state= , int new_state) } } =20 +static struct DirtyRateInfo *query_dirty_rate_info(void) +{ + int64_t dirty_rate =3D DirtyStat.dirty_rate; + struct DirtyRateInfo *info =3D g_malloc0(sizeof(DirtyRateInfo)); + + if (atomic_read(&CalculatingState) =3D=3D DIRTY_RATE_STATUS_MEASURED) { + info->dirty_rate =3D dirty_rate; + } else { + info->dirty_rate =3D -1; + } + + info->status =3D CalculatingState; + info->start_time =3D DirtyStat.start_time; + info->calc_time =3D DirtyStat.calc_time; + + return info; +} + static void reset_dirtyrate_stat(void) { DirtyStat.total_dirty_samples =3D 0; @@ -320,6 +338,8 @@ static void calculate_dirtyrate(struct DirtyRateConfig = config) =20 msec =3D config.sample_period_seconds * 1000; msec =3D set_sample_page_period(msec, initial_time); + DirtyStat.start_time =3D initial_time / 1000; + DirtyStat.calc_time =3D msec / 1000; =20 rcu_read_lock(); if (compare_page_hash_info(block_dinfo, block_index) < 0) { @@ -355,3 +375,45 @@ void *get_dirtyrate_thread(void *arg) } return NULL; } + +void qmp_calc_dirty_rate(int64_t calc_time, Error **errp) +{ + static struct DirtyRateConfig config; + QemuThread thread; + int ret; + + /* + * If the dirty rate is already being measured, don't attempt to start. + */ + if (atomic_read(&CalculatingState) =3D=3D DIRTY_RATE_STATUS_MEASURING)= { + error_setg(errp, "the dirty rate is already being measured."); + return; + } + + if (!is_sample_period_valid(calc_time)) { + error_setg(errp, "calc-time is out of range[%d, %d].", + MIN_FETCH_DIRTYRATE_TIME_SEC, + MAX_FETCH_DIRTYRATE_TIME_SEC); + return; + } + + /* + * Init calculation state as unstarted. + */ + ret =3D dirtyrate_set_state(&CalculatingState, CalculatingState, + DIRTY_RATE_STATUS_UNSTARTED); + if (ret =3D=3D -1) { + error_setg(errp, "init dirty rate calculation state failed."); + return; + } + + config.sample_period_seconds =3D calc_time; + config.sample_pages_per_gigabytes =3D DIRTYRATE_DEFAULT_SAMPLE_PAGES; + qemu_thread_create(&thread, "get_dirtyrate", get_dirtyrate_thread, + (void *)&config, QEMU_THREAD_DETACHED); +} + +struct DirtyRateInfo *qmp_query_dirty_rate(Error **errp) +{ + return query_dirty_rate_info(); +} diff --git a/qapi/migration.json b/qapi/migration.json index 061ff25..4b980a0 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -1737,3 +1737,53 @@ ## { 'enum': 'DirtyRateStatus', 'data': [ 'unstarted', 'measuring', 'measured'] } + +## +# @DirtyRateInfo: +# +# Information about current dirty page rate of vm. +# +# @dirty-rate: @dirtyrate describing the dirty page rate of vm +# in units of MB/s. +# If this field return '-1', it means querying is not +# start or not complete. +# +# @status: status containing dirtyrate query status includes +# 'unstarted' or 'measuring' or 'measured' +# +# @start-time: start time in units of second for calculation +# +# @calc-time: time in units of second for sample dirty pages +# +# Since: 5.2 +# +## +{ 'struct': 'DirtyRateInfo', + 'data': {'dirty-rate': 'int64', + 'status': 'DirtyRateStatus', + 'start-time': 'int64', + 'calc-time': 'int64'} } + +## +# @calc-dirty-rate: +# +# start calculating dirty page rate for vm +# +# @calc-time: time in units of second for sample dirty pages +# +# Since: 5.2 +# +# Example: +# {"command": "calc-dirty-rate", "data": {"calc-time": 1} } +# +## +{ 'command': 'calc-dirty-rate', 'data': {'calc-time': 'int64'} } + +## +# @query-dirty-rate: +# +# query dirty page rate in units of MB/s for vm +# +# Since: 5.2 +## +{ 'command': 'query-dirty-rate', 'returns': 'DirtyRateInfo' } --=20 1.8.3.1 From nobody Sun May 5 11:47:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1600073994; cv=none; d=zohomail.com; s=zohoarc; b=nXmqxYGL2ZYRes87qyhcMLNTAyOwKBrYFsNgJ4SIys9ao1ZyxmFiCe+kSeB6k+Yi3qgG0Zg1nBRx2MaXY8ZilVxSb40nXBUsFogm6LJWxoNOm28OzvGnJGA5f+X0BBCUTQ8/jb9QwNm6jRI3HaAuLSzr4509Oqdsj+tl4PhZ784= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600073994; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=XP1Cxl03NEE01YXOxx9z5ckRUcgnZvlAG1llZq4GprA=; b=P0lIKroSm/h+8VB8YxDCibWgU5m0EF0IPMYRit/UCFbfQY+NCqctXa44FZack9+ceSGiS5kj7BGliivfWIVGoa7wWl8nFf2uhAlNNLaFXkTQrYuagIFbDUOdwl4Ba++hkxfVXMk30gQwgIBaYbLXAbc+9eBMSrhW394kIp6s4a0= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600073994030982.8325029247989; Mon, 14 Sep 2020 01:59:54 -0700 (PDT) Received: from localhost ([::1]:52100 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHkL2-0002v6-Uh for importer@patchew.org; Mon, 14 Sep 2020 04:59:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42306) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHkE2-00064a-9z for qemu-devel@nongnu.org; Mon, 14 Sep 2020 04:52:38 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:32886 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHkDz-0005la-QL for qemu-devel@nongnu.org; Mon, 14 Sep 2020 04:52:38 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 4534A986C89A8ACC6714; Mon, 14 Sep 2020 16:52:31 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.487.0; Mon, 14 Sep 2020 16:52:23 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v8 12/12] migration/dirtyrate: Add trace_calls to make it easier to debug Date: Mon, 14 Sep 2020 17:03:05 +0800 Message-ID: <1600074185-91624-13-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600074185-91624-1-git-send-email-zhengchuan@huawei.com> References: <1600074185-91624-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.32; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/14 04:52:27 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: zhengchuan@huawei.com, zhang.zhanghailiang@huawei.com, yuxiating@huawei.com, liq3ea@gmail.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@huawei.com, jinyan12@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add trace_calls to make it easier to debug Signed-off-by: Chuan Zheng Reviewed-by: Dr. David Alan Gilbert Reviewed-by: David Edmondson --- migration/dirtyrate.c | 9 +++++++++ migration/trace-events | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 917edef..f808037 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -22,6 +22,7 @@ #include "qapi/qapi-commands-migration.h" #include "migration.h" #include "ram.h" +#include "trace.h" #include "dirtyrate.h" =20 static int CalculatingState =3D DIRTY_RATE_STATUS_UNSTARTED; @@ -54,6 +55,7 @@ static bool is_sample_period_valid(int64_t sec) static int dirtyrate_set_state(int *state, int old_state, int new_state) { assert(new_state < DIRTY_RATE_STATUS__MAX); + trace_dirtyrate_set_state(DirtyRateStatus_str(new_state)); if (atomic_cmpxchg(state, old_state, new_state) =3D=3D old_state) { return 0; } else { @@ -76,6 +78,8 @@ static struct DirtyRateInfo *query_dirty_rate_info(void) info->start_time =3D DirtyStat.start_time; info->calc_time =3D DirtyStat.calc_time; =20 + trace_query_dirty_rate_info(DirtyRateStatus_str(CalculatingState)); + return info; } =20 @@ -123,6 +127,7 @@ static uint32_t get_ramblock_vfn_hash(struct RamblockDi= rtyInfo *info, crc =3D crc32(0, (info->ramblock_addr + vfn * TARGET_PAGE_SIZE), TARGET_PAGE_SIZE); =20 + trace_get_ramblock_vfn_hash(info->idstr, vfn, crc); return crc; } =20 @@ -201,6 +206,8 @@ static bool skip_sample_ramblock(RAMBlock *block) * Sample only blocks larger than MIN_RAMBLOCK_SIZE. */ if (qemu_ram_get_used_length(block) < (MIN_RAMBLOCK_SIZE << 10)) { + trace_skip_sample_ramblock(block->idstr, + qemu_ram_get_used_length(block)); return true; } =20 @@ -262,6 +269,7 @@ static void calc_page_dirty_rate(struct RamblockDirtyIn= fo *info) for (i =3D 0; i < info->sample_pages_count; i++) { crc =3D get_ramblock_vfn_hash(info, info->sample_page_vfn[i]); if (crc !=3D info->hash_result[i]) { + trace_calc_page_dirty_rate(info->idstr, crc, info->hash_result= [i]); info->sample_dirty_count++; } } @@ -287,6 +295,7 @@ find_page_matched(RAMBlock *block, int count, if (infos[i].ramblock_addr !=3D qemu_ram_get_host_addr(block) || infos[i].ramblock_pages !=3D (qemu_ram_get_used_length(block) >> TARGET_PAGE_BITS)) { + trace_find_page_matched(block->idstr); return NULL; } =20 diff --git a/migration/trace-events b/migration/trace-events index 4ab0a50..8c2b58f 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -312,3 +312,11 @@ dirty_bitmap_load_bits_zeroes(void) "" dirty_bitmap_load_header(uint32_t flags) "flags 0x%x" dirty_bitmap_load_enter(void) "" dirty_bitmap_load_success(void) "" + +# dirtyrate.c +dirtyrate_set_state(const char *new_state) "new state %s" +query_dirty_rate_info(const char *new_state) "current state %s" +get_ramblock_vfn_hash(const char *idstr, uint64_t vfn, uint32_t crc) "ramb= lock name: %s, vfn: %"PRIu64 ", crc: %" PRIu32 +calc_page_dirty_rate(const char *idstr, uint32_t new_crc, uint32_t old_crc= ) "ramblock name: %s, new crc: %" PRIu32 ", old crc: %" PRIu32 +skip_sample_ramblock(const char *idstr, uint64_t ramblock_size) "ramblock = name: %s, ramblock size: %" PRIu64 +find_page_matched(const char *idstr) "ramblock %s addr or size changed" --=20 1.8.3.1