From nobody Fri May 3 11:05:28 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=1600137305; cv=none; d=zohomail.com; s=zohoarc; b=lgM4sM8SnqW7WMLpN0PPzL6l1/kvZmzwMV6gqt7+3CP1EnD2SUnhdn2aqqR3xQEmO2U9e4OQpoilmcOaMG1j66vHZSOfqejazUQSQy4ovBqxpK+iTt/a2k1IiEAywF6Hvm046O8F1VXQR8f+ZilbeVJ7gGujyoMovTX9rai6ly8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600137305; 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=FGsfnz+Eii7XId3CX8i0tERpd5/jVlI6YEz98XLpnRgR6cPCjCoqlSIy2IooCCwKzP+5JFUhctbn1U5PqxBC7sRyGwyQzlQqyuDoHuuY6A1gj0DQ/+i1g0cfDTQe7T3Wk0NkLgcUlXLNJqrJiu7Uua32EOi/Dq1c6JUqNlf4t/k= 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 1600137305521564.6438537719201; Mon, 14 Sep 2020 19:35:05 -0700 (PDT) Received: from localhost ([::1]:53172 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kI0oB-0003wu-UA for importer@patchew.org; Mon, 14 Sep 2020 22:35:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39518) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kI0nJ-0002LX-W3 for qemu-devel@nongnu.org; Mon, 14 Sep 2020 22:34:10 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:48908 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 1kI0nH-0005sz-JW for qemu-devel@nongnu.org; Mon, 14 Sep 2020 22:34:09 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 27BD3B59DE0F5402C2C8; Tue, 15 Sep 2020 10:34:02 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Tue, 15 Sep 2020 10:33:55 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v9 01/12] migration/dirtyrate: setup up query-dirtyrate framwork Date: Tue, 15 Sep 2020 10:44:36 +0800 Message-ID: <1600137887-58739-2-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600137887-58739-1-git-send-email-zhengchuan@huawei.com> References: <1600137887-58739-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.35; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/14 22:34:04 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.001, RCVD_IN_MSPIKE_WL=0.001, 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 Reviewed-by: Li Qiang --- 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 Fri May 3 11:05:28 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=1600137426; cv=none; d=zohomail.com; s=zohoarc; b=b1gPW7DU1XosiecfPO/hbx+3q8Fc/k9y0yiAF4E9MmeZVeP1m0bedOjJOkV45HJBfjE8gAk6AaBnbUuDNGFdSU8/+x3OcCRLBCo1P9Qb6dOR1i1vLlczwnnWUQa0yHi6rUibKDhLPuv23fP1t5f21SnNaoW1OcNe4tWNX8xBRhE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600137426; 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=O2uokNYsxkNUauRPkh6XrIQskpFmu+vAqVHPrn3iglkZKCcP3mR6HnebH/lq5th/hn0KPPdsYeyda1hcl+DBWCaflIfWYfr2o5khHB88iCwCRB6ZvDwRV4brlJnBD7fiznzh8pX73eAgu9TPmthyM5GwkLV0LrAvAyMHfETpBx0= 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 1600137426668481.5612655518054; Mon, 14 Sep 2020 19:37:06 -0700 (PDT) Received: from localhost ([::1]:33284 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kI0q9-0007Th-KE for importer@patchew.org; Mon, 14 Sep 2020 22:37:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39586) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kI0nM-0002Mf-Jy for qemu-devel@nongnu.org; Mon, 14 Sep 2020 22:34:12 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:48906 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 1kI0nJ-0005sy-Ib for qemu-devel@nongnu.org; Mon, 14 Sep 2020 22:34:12 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 2E181DBB89DFA140C1C9; Tue, 15 Sep 2020 10:34:02 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Tue, 15 Sep 2020 10:33:55 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v9 02/12] migration/dirtyrate: add DirtyRateStatus to denote calculation status Date: Tue, 15 Sep 2020 10:44:37 +0800 Message-ID: <1600137887-58739-3-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600137887-58739-1-git-send-email-zhengchuan@huawei.com> References: <1600137887-58739-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.35; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/14 22:34:04 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.001, RCVD_IN_MSPIKE_WL=0.001, 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 Reviewed-by: Li Qiang --- 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 Fri May 3 11:05:28 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=1600137305; cv=none; d=zohomail.com; s=zohoarc; b=JovRuiU6JchG7wuw83HQI5KGYfwXtqgOrNCH/niyr7gnBRS60D2CQkrhkaZIG4ecOWWiJikiyckyYi59GfCTFskOqD8EbULq9y7AtKFXrjx2a4Bl0582h0WTFtFEynmAoeIEMHUXmxD+97OpV8035/YWiXUVEdn7+wIHzDn4BwA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600137305; 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=YiWBBiN7FP+TqsLpzy8eoRTHHjcZp1QFmLTcUm8RhYXnEIs+aAStCcpKvSMh3368oiipLnck0wmTHpbxahgO0uU0ZlgKyrZVmudQqcMbhICyA+KcmZkInTUoUU0/rYhdu1KgXXL7DuRETEfaiLEn2hHEg7SAmX26MY+BiBBVZys= 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 1600137305688124.51925333870827; Mon, 14 Sep 2020 19:35:05 -0700 (PDT) Received: from localhost ([::1]:53120 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kI0oB-0003vb-VX for importer@patchew.org; Mon, 14 Sep 2020 22:35:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39520) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kI0nK-0002LY-1V for qemu-devel@nongnu.org; Mon, 14 Sep 2020 22:34:10 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:48904 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 1kI0nH-0005t0-GU for qemu-devel@nongnu.org; Mon, 14 Sep 2020 22:34:09 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 3A31E85A9E4C396CB72B; Tue, 15 Sep 2020 10:34:02 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Tue, 15 Sep 2020 10:33:56 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v9 03/12] migration/dirtyrate: Add RamblockDirtyInfo to store sampled page info Date: Tue, 15 Sep 2020 10:44:38 +0800 Message-ID: <1600137887-58739-4-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600137887-58739-1-git-send-email-zhengchuan@huawei.com> References: <1600137887-58739-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.35; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/14 22:34:04 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.001, RCVD_IN_MSPIKE_WL=0.001, 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 Reviewed-by: Li Qiang --- 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 Fri May 3 11:05:28 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=1600137568; cv=none; d=zohomail.com; s=zohoarc; b=nVBC3QMr89yxqTBGp2mmYWf46NyFCWW61nIP4MTQTL9JvXsC4T7b0+Jb+JPJryFirmhKEshB1vj3gS10XH860YB01SpDSwEEpVuBSu3sdO2chuw9JAt88GjY/4somAjRvUhyO11CO6yIaWU10sbzeln+OONRTX7cK6ItxybrHUI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600137568; 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=9waWkGKO76LYa3P8Y6ULCD5BqSm3eEpEIvPj9Jnvbaw=; b=lFY+H2+dsJcNhgGz06na12AyMGQ5BtN97J6BxuGktP7hhqQFRJGy7StBi7/fV4sVsE/fEPjGtcnPnQx2/IPOPqQ3tOqF8gXLD8G5E3o17LOClGOCfz0mgUaCrWs48+5mQ3g4DYBM/DiHyL1kWnr83Yyje73PHK9rgpe+VQWpwDE= 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 1600137568524798.4850962896107; Mon, 14 Sep 2020 19:39:28 -0700 (PDT) Received: from localhost ([::1]:40914 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kI0sR-0002A5-Cj for importer@patchew.org; Mon, 14 Sep 2020 22:39:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39628) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kI0nO-0002Ri-Hq for qemu-devel@nongnu.org; Mon, 14 Sep 2020 22:34:14 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:49082 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 1kI0nM-0005tq-2k for qemu-devel@nongnu.org; Mon, 14 Sep 2020 22:34:14 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 3F609B5F952EA9BA9ABD; Tue, 15 Sep 2020 10:34:07 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Tue, 15 Sep 2020 10:33:56 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v9 04/12] migration/dirtyrate: Add dirtyrate statistics series functions Date: Tue, 15 Sep 2020 10:44:39 +0800 Message-ID: <1600137887-58739-5-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600137887-58739-1-git-send-email-zhengchuan@huawei.com> References: <1600137887-58739-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.35; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/14 22:34:04 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.001, RCVD_IN_MSPIKE_WL=0.001, 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 Reviewed-by: Li Qiang --- 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..ab372ba 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 -1; + 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 Fri May 3 11:05:28 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=1600137696; cv=none; d=zohomail.com; s=zohoarc; b=H7R92RSvyO/W91EYtAuRTEDU9rqDCrqE9tC+jQbzTvAT6fdUntMKiDoLGUUzwGr7vTQiWnqfekxN49LAHB06ZGUeghLvA252/42yx/g5eD03BnwDx3X0BRDOwmXtkDKQGj6t7SasFzwuh3ftfAhIaZVYP7CNm2riCM91R1sC+CQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600137696; 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=8bKeoGaOAh1ubmUS4sdJsoWkhv3NrWQq3Gr+yB2IlW4=; b=eJU29uz43bGO9HhNgllODkQ6ZwhLyVAoCnAcF0Beqw06odFQzoeS/R5NSwOXTDonUM827ejPCpUVGIU3LT199oDaIYb0kmA0jwUjb0YPybMMU5Gy9ZOgyeuKhMb21JSW5fZnPjhhGriOo9qQ+/63XzNB61oLz5L89KDfFpFpKuY= 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 1600137696580335.6671032867546; Mon, 14 Sep 2020 19:41:36 -0700 (PDT) Received: from localhost ([::1]:46916 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kI0uV-0004ey-9F for importer@patchew.org; Mon, 14 Sep 2020 22:41:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39632) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kI0nP-0002T4-1N for qemu-devel@nongnu.org; Mon, 14 Sep 2020 22:34:15 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:49084 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 1kI0nM-0005tv-A9 for qemu-devel@nongnu.org; Mon, 14 Sep 2020 22:34:14 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 4F40DA0BDEB33983EE16; Tue, 15 Sep 2020 10:34:07 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Tue, 15 Sep 2020 10:33:57 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v9 05/12] migration/dirtyrate: move RAMBLOCK_FOREACH_MIGRATABLE into ram.h Date: Tue, 15 Sep 2020 10:44:40 +0800 Message-ID: <1600137887-58739-6-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600137887-58739-1-git-send-email-zhengchuan@huawei.com> References: <1600137887-58739-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.35; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/14 22:34:04 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.001, RCVD_IN_MSPIKE_WL=0.001, 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 Reviewed-by: Li Qiang --- 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 ab372ba..7366bf3 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 Fri May 3 11:05:28 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=1600137307; cv=none; d=zohomail.com; s=zohoarc; b=k4jzKXgekpMGDxGKvodwMvHvquzYWLW8wwx6cZPQ/KjZWQ9YhlNOO1/kOvRkaR9Ov8DcVrfLy4UGkibVTwmip9FUMQfP24CJ1A5nRM4/4fvjuAQyg1t9SPXhiOQU90Is8HO5bmdBeetOaRB5i7o4GRiXrtym64c0O/usAFnRKDE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600137307; 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=rf7sKY0fkwTY8XZmWyktVi1pmO/fnCTr+xGfUdw6UgQ=; b=I0Cvxi9HO9+4vm346T7rXoQO3uzcD/xDX2Sy+WlMruH91E1rX8gc2HFi/VvtjIpqwKJcOmzGtLOAGCezhwxBPKerSRJusQcl06p8yFeh9WR57UTJG1kLkvqIB/sI3mJz7aqcw+SRT86Gt64rywd2gn6OC/ENEsyM3/60zDvLUBw= 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 1600137307649179.22606383080972; Mon, 14 Sep 2020 19:35:07 -0700 (PDT) Received: from localhost ([::1]:53440 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kI0oE-00043t-GT for importer@patchew.org; Mon, 14 Sep 2020 22:35:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39608) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kI0nN-0002OM-CE for qemu-devel@nongnu.org; Mon, 14 Sep 2020 22:34:13 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:4745 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 1kI0nK-0005tS-Pu for qemu-devel@nongnu.org; Mon, 14 Sep 2020 22:34:13 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 69923C1715A014D2201B; Tue, 15 Sep 2020 10:34:07 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Tue, 15 Sep 2020 10:33:58 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v9 06/12] migration/dirtyrate: Record hash results for each sampled page Date: Tue, 15 Sep 2020 10:44:41 +0800 Message-ID: <1600137887-58739-7-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600137887-58739-1-git-send-email-zhengchuan@huawei.com> References: <1600137887-58739-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.191; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/14 22:34:07 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.001, RCVD_IN_MSPIKE_WL=0.001, 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 Reviewed-by: Li Qiang --- migration/dirtyrate.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 109 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 7366bf3..5e6eedf 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,114 @@ 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_count) +{ + struct RamblockDirtyInfo *info =3D NULL; + struct RamblockDirtyInfo *dinfo =3D NULL; + RAMBlock *block =3D NULL; + int total_count =3D 0; + int index =3D 0; + bool ret =3D false; + + RAMBLOCK_FOREACH_MIGRATABLE(block) { + total_count++; + } + + dinfo =3D g_try_malloc0_n(total_count, sizeof(struct RamblockDirtyInfo= )); + if (dinfo =3D=3D NULL) { + goto out; + } + + RAMBLOCK_FOREACH_MIGRATABLE(block) { + if (index >=3D total_count) { + break; + } + info =3D &dinfo[index]; + get_ramblock_dirty_info(block, info, &config); + if (!save_ramblock_hash(info)) { + goto out; + } + index++; + } + ret =3D true; + +out: + *block_count =3D index; + *block_dinfo =3D dinfo; + return ret; +} + static void calculate_dirtyrate(struct DirtyRateConfig config) { /* todo */ --=20 1.8.3.1 From nobody Fri May 3 11:05:28 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=1600137428; cv=none; d=zohomail.com; s=zohoarc; b=g3w2fKaD/19i4IcJtfvN+q+KKRvApbwCqJd8sgxIRJBPYsG65hwI0Efe/YqcuaD+cjTjKCB/MIdobWe9BO3pHfwsLVrtSZcpTWyoSelTJOF8RBVMKI/kMriNxF/mSKBG1vpVXkv6cI7E3h+JoYvdhx0Qma81uUJKLWm161BKzYI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600137428; 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=FiXA47jsV1xTvyp4UPIKrFq96gt942+cYov2/LLJ5b0=; b=Gperx38YPDwRXBpyePIzBCn0xiVcb6hqss8ecY5wJmex/HaeAmyCz5WSaVvEqZFZoL1qKwdsuDj7jt0Ea7BHcli1LlXHB3UdYzu+4wWxON0YMwHiV5hUOxfE2MkzpmDfN80Yd7u41/rRgInIQVajMXVToBWdqYzyPeaCZ50M0Rc= 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 1600137428436760.6454637680675; Mon, 14 Sep 2020 19:37:08 -0700 (PDT) Received: from localhost ([::1]:33526 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kI0qB-0007ZV-8V for importer@patchew.org; Mon, 14 Sep 2020 22:37:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39622) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kI0nN-0002Q8-UE for qemu-devel@nongnu.org; Mon, 14 Sep 2020 22:34:13 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:34028 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 1kI0nK-0005tT-Rp for qemu-devel@nongnu.org; Mon, 14 Sep 2020 22:34:13 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 83C919148793D719AD73; Tue, 15 Sep 2020 10:34:07 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Tue, 15 Sep 2020 10:33:59 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v9 07/12] migration/dirtyrate: Compare page hash results for recorded sampled page Date: Tue, 15 Sep 2020 10:44:42 +0800 Message-ID: <1600137887-58739-8-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600137887-58739-1-git-send-email-zhengchuan@huawei.com> References: <1600137887-58739-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 21:28:41 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.001, RCVD_IN_MSPIKE_WL=0.001, 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 5e6eedf..2d48eb8 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -177,6 +177,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 <=3D 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 bool compare_page_hash_info(struct RamblockDirtyInfo *info, + int block_count) +{ + struct RamblockDirtyInfo *block_dinfo =3D NULL; + RAMBlock *block =3D NULL; + + RAMBLOCK_FOREACH_MIGRATABLE(block) { + block_dinfo =3D find_page_matched(block, block_count, 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 false; + } + + return true; +} + static void calculate_dirtyrate(struct DirtyRateConfig config) { /* todo */ --=20 1.8.3.1 From nobody Fri May 3 11:05:28 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=1600137566; cv=none; d=zohomail.com; s=zohoarc; b=czqqUCwGT5X2WSRMiPXpwqmlF0ygeJalk6mzOA9hE6NTMiDMQ/qulGig/suqLttzmoaVI4WVasd5GYq089sBHQuEvmFy9ZytwKNQBpDysVMDQ68Sl341OV89GsxT7x++gxbXwDH0z8B9QjRBPe3/s/HXiSV+AbRBRnQG0pnfQ6s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600137566; 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=/YlMSiTgDs4m34eDA24Bl4FglRPqWecW8kK31kPFMMA=; b=Wi+QLBl+9YA8EMQFcON3QIzckS7Fx6t18OmLNHxJzaS/JPHrI1m1d/DVqVjjGBK4C3401Ifsr4yDkMC3NgtQd+/DBOuMI9ulEOci7l1SxzaRPyfujQhuc500TX7/lnd00lxGVuyWLcJhDV7VXLCwhF1NR5CW2oUO04767m5osDk= 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 1600137566345191.67564494226679; Mon, 14 Sep 2020 19:39:26 -0700 (PDT) Received: from localhost ([::1]:40674 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kI0sP-00023J-6P for importer@patchew.org; Mon, 14 Sep 2020 22:39:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39630) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kI0nO-0002SH-Of for qemu-devel@nongnu.org; Mon, 14 Sep 2020 22:34:14 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:49086 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 1kI0nM-0005tu-9v for qemu-devel@nongnu.org; Mon, 14 Sep 2020 22:34:14 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 4A155977810104AD6811; Tue, 15 Sep 2020 10:34:07 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Tue, 15 Sep 2020 10:33:59 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v9 08/12] migration/dirtyrate: skip sampling ramblock with size below MIN_RAMBLOCK_SIZE Date: Tue, 15 Sep 2020 10:44:43 +0800 Message-ID: <1600137887-58739-9-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600137887-58739-1-git-send-email-zhengchuan@huawei.com> References: <1600137887-58739-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.35; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/14 22:34:04 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.001, RCVD_IN_MSPIKE_WL=0.001, 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 Reviewed-by: Li Qiang --- migration/dirtyrate.c | 21 +++++++++++++++++++++ migration/dirtyrate.h | 5 +++++ 2 files changed, 26 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 2d48eb8..903f728 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_count) @@ -150,6 +162,9 @@ static bool record_ramblock_hash_info(struct RamblockDi= rtyInfo **block_dinfo, bool ret =3D false; =20 RAMBLOCK_FOREACH_MIGRATABLE(block) { + if (skip_sample_ramblock(block)) { + continue; + } total_count++; } =20 @@ -159,6 +174,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_count) { break; } @@ -225,6 +243,9 @@ static bool compare_page_hash_info(struct RamblockDirty= Info *info, RAMBlock *block =3D NULL; =20 RAMBLOCK_FOREACH_MIGRATABLE(block) { + if (skip_sample_ramblock(block)) { + continue; + } block_dinfo =3D find_page_matched(block, block_count, 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 Fri May 3 11:05:28 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=1600137426; cv=none; d=zohomail.com; s=zohoarc; b=SpP7C5dIgrBaWRdoXjvYXrXNOMvHVwDyKpyIkE6IsNO6salLVV/nNewldE0NPvHqyYvP2AfFpJUXoh5CqHNrt0AsPsvjsxJ/kmjdrT2H7RwWrIA6FVdo2y8n0Alo+0nrJQhrqrepdNwiMd/YuSVN9K51+tKiQGW+lg3gNFtYQ0c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600137426; 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=RxFdoYu5z2pPrPxXYFdUn9R5+mzA5GG9tMHu+JxEl18=; b=bWGIxTCJxDUgTkd7RK0XKqdMpZkp2FDajcKCeGp2xLBBSNO6gy/Mky3g5L0W72wE+dVXIQ2O/mSPp0UJJzvGn1jrJsxnSFXd8hmZqU9ELM4RQIYDBgKL56OmYateokj9ckANsMsSebEntSzx6kZS7kDjlfYCdkncWF6vuTW0g3o= 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 1600137426265338.6254793674419; Mon, 14 Sep 2020 19:37:06 -0700 (PDT) Received: from localhost ([::1]:33256 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kI0q9-0007Sw-5u for importer@patchew.org; Mon, 14 Sep 2020 22:37:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39562) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kI0nL-0002Ll-98 for qemu-devel@nongnu.org; Mon, 14 Sep 2020 22:34:11 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:48968 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 1kI0nJ-0005tP-FG for qemu-devel@nongnu.org; Mon, 14 Sep 2020 22:34:11 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 39F1B6B1A8C28649F8E5; Tue, 15 Sep 2020 10:34:07 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Tue, 15 Sep 2020 10:34:00 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v9 09/12] migration/dirtyrate: Implement set_sample_page_period() and is_sample_period_valid() Date: Tue, 15 Sep 2020 10:44:44 +0800 Message-ID: <1600137887-58739-10-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600137887-58739-1-git-send-email-zhengchuan@huawei.com> References: <1600137887-58739-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.35; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/14 22:34:04 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.001, RCVD_IN_MSPIKE_WL=0.001, 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 Reviewed-by: Li Qiang --- migration/dirtyrate.c | 24 ++++++++++++++++++++++++ migration/dirtyrate.h | 6 ++++++ 2 files changed, 30 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 903f728..bcff10e 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 Fri May 3 11:05:28 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=1600137428; cv=none; d=zohomail.com; s=zohoarc; b=nPIRdfz8s3mf97FWBpWOahKMTWrce/u8RXL8+fx8NK0lVP2PDxbj23jzBJuMksPHIX4pah2QX2FPE19IHHlePJrrqi0pdQFDx07QgaZFZUxcZHH7fLX/DM/PmqB+i7RRcJWp1bH89jf18lUbygpF5JIDlONnsxMqY2B99Q9LBRM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600137428; 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=viMp5beuI06qQJDZXUzjdn9sYgn73PURIhZstFM9SXw=; b=Uej0akGSN+6cuFhyHp1faEaEj81wEx0+9Mzjx2ouvDjujEj8vIm4w3mH/VtatjqBSoyxBrZtFvO2UT7qB8ulPAyAD5MQnnQ8lncOf9uqvsrE6armZIMcq+E/dZZ/6hSw8e5P0uMCSPBJIsg9+w53yfSqHrQiczkWBaF0RHtHk+A= 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 1600137428174536.6040700082377; Mon, 14 Sep 2020 19:37:08 -0700 (PDT) Received: from localhost ([::1]:33454 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kI0qB-0007Xm-2P for importer@patchew.org; Mon, 14 Sep 2020 22:37:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39642) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kI0nP-0002U5-IX for qemu-devel@nongnu.org; Mon, 14 Sep 2020 22:34:15 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:49080 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 1kI0nM-0005tr-3Y for qemu-devel@nongnu.org; Mon, 14 Sep 2020 22:34:15 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 44F80B7CE818E7094A17; Tue, 15 Sep 2020 10:34:07 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Tue, 15 Sep 2020 10:34:01 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v9 10/12] migration/dirtyrate: Implement calculate_dirtyrate() function Date: Tue, 15 Sep 2020 10:44:45 +0800 Message-ID: <1600137887-58739-11-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600137887-58739-1-git-send-email-zhengchuan@huawei.com> References: <1600137887-58739-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.35; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/14 22:34:04 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.001, RCVD_IN_MSPIKE_WL=0.001, 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 Reviewed-by: Li Qiang --- migration/dirtyrate.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index bcff10e..af02647 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) { /* @@ -287,8 +302,34 @@ static bool compare_page_hash_info(struct RamblockDirt= yInfo *info, =20 static void calculate_dirtyrate(struct DirtyRateConfig config) { - /* todo */ - return; + struct RamblockDirtyInfo *block_dinfo =3D NULL; + int block_count =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_count)) { + 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_count)) { + goto out; + } + + update_dirtyrate(msec); + +out: + rcu_read_unlock(); + free_ramblock_dirty_info(block_dinfo, block_count); + rcu_unregister_thread(); } =20 void *get_dirtyrate_thread(void *arg) --=20 1.8.3.1 From nobody Fri May 3 11:05:28 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=1600137566; cv=none; d=zohomail.com; s=zohoarc; b=oJ2fzddZN/ixXkhxmc1ZyhRt0UBmJ8gffYmzlAoYAEn0QLjKs75mg+rVsFipr0npb2qt2Fhm/mZBdHirHuqF4VVhjrRo+SW6hDpGflfOwODDGw8PboDGmzO4+IQi7n2X32mW/BCVEqVpB+0F2AwBqodbdfzMpHXL9pomsjpiLZk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600137566; 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=zYV5Un/6NLFpuMSAH2k+QI+gdgcGnbBYCzI9QEd+ZNw=; b=GjlmP5dab1zyywze1b3TJQ7r0bOU5m4o5fZTnk/ugfaZ6btAozIpkffVm3G8dzbCiQ2Deo/Xh7ZCgYfvHEYLJsmm/u+jzHyPhpeXQlf41P860E82Io+hjQJPTNkFd3JYVBM0qJKxXrTpOxhaBeHLEDJQOjgPtyOWxuvaqX3oOU8= 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 1600137566357922.4053855377109; Mon, 14 Sep 2020 19:39:26 -0700 (PDT) Received: from localhost ([::1]:40696 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kI0sP-00023q-7x for importer@patchew.org; Mon, 14 Sep 2020 22:39:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39672) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kI0nQ-0002YJ-RU for qemu-devel@nongnu.org; Mon, 14 Sep 2020 22:34:16 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:34158 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 1kI0nO-0005uZ-O5 for qemu-devel@nongnu.org; Mon, 14 Sep 2020 22:34:16 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 8A35ECD0F257DD5D63F8; Tue, 15 Sep 2020 10:34:12 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Tue, 15 Sep 2020 10:34:01 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v9 11/12] migration/dirtyrate: Implement qmp_cal_dirty_rate()/qmp_get_dirty_rate() function Date: Tue, 15 Sep 2020 10:44:46 +0800 Message-ID: <1600137887-58739-12-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600137887-58739-1-git-send-email-zhengchuan@huawei.com> References: <1600137887-58739-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 21:28:41 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.001, RCVD_IN_MSPIKE_WL=0.001, 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 af02647..37d4bdf 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; @@ -318,6 +336,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_count)) { @@ -353,3 +373,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 Fri May 3 11:05:28 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=1600137698; cv=none; d=zohomail.com; s=zohoarc; b=aVy2D3gOlH350ARXNPa+O9yZuOBadE0TpbojvDNWmrupJ9kEqNIm12lR5tlRt9VDO6p1jSe87TO+/gGJojN+pgmbnpf6yYRVpRHs6WsTYIZdzS3w5QvWwmbBMJ617IiJ4BzRyT3CDEMWc/o6I5uBhHru/L+Re2leGTe1pXy1u7s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600137698; 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=pniEtbHQGcgi/dbtEbAQ+vvp3YsJ0kk2OyD/NqwIxoI=; b=ctdyZNaNfUKRTncr+NSTuZu1DjKAikpi7nVTpzKyMy3HlBaDXq4Lgyp/1MObeXyUNhhUMlCmsa4QEf6yxqqRslVvkU+iejfXbWK+PFVrTjsPoYXxTy9zzWof8pJ1ZjkbztkwaK/okNyf5kQC4L9C6LhGd/K1sqL1PueQ+uQSIAA= 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 1600137698635521.9736275445458; Mon, 14 Sep 2020 19:41:38 -0700 (PDT) Received: from localhost ([::1]:47156 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kI0uX-0004kg-Jn for importer@patchew.org; Mon, 14 Sep 2020 22:41:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39678) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kI0nR-0002ak-MP for qemu-devel@nongnu.org; Mon, 14 Sep 2020 22:34:17 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:34154 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 1kI0nP-0005uY-Ky for qemu-devel@nongnu.org; Mon, 14 Sep 2020 22:34:17 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 84D2541C577D8AE60B72; Tue, 15 Sep 2020 10:34:12 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Tue, 15 Sep 2020 10:34:02 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v9 12/12] migration/dirtyrate: Add trace_calls to make it easier to debug Date: Tue, 15 Sep 2020 10:44:47 +0800 Message-ID: <1600137887-58739-13-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600137887-58739-1-git-send-email-zhengchuan@huawei.com> References: <1600137887-58739-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 21:28:41 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.001, RCVD_IN_MSPIKE_WL=0.001, 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 37d4bdf..0090efd 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 @@ -260,6 +267,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++; } } @@ -285,6 +293,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