From nobody Sun May 19 04:05:27 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=1598319126; cv=none; d=zohomail.com; s=zohoarc; b=V1iU68XzcfJJSf08cWMV4y+lBxHS5IkLiG1dDaG/QiLgRtO0IIgEVZSm0BZjm5zBhLE9/RIQNoxWhUpaTas9QDrgX9NTLs3EyXpWHwGbjpvhaW4+vSuSTrnZz3+IASpcqxA1aJqZS7yKBjIKLEteka1v3a4o/UqplZb0z5v7fgU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598319126; 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=l71mtvpS4n7iJ5M6/zmtH3TCmt6LvG8mkdu+2RRrcHY=; b=cpXZ5wdOhnPn/NzzVc7cB9QVxsbn8MZPKNqbt1dV6Gri7i/O0KhLO20iiTD2FIcOEprBIF6hMJ4u0jJP0xSEP9M6Q+VXYzxL1tZ0bgqSrgk6uQBfZjngPz8U44gSkWvo6s9vYrX5nMuII5HGqLqYJ/6Y2S60sIwU04zp7DtRUJ4= 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 1598319126506853.3234525853854; Mon, 24 Aug 2020 18:32:06 -0700 (PDT) Received: from localhost ([::1]:50820 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kANoi-0006TL-QT for importer@patchew.org; Mon, 24 Aug 2020 21:32:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60648) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kANno-0004tN-Cm for qemu-devel@nongnu.org; Mon, 24 Aug 2020 21:31:08 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4210 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 1kANnj-0005pi-GD for qemu-devel@nongnu.org; Mon, 24 Aug 2020 21:31:08 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 3635A9AE33910D6DCE78; Tue, 25 Aug 2020 09:30:57 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.487.0; Tue, 25 Aug 2020 09:30:49 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v5 01/12] migration/dirtyrate: setup up query-dirtyrate framwork Date: Tue, 25 Aug 2020 09:40:39 +0800 Message-ID: <1598319650-36762-2-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1598319650-36762-1-git-send-email-zhengchuan@huawei.com> References: <1598319650-36762-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.190; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/24 21:30:58 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: zhang.zhanghailiang@huawei.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@huawei.com, ann.zhuangyanying@huawei.com, fangying1@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 --- migration/dirtyrate.c | 39 +++++++++++++++++++++++++++++++++++++++ migration/dirtyrate.h | 32 ++++++++++++++++++++++++++++++++ migration/meson.build | 1 + 3 files changed, 72 insertions(+) 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..366f4e9 --- /dev/null +++ b/migration/dirtyrate.c @@ -0,0 +1,39 @@ +/* + * Dirtyrate implement code + * + * Copyright (c) 2017-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 "crypto/hash.h" +#include "crypto/random.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..33669b7 --- /dev/null +++ b/migration/dirtyrate.h @@ -0,0 +1,32 @@ +/* + * 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 + +/* Take 1s as default for calculation duration */ +#define DEFAULT_FETCH_DIRTYRATE_TIME_SEC 1 + +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..30cc6c3 100644 --- a/migration/meson.build +++ b/migration/meson.build @@ -21,6 +21,7 @@ softmmu_ss.add(files( 'channel.c', 'colo-failover.c', 'colo.c', + 'dirtyrate.c', 'exec.c', 'fd.c', 'global_state.c', --=20 1.8.3.1 From nobody Sun May 19 04:05:27 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=1598319275; cv=none; d=zohomail.com; s=zohoarc; b=HFirL/qowl1rsKU5l+VpKgCpZrgw3rwM6Oz6OuJFUy0sba28XZGMSGQ1I2Kn+7IR7dnfMEeypkP8qf2LYNvN2YUmLZzqW4PGT60tqQFSZ4wivGXsgEQh+63TQe9Sk9nklkyDvQysGPWqJTOFiHPv+y/bn6s075S8ReldC1VzCKc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598319275; 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=KZz5pJUsrZxA9L+/uyMk5xjerU5lY4hNEayfBc6vYlU=; b=n81mGHyocVeQ7CSP1766t2eFOeapXa4yuswjFoV6WSpd1tQ5NXHT/bnEyrsrbvH4CgyL9k1QrU4z5PBbXXW4/w89dtIRyaBCeBkdTiZpHDI3PhiqRx2Y7FETPLGc69+ecu/2lm4yPAtElvyt0DduzWdvESyvMA2tHiZ9WMkvYLk= 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 159831927567321.231326651043105; Mon, 24 Aug 2020 18:34:35 -0700 (PDT) Received: from localhost ([::1]:38452 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kANr8-0004ML-EY for importer@patchew.org; Mon, 24 Aug 2020 21:34:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60654) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kANnp-0004uB-Fx for qemu-devel@nongnu.org; Mon, 24 Aug 2020 21:31:09 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4211 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 1kANnj-0005pf-J7 for qemu-devel@nongnu.org; Mon, 24 Aug 2020 21:31:09 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 3B6CED22C2220DACB1FB; Tue, 25 Aug 2020 09:30:57 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.487.0; Tue, 25 Aug 2020 09:30:49 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v5 02/12] migration/dirtyrate: add DirtyRateStatus to denote calculation status Date: Tue, 25 Aug 2020 09:40:40 +0800 Message-ID: <1598319650-36762-3-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1598319650-36762-1-git-send-email-zhengchuan@huawei.com> References: <1598319650-36762-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.190; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/24 21:30:58 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: zhang.zhanghailiang@huawei.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@huawei.com, ann.zhuangyanying@huawei.com, fangying1@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" add DirtyRateStatus to denote calculating status. Signed-off-by: Chuan Zheng Reviewed-by: Dr. David Alan Gilbert --- migration/dirtyrate.c | 22 ++++++++++++++++++++++ qapi/migration.json | 17 +++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 366f4e9..91987c5 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -23,6 +23,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 */ @@ -32,8 +45,17 @@ 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) { + return NULL; + } =20 calculate_dirtyrate(config); =20 + ret =3D dirtyrate_set_state(&CalculatingState, DIRTY_RATE_STATUS_MEASU= RING, + DIRTY_RATE_STATUS_MEASURED); return NULL; } diff --git a/qapi/migration.json b/qapi/migration.json index 5f6b061..d640165 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: query-dirtyrate thread is not initial. +# +# @measuring: query-dirtyrate thread is created and start to measure. +# +# @measured: query-dirtyrate thread is end, we can get result. +# +# Since: 5.2 +# +## +{ 'enum': 'DirtyRateStatus', + 'data': [ 'unstarted', 'measuring', 'measured'] } --=20 1.8.3.1 From nobody Sun May 19 04:05:27 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=1598319196; cv=none; d=zohomail.com; s=zohoarc; b=NA7461hkcc3bcghPuNaUhXpKsJoLA9liZMnhlEJJZzwvhNhN49alWdT9s8m+ZxwO0bVuzOolP/rm0BHKD1Rys/BwzGCemtfNxQI07hF9uo2oryiMGx2Y2hjYJm8czOb8Q1C/bc4Kytuw975B8bvzcuq9QZ/ubp1/IFg1FQUdVyA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598319196; 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=OHLYJLN0uuLdefyAihwNqCazk4yEu/ZSC3N2deBq7Do=; b=YZWJrpEI2fNTNjlLsPNKAW+USvC39ove8SIkYISz+O2Sp0q2Nj0uyx783w+VubAs9FrliWgVwx42h5FqgckniY7TlrSZBy5LrQFiqAm39Fdgh+VygTFM6PFgqPXfRk1w+QCkbcbEV2JEXSOCzS6N8N4/lKSqTNoSBA6d9rsy+2E= 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 1598319196754649.7882824667794; Mon, 24 Aug 2020 18:33:16 -0700 (PDT) Received: from localhost ([::1]:59018 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kANpr-0001Jg-GG for importer@patchew.org; Mon, 24 Aug 2020 21:33:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60662) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kANnp-0004uZ-QE for qemu-devel@nongnu.org; Mon, 24 Aug 2020 21:31:09 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4208 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 1kANnj-0005ph-Rk for qemu-devel@nongnu.org; Mon, 24 Aug 2020 21:31:09 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 451EA4FD5B7A7914F2A4; Tue, 25 Aug 2020 09:30:57 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.487.0; Tue, 25 Aug 2020 09:30:50 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v5 03/12] migration/dirtyrate: Add RamlockDirtyInfo to store sampled page info Date: Tue, 25 Aug 2020 09:40:41 +0800 Message-ID: <1598319650-36762-4-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1598319650-36762-1-git-send-email-zhengchuan@huawei.com> References: <1598319650-36762-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.190; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/24 21:30:58 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: zhang.zhanghailiang@huawei.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@huawei.com, ann.zhuangyanying@huawei.com, fangying1@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 RamlockDirtyInfo to store sampled page info of each ramblock. Signed-off-by: Chuan Zheng Reviewed-by: Dr. David Alan Gilbert --- migration/dirtyrate.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/migration/dirtyrate.h b/migration/dirtyrate.h index 33669b7..dc45419 100644 --- a/migration/dirtyrate.h +++ b/migration/dirtyrate.h @@ -19,6 +19,11 @@ */ #define DIRTYRATE_DEFAULT_SAMPLE_PAGES 512 =20 +/* + * Record ramblock idstr + */ +#define RAMBLOCK_INFO_MAX_LEN 256 + /* Take 1s as default for calculation duration */ #define DEFAULT_FETCH_DIRTYRATE_TIME_SEC 1 =20 @@ -27,6 +32,19 @@ struct DirtyRateConfig { 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 4K-page */ + uint64_t *sample_page_vfn; /* relative offset address for sampled page= */ + uint64_t sample_pages_count; /* count of sampled pages */ + uint64_t sample_dirty_count; /* count of dirty pages we measure */ + uint32_t *hash_result; /* array of hash result for sampled pages */ +}; + void *get_dirtyrate_thread(void *arg); #endif =20 --=20 1.8.3.1 From nobody Sun May 19 04:05:27 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=1598319127; cv=none; d=zohomail.com; s=zohoarc; b=U9iswHRUprUipEj0fwOS4hCRfEWvHVB6e8xxkHNyoOT1X77SPfuQZvqSBYQK4WFCkwt+0HpKsp0fjkX/0TfGbBRy3okMr5RRdekCd8D4Ylhll7UYZ1F7+ZwizipmP1S3XNVxcEdAFV0L9HLC295aPCaH09gJzEHdJ1omwMOoGfs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598319127; 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=a0EpRsFwEIoqf2Y2F+LE2rc2PNBmY7DRLvBCr5GSpVQ=; b=XswrBvpfM4Qdip5BJxiruoxapeYVHfFN2Y2hbU5qDKMlaQvWqsSkm/S4gFXsP/mnBK9BGuzZJU9JVoiYUwULUfWXtCqKaUnVqE56MOZL7/gr+nm4d3YZHf86OPVOj/myLTPWkxFT64wEBeYY8aLrBP/VrC19VpEm8HqXOQ17zqA= 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 1598319127535129.87768756096705; Mon, 24 Aug 2020 18:32:07 -0700 (PDT) Received: from localhost ([::1]:51026 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kANoj-0006YJ-WC for importer@patchew.org; Mon, 24 Aug 2020 21:32:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60642) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kANno-0004tJ-5l for qemu-devel@nongnu.org; Mon, 24 Aug 2020 21:31:08 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4209 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 1kANnj-0005pe-IA for qemu-devel@nongnu.org; Mon, 24 Aug 2020 21:31:07 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 405201C9C8AF9ADF5ECF; Tue, 25 Aug 2020 09:30:57 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.487.0; Tue, 25 Aug 2020 09:30:50 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v5 04/12] migration/dirtyrate: Add dirtyrate statistics series functions Date: Tue, 25 Aug 2020 09:40:42 +0800 Message-ID: <1598319650-36762-5-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1598319650-36762-1-git-send-email-zhengchuan@huawei.com> References: <1598319650-36762-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.190; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/24 21:30:58 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: zhang.zhanghailiang@huawei.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@huawei.com, ann.zhuangyanying@huawei.com, fangying1@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 to record/update dirtyrate info. Signed-off-by: Chuan Zheng --- migration/dirtyrate.c | 29 +++++++++++++++++++++++++++++ migration/dirtyrate.h | 10 ++++++++++ 2 files changed, 39 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 91987c5..0d7163f 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -24,6 +24,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) { @@ -35,6 +36,34 @@ static int dirtyrate_set_state(int *state, int old_state= , int new_state) } } =20 +static void reset_dirtyrate_stat(void) +{ + DirtyStat.total_dirty_samples =3D 0; + DirtyStat.total_sample_count =3D 0; + DirtyStat.total_block_mem_MB =3D 0; + DirtyStat.dirty_rate =3D 0; +} + +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 4K pages in MB */ + DirtyStat.total_block_mem_MB +=3D info->ramblock_pages / 256; +} + +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 dc45419..8e25d93 100644 --- a/migration/dirtyrate.h +++ b/migration/dirtyrate.h @@ -45,6 +45,16 @@ 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 */ +}; + void *get_dirtyrate_thread(void *arg); #endif =20 --=20 1.8.3.1 From nobody Sun May 19 04:05:27 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=1598319199; cv=none; d=zohomail.com; s=zohoarc; b=LrU4T9Du5Nd3IG72BsbgaIU7nzdZ3yn1gbIzFqxAJd7Ms/D/lPlj5dxZHcKPcUfmFpTqAQGU9Erv5eFPFIExrtdKJaROSucQjMs0bvRhvRmExeAKbIiMdItzbFEseRRSp+lyqZsFs2ZMvz06CsTwdT4BDB7CCGP16YQdCZW51F8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598319199; 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=jn8Oc2kShlVA9eAbi/eW8dw3OBC8GX/yl9l/BXxJ1ac=; b=eQ9+hdBi7N+j+HBgCTmHa0HdloicDaYwMl7ozmmx7F1YCbhDr6iJv8YEVDKwdHX0Uj3NR6HseuBfAzjotX+6VKvxPbsysDhPtprDF6J9mbiozvwWc7a2xnMqS+cT/GroN+p/bkskKjMbl53HNNkbyRtCrC7ic7P583OnC2XEJBg= 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 1598319199814999.0444054590967; Mon, 24 Aug 2020 18:33:19 -0700 (PDT) Received: from localhost ([::1]:59446 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kANpu-0001U1-Kh for importer@patchew.org; Mon, 24 Aug 2020 21:33:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60736) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kANns-0004za-JN for qemu-devel@nongnu.org; Mon, 24 Aug 2020 21:31:12 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4216 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 1kANnq-0005qp-5M for qemu-devel@nongnu.org; Mon, 24 Aug 2020 21:31:12 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 3826F4E8242795F7BD28; Tue, 25 Aug 2020 09:31:02 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.487.0; Tue, 25 Aug 2020 09:30:51 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v5 05/12] migration/dirtyrate: move RAMBLOCK_FOREACH_MIGRATABLE into ram.h Date: Tue, 25 Aug 2020 09:40:43 +0800 Message-ID: <1598319650-36762-6-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1598319650-36762-1-git-send-email-zhengchuan@huawei.com> References: <1598319650-36762-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.190; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/24 21:30:58 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: zhang.zhanghailiang@huawei.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@huawei.com, ann.zhuangyanying@huawei.com, fangying1@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 --- 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 0d7163f..f6a94d8 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -21,6 +21,7 @@ #include "qemu/rcu_queue.h" #include "qapi/qapi-commands-migration.h" #include "migration.h" +#include "ram.h" #include "dirtyrate.h" =20 static int CalculatingState =3D DIRTY_RATE_STATUS_UNSTARTED; diff --git a/migration/ram.c b/migration/ram.c index 76d4fee..37ef0da 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -158,21 +158,12 @@ out: return ret; } =20 -static bool ramblock_is_ignored(RAMBlock *block) +bool ramblock_is_ignored(RAMBlock *block) { return !qemu_ram_is_migratable(block) || (migrate_ignore_shared() && qemu_ram_is_shared(block)); } =20 -/* Should be holding either ram_list.mutex, or the RCU lock. */ -#define RAMBLOCK_FOREACH_NOT_IGNORED(block) \ - INTERNAL_RAMBLOCK_FOREACH(block) \ - if (ramblock_is_ignored(block)) {} else - -#define RAMBLOCK_FOREACH_MIGRATABLE(block) \ - INTERNAL_RAMBLOCK_FOREACH(block) \ - if (!qemu_ram_is_migratable(block)) {} else - #undef RAMBLOCK_FOREACH =20 int foreach_not_ignored_block(RAMBlockIterFunc func, void *opaque) diff --git a/migration/ram.h b/migration/ram.h index 2eeaacf..011e854 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -37,6 +37,16 @@ extern MigrationStats ram_counters; extern XBZRLECacheStats xbzrle_counters; extern CompressionStats compression_counters; =20 +bool ramblock_is_ignored(RAMBlock *block); +/* Should be holding either ram_list.mutex, or the RCU lock. */ +#define RAMBLOCK_FOREACH_NOT_IGNORED(block) \ + INTERNAL_RAMBLOCK_FOREACH(block) \ + if (ramblock_is_ignored(block)) {} else + +#define RAMBLOCK_FOREACH_MIGRATABLE(block) \ + INTERNAL_RAMBLOCK_FOREACH(block) \ + if (!qemu_ram_is_migratable(block)) {} else + int xbzrle_cache_resize(int64_t new_size, Error **errp); uint64_t ram_bytes_remaining(void); uint64_t ram_bytes_total(void); --=20 1.8.3.1 From nobody Sun May 19 04:05:27 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=1598319198; cv=none; d=zohomail.com; s=zohoarc; b=iug4qi/yEfG3+QRWo71LMyPCcyL3pBANsyjSChNoDBRILbWC2F2XVxjusp6IyxfTipiLbAf/L0aSSKyXwq5wkrRjInjU/TiWgTSc+s8qA5NmTCadVaW5MMJM9c0+q1EELkMPNKprBPd5Dof10WYvhLyZDMGUMG2alkDnMmBRWB8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598319198; 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=Qg+0o6G9UIH8sVfNBW52y5oUHMsxC1bnBCZ3SLdrWq8=; b=MT4kn8M1z+xlGViQ9SeXNFcHO2hkwiRLN8/mMGdkdRWcI0b77o95HgU2gc3Df316Cm8VMUanVMEXZlkl2jhp9IywPd7cqW0hdX5c1LbViLF9zwDoe23Cyh2UyRbdJ+C/VrwAl6FbuO1EUbxiknA/KhlrEFZyN/Cnfcbyw3McxC4= 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 1598319198818168.02112460519743; Mon, 24 Aug 2020 18:33:18 -0700 (PDT) Received: from localhost ([::1]:59238 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kANpt-0001P4-FA for importer@patchew.org; Mon, 24 Aug 2020 21:33:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60650) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kANnp-0004to-4A for qemu-devel@nongnu.org; Mon, 24 Aug 2020 21:31:09 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:4265 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 1kANnm-0005qF-L9 for qemu-devel@nongnu.org; Mon, 24 Aug 2020 21:31:08 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 5EB56DF69B3E2C5F742C; Tue, 25 Aug 2020 09:31:02 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.487.0; Tue, 25 Aug 2020 09:30:52 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v5 06/12] migration/dirtyrate: Record hash results for each sampled page Date: Tue, 25 Aug 2020 09:40:44 +0800 Message-ID: <1598319650-36762-7-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1598319650-36762-1-git-send-email-zhengchuan@huawei.com> References: <1598319650-36762-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/08/24 21:31:03 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: zhang.zhanghailiang@huawei.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@huawei.com, ann.zhuangyanying@huawei.com, fangying1@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 4K-page. Signed-off-by: Chuan Zheng Signed-off-by: YanYing Zhuang --- migration/dirtyrate.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ migration/dirtyrate.h | 15 ++++++ 2 files changed, 151 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index f6a94d8..66de426 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 "crypto/hash.h" @@ -66,6 +67,141 @@ static void update_dirtyrate(uint64_t msec) DirtyStat.dirty_rate =3D dirtyrate; } =20 +/* + * get hash result for the sampled memory with length of 4K byte in ramblo= ck, + * which starts from ramblock base address. + */ +static uint32_t get_ramblock_vfn_hash(struct RamblockDirtyInfo *info, + uint64_t vfn) +{ + struct iovec iov_array; + uint32_t crc; + + iov_array.iov_base =3D info->ramblock_addr + + vfn * DIRTYRATE_SAMPLE_PAGE_SIZE; + iov_array.iov_len =3D DIRTYRATE_SAMPLE_PAGE_SIZE; + + crc =3D crc32(0, iov_array.iov_base, iov_array.iov_len); + + return crc; +} + +static int save_ramblock_hash(struct RamblockDirtyInfo *info) +{ + unsigned int sample_pages_count; + int i; + int ret =3D -1; + GRand *rand =3D g_rand_new(); + + 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)) { + ret =3D 0; + goto out; + } + + info->hash_result =3D g_try_malloc0_n(sample_pages_count, + sizeof(uint32_t)); + if (!info->hash_result) { + ret =3D -1; + goto out; + } + + 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); + ret =3D -1; + goto out; + } + + 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]); + } + ret =3D 0; + +out: + g_rand_free(rand); + return ret; +} + +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 block size in GB */ + info->sample_pages_count =3D (qemu_ram_get_used_length(block) * + sample_pages_per_gigabytes) >> + DIRTYRATE_PAGE_SHIFT_GB; + + /* Right shift 12 bits to calc page count in 4KB */ + info->ramblock_pages =3D qemu_ram_get_used_length(block) >> + DIRTYRATE_PAGE_SHIFT_KB; + info->ramblock_addr =3D qemu_ram_get_host_addr(block); + strcpy(info->idstr, qemu_ram_get_idstr(block)); +} + +static struct RamblockDirtyInfo * +alloc_ramblock_dirty_info(int *block_index, + struct RamblockDirtyInfo *block_dinfo) +{ + struct RamblockDirtyInfo *info =3D NULL; + int index =3D *block_index; + + if (!block_dinfo) { + index =3D 0; + block_dinfo =3D g_try_new(struct RamblockDirtyInfo, 1); + } else { + index++; + block_dinfo =3D g_try_realloc(block_dinfo, (index + 1) * + sizeof(struct RamblockDirtyInfo)); + } + if (!block_dinfo) { + return NULL; + } + + info =3D &block_dinfo[index]; + *block_index =3D index; + memset(info, 0, sizeof(struct RamblockDirtyInfo)); + + return block_dinfo; +} + +static int record_ramblock_hash_info(struct RamblockDirtyInfo **block_dinf= o, + struct DirtyRateConfig config, + int *block_index) +{ + struct RamblockDirtyInfo *info =3D NULL; + struct RamblockDirtyInfo *dinfo =3D NULL; + RAMBlock *block =3D NULL; + int index =3D 0; + + RAMBLOCK_FOREACH_MIGRATABLE(block) { + dinfo =3D alloc_ramblock_dirty_info(&index, dinfo); + if (dinfo =3D=3D NULL) { + return -1; + } + info =3D &dinfo[index]; + get_ramblock_dirty_info(block, info, &config); + if (save_ramblock_hash(info) < 0) { + *block_dinfo =3D dinfo; + *block_index =3D index; + return -1; + } + } + + *block_dinfo =3D dinfo; + *block_index =3D index; + + return 0; +} + static void calculate_dirtyrate(struct DirtyRateConfig config) { /* todo */ diff --git a/migration/dirtyrate.h b/migration/dirtyrate.h index 8e25d93..e3adead 100644 --- a/migration/dirtyrate.h +++ b/migration/dirtyrate.h @@ -24,6 +24,21 @@ */ #define RAMBLOCK_INFO_MAX_LEN 256 =20 +/* + * Sample page size 4K as default. + */ +#define DIRTYRATE_SAMPLE_PAGE_SIZE 4096 + +/* + * Sample page size 4K shift + */ +#define DIRTYRATE_PAGE_SHIFT_KB 12 + +/* + * Sample page size 1G shift + */ +#define DIRTYRATE_PAGE_SHIFT_GB 30 + /* Take 1s as default for calculation duration */ #define DEFAULT_FETCH_DIRTYRATE_TIME_SEC 1 =20 --=20 1.8.3.1 From nobody Sun May 19 04:05:27 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=1598319278; cv=none; d=zohomail.com; s=zohoarc; b=aNL1w1MwgGeHkxAvakOIE+QN6sruaj4E33R6y/Yzv+aOzcjOJEnECjSQ3TAi8uLxVdVhLW00yaL3oyh96ubL/UTLMcXigB6p7nxuncQ1D+mCSsl2YdX9q9xWm3cz0VtBOLozmZrNLUqnj5aDH0sFnXej2xFXnwtUOMsbMaogQ5k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598319278; 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=OnW0u0fz114+fzRsMLaSO0jVaWdU2tqs5veV4wasIeU=; b=HjCY2MuX0P2I2Dq4OzYGoRfa8A0lWigCdPBLNKO136rOqULdANdMNN3lYynOHwvmDn7Ty8yfyBWoWpO/k5tnuIfc1xvJq0ZOcf4G5Wb2DSnn2TevfBYlUsE6eq2huSUyuie+TyHzXzA8jyI5f6kRM3zR/n3eGnJJ5TZi5s3KPoQ= 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 1598319278793658.0126134707659; Mon, 24 Aug 2020 18:34:38 -0700 (PDT) Received: from localhost ([::1]:38872 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kANrB-0004WQ-KS for importer@patchew.org; Mon, 24 Aug 2020 21:34:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60810) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kANo3-0005QC-DF for qemu-devel@nongnu.org; Mon, 24 Aug 2020 21:31:23 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4653 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 1kANo1-0005rj-FV for qemu-devel@nongnu.org; Mon, 24 Aug 2020 21:31:23 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 507669C88A0AA1CAB2F1; Tue, 25 Aug 2020 09:31:02 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.487.0; Tue, 25 Aug 2020 09:30:52 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v5 07/12] migration/dirtyrate: Compare page hash results for recorded sampled page Date: Tue, 25 Aug 2020 09:40:45 +0800 Message-ID: <1598319650-36762-8-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1598319650-36762-1-git-send-email-zhengchuan@huawei.com> References: <1598319650-36762-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.190; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/24 21:30:58 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: zhang.zhanghailiang@huawei.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@huawei.com, ann.zhuangyanying@huawei.com, fangying1@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 --- migration/dirtyrate.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 64 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 66de426..050270d 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -202,6 +202,70 @@ static int record_ramblock_hash_info(struct RamblockDi= rtyInfo **block_dinfo, return 0; } =20 +static int 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++; + } + } + + return 0; +} + +static bool find_page_matched(RAMBlock *block, struct RamblockDirtyInfo *i= nfos, + int count, struct RamblockDirtyInfo **matche= d) +{ + int i; + + for (i =3D 0; i < count; i++) { + if (!strcmp(infos[i].idstr, qemu_ram_get_idstr(block))) { + break; + } + } + + if (i =3D=3D count) { + return false; + } + + if (infos[i].ramblock_addr !=3D qemu_ram_get_host_addr(block) || + infos[i].ramblock_pages !=3D + (qemu_ram_get_used_length(block) >> DIRTYRATE_PAGE_SHIFT_KB)) { + return false; + } + + *matched =3D &infos[i]; + return true; +} + +static int compare_page_hash_info(struct RamblockDirtyInfo *info, + int block_index) +{ + struct RamblockDirtyInfo *block_dinfo =3D NULL; + RAMBlock *block =3D NULL; + + RAMBLOCK_FOREACH_MIGRATABLE(block) { + block_dinfo =3D NULL; + if (!find_page_matched(block, info, block_index + 1, &block_dinfo)= ) { + continue; + } + if (calc_page_dirty_rate(block_dinfo) < 0) { + return -1; + } + update_dirtyrate_stat(block_dinfo); + } + + if (!DirtyStat.total_sample_count) { + return -1; + } + + return 0; +} + static void calculate_dirtyrate(struct DirtyRateConfig config) { /* todo */ --=20 1.8.3.1 From nobody Sun May 19 04:05:27 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=1598319203; cv=none; d=zohomail.com; s=zohoarc; b=Vi3q/a+a/jmLGUpkKSM/Q0kE5R+k/YU5x/NYGDDn2bvJk8NQlMwm0XJgR/pcTYsQENLsiWtUe3HXmCEELwJ4AG7jEKzGbP6SErHQO6h2VWywiIKmTTSn9ud98LHpMbahgSSUX7VyzMbePiiqbiWRBw/L+LeeMQ7dCzsFZN+VPNw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598319203; 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=Dehe9FQDNttJobfSSCg0i+vR+tLAyTz96yRPZIyWfTE=; b=m5VrYTPR2TUQQELAllp1PViVjks11mwhzHZytaa5a3P52BKqOOzFy4A1jQig9kmRfPoaUfRMIG8gmzo0rmcCFNo25uMiWjrhCtKG9CKG0pQ1SYzM95WCl64HvmOXElrOSQPG9saLKfRthBDRjOL26qwFQvimcrHZzislVyvaKRo= 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 1598319203491270.53399353075974; Mon, 24 Aug 2020 18:33:23 -0700 (PDT) Received: from localhost ([::1]:59826 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kANpy-0001dG-7a for importer@patchew.org; Mon, 24 Aug 2020 21:33:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60722) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kANns-0004yb-6o for qemu-devel@nongnu.org; Mon, 24 Aug 2020 21:31:12 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4215 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 1kANnq-0005qq-3l for qemu-devel@nongnu.org; Mon, 24 Aug 2020 21:31:11 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 3D144C02613669491D43; Tue, 25 Aug 2020 09:31:02 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.487.0; Tue, 25 Aug 2020 09:30:53 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v5 08/12] migration/dirtyrate: skip sampling ramblock with size below MIN_RAMBLOCK_SIZE Date: Tue, 25 Aug 2020 09:40:46 +0800 Message-ID: <1598319650-36762-9-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1598319650-36762-1-git-send-email-zhengchuan@huawei.com> References: <1598319650-36762-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.190; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/24 21:30:58 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: zhang.zhanghailiang@huawei.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@huawei.com, ann.zhuangyanying@huawei.com, fangying1@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 --- migration/dirtyrate.c | 24 ++++++++++++++++++++++++ migration/dirtyrate.h | 10 ++++++++++ 2 files changed, 34 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 050270d..bd398b7 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -173,6 +173,24 @@ alloc_ramblock_dirty_info(int *block_index, return block_dinfo; } =20 +static int skip_sample_ramblock(RAMBlock *block) +{ + int64_t ramblock_size; + + /* ramblock size in MB */ + ramblock_size =3D qemu_ram_get_used_length(block) >> DIRTYRATE_PAGE_SH= IFT_MB; + + /* + * Consider ramblock with size larger than 128M is what we + * want to sample. + */ + if (ramblock_size < MIN_RAMBLOCK_SIZE) { + return -1; + } + + return 0; +} + static int record_ramblock_hash_info(struct RamblockDirtyInfo **block_dinf= o, struct DirtyRateConfig config, int *block_index) @@ -183,6 +201,9 @@ static int record_ramblock_hash_info(struct RamblockDir= tyInfo **block_dinfo, int index =3D 0; =20 RAMBLOCK_FOREACH_MIGRATABLE(block) { + if (skip_sample_ramblock(block) < 0) { + continue; + } dinfo =3D alloc_ramblock_dirty_info(&index, dinfo); if (dinfo =3D=3D NULL) { return -1; @@ -249,6 +270,9 @@ static int compare_page_hash_info(struct RamblockDirtyI= nfo *info, RAMBlock *block =3D NULL; =20 RAMBLOCK_FOREACH_MIGRATABLE(block) { + if (skip_sample_ramblock(block) < 0) { + continue; + } block_dinfo =3D NULL; if (!find_page_matched(block, info, block_index + 1, &block_dinfo)= ) { continue; diff --git a/migration/dirtyrate.h b/migration/dirtyrate.h index e3adead..600bceb 100644 --- a/migration/dirtyrate.h +++ b/migration/dirtyrate.h @@ -35,10 +35,20 @@ #define DIRTYRATE_PAGE_SHIFT_KB 12 =20 /* + * Sample page size MB shift + */ +#define DIRTYRATE_PAGE_SHIFT_MB 20 + +/* * Sample page size 1G shift */ #define DIRTYRATE_PAGE_SHIFT_GB 30 =20 +/* + * minimum ramblock size to sampled + */ +#define MIN_RAMBLOCK_SIZE 128 + /* Take 1s as default for calculation duration */ #define DEFAULT_FETCH_DIRTYRATE_TIME_SEC 1 =20 --=20 1.8.3.1 From nobody Sun May 19 04:05:27 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=1598319335; cv=none; d=zohomail.com; s=zohoarc; b=in4LxoJBaq0rXKTwpk2cUsYqhBWJEEkeGfkrliznkD+XxA49FQP9fSj1Xdi/jIbZUogsCRwGbeN9/LqgbWM3nPq9Xm4ARfodKBhhouSAm+jPhsl2XpJNT2BV6CA7/HDYm5q3o7PlcsdhSy7RcEB8UMcaMyDggUc7HAMbObCYxJ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598319335; 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=h2Tpa8CFuB8z8s8uIKQfdI3uI2JriHphLFf8u8DbXDo=; b=kCJRm2mI+xzv3FnevU9HyrOv6gQGIp2am3TMOHpazI5p15Jos1tmTBlU45Lh2iliaDVByZ0sTx4hLUFyDNCokCRpXzn4UBx4q71wGioHnY9jGiCZtnpOUw3brpLCt7oGBRsWogf27sUs4Nco+FyLFZWBm09yalY5Ni0HyrT+gaE= 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 1598319335782377.8726961247037; Mon, 24 Aug 2020 18:35:35 -0700 (PDT) Received: from localhost ([::1]:42836 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kANs6-00068J-Jw for importer@patchew.org; Mon, 24 Aug 2020 21:35:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60704) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kANnr-0004xS-M9 for qemu-devel@nongnu.org; Mon, 24 Aug 2020 21:31:11 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4214 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 1kANnp-0005qW-6C for qemu-devel@nongnu.org; Mon, 24 Aug 2020 21:31:11 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 335EFBDBF03D4D888611; Tue, 25 Aug 2020 09:31:02 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.487.0; Tue, 25 Aug 2020 09:30:54 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v5 09/12] migration/dirtyrate: Implement get_sample_page_period() and block_sample_page_period() Date: Tue, 25 Aug 2020 09:40:47 +0800 Message-ID: <1598319650-36762-10-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1598319650-36762-1-git-send-email-zhengchuan@huawei.com> References: <1598319650-36762-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.190; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/24 21:30:58 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: zhang.zhanghailiang@huawei.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@huawei.com, ann.zhuangyanying@huawei.com, fangying1@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 get_sample_page_period() and set_sample_page_period() to sleep specific time between sample actions. Signed-off-by: Chuan Zheng Reviewed-by: Dr. David Alan Gilbert --- migration/dirtyrate.c | 24 ++++++++++++++++++++++++ migration/dirtyrate.h | 2 ++ 2 files changed, 26 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index bd398b7..d1c0a78 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -28,6 +28,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 int64_t get_sample_page_period(int64_t sec) +{ + if (sec <=3D MIN_FETCH_DIRTYRATE_TIME_SEC || + sec > MAX_FETCH_DIRTYRATE_TIME_SEC) { + sec =3D DEFAULT_FETCH_DIRTYRATE_TIME_SEC; + } + + return sec; +} + 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 600bceb..cf14647 100644 --- a/migration/dirtyrate.h +++ b/migration/dirtyrate.h @@ -51,6 +51,8 @@ =20 /* Take 1s as default for calculation duration */ #define DEFAULT_FETCH_DIRTYRATE_TIME_SEC 1 +#define MIN_FETCH_DIRTYRATE_TIME_SEC 0 +#define MAX_FETCH_DIRTYRATE_TIME_SEC 60 =20 struct DirtyRateConfig { uint64_t sample_pages_per_gigabytes; /* sample pages per GB */ --=20 1.8.3.1 From nobody Sun May 19 04:05:27 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=1598319271; cv=none; d=zohomail.com; s=zohoarc; b=IPU34nM3Gt+4a9XA0RRlT+aOBA4wE/C7w2ooF7Zrz3pzdBcPwp4I+SeimuoAT9udg1nKLw4kxot3NJ5ER3KamqF/ON20aoFq73aCGDG4w3eGmwL06DllWO6dP2T0pIHj+ZUlmYZpSh15nGDnF6NauB/IiKXz6uVrzQEkp0cAblc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598319271; 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=cWv1NIRZuKok1PouGcFPc3m7ZDfP5xfmVKij8kNKSUA=; b=RgKGiwTtRbKGqTrVduF08Q8AwRfS26ZAy4f4s+K8NGlvA/UsDVxXUeCetaTUSXidyQuZyOOLIqbCRpuHhC3ppMCRqDa8BT6HY2LWzCm0qNRSUrH0gF/Acq0OwqrOYOLeYeqY+8TQrWnMWMzAKQuEPIsJ6GiFvHlBz0wSVrLiAZQ= 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 1598319271906157.1870430413942; Mon, 24 Aug 2020 18:34:31 -0700 (PDT) Received: from localhost ([::1]:38198 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kANr4-0004Fv-Kz for importer@patchew.org; Mon, 24 Aug 2020 21:34:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60688) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kANnr-0004wJ-30 for qemu-devel@nongnu.org; Mon, 24 Aug 2020 21:31:11 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4213 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 1kANnp-0005qV-5V for qemu-devel@nongnu.org; Mon, 24 Aug 2020 21:31:10 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 2E2EB96AE5C1B05EB132; Tue, 25 Aug 2020 09:31:02 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.487.0; Tue, 25 Aug 2020 09:30:54 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v5 10/12] migration/dirtyrate: Implement calculate_dirtyrate() function Date: Tue, 25 Aug 2020 09:40:48 +0800 Message-ID: <1598319650-36762-11-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1598319650-36762-1-git-send-email-zhengchuan@huawei.com> References: <1598319650-36762-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.190; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/24 21:30:58 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: zhang.zhanghailiang@huawei.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@huawei.com, ann.zhuangyanying@huawei.com, fangying1@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 --- migration/dirtyrate.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index d1c0a78..9f52f5f 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -171,6 +171,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 struct RamblockDirtyInfo * alloc_ramblock_dirty_info(int *block_index, struct RamblockDirtyInfo *block_dinfo) @@ -316,8 +331,34 @@ static int compare_page_hash_info(struct RamblockDirty= Info *info, =20 static void calculate_dirtyrate(struct DirtyRateConfig config) { - /* todo */ - return; + struct RamblockDirtyInfo *block_dinfo =3D NULL; + int block_index =3D 0; + int64_t msec =3D 0; + int64_t initial_time; + + rcu_register_thread(); + reset_dirtyrate_stat(); + initial_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); + rcu_read_lock(); + if (record_ramblock_hash_info(&block_dinfo, config, &block_index) < 0)= { + goto out; + } + rcu_read_unlock(); + + msec =3D config.sample_period_seconds * 1000; + msec =3D set_sample_page_period(msec, initial_time); + + rcu_read_lock(); + if (compare_page_hash_info(block_dinfo, block_index) < 0) { + goto out; + } + + update_dirtyrate(msec); + +out: + rcu_read_unlock(); + free_ramblock_dirty_info(block_dinfo, block_index + 1); + rcu_unregister_thread(); } =20 void *get_dirtyrate_thread(void *arg) --=20 1.8.3.1 From nobody Sun May 19 04:05:27 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=1598319131; cv=none; d=zohomail.com; s=zohoarc; b=M4dvAlojTGFmmhCl4onrPV57cugdyTSeo5M3Qmg/wH7hq/BSnvLlr1VTwyb3wNxKypzvm63OaPzVpQLozQwwK+g8nLknh2g2FIS5YsW0YyuvgsYW+U9Zr7kQDVkplzIXSCaCqReeiyCDGHkKzYlRYg9PCxhTJ5wxTXkKdfXMB9Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598319131; 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=dlBsTBW0DCyKiLS+SDhU9QEaD7vct466WHMY5LxPvCo=; b=Aj49POTXSE04Q3NY+Evb8Ul0iC7SygAIVXvdjAFvHIo6Hd6NsrynpPlCWgWqgFTd5dnsOYegHGCHK31Ok/qYP8u7d2HXeRnz/d6fZ8fm1jkiBYA2Q65+QS/EQETGnetBLOaq64B6A31buIne8aBgF0T6x7EOO+6QYngvCJGYm0g= 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 1598319131828710.0145535355813; Mon, 24 Aug 2020 18:32:11 -0700 (PDT) Received: from localhost ([::1]:51470 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kANoo-0006jB-Fs for importer@patchew.org; Mon, 24 Aug 2020 21:32:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60748) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kANns-00050U-SL for qemu-devel@nongnu.org; Mon, 24 Aug 2020 21:31:12 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4652 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 1kANnq-0005rE-MX for qemu-devel@nongnu.org; Mon, 24 Aug 2020 21:31:12 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 488B19A6735553E92BC4; Tue, 25 Aug 2020 09:31:02 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.487.0; Tue, 25 Aug 2020 09:30:55 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v5 11/12] migration/dirtyrate: Implement qmp_cal_dirty_rate()/qmp_get_dirty_rate() function Date: Tue, 25 Aug 2020 09:40:49 +0800 Message-ID: <1598319650-36762-12-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1598319650-36762-1-git-send-email-zhengchuan@huawei.com> References: <1598319650-36762-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.190; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/24 21:30:58 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: zhang.zhanghailiang@huawei.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@huawei.com, ann.zhuangyanying@huawei.com, fangying1@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 | 45 +++++++++++++++++++++++++++++++++++++++++++++ qapi/migration.json | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 9f52f5f..08c46d3 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -62,6 +62,28 @@ 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 (CalculatingState =3D=3D DIRTY_RATE_STATUS_MEASURED) { + info->dirty_rate =3D dirty_rate; + } else { + info->dirty_rate =3D -1; + } + + info->status =3D CalculatingState; + /* + * Only support query once for each calculation, + * reset as DIRTY_RATE_STATUS_UNSTARTED after query + */ + (void)dirtyrate_set_state(&CalculatingState, CalculatingState, + DIRTY_RATE_STATUS_UNSTARTED); + + return info; +} + static void reset_dirtyrate_stat(void) { DirtyStat.total_dirty_samples =3D 0; @@ -378,3 +400,26 @@ void *get_dirtyrate_thread(void *arg) DIRTY_RATE_STATUS_MEASURED); return NULL; } + +void qmp_calc_dirty_rate(int64_t calc_time, Error **errp) +{ + static struct DirtyRateConfig config; + QemuThread thread; + + /* + * We don't begin calculating thread only when it's in calculating sta= tus. + */ + if (CalculatingState =3D=3D DIRTY_RATE_STATUS_MEASURING) { + return; + } + + config.sample_period_seconds =3D get_sample_page_period(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 d640165..826bfd7 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -1737,3 +1737,47 @@ ## { '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' +# +# Since: 5.2 +# +## +{ 'struct': 'DirtyRateInfo', + 'data': {'dirty-rate': 'int64', + 'status': 'DirtyRateStatus'} } + +## +# @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": "cal-dirty-rate", "data": {"calc-time": 1} } +# +## +{ 'command': 'calc-dirty-rate', 'data': {'calc-time': 'int64'} } + +## +# @query-dirty-rate: +# +# query dirty page rate in units of MB/s for vm +# +# Since: 5.2 +## +{ 'command': 'query-dirty-rate', 'returns': 'DirtyRateInfo' } --=20 1.8.3.1 From nobody Sun May 19 04:05:27 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=1598319391; cv=none; d=zohomail.com; s=zohoarc; b=AaIMJSNFy0SN1CxKllZAPePu1fpyDNieOA/QpgNorX0UnAiOK4soEumiCQQ4iY0ZBdgq5PhdyR50sLRrK6KsaKsYJWpxDGQN3N1FUN8A8Q4vrjwjbG537oeYoGAx5v0ToZYCNeWHTQf5NS0HrL2F3Vu5Ciu/xdnANm2/PTTn9mA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598319391; 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=RILeItwUn1JEBv2tOPXQEpNzNDeTAdQWigvnIGRG/6o=; b=GamsLvIng+gBOP/JFST7bzAffWvtjrDeWWubABlrvSdx7krobkZvyaP6+Cl2NecJgB7y48u4Svu4SYwVNZlFtUhD7TIsUoq4EQD22TKuALHGXSfExaIoBpV2S91cM2xOSlTffgvzX2DqaXnFUVzWnHvV1rHbEsJQVL3jc5/RmUw= 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 15983193912430.9453023980852322; Mon, 24 Aug 2020 18:36:31 -0700 (PDT) Received: from localhost ([::1]:44940 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kANt0-00074o-31 for importer@patchew.org; Mon, 24 Aug 2020 21:36:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60800) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kANo2-0005Oc-OW for qemu-devel@nongnu.org; Mon, 24 Aug 2020 21:31:22 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4217 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 1kANo0-0005rF-Mb for qemu-devel@nongnu.org; Mon, 24 Aug 2020 21:31:22 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 41ED7F8F06CBE946409F; Tue, 25 Aug 2020 09:31:02 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.487.0; Tue, 25 Aug 2020 09:30:55 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v5 12/12] migration/dirtyrate: Add trace_calls to make it easier to debug Date: Tue, 25 Aug 2020 09:40:50 +0800 Message-ID: <1598319650-36762-13-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1598319650-36762-1-git-send-email-zhengchuan@huawei.com> References: <1598319650-36762-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.190; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/24 21:30:58 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: zhang.zhanghailiang@huawei.com, qemu-devel@nongnu.org, xiexiangyou@huawei.com, alex.chen@huawei.com, ann.zhuangyanying@huawei.com, fangying1@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 --- migration/dirtyrate.c | 7 +++++++ migration/trace-events | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 08c46d3..3513ef3 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -23,6 +23,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; @@ -55,6 +56,7 @@ static int64_t get_sample_page_period(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 { @@ -78,6 +80,7 @@ static struct DirtyRateInfo *query_dirty_rate_info(void) * Only support query once for each calculation, * reset as DIRTY_RATE_STATUS_UNSTARTED after query */ + trace_query_dirty_rate_info(DirtyRateStatus_str(CalculatingState)); (void)dirtyrate_set_state(&CalculatingState, CalculatingState, DIRTY_RATE_STATUS_UNSTARTED); =20 @@ -129,6 +132,7 @@ static uint32_t get_ramblock_vfn_hash(struct RamblockDi= rtyInfo *info, =20 crc =3D crc32(0, iov_array.iov_base, iov_array.iov_len); =20 + trace_get_ramblock_vfn_hash(info->idstr, vfn, crc); return crc; } =20 @@ -246,6 +250,7 @@ static int skip_sample_ramblock(RAMBlock *block) * want to sample. */ if (ramblock_size < MIN_RAMBLOCK_SIZE) { + trace_skip_sample_ramblock(block->idstr, ramblock_size); return -1; } =20 @@ -292,6 +297,7 @@ static int calc_page_dirty_rate(struct RamblockDirtyInf= o *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++; } } @@ -317,6 +323,7 @@ static bool find_page_matched(RAMBlock *block, struct R= amblockDirtyInfo *infos, if (infos[i].ramblock_addr !=3D qemu_ram_get_host_addr(block) || infos[i].ramblock_pages !=3D (qemu_ram_get_used_length(block) >> DIRTYRATE_PAGE_SHIFT_KB)) { + trace_find_page_matched(block->idstr); return false; } =20 diff --git a/migration/trace-events b/migration/trace-events index 4ab0a50..34569b9 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, int64_t ramblock_size) "ramblock n= ame: %s, ramblock size: %" PRIu64 +find_page_matched(const char *idstr) "ramblock %s addr or size changed" --=20 1.8.3.1