From nobody Fri Apr 19 01:14:08 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=1600237134; cv=none; d=zohomail.com; s=zohoarc; b=jIK14jjHlN6X8Z8x897qxc42qCyELbmM5j/dAsTLsjwT+WdjS4Ogd52rw+WobM9KuVrhXyS6d6Xh5NyRa39iyiXwfyPsU0QrWkqb5BPqVbjtXNbe8r1yrXNO9tl0/oh49Sqgmv91kXX2fUFcPvb7eSER/yfdgG7VNWavXr/QqkI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600237134; 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=zqLdziSm8Tyr8IINQn4oskGyo1MVq+mXiQfzp0eFIcQ=; b=TfJEzfqud0WzMOKnaGhgziphV3LtTutzdgAgmRt3dJrI9zHE3Ec9rb8NBy+++3nCDpRcDyr7+luYVvsfX+KcpmrOElmv6LVPUDo3tYpgyTn3IoxX2v52F2CtPQXPFzC0AQP7653bW1B70lVWeAnT3SWjEw04QjgEv+Sjn8wqaCk= 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 1600237134297697.5761764096749; Tue, 15 Sep 2020 23:18:54 -0700 (PDT) Received: from localhost ([::1]:52044 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIQmK-0006nM-Tw for importer@patchew.org; Wed, 16 Sep 2020 02:18:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58890) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIQfM-0006pi-Qf for qemu-devel@nongnu.org; Wed, 16 Sep 2020 02:11:40 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:37016 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 1kIQfD-0005XU-AF for qemu-devel@nongnu.org; Wed, 16 Sep 2020 02:11:40 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 1CE9487D3BF1F4283FFD; Wed, 16 Sep 2020 14:11:25 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.487.0; Wed, 16 Sep 2020 14:11:15 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v10 01/12] migration/dirtyrate: setup up query-dirtyrate framwork Date: Wed, 16 Sep 2020 14:21:56 +0800 Message-ID: <1600237327-33618-2-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600237327-33618-1-git-send-email-zhengchuan@huawei.com> References: <1600237327-33618-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/16 02:11:25 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, liq3ea@gmail.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@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 Apr 19 01:14:08 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=1600236942; cv=none; d=zohomail.com; s=zohoarc; b=WPLQxFu//8SeQCC85QCH7g+hgEe0UsyQF010XhizW/UcUHhoKlHeKX0jVqTaLraBdng5YHLgirLZR0tVU9XZcLojPSykg9F/mAmhMlvP0zPTd7tSQAHG77bg3X8tgEvYPGblt4KrwTq8pdSFC2q6HiSqKpAYPrYoXe9XYBk2clo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600236942; 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=ORLsEjBkeUbZlFrRMw5iv1hRFwqXG3y8qJRWUvAHG0U=; b=S9KWqy/U2/nRG8YsawF0H2AangL5DrIhFTUn1FML7l2gii3jvvc2C+GnQDQbHtmmvvgUhO3GkTXXuNer4IZXFXN8DdlJtvjlkTYwGrW/P89HBtYAj/tHCf9s+t1cv+88SLo67LSK72qCGoaNDe5l9+V7WWicnqRnw2rui4T7Y5U= 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 1600236942128936.8002463978632; Tue, 15 Sep 2020 23:15:42 -0700 (PDT) Received: from localhost ([::1]:44014 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIQjE-0003La-TB for importer@patchew.org; Wed, 16 Sep 2020 02:15:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58826) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIQfI-0006kC-Nb for qemu-devel@nongnu.org; Wed, 16 Sep 2020 02:11:36 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:37006 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 1kIQfD-0005XW-7L for qemu-devel@nongnu.org; Wed, 16 Sep 2020 02:11:36 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 1817B32C4FA132D9F4E5; Wed, 16 Sep 2020 14:11:25 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.487.0; Wed, 16 Sep 2020 14:11:16 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v10 02/12] migration/dirtyrate: add DirtyRateStatus to denote calculation status Date: Wed, 16 Sep 2020 14:21:57 +0800 Message-ID: <1600237327-33618-3-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600237327-33618-1-git-send-email-zhengchuan@huawei.com> References: <1600237327-33618-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/16 02:11:25 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, liq3ea@gmail.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@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 Apr 19 01:14:08 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=1600236805; cv=none; d=zohomail.com; s=zohoarc; b=a2hXsWs/OJzvTQdC/9/L27uYZ9v+dgbwVgj3fN9+EaNGXxAKGbbmjmYflHwIxQ/Q92mzhVUsUsOnNRdljJx/q6VBuxfgDvJEQOyd9BV3OL9E3pyh/SnACVNpI3X9LNm5DY49eQKDade6rP+0LIn2Tui00ZlvYzySbFj8hFsBkaw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600236805; 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=rIKs1wJ3DwcumJu/zOj5jU5z32mpYvVaHAGouwgHKiI=; b=IP8rsqBI72bGRIkvio8IvwY6Hlb+B+i6trkEQ/HA2Y/zVNrZ6fqBb1rlRnIxmphcE+GKHzI0j3n66C0CkHhxWSaIOO4yGxxkuAoV86lqEt6lT8iD3V5xlGLrWjK3yGUssEgL68wvLjqnr79z2pJIFM3bod8szKeUS2n51uWNedY= 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 1600236805092196.05038011867327; Tue, 15 Sep 2020 23:13:25 -0700 (PDT) Received: from localhost ([::1]:35604 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIQh1-0008HH-E2 for importer@patchew.org; Wed, 16 Sep 2020 02:13:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58764) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIQfF-0006jH-5E for qemu-devel@nongnu.org; Wed, 16 Sep 2020 02:11:33 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:37008 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 1kIQfC-0005XV-CZ for qemu-devel@nongnu.org; Wed, 16 Sep 2020 02:11:32 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 225AF8B5049A6D4EF96B; Wed, 16 Sep 2020 14:11:25 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.487.0; Wed, 16 Sep 2020 14:11:16 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v10 03/12] migration/dirtyrate: Add RamblockDirtyInfo to store sampled page info Date: Wed, 16 Sep 2020 14:21:58 +0800 Message-ID: <1600237327-33618-4-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600237327-33618-1-git-send-email-zhengchuan@huawei.com> References: <1600237327-33618-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/16 02:11:25 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, liq3ea@gmail.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@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 Apr 19 01:14:08 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=1600236937; cv=none; d=zohomail.com; s=zohoarc; b=m9yE6U3oyAblgK/JEkG2vJJr9pD9f8xiCseDCXV/WZWSO/n6d6eJGeJPQaCYGGwlIEcwmQbplZEOb0ain3Dbpx67ieJqhvDGsKxTgUUwqsMZO0RjaIzc0b5xP9Qvps3AFS0I6SghVvXGtJwjCHFRCJxFpNol/hATWGUyzI1HRo0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600236937; 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=d5M6dco0VEjoqSYQlf9yMyOrFhFmDsci1TdHeNH8vaU=; b=DCiJtqK5jHqGXVjpBx2T4D7nKVs0Aa1qZaN1Joi92PqtD0qIWoynTs1NsW+Nn9ponLTSs1NKWOdBvu6KibiWfTnm45DzjATxMdkWH4o1oIVQB80LYSSkctmPsk+/Ja4oJZgdSXSGd3bPssC8GzlITv+h7WeF73gzU5ijCbjTxBs= 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 1600236937369983.1240703817333; Tue, 15 Sep 2020 23:15:37 -0700 (PDT) Received: from localhost ([::1]:43752 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIQjA-0003Ex-6V for importer@patchew.org; Wed, 16 Sep 2020 02:15:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58802) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIQfH-0006jf-EC for qemu-devel@nongnu.org; Wed, 16 Sep 2020 02:11:35 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:37012 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 1kIQfD-0005XT-3t for qemu-devel@nongnu.org; Wed, 16 Sep 2020 02:11:35 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 0DCE61D0AF18F228603E; Wed, 16 Sep 2020 14:11:25 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.487.0; Wed, 16 Sep 2020 14:11:17 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v10 04/12] migration/dirtyrate: Add dirtyrate statistics series functions Date: Wed, 16 Sep 2020 14:21:59 +0800 Message-ID: <1600237327-33618-5-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600237327-33618-1-git-send-email-zhengchuan@huawei.com> References: <1600237327-33618-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/16 02:11:25 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, liq3ea@gmail.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@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 Apr 19 01:14:08 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=1600236805; cv=none; d=zohomail.com; s=zohoarc; b=jBkaXjJAV0WdW8PzReUQZ8nzDA08iiomH7vMBCyqWnm5a9DEk7aqZFOcdMFeOcn0K3z0nCvvghDwFCviuWW9Ssm4BSPoBAHKxilgECXuIXiaGTZx03YdRYv9LQtVXumNoMbEIm9akHBJPO4ALYqIMTR/9OyJnlpCLaQfyipt4fM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600236805; 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=c+FlNmgCWDI17sStTpko3SiDnZxIPZ7bQrDmhrHh2eA=; b=jQklDp+3dta6gUBFsKK0gK31s7W7UHTyeFcXJpvg1VY9vDGkg6//75cz3EEgQ2GerfE3N9BKWx/u70AOWA5e9P0NIE2VtwA7JaqIZZaNpwXKFBSOLBwaFBnaaqnzJYle1ynaOig2KOA6XFXF+wZPZgZuJOKpo0X+J1mcMEKPYzY= 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 1600236805255811.8692995393671; Tue, 15 Sep 2020 23:13:25 -0700 (PDT) Received: from localhost ([::1]:35670 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIQh1-0008J0-SL for importer@patchew.org; Wed, 16 Sep 2020 02:13:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58792) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIQfG-0006jS-Ml for qemu-devel@nongnu.org; Wed, 16 Sep 2020 02:11:34 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:37010 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 1kIQfC-0005XX-F6 for qemu-devel@nongnu.org; Wed, 16 Sep 2020 02:11:34 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 12E40AB17F1773FD5DC5; Wed, 16 Sep 2020 14:11:25 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.487.0; Wed, 16 Sep 2020 14:11:18 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v10 05/12] migration/dirtyrate: move RAMBLOCK_FOREACH_MIGRATABLE into ram.h Date: Wed, 16 Sep 2020 14:22:00 +0800 Message-ID: <1600237327-33618-6-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600237327-33618-1-git-send-email-zhengchuan@huawei.com> References: <1600237327-33618-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/16 02:11:25 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, liq3ea@gmail.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@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 Apr 19 01:14:08 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=1600237301; cv=none; d=zohomail.com; s=zohoarc; b=X8SY7XKEBUuR3534lYBYAku0JmI5Mz4/Jjgm2jhox81ywsd0zC8f7A9LOh3qwYB8jcI2J2Cq7Q83+yn1Bhnekh3I65b8Pko4ICh+/OaaGfvY343DbZWTyOLckEelU6P9n5iPSEihvhii+XkzCBeqGNnQ+DWXRffBQs96JxwSaWY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600237301; 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=njGHsL/7KyCED8RmMJwHzqmHH8hH1+vw+MWB2VdfBmg=; b=AtuTtfGv7N8YHQjD/YOXNDKaSQcVd8PaHw7Oa2lkj7W9bL4bCj5pRz/M1To9hE9aPJiJgTUKGtHmpzOPre9nw1zSYPVUgwGz2q91sIHAhSxZrO0vjwUoR7HZ6n6VxS3UycrDJMbAbAfrxqjHlomI+7+wg7DgZxXE2OyVKnbaZdk= 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 1600237301264278.6354788989976; Tue, 15 Sep 2020 23:21:41 -0700 (PDT) Received: from localhost ([::1]:60268 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIQp2-0001yt-3y for importer@patchew.org; Wed, 16 Sep 2020 02:21:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58904) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIQfN-0006rZ-Rh for qemu-devel@nongnu.org; Wed, 16 Sep 2020 02:11:41 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:37284 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 1kIQfI-0005YA-Ed for qemu-devel@nongnu.org; Wed, 16 Sep 2020 02:11:41 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 27711978A3535B9076B1; Wed, 16 Sep 2020 14:11:25 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.487.0; Wed, 16 Sep 2020 14:11:18 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v10 06/12] migration/dirtyrate: Record hash results for each sampled page Date: Wed, 16 Sep 2020 14:22:01 +0800 Message-ID: <1600237327-33618-7-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600237327-33618-1-git-send-email-zhengchuan@huawei.com> References: <1600237327-33618-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/16 02:11:25 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, liq3ea@gmail.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@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 Apr 19 01:14:08 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=1600237427; cv=none; d=zohomail.com; s=zohoarc; b=MIAJv8AXZ88Dul7CPOEz32QyNRvoxpx6E2bGwLqiwAhTt4tt6YSwotxDM7YwIJ2OqGHq7CiVo+w6wa+Mp9TqtL+5uqPaJcwAdFP8UYaRXLSvfAYE+iXf6qvY+Trx3dD3B4UqWMJ8h1ExLREi8/qDGn9QNtQBEyjWfrzKsMTHJ4Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600237427; 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=qGueZNR0g6L0BRYw6PBCxgx0HoMwoU/vCX69EXx5MSM=; b=dYBZFlz5+MBnhPHIyTfyrKVADB/dXtX2QGhZrgwf14S6M/ED5uGP9gvkwwCdQYC4Gz6I2VQe08cP4qehyKKbssZzlQKbSF1ohUEBFgoARoqCrWePmIJ9XUBEmdizT2rTqBwNlttf/5kUOQ0KhrQuXL6L9kyfG/99bGu1J0meBlE= 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 1600237427351692.6349297464069; Tue, 15 Sep 2020 23:23:47 -0700 (PDT) Received: from localhost ([::1]:39558 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIQr3-00058d-Qh for importer@patchew.org; Wed, 16 Sep 2020 02:23:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58916) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIQfP-0006uM-1v for qemu-devel@nongnu.org; Wed, 16 Sep 2020 02:11:43 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:37286 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 1kIQfI-0005YB-EK for qemu-devel@nongnu.org; Wed, 16 Sep 2020 02:11:42 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 2D08EDC2B3C4055D08DC; Wed, 16 Sep 2020 14:11:25 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.487.0; Wed, 16 Sep 2020 14:11:19 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v10 07/12] migration/dirtyrate: Compare page hash results for recorded sampled page Date: Wed, 16 Sep 2020 14:22:02 +0800 Message-ID: <1600237327-33618-8-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600237327-33618-1-git-send-email-zhengchuan@huawei.com> References: <1600237327-33618-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/16 02:11:25 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, liq3ea@gmail.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@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 Reviewed-by: Li Qiang --- migration/dirtyrate.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 63 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 5e6eedf..68561af 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_block_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 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_block_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 Apr 19 01:14:08 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=1600237445; cv=none; d=zohomail.com; s=zohoarc; b=BpbJnaR0pUAinO59I8E2zz4Ld9pOD4l+J5LrC90DKC7o43WmFhbTsEDpt1JLUS6vjOag7knpjU1VlK/Jkq26iJxkNRezvVXEyCan5xQw5IMk0GYi7DcUDUE8u97ajTVrjDrQ8jhXC/37JTOROVihGyUuFgvMP4N6wBmvHEDlnGc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600237445; 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=ssxvKdMNOLzyX3yM5BaQrElgR/WnA/9BlzDi9izbBk8=; b=P9TF/yfmESlVBW33RpbE2R0iNB3JeFGiU6PI0apHyGNSNSbdnlGE9KH5McIWnrSCStLuZZ16Dg/xnjcS91HxQi2EglsEF1ouENRyEVIWLyjEP0Ibz1bEv/QEjG79h3r7fcNn75J1U9dTEt2uE8HPA07moOybPtkr79vaJJcSdbE= 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 1600237445386847.3048783303027; Tue, 15 Sep 2020 23:24:05 -0700 (PDT) Received: from localhost ([::1]:39788 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIQrL-0005EJ-LY for importer@patchew.org; Wed, 16 Sep 2020 02:24:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58912) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIQfO-0006sN-6w for qemu-devel@nongnu.org; Wed, 16 Sep 2020 02:11:42 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:37290 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 1kIQfJ-0005YR-Li for qemu-devel@nongnu.org; Wed, 16 Sep 2020 02:11:41 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 3E09CF5C3822DA22D996; Wed, 16 Sep 2020 14:11:30 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.487.0; Wed, 16 Sep 2020 14:11:19 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v10 08/12] migration/dirtyrate: skip sampling ramblock with size below MIN_RAMBLOCK_SIZE Date: Wed, 16 Sep 2020 14:22:03 +0800 Message-ID: <1600237327-33618-9-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600237327-33618-1-git-send-email-zhengchuan@huawei.com> References: <1600237327-33618-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/16 02:11:25 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, liq3ea@gmail.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@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 68561af..ede8063 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_block_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 Apr 19 01:14:08 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=1600236868; cv=none; d=zohomail.com; s=zohoarc; b=X/xXIA3a16kZOrIil9XX5HIRLisUlq6G//KOciepw6qrXOxEeBJSk34hCGjj+8ZoKJloRcAX1oG96Ipl2TJujF/FgEsHjadloW+Ey0dSyap87P5f6Dlcy0qVsGk/1NKOg/6Z9wl3SNU6NxfSDZ30NOcZ/4BHgZnM13NYK1N8lo0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600236868; 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=dLijg3qwjqdqMA5NjWERZ5FulasMP+ktW+w/X3I5CIE=; b=RBBAhxPN+Am2gho5+J8QvvkSj0IOrxOk25cg03ISraom2MhVG3AegWquLsf9ljJpo84JBOO3Pe2WK97U3DTvGgCYWBosX3vrd/RJ09eomigCeukZ92PNl6xc3JC9L/cldUn5cE98LPIc7OXwuZWTSk/CBU5+Pg8GGcmGTfMPI4s= 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 1600236868435160.5728124528457; Tue, 15 Sep 2020 23:14:28 -0700 (PDT) Received: from localhost ([::1]:39638 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIQi3-0001Yv-8N for importer@patchew.org; Wed, 16 Sep 2020 02:14:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58918) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIQfP-0006vL-DV for qemu-devel@nongnu.org; Wed, 16 Sep 2020 02:11:43 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:52394 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 1kIQfI-0005Xs-E1 for qemu-devel@nongnu.org; Wed, 16 Sep 2020 02:11:43 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 16F7414594BC821CA2F4; Wed, 16 Sep 2020 14:11:30 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.487.0; Wed, 16 Sep 2020 14:11:20 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v10 09/12] migration/dirtyrate: Implement set_sample_page_period() and is_sample_period_valid() Date: Wed, 16 Sep 2020 14:22:04 +0800 Message-ID: <1600237327-33618-10-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600237327-33618-1-git-send-email-zhengchuan@huawei.com> References: <1600237327-33618-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/16 02:11:31 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, liq3ea@gmail.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@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 ede8063..ef77483 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 Apr 19 01:14:08 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=1600237129; cv=none; d=zohomail.com; s=zohoarc; b=VIxuFwulDg2vjZ6iok+euwncJ9U4fYogxvG406YAw4HflyB2+i/2ogZxaLavqZaAYa8dP9NHEFQTcNoL4dz9+n+qF8KsHnZpXKnFN1Inpt8wPqlas6XCbGCbwvoIDMr97bYX/6wy8W4iqnoXB7/m7o6gZyMKyMfTZWUm4EtrfYE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600237129; 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=Slc9pxssIwQcDk9PauOpV8Ficadtw+tfGneY7Glhv6Y=; b=f8ivyf/sSxYYnHJHcAiKtBC1tMxAmEasUKBh3Rxx7NRS1HSYiyQErl25IGUykLLV5+sAcvpWGlKfJwETRliWuVoqsnFTH8ziyKOC+No5XZLvXfq+hvN6vTirodicOUelJaUHtCfV81fqDljKXnc+8xwBjY+cvy99Anxb+Q+HJPY= 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 1600237129011128.72838807839582; Tue, 15 Sep 2020 23:18:49 -0700 (PDT) Received: from localhost ([::1]:51762 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIQmF-0006gS-P8 for importer@patchew.org; Wed, 16 Sep 2020 02:18:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58876) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIQfM-0006og-Bx for qemu-devel@nongnu.org; Wed, 16 Sep 2020 02:11:40 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:52400 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 1kIQfH-0005Xq-4G for qemu-devel@nongnu.org; Wed, 16 Sep 2020 02:11:40 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 1C27AC7149DBE9E03902; Wed, 16 Sep 2020 14:11:30 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.487.0; Wed, 16 Sep 2020 14:11:20 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v10 10/12] migration/dirtyrate: Implement calculate_dirtyrate() function Date: Wed, 16 Sep 2020 14:22:05 +0800 Message-ID: <1600237327-33618-11-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600237327-33618-1-git-send-email-zhengchuan@huawei.com> References: <1600237327-33618-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/16 02:11:31 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, liq3ea@gmail.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@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 ef77483..2a1a7fa 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 Apr 19 01:14:08 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=1600237297; cv=none; d=zohomail.com; s=zohoarc; b=TcqH7ymvF8J+DClP6Ht/msihk9TAaqTKt7wu2fHSZTOfXPPYWg15OJ+xkp0FLJ6xDCiLbkp+b9RcKK1I0H6jm3cZar8bwybgj13yqRq/P0kByGUEXfJga5lbUcR5KsXpsuGer/VXi5shOe8c+ZlJrd5mu1j09HnwHKfmqyhJCzY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600237297; 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=Clvk5Cxi0EGtu8NA+tbeP21rYyZn+6pphGeQSduXqis=; b=R0lagzWSXGeNyhTKw3QDPD6FOcfEreAVm1W+1hW6RJ4kUQ2HHtJE9PO8I3Zbe+nS4QhgTjH049N+w8hZnaBaKl1IDXTdxkFapkFtIw+gfCIB6LI2Whk/9e4b5/6d0ovJFFxUnQa/g8hknJ1q+hQs6a44stG3UNuD91/MD+cjvvk= 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 1600237297500172.3430782113378; Tue, 15 Sep 2020 23:21:37 -0700 (PDT) Received: from localhost ([::1]:59872 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIQoy-0001mX-9k for importer@patchew.org; Wed, 16 Sep 2020 02:21:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58902) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIQfN-0006qy-HE for qemu-devel@nongnu.org; Wed, 16 Sep 2020 02:11:41 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:52396 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 1kIQfH-0005Xt-EH for qemu-devel@nongnu.org; Wed, 16 Sep 2020 02:11:41 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 20F517D44014809C9DC5; Wed, 16 Sep 2020 14:11:30 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.487.0; Wed, 16 Sep 2020 14:11:21 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v10 11/12] migration/dirtyrate: Implement qmp_cal_dirty_rate()/qmp_get_dirty_rate() function Date: Wed, 16 Sep 2020 14:22:06 +0800 Message-ID: <1600237327-33618-12-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600237327-33618-1-git-send-email-zhengchuan@huawei.com> References: <1600237327-33618-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/16 02:11:31 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, liq3ea@gmail.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@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 Reviewed-by: Dr. David Alan Gilbert --- migration/dirtyrate.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ qapi/migration.json | 50 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 2a1a7fa..06f455d 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 Apr 19 01:14:08 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=1600236809; cv=none; d=zohomail.com; s=zohoarc; b=bvNNXkSr6sLOg/xqyN5BJynNq49QrmiCQ0D52lQ19Vv+yk+t3Me+8024XL5dQFqIe79uZ8zO+WCxqqliWXp0upSVtzZzm16m5nxdOKTKRujbM/UAam4sTRTEJfxOOmPg8VsFxeuT+J7DYfzDp1J+FFOKYhwAR55AqKksTlPvr8I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600236809; 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=M85CSwRxMgcyx9yQFfVj0iMuSIt4fAGzL7snz2RUMdA=; b=GGRkk3tfb4fJl2FBF0gDh3Km6z/ST9X+e2VV7ELSCQTYH5fqooVENLWf9EnYfyegtxhapmvxTWejNh90rxbZkppRQcUT1BO6/6lUrvvQSQxfXrt9H9Z24zIOThUSSMgw7fPnbKSRy7eE1R9cxQ6jc2ivaJDp4TK6CMa+XuLU4sk= 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 1600236809517286.5355755765297; Tue, 15 Sep 2020 23:13:29 -0700 (PDT) Received: from localhost ([::1]:36168 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIQh6-0008Vh-8P for importer@patchew.org; Wed, 16 Sep 2020 02:13:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58872) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIQfM-0006oC-4j for qemu-devel@nongnu.org; Wed, 16 Sep 2020 02:11:40 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:52398 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 1kIQfH-0005Xp-5Q for qemu-devel@nongnu.org; Wed, 16 Sep 2020 02:11:39 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 113619CD38B00366F12B; Wed, 16 Sep 2020 14:11:30 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.487.0; Wed, 16 Sep 2020 14:11:22 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v10 12/12] migration/dirtyrate: Add trace_calls to make it easier to debug Date: Wed, 16 Sep 2020 14:22:07 +0800 Message-ID: <1600237327-33618-13-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600237327-33618-1-git-send-email-zhengchuan@huawei.com> References: <1600237327-33618-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/16 02:11:31 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, liq3ea@gmail.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@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 06f455d..f432840 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_block_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