From nobody Sun May 19 03:38:16 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=1598240521; cv=none; d=zohomail.com; s=zohoarc; b=akUl+QkKmdljZ92n3pQXPtTyHi6JiNEmFubBTD8fd7JadNxvQs/u3rq47Rki+/1eT3yFOza8ljD06wkSm8V0ezruTbj7dYis8zZVeF+WNDyRm4OLPRVjL13gbTqOsd5mS9FBtOjAryqvG0OdIaBfHWv7WC9+Q+A27DdiWphGzYg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598240521; 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=j7PpD2YWqf/dh/549nIRYL/sSKX3Caspot6PLwyQdzE=; b=GxfSV+qW8uZpsvJ4YP+5jtPMNBjCggMcAwUDonygEqwyoPlOFnQWqLnHNZfNeWCaTaL2AUS/v9a64WnBPcMF9dgtmIXlAUpR7mQTzwuvPFWI0Iga4O1fd9ijGNQf5hY/LtcyFgz7eI3ZghSF20uVUfEFniRaMM1ja9WF1+lHVgo= 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 1598240521610923.1645673230015; Sun, 23 Aug 2020 20:42:01 -0700 (PDT) Received: from localhost ([::1]:57414 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kA3Mu-000071-0Z for importer@patchew.org; Sun, 23 Aug 2020 23:42:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58690) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kA3Lw-0006vx-S5 for qemu-devel@nongnu.org; Sun, 23 Aug 2020 23:41:00 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4200 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 1kA3Ls-0005SC-Dc for qemu-devel@nongnu.org; Sun, 23 Aug 2020 23:41:00 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 04AD01999642FA915E74; Mon, 24 Aug 2020 11:40:45 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Mon, 24 Aug 2020 11:40:36 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v4 01/12] migration/dirtyrate: setup up query-dirtyrate framwork Date: Mon, 24 Aug 2020 11:51:52 +0800 Message-ID: <1598241123-118714-2-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1598241123-118714-1-git-send-email-zhengchuan@huawei.com> References: <1598241123-118714-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/23 23:40:45 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 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 --- migration/Makefile.objs | 1 + migration/dirtyrate.c | 39 +++++++++++++++++++++++++++++++++++++++ migration/dirtyrate.h | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 migration/dirtyrate.c create mode 100644 migration/dirtyrate.h diff --git a/migration/Makefile.objs b/migration/Makefile.objs index 0fc619e..12ae98c 100644 --- a/migration/Makefile.objs +++ b/migration/Makefile.objs @@ -6,6 +6,7 @@ common-obj-y +=3D qemu-file.o global_state.o common-obj-y +=3D qemu-file-channel.o common-obj-y +=3D xbzrle.o postcopy-ram.o common-obj-y +=3D qjson.o +common-obj-y +=3D dirtyrate.o common-obj-y +=3D block-dirty-bitmap.o common-obj-y +=3D multifd.o common-obj-y +=3D multifd-zlib.o 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 + --=20 1.8.3.1 From nobody Sun May 19 03:38:16 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=1598240618; cv=none; d=zohomail.com; s=zohoarc; b=iOtsOwpPJ9ZMkfCTz2PVGoqC4NGuaeCaloAus39LDPlM6+jv9dro0QO0CVHbBaZ1ScwBg8G+/CPI4QJ6AyV6oHRLkWAr/F3fBGUFYDwXpptTgFfZijcVXyfMw/z9Zql7kpfkq0xKGY9/Sfzjx4flH/q1GPPYOZT8Z+cTcSxeTYc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598240618; 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=3jrbbfiuE2J0LLqoSFr9CQssk8bc2YRRs4MMju0PQRw=; b=EOSk69ZDmcDAIQVA1kQjsna4Fqmj3KUOP+0tTjLwKqlZ9ld8A9FWw5X36IKc/j3HHycxfjtC125KI2DFPCNjVOLjcAzdLqAwtu9zLJ83OUS9IL7cUn8RT7uUEpFvwp8wIXVgAgIYmIvx4KCIhw46RJX9/PRYmwC0JfaL3q2QEHg= 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 1598240618762194.79726884288073; Sun, 23 Aug 2020 20:43:38 -0700 (PDT) Received: from localhost ([::1]:36560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kA3OT-00036f-CQ for importer@patchew.org; Sun, 23 Aug 2020 23:43:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58682) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kA3Lv-0006vE-O8 for qemu-devel@nongnu.org; Sun, 23 Aug 2020 23:40:59 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4199 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 1kA3Ls-0005SA-Dg for qemu-devel@nongnu.org; Sun, 23 Aug 2020 23:40:59 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id F40A46C9EAF4B7F24E0C; Mon, 24 Aug 2020 11:40:44 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Mon, 24 Aug 2020 11:40:37 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v4 02/12] migration/dirtyrate: add DirtyRateStatus to denote calculation status Date: Mon, 24 Aug 2020 11:51:53 +0800 Message-ID: <1598241123-118714-3-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1598241123-118714-1-git-send-email-zhengchuan@huawei.com> References: <1598241123-118714-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/23 23:40:45 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 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 --- 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 d500055..d1a7b2d 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -1621,3 +1621,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 03:38:16 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=1598240521; cv=none; d=zohomail.com; s=zohoarc; b=aDj0cIRIQApaaT0IYGOjBV4nAmgYU8dkb92mF6OcPY6GKFkZIOAl08fWt9FYZS/FgBURCMO9MZkCDAiqf3TY/wogVwsukWCgAC/rV8J4wftdwZ1D73WiyLeteQxvVMZLbGAuj5iiO1BsDxpmVQQd8X9kSrIhEFs5Q30ixaI6EcM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598240521; 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=mXRbqwD+NrzJo22P8/q9SAVcorcSJdrRc1Vp2BXR1z8=; b=U9HL4awVfFnhOcfbdDNdT8fVRki6HVtdRLpGhYeyd4lq8KJQ1BxuofGnC8pDDW21ekB74+elOzzewwCw+au+3jXTBviLZLkS08E0dBl30izBzjnr8XM8TAfdVxJncIgOhpOeu2YNdLJ8jRHgGHyUP6oqpznmzCGyBkVW/mRn/F4= 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 1598240521611163.60742572069523; Sun, 23 Aug 2020 20:42:01 -0700 (PDT) Received: from localhost ([::1]:57408 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kA3Mt-00006t-Ru for importer@patchew.org; Sun, 23 Aug 2020 23:41:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58676) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kA3Lv-0006v8-Fn for qemu-devel@nongnu.org; Sun, 23 Aug 2020 23:40:59 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4198 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 1kA3Ls-0005S9-DR for qemu-devel@nongnu.org; Sun, 23 Aug 2020 23:40:59 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id EF96E99C744DF19E146C; Mon, 24 Aug 2020 11:40:44 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Mon, 24 Aug 2020 11:40:37 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v4 03/12] migration/dirtyrate: Add RamlockDirtyInfo to store sampled page info Date: Mon, 24 Aug 2020 11:51:54 +0800 Message-ID: <1598241123-118714-4-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1598241123-118714-1-git-send-email-zhengchuan@huawei.com> References: <1598241123-118714-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/23 23:40:45 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 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 --- migration/dirtyrate.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/migration/dirtyrate.h b/migration/dirtyrate.h index 33669b7..70000da 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; /* cout 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 03:38:16 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=1598240625; cv=none; d=zohomail.com; s=zohoarc; b=SrPPVjyycrw44SJ7cIIvu9WyYfG2uutX48BQwaaXBF6pf4tH6LZRRcc/upP2yAQjiNC9qD4/4s9aE7R14UfJnpVFqynlsfv1fyGQyaVRaJEmLru2PofLdF+0cG8q5DZeJE6Q68+/TgA6HfSFGYm7PNRqM744Vq/RloHR5Edn1oo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598240625; 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=++AK6HmXzbBF2ojGgOwsthbigdotwSc6r2TWLjNyZds=; b=A0wKKy9CXo9IFmKI2844vUy2Um1ZckZdDBuxulgVsNtgSlzjZzndHTwYiJkwqinPuQikri90mvKr3dQstX/4sHs2nGrljYD+ZoS8hBTQoas6oMGBhSQwxYMC8oJkkMkdZo5HohwZ80JqNJN5YIHPl5UnY1qiFDkEYQFmgK3guvQ= 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 1598240625503859.5345343902654; Sun, 23 Aug 2020 20:43:45 -0700 (PDT) Received: from localhost ([::1]:36690 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kA3Oa-00039n-8L for importer@patchew.org; Sun, 23 Aug 2020 23:43:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58688) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kA3Lw-0006vj-NE for qemu-devel@nongnu.org; Sun, 23 Aug 2020 23:41:00 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4196 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 1kA3Ls-0005S8-EA for qemu-devel@nongnu.org; Sun, 23 Aug 2020 23:41:00 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id E5AFF13587374D9FA39A; Mon, 24 Aug 2020 11:40:44 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Mon, 24 Aug 2020 11:40:38 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v4 04/12] migration/dirtyrate: Add dirtyrate statistics series functions Date: Mon, 24 Aug 2020 11:51:55 +0800 Message-ID: <1598241123-118714-5-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1598241123-118714-1-git-send-email-zhengchuan@huawei.com> References: <1598241123-118714-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/23 23:40:45 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 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 70000da..9db269d 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 03:38:16 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=1598240521; cv=none; d=zohomail.com; s=zohoarc; b=oJ6cRdm7Bh0X9qU/CjKUiUmpKwGgIFsq2RSe9GEKzw2iYs8Mul1/b8kx7SWerS1YYk6JVn3/2mDEsC1Y+AftI+muqM0Lk6loK2pszloijPALWSOFNfC/GB9jQ0zc6zhlqaziURUlMsAzqKQjl9IoOAzYJtdQSieHYd80/U0JJKA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598240521; 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=F7SvXDfPaCW2pL76chu+JpTYvM5xSkNs5GokEfHjwZA=; b=KXM4355oNOpMzw9Kf33I5hEZyrBkXzFQVaVRKUsNvhZku+2//MNR7+KEEdklYZU7HNFZsJWRrSdNRBZ0YPBvOUhU+gnlyK2+OEXeAKGo6yKxk/rayR65LdIGiCiPDPQLXLGqiULG3wWBP5mMCBosHybQ1AoDfVK6gSQCZ6/VlnI= 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 1598240521539246.83731572003717; Sun, 23 Aug 2020 20:42:01 -0700 (PDT) Received: from localhost ([::1]:57260 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kA3Ms-0008VF-IO for importer@patchew.org; Sun, 23 Aug 2020 23:41:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58642) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kA3Lu-0006uz-FV for qemu-devel@nongnu.org; Sun, 23 Aug 2020 23:40:58 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4197 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 1kA3Ls-0005SB-DR for qemu-devel@nongnu.org; Sun, 23 Aug 2020 23:40:58 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id EAB0BF753A3709444B42; Mon, 24 Aug 2020 11:40:44 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Mon, 24 Aug 2020 11:40:38 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v4 05/12] migration/dirtyrate: move RAMBLOCK_FOREACH_MIGRATABLE into ram.h Date: Mon, 24 Aug 2020 11:51:56 +0800 Message-ID: <1598241123-118714-6-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1598241123-118714-1-git-send-email-zhengchuan@huawei.com> References: <1598241123-118714-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/23 23:40:45 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 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 --- 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 03:38:16 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=1598240696; cv=none; d=zohomail.com; s=zohoarc; b=FtrQZedEKl0Fi19dgjxRdof15W6J1TOVgjeHfoPVJgByuKywCMglY8iZ24chrkj1B40Rbm1Rx1i/8J5J66GL9ooT8CwTa3mXtq+wyOynngkSUydd7EUCiiqBxOlqlPte+Odu+i3o1NNgRcbOHHh1Y/0OVpP7AXe8rI6BzxZqgfk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598240696; 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=kxHzdmyFGM/3srnFfDxc8B3cE0uNsoQWTc1IpUSRkJw=; b=kmYg6yUE3goXdSIveWzEJN43kWLDHnfAm76CdzpsVtIO7YrhzWxqsdxDj+/efcfBlDIQ5PomYmztyMovLduJPt/qyXtrrC73DthNLMFK2Ks6Kg1zi8E+lP3Odni5i7p9Y9Dcviadc0uV53ig2Z1mGiBrjD6H9SL0AIZqFNIC0gg= 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 1598240696706219.13286742156845; Sun, 23 Aug 2020 20:44:56 -0700 (PDT) Received: from localhost ([::1]:42090 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kA3Pi-0005Pf-Fn for importer@patchew.org; Sun, 23 Aug 2020 23:44:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58722) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kA3Lz-00071m-F2 for qemu-devel@nongnu.org; Sun, 23 Aug 2020 23:41:03 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4202 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 1kA3Lx-0005UR-Ad for qemu-devel@nongnu.org; Sun, 23 Aug 2020 23:41:03 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 098FFAA79D42DB227C87; Mon, 24 Aug 2020 11:40:45 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Mon, 24 Aug 2020 11:40:39 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v4 06/12] migration/dirtyrate: Record hash results for each sampled page Date: Mon, 24 Aug 2020 11:51:57 +0800 Message-ID: <1598241123-118714-7-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1598241123-118714-1-git-send-email-zhengchuan@huawei.com> References: <1598241123-118714-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/23 23:40:45 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 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 9db269d..5050add 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 03:38:16 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=1598240765; cv=none; d=zohomail.com; s=zohoarc; b=Egm/ezlFo+lOml/aS1Mu5xCE9JICeTQfoRZ8O0c4vID8sBC/YIRaL+E9aUKarmoahW0wUMhUyjMMNTRFXJvP6fa7jIFFWr7CoNot5LNZK9sXHF+io10ov1dAURFfmXH5i3NDucfLmWnUOGYwv7ClS9EHR+LHx4nZRhmzXO4F980= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598240765; 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=lgGQHDxQu8UZZ/sxdBeG1YRXa9hvCaM6vv6J0nI9ZfIKkNddevLIcp24MfQtJxPfCN8plAGJgXmA6pcwhRKNaJiPRYfoy3Rap/sL74zH6nwxjhe79HIOe5JCzUBSXiQOCQTJNr7W1QdX9cpxxmWnRKgZ03gmQ9tb2n6MDFPfjF0= 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 1598240765695121.10758124471238; Sun, 23 Aug 2020 20:46:05 -0700 (PDT) Received: from localhost ([::1]:46208 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kA3Qq-0007C5-EY for importer@patchew.org; Sun, 23 Aug 2020 23:46:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58770) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kA3M1-00076S-BZ for qemu-devel@nongnu.org; Sun, 23 Aug 2020 23:41:05 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4206 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 1kA3Lz-0005Un-6o for qemu-devel@nongnu.org; Sun, 23 Aug 2020 23:41:04 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 08E2942B6DD37E27F542; Mon, 24 Aug 2020 11:40:50 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Mon, 24 Aug 2020 11:40:39 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v4 07/12] migration/dirtyrate: Compare page hash results for recorded sampled page Date: Mon, 24 Aug 2020 11:51:58 +0800 Message-ID: <1598241123-118714-8-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1598241123-118714-1-git-send-email-zhengchuan@huawei.com> References: <1598241123-118714-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/23 23:40:45 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 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 03:38:16 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=1598240836; cv=none; d=zohomail.com; s=zohoarc; b=cgcjJ3KmxjlqHms88YFERctjTMTf1WRU2G4MAlqxv2PJ5RmxfqEhdwgWKhh0C0QB3+H58ykFIWfISZfh511zr+6l1oD582VBjXB6q+WyRnwLVMD7ac35g/q+0Zsz23yirxI6NjN08UeDIC+hhKJvRYC5NcfGyYGWpRL++i4gNKY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598240836; 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=COi6Hs/Ov+Y+Q6KXIf1W1DKty4pD1s1PvNRV42cHJWk=; b=MkHS9q4Js8uXltVAksjmwPzPpRGkzDgXiTmpJ/g0lA7k/oQb1YaeltJKeS+qLIsXVm0LfpXUa4Of0HQHfJxvTvHHjoubgqhCXFqgxEGuAM2ysiwLsFKWuKAbAyX4LFK2UeUvuUnEfliUk8wLbEoS7rsqUYNS1sdMeIFl/n65Rq0= 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 1598240836258624.8153216596564; Sun, 23 Aug 2020 20:47:16 -0700 (PDT) Received: from localhost ([::1]:51070 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kA3Rz-0000kV-2Y for importer@patchew.org; Sun, 23 Aug 2020 23:47:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58762) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kA3M0-00075E-SX for qemu-devel@nongnu.org; Sun, 23 Aug 2020 23:41:04 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4203 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 1kA3Ly-0005Uf-0g for qemu-devel@nongnu.org; Sun, 23 Aug 2020 23:41:04 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 03EF942845C015CA5C05; Mon, 24 Aug 2020 11:40:50 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Mon, 24 Aug 2020 11:40:40 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v4 08/12] migration/dirtyrate: skip sampling ramblock with size below MIN_RAMBLOCK_SIZE Date: Mon, 24 Aug 2020 11:51:59 +0800 Message-ID: <1598241123-118714-9-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1598241123-118714-1-git-send-email-zhengchuan@huawei.com> References: <1598241123-118714-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/23 23:40:45 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 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 5050add..41bc264 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 03:38:16 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=1598240693; cv=none; d=zohomail.com; s=zohoarc; b=HVvWMKieXON+NDBCdtkZMU1vV+iG667IgDcjlUFeXMbTwycn0ZRGrvx8rhv3ju8lf5jJcm+eIgbXrjYBDl1iY6m+0ZE9z0+WVDqnJhw56F7nET49XRzPafCHJ33RqkCaPMLqs3YA3cEAYSd8SMPJSy9dcTVE+Q7RLlDz/T9hbUs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598240693; 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=SPf7ruHt5iQ4PXzSmn7yxN1jeLaZOs69GCxSrUyK/rM=; b=QSYtd4Q8S1S4LrlWXPKxao6VTxve9hSWkIC8V8SyNLk+o2k0FJJQLsorOAOgPuxgmAV3o8ADP6LAME1bB5JOKiP10l5BhyTkkI1JW2oscbZ++gkglv7ewTBeIC4X7spy03rwFBtKtwtmWfxQAe4N9Y0E8PZfKV03hqKfY2t5DT8= 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 1598240693377965.0841735447849; Sun, 23 Aug 2020 20:44:53 -0700 (PDT) Received: from localhost ([::1]:41926 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kA3Pg-0005Lk-45 for importer@patchew.org; Sun, 23 Aug 2020 23:44:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58694) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kA3Lx-0006wv-J7 for qemu-devel@nongnu.org; Sun, 23 Aug 2020 23:41:01 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:48806 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 1kA3Lt-0005Sw-0r for qemu-devel@nongnu.org; Sun, 23 Aug 2020 23:41:01 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 33DFE21AD12D7B5A3081; Mon, 24 Aug 2020 11:40:50 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Mon, 24 Aug 2020 11:40:40 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v4 09/12] migration/dirtyrate: Implement get_sample_page_period() and block_sample_page_period() Date: Mon, 24 Aug 2020 11:52:00 +0800 Message-ID: <1598241123-118714-10-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1598241123-118714-1-git-send-email-zhengchuan@huawei.com> References: <1598241123-118714-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/08/23 23:40:50 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 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 --- 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 41bc264..50a5636 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 03:38:16 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=1598240626; cv=none; d=zohomail.com; s=zohoarc; b=ayFjfdtj/jx1Qo6ZsI+ihokoTWCzFhA8uuAohtwF7ecMAP2A51+vscIVJjW4BQO2Y2BI6c5HbAzB78NojACKFOnknFVKkPR0v8eKne5IiPc/LjtWh0MuOTVRsYlfxeUouVVjn5HfKi2Efwx4jO+os5uApRgcaU35lIqddDPMSXM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598240626; 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=BIaShMeQmKn9RnWy+6MMcf83MctfA+3ZRVhlEoVO0IlBW+UTrdsm5tGjPZscBQl/PWUlxgKqbkGDz1qgpk9XfnOnnSQc04I0Bv482MZWBbt7LvB3yky+rRDYbrrs6vPqB6sMbU8r7TXY93XIbqVijAztG9NjuZW/gcyS1B69RbM= 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 1598240626543363.2932753501078; Sun, 23 Aug 2020 20:43:46 -0700 (PDT) Received: from localhost ([::1]:36678 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kA3Ob-00039b-CQ for importer@patchew.org; Sun, 23 Aug 2020 23:43:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58774) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kA3M2-00078T-0g for qemu-devel@nongnu.org; Sun, 23 Aug 2020 23:41:06 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4205 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 1kA3Ly-0005Um-Ce for qemu-devel@nongnu.org; Sun, 23 Aug 2020 23:41:05 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 0DB2968BD3EE1A37DCAC; Mon, 24 Aug 2020 11:40:50 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Mon, 24 Aug 2020 11:40:41 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v4 10/12] migration/dirtyrate: Implement calculate_dirtyrate() function Date: Mon, 24 Aug 2020 11:52:01 +0800 Message-ID: <1598241123-118714-11-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1598241123-118714-1-git-send-email-zhengchuan@huawei.com> References: <1598241123-118714-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/23 23:40:45 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 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 03:38:16 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=1598240527; cv=none; d=zohomail.com; s=zohoarc; b=RYD6wVco7zd/kSnBAep8VC66EQDmCNLSD4Bt1uUXFKt+1ykEneUaJgFM0zav4lIzcq4989upo3j+KOCXRQQtm45IUAp8YwCq+lSQ6sdSQLoGfVocUe8vydfJRmzNKn78SiPNKdy0Rm4sgVFxw6L0qY3IVHrlc2HX7LB8xpNLxYc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598240527; 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=kfM9hgHv+sUPcvH+e62/x3otvyvRUcP1dSoKmuYKvZE=; b=VUfhcYFIt5d7RoGYiGlCN9WiSJqI79QFsBficdLwjGQWjxO5vGCixa6Yyc4pcGArc+OWii+sVTYRj1JB3Hf+rfJCi7lNg5/QmSuEjxpScaA1H2SCsSUvjALHejQ758JcvILtx6EHh6qQg+AmcPy220qaqMjNGO0yvwbKWt/czBM= 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 1598240527637537.7331898197232; Sun, 23 Aug 2020 20:42:07 -0700 (PDT) Received: from localhost ([::1]:57882 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kA3N0-0000JN-DU for importer@patchew.org; Sun, 23 Aug 2020 23:42:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58692) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kA3Lx-0006wN-5Z for qemu-devel@nongnu.org; Sun, 23 Aug 2020 23:41:01 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:48804 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 1kA3Ls-0005Sv-TT for qemu-devel@nongnu.org; Sun, 23 Aug 2020 23:41:00 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 2D9FBF81B30643F39F0C; Mon, 24 Aug 2020 11:40:50 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Mon, 24 Aug 2020 11:40:41 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v4 11/12] migration/dirtyrate: Implement qmp_cal_dirty_rate()/qmp_get_dirty_rate() function Date: Mon, 24 Aug 2020 11:52:02 +0800 Message-ID: <1598241123-118714-12-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1598241123-118714-1-git-send-email-zhengchuan@huawei.com> References: <1598241123-118714-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/08/23 23:40:50 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 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 d1a7b2d..97c5aba 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -1638,3 +1638,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 03:38:16 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=1598240832; cv=none; d=zohomail.com; s=zohoarc; b=fkWc91mfUK7mi/Z2gBRGtcC8dOv0MyiKMeyqgNtXBcrRauVHKKrTh1boU+jRNE4DVwtG0YE4yaZFbVyik3pKsg01EJhjE48c0NV31WGXQXvHzCbMMHduB28QnfbaZmVUsFDCfqXBNOh8r1lMYNtDdMt3voyTGYA91VDV3dq8EPI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598240832; 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=jqtugOYX2gyVDLeXhKVp2maqQNWEhgC331oRcPbYHtOIgdbK345px/xsT+Tyn7tPPakYOMgDn9gbsoyKHukx+++HJzmDBuCnIaXNXMbHIZpqhCBA4yX6jpCQy9r85kFnSw54LtxOe0OAAJ8BetB+RTB9rGqZ6pZC0iaOZMuDTD8= 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 1598240832257663.6568148787337; Sun, 23 Aug 2020 20:47:12 -0700 (PDT) Received: from localhost ([::1]:50872 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kA3Ru-0000fb-Fr for importer@patchew.org; Sun, 23 Aug 2020 23:47:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58780) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kA3M3-0007DL-9D for qemu-devel@nongnu.org; Sun, 23 Aug 2020 23:41:07 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4204 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 1kA3Ly-0005Uh-4s for qemu-devel@nongnu.org; Sun, 23 Aug 2020 23:41:06 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id F2FB18DDE46059A5037C; Mon, 24 Aug 2020 11:40:49 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Mon, 24 Aug 2020 11:40:42 +0800 From: Chuan Zheng To: , , , Subject: [PATCH v4 12/12] migration/dirtyrate: Add trace_calls to make it easier to debug Date: Mon, 24 Aug 2020 11:52:03 +0800 Message-ID: <1598241123-118714-13-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1598241123-118714-1-git-send-email-zhengchuan@huawei.com> References: <1598241123-118714-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/23 23:40:45 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 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 --- 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