From nobody Sun May 12 18:20:36 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=1597514761; cv=none; d=zohomail.com; s=zohoarc; b=MaZOJsAMpZnsQBVv8IUy4zkHQBib2K50z88qa+ZhjsLy+ZMsElHn7Tx/VMNfAF6upB88kPiaQ5JVcgi8A6U/sASGEJoj3GBVxv2G5iRwUJmiOayZj4drlBCx+Hl5gt9v762hYX5anVPmBkKkqkpPoGEijPI3w2QWUky4MwwHvCE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597514761; 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=pqfZ+BogYg0FT9R5M7sVHq9aNKPtB+dbfwrtlsJwYPk=; b=igroWg/2TDU1Thi1mNXyMebh3wgGUwpq1lyqrAVo/SDcEHvXIvuJx3Fs5JUqVHkmCVvXV82VBIx/zxEW45AgnCQ5TcK3B+owhRn2EXb4j//nmstHftLgp9EP/zmQWucya2N2Do/oy2OTjWWv9h0q96E7XZEQGwA19jS/MmqOa8E= 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 1597514761151708.8592872017616; Sat, 15 Aug 2020 11:06:01 -0700 (PDT) Received: from localhost ([::1]:39298 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k70Z5-00064r-TC for importer@patchew.org; Sat, 15 Aug 2020 14:05:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51868) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k70VR-0001Dw-Lg for qemu-devel@nongnu.org; Sat, 15 Aug 2020 14:02:13 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:4251 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 1k70VN-0007Ec-Ur for qemu-devel@nongnu.org; Sat, 15 Aug 2020 14:02:13 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 21F87FD342A7409CD9D9; Sat, 15 Aug 2020 10:11:12 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Sat, 15 Aug 2020 10:11:05 +0800 From: Chuan Zheng To: , , Subject: [PATCH v2 01/10] migration/dirtyrate: Add get_dirtyrate_thread() function Date: Sat, 15 Aug 2020 10:22:51 +0800 Message-ID: <1597458180-16945-2-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1597458180-16945-1-git-send-email-zhengchuan@huawei.com> References: <1597458180-16945-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/15 14:02:05 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, linyilu@huawei.com, qemu-devel@nongnu.org, 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" From: Zheng Chuan Add get_dirtyrate_thread() functions Signed-off-by: Zheng Chuan Signed-off-by: YanYing Zhuang --- migration/Makefile.objs | 1 + migration/dirtyrate.c | 64 +++++++++++++++++++++++++++++++++++++++++++++= ++++ migration/dirtyrate.h | 44 ++++++++++++++++++++++++++++++++++ 3 files changed, 109 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..bb0ebe9 --- /dev/null +++ b/migration/dirtyrate.c @@ -0,0 +1,64 @@ +/* + * 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" + +CalculatingDirtyRateState CalculatingState =3D CAL_DIRTY_RATE_INIT; + +static int dirty_rate_set_state(int new_state) +{ + int old_state =3D CalculatingState; + + if (new_state =3D=3D old_state) { + return -1; + } + + if (atomic_cmpxchg(&CalculatingState, old_state, new_state) !=3D old_s= tate) { + return -1; + } + + return 0; +} + +static void calculate_dirtyrate(struct DirtyRateConfig config) +{ + /* todo */ + return; +} + +void *get_dirtyrate_thread(void *arg) +{ + struct DirtyRateConfig config =3D *(struct DirtyRateConfig *)arg; + int ret; + + ret =3D dirty_rate_set_state(CAL_DIRTY_RATE_ACTIVE); + if (ret =3D=3D -1) { + return NULL; + } + + calculate_dirtyrate(config); + + ret =3D dirty_rate_set_state(CAL_DIRTY_RATE_END); + + return NULL; +} diff --git a/migration/dirtyrate.h b/migration/dirtyrate.h new file mode 100644 index 0000000..914c363 --- /dev/null +++ b/migration/dirtyrate.h @@ -0,0 +1,44 @@ +/* + * 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 256 pages per GB as default. + * TODO: Make it configurable. + */ +#define DIRTYRATE_DEFAULT_SAMPLE_PAGES 256 + +/* 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 */ +}; + +/* + * To record calculate dirty_rate status: + * 0: initial status, calculating thread is not be created here. + * 1: calculating thread is created. + * 2: calculating thread is end, we can get result. + */ +typedef enum { + CAL_DIRTY_RATE_INIT =3D 0, + CAL_DIRTY_RATE_ACTIVE, + CAL_DIRTY_RATE_END, +} CalculatingDirtyRateState; + +void *get_dirtyrate_thread(void *arg); +#endif + --=20 1.8.3.1 From nobody Sun May 12 18:20:36 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=1597514633; cv=none; d=zohomail.com; s=zohoarc; b=eHl/qPmu2venUKXdMYlZvOihN29GZEgo3kzYC0X2n2cCCH8UzOG+Yy/kXEaYrsjo5FSzu/VnQcWYNFXFnh0lPV5VADZSmYr5LMVxLMH6RnMgYt654TS4mqfllwSJPkAQtOF3kJtFk/gb+3zPgwb/SDX4arvZshdBPtOJaYxaFFE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597514633; 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=0YDxAj1OjdUfCkdw/hDsze45R34BxAGgec8LL+FYfzY=; b=aHnMrZLa2JcvabPLtNIgjW+ngP9tkuCytr+cAEtUwDRFnETntszIoVLrFV0o0CWkJM60+qdDqPf4FkkuDlBOk/FYaSI6ukQ/h2t5FM4XkisdrbwczKbf0I0h2dYWpMEZl88DV6EkCJ59ejMuMXbG/vS2SgwkQqbObDEegX50PnQ= 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 1597514633983298.4300877218726; Sat, 15 Aug 2020 11:03:53 -0700 (PDT) Received: from localhost ([::1]:58560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k70X1-0002OQ-Rs for importer@patchew.org; Sat, 15 Aug 2020 14:03:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51756) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k70VF-0000pI-5n for qemu-devel@nongnu.org; Sat, 15 Aug 2020 14:02:01 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:57326 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 1k70VD-0007DV-10 for qemu-devel@nongnu.org; Sat, 15 Aug 2020 14:02:00 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 03637AA08AA0E28D99EA; Sat, 15 Aug 2020 10:11:17 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Sat, 15 Aug 2020 10:11:06 +0800 From: Chuan Zheng To: , , Subject: [PATCH v2 02/10] migration/dirtyrate: Add RamlockDirtyInfo to store sampled page info Date: Sat, 15 Aug 2020 10:22:52 +0800 Message-ID: <1597458180-16945-3-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1597458180-16945-1-git-send-email-zhengchuan@huawei.com> References: <1597458180-16945-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.32; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/15 14:01:48 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, linyilu@huawei.com, qemu-devel@nongnu.org, 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" From: Zheng Chuan Add RamlockDirtyInfo to store sampled page info of each ramblock. Signed-off-by: Zheng Chuan --- migration/dirtyrate.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/migration/dirtyrate.h b/migration/dirtyrate.h index 914c363..9650566 100644 --- a/migration/dirtyrate.h +++ b/migration/dirtyrate.h @@ -19,6 +19,11 @@ */ #define DIRTYRATE_DEFAULT_SAMPLE_PAGES 256 =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 @@ -39,6 +44,19 @@ typedef enum { CAL_DIRTY_RATE_END, } CalculatingDirtyRateState; =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 */ + size_t ramblock_pages; /* sum of dividation by 4K pages for ramblock */ + size_t *sample_page_vfn; /* relative offset address for sampled page */ + unsigned int sample_pages_count; /* sum of sampled pages */ + unsigned int sample_dirty_count; /* sum of dirty pages we measure */ + uint8_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 12 18:20:36 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=1597514653; cv=none; d=zohomail.com; s=zohoarc; b=X+vh15ntgauTEYSzxJC7toaPZV4UmV5eF5i9R6hoR3Y+1fKsBRn6KVKLe9QCGTLH5uco5wxqfDeYb1MwcwzWhDzG5uRBG312tDxL3ROLMZ/XzqPwRuvtFhGZ5CbzZ3ytu2znUbr9gGb2tmx4lxqtjubGlnTAZcyVaJiZpykgcQw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597514653; 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=AlbyQKj1XzJinRcZyGFYGwOlVZf4i75QPqkicIk5jjE=; b=lG8L4Q3LJLVORa+Qm3ym3SfiQfhYfcg3yOAWg8pDasU46+ZfMxh26Gq94f6NLqOawz9LiPBfyvCJd5WOLbkg5v2lI15bLtNNsbiNXtcao2fhWYK1M3GWLDrZKHnbKN1ON689EAKRMI0mfeKOF702MR7rskmzz0Ln/4d5zGO1Fu0= 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 1597514653355575.9465041789206; Sat, 15 Aug 2020 11:04:13 -0700 (PDT) Received: from localhost ([::1]:59094 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k70XM-0002bT-34 for importer@patchew.org; Sat, 15 Aug 2020 14:04:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51814) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k70VJ-0000uk-N5 for qemu-devel@nongnu.org; Sat, 15 Aug 2020 14:02:05 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:57582 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 1k70VH-0007E2-RI for qemu-devel@nongnu.org; Sat, 15 Aug 2020 14:02:05 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 1A38440DCC001D5839C9; Sat, 15 Aug 2020 10:11:17 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Sat, 15 Aug 2020 10:11:06 +0800 From: Chuan Zheng To: , , Subject: [PATCH v2 03/10] migration/dirtyrate: Add dirtyrate statistics series functions Date: Sat, 15 Aug 2020 10:22:53 +0800 Message-ID: <1597458180-16945-4-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1597458180-16945-1-git-send-email-zhengchuan@huawei.com> References: <1597458180-16945-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.32; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/15 14:01:48 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, linyilu@huawei.com, qemu-devel@nongnu.org, 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" From: Zheng Chuan Add dirtyrate statistics to record/update dirtyrate info. Signed-off-by: Zheng Chuan --- migration/dirtyrate.c | 30 ++++++++++++++++++++++++++++++ migration/dirtyrate.h | 10 ++++++++++ 2 files changed, 40 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index bb0ebe9..8708090 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -24,6 +24,7 @@ #include "dirtyrate.h" =20 CalculatingDirtyRateState CalculatingState =3D CAL_DIRTY_RATE_INIT; +static struct DirtyRateStat dirty_stat; =20 static int dirty_rate_set_state(int new_state) { @@ -40,6 +41,35 @@ static int dirty_rate_set_state(int new_state) return 0; } =20 +static void reset_dirtyrate_stat(void) +{ + dirty_stat.total_dirty_samples =3D 0; + dirty_stat.total_sample_count =3D 0; + dirty_stat.total_block_mem_MB =3D 0; + dirty_stat.dirty_rate =3D 0; +} + +static void update_dirtyrate_stat(struct RamblockDirtyInfo *info) +{ + dirty_stat.total_dirty_samples +=3D info->sample_dirty_count; + dirty_stat.total_sample_count +=3D info->sample_pages_count; + /* size of 4K pages in MB */ + dirty_stat.total_block_mem_MB +=3D info->ramblock_pages / 256; +} + +static void update_dirtyrate(uint64_t msec) +{ + uint64_t dirty_rate; + unsigned int total_dirty_samples =3D dirty_stat.total_dirty_samples; + unsigned int total_sample_count =3D dirty_stat.total_sample_count; + size_t total_block_mem_MB =3D dirty_stat.total_block_mem_MB; + + dirty_rate =3D total_dirty_samples * total_block_mem_MB * + 1000 / (total_sample_count * msec); + + dirty_stat.dirty_rate =3D dirty_rate; +} + static void calculate_dirtyrate(struct DirtyRateConfig config) { /* todo */ diff --git a/migration/dirtyrate.h b/migration/dirtyrate.h index 9650566..af57c80 100644 --- a/migration/dirtyrate.h +++ b/migration/dirtyrate.h @@ -57,6 +57,16 @@ struct RamblockDirtyInfo { uint8_t *hash_result; /* array of hash result for sampled pages */ }; =20 +/* + * Store calculate statistics for each measure. + */ +struct DirtyRateStat { + unsigned int total_dirty_samples; /* total dirty pages for this measur= e */ + unsigned int total_sample_count; /* total sampled pages for this measu= re */ + size_t total_block_mem_MB; /* size of sampled pages in MB */ + int64_t dirty_rate; /* dirty rate for this measure */ +}; + void *get_dirtyrate_thread(void *arg); #endif =20 --=20 1.8.3.1 From nobody Sun May 12 18:20:36 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=1597514874; cv=none; d=zohomail.com; s=zohoarc; b=ZHcu1sZSyhF1YGCV+44OAjvLDoBvCF8XQQdXH4kuOGvWB/793cgpX4wCyUJ4TEG0EFrb5vArj1DCLlPDtyodOdZJXqsab5N/Kqipo8oH1idLNz4/0zeWGErcU31gbjvFq58+DBT5ppVKSEMKScrkoK2XhwADTeo19fU/k7B8qXk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597514874; 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=PHDA2+iF94Ny/LkZ45MuC2xUgRBe6WsvumRKiqo0NUQ=; b=eD9B1TixbjIpXlwC6PivjtAWcXag2UE3T2l+zUpjDljta39m026d8agOJFLmECvw9rIr/Ms1oVLbdsYI/R+bEd7T3A12GhA4J7HBu0vZWraty+cx7XJ62TG1/b3jrx/Oy3xEeKcpnse073MceVaxKKVciA2JDoV93aJ4G/Eas9Q= 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 1597514874273922.4065353063437; Sat, 15 Aug 2020 11:07:54 -0700 (PDT) Received: from localhost ([::1]:46870 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k70av-0000Z5-3S for importer@patchew.org; Sat, 15 Aug 2020 14:07:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51832) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k70VK-0000wS-MU for qemu-devel@nongnu.org; Sat, 15 Aug 2020 14:02:06 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:57580 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 1k70VH-0007E4-QR for qemu-devel@nongnu.org; Sat, 15 Aug 2020 14:02:06 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 1E66BAA7B85AFA6BCE1E; Sat, 15 Aug 2020 10:11:17 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Sat, 15 Aug 2020 10:11:07 +0800 From: Chuan Zheng To: , , Subject: [PATCH v2 04/10] migration/dirtyrate: move RAMBLOCK_FOREACH_MIGRATABLE into ram.h Date: Sat, 15 Aug 2020 10:22:54 +0800 Message-ID: <1597458180-16945-5-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1597458180-16945-1-git-send-email-zhengchuan@huawei.com> References: <1597458180-16945-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.32; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/15 14:01:48 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, linyilu@huawei.com, qemu-devel@nongnu.org, 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" From: Zheng Chuan RAMBLOCK_FOREACH_MIGRATABLE is need in dirtyrate measure, move the existing definition up into migration/ram.h Signed-off-by: Zheng Chuan --- 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 8708090..c4304ef 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 CalculatingDirtyRateState CalculatingState =3D CAL_DIRTY_RATE_INIT; 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 12 18:20:36 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=1597514653; cv=none; d=zohomail.com; s=zohoarc; b=RuqtxrepWaB2kiMo+KWnwMrl0X/VrGjbErbLKz8zV1TdSWFtB2FoVvGGN3TZtF5y0ozPg7yOg/etWy0PGjKOxKzkBKujhQdBG7GiLbieKGDVuUetBb5vvoLQ53rJVi7zlkjHyATLU1An+oMrJw8MzP9Ph6JWJjXWpVzOVM1T1g8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597514653; 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=XLOwFckvvoG9sLmHn+TY/DG7ZqsqB+fXiSLQws8N+ts=; b=kesy6Q+PiWY/wDQWjT3dhlAHctYBXG/GxeZfoD8ONy1RdQZJwScs60JxwaSQHpdtLw74P+C49wf0XjHeiAQ1BqvpQ8WWCl+GsJf/n7qlcdh7tGRliqBuylFEh+Wnu3QmQ1K7VPValvVqFYfk9wLBs0HXKZryX3/WVcuuCQwyZYA= 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 1597514653001774.9862397129622; Sat, 15 Aug 2020 11:04:13 -0700 (PDT) Received: from localhost ([::1]:59100 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k70XL-0002bc-Ks for importer@patchew.org; Sat, 15 Aug 2020 14:04:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51788) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k70VI-0000rz-2l for qemu-devel@nongnu.org; Sat, 15 Aug 2020 14:02:04 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:57324 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 1k70VD-0007DS-8m for qemu-devel@nongnu.org; Sat, 15 Aug 2020 14:02:03 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 15330EF42AC93647B124; Sat, 15 Aug 2020 10:11:17 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Sat, 15 Aug 2020 10:11:07 +0800 From: Chuan Zheng To: , , Subject: [PATCH v2 05/10] migration/dirtyrate: Record hash results for each sampled page Date: Sat, 15 Aug 2020 10:22:55 +0800 Message-ID: <1597458180-16945-6-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1597458180-16945-1-git-send-email-zhengchuan@huawei.com> References: <1597458180-16945-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.32; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/15 14:01:48 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, linyilu@huawei.com, qemu-devel@nongnu.org, 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" From: Zheng Chuan Record hash results for each sampled page. Signed-off-by: Zheng Chuan Signed-off-by: YanYing Zhuang --- migration/dirtyrate.c | 135 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ migration/dirtyrate.h | 7 +++ 2 files changed, 142 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index c4304ef..11c0051 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -25,6 +25,7 @@ #include "dirtyrate.h" =20 CalculatingDirtyRateState CalculatingState =3D CAL_DIRTY_RATE_INIT; +static unsigned long int qcrypto_hash_len =3D QCRYPTO_HASH_LEN; static struct DirtyRateStat dirty_stat; =20 static int dirty_rate_set_state(int new_state) @@ -71,6 +72,140 @@ static void update_dirtyrate(uint64_t msec) dirty_stat.dirty_rate =3D dirty_rate; } =20 +/* + * get hash result for the sampled memory with length of 4K byte in ramblo= ck, + * which starts from ramblock base address. + */ +static int get_ramblock_vfn_hash(struct RamblockDirtyInfo *info, unsigned = long vfn, + uint8_t **md) +{ + struct iovec iov_array; + int ret =3D 0; + int nkey =3D 1; + + iov_array.iov_base =3D info->ramblock_addr + + vfn * DIRTYRATE_SAMPLE_PAGE_SIZE; + iov_array.iov_len =3D DIRTYRATE_SAMPLE_PAGE_SIZE; + + if (qcrypto_hash_bytesv(QCRYPTO_HASH_ALG_MD5, + &iov_array, nkey, + md, &qcrypto_hash_len, NULL) < 0) { + ret =3D -1; + } + + return ret; +} + +static int save_ramblock_hash(struct RamblockDirtyInfo *info) +{ + unsigned int sample_pages_count; + uint8_t *md =3D NULL; + 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(uint8= _t) * qcrypto_hash_len); + if (!info->hash_result) { + ret =3D -1; + goto out; + } + + info->sample_page_vfn =3D g_try_malloc0_n(sample_pages_count, sizeof(u= nsigned long)); + if (!info->sample_page_vfn) { + g_free(info->hash_result); + ret =3D -1; + goto out; + } + + for (i =3D 0; i < sample_pages_count; i++) { + md =3D info->hash_result + i * qcrypto_hash_len; + info->sample_page_vfn[i] =3D g_rand_int_range(rand, 0, info->rambl= ock_pages - 1); + ret =3D get_ramblock_vfn_hash(info, info->sample_page_vfn[i], &md); + if (ret < 0) { + goto out; + } + } + ret =3D 0; + +out: + g_rand_free(rand); + return ret; +} + +static void get_ramblock_dirty_info(RAMBlock *block, struct RamblockDirtyI= nfo *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) >> 30; + + /* Right shift 12 bits to calc page count in 4KB */ + info->ramblock_pages =3D qemu_ram_get_used_length(block) >> 12; + 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) { + block_dinfo =3D g_try_new(struct RamblockDirtyInfo, 1); + index =3D 0; + } 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]; + memset(info, 0, sizeof(struct RamblockDirtyInfo)); + + *block_index =3D index; + return block_dinfo; +} + +static int record_ramblock_hash_info(struct DirtyRateConfig config, + struct RamblockDirtyInfo **block_dinf= o, 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 af57c80..0812b16 100644 --- a/migration/dirtyrate.h +++ b/migration/dirtyrate.h @@ -20,10 +20,17 @@ #define DIRTYRATE_DEFAULT_SAMPLE_PAGES 256 =20 /* + * Sample page size 4K as default. + */ +#define DIRTYRATE_SAMPLE_PAGE_SIZE 4096 + +/* * Record ramblock idstr */ #define RAMBLOCK_INFO_MAX_LEN 256 =20 +#define QCRYPTO_HASH_LEN 16 + /* Take 1s as default for calculation duration */ #define DEFAULT_FETCH_DIRTYRATE_TIME_SEC 1 =20 --=20 1.8.3.1 From nobody Sun May 12 18:20:36 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=1597514761; cv=none; d=zohomail.com; s=zohoarc; b=PMJDbVux66z/TTa0qXWVmWp8iwVuuZSya6eJ4v/BI5pMHt1uPERmfWdkUxgomjH/YOtgETUH5JDdaSAFJdgBXyS8CC8eUpuIgTAD1YwOB+wpwwgBz4RinCJcRECM7OLMgvKc0NR9KzTRbb9gyracYIhVnbuU0QYGOREipBWBlW8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597514761; 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=UP7lj5sdpyJv4xK9jB7d0vbSnLD31HsjCLL17nSpu0Y=; b=Dc1+hP7ptDgfFlRbSSe4iYbAlnRmio75cC4VX0JscncVLsxQrsyqYuai+cadEzRiyyo2pxcoGVudE9sXfMBMWN1VNwkNspg6FLX6PawUo//6azRJV6YPH1YECzB9bFH/LVn8OnSuPPvMgg+Q0ujiyrNC3MT3TYemuQPzf1o6CJ4= 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 1597514761308529.4480745554238; Sat, 15 Aug 2020 11:06:01 -0700 (PDT) Received: from localhost ([::1]:39322 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k70Z6-00065R-0P for importer@patchew.org; Sat, 15 Aug 2020 14:06:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51834) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k70VL-0000xj-9z for qemu-devel@nongnu.org; Sat, 15 Aug 2020 14:02:07 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:57596 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 1k70VI-0007EB-9r for qemu-devel@nongnu.org; Sat, 15 Aug 2020 14:02:06 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 22AF23EF52AFBC26264C; Sat, 15 Aug 2020 10:11:17 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Sat, 15 Aug 2020 10:11:08 +0800 From: Chuan Zheng To: , , Subject: [PATCH v2 06/10] migration/dirtyrate: Compare page hash results for recorded sampled page Date: Sat, 15 Aug 2020 10:22:56 +0800 Message-ID: <1597458180-16945-7-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1597458180-16945-1-git-send-email-zhengchuan@huawei.com> References: <1597458180-16945-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.32; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/15 14:01:48 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, linyilu@huawei.com, qemu-devel@nongnu.org, 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" From: Zheng Chuan Compare page hash results for recorded sampled page. Signed-off-by: Zheng Chuan Signed-off-by: YanYing Zhuang --- migration/dirtyrate.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 73 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 11c0051..f136067 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -206,6 +206,79 @@ static int record_ramblock_hash_info(struct DirtyRateC= onfig config, return 0; } =20 +static int calc_page_dirty_rate(struct RamblockDirtyInfo *info) +{ + uint8_t *md =3D NULL; + int i; + int ret =3D 0; + + md =3D g_try_new0(uint8_t, qcrypto_hash_len); + if (!md) + return -1; + + for (i =3D 0; i < info->sample_pages_count; i++) { + ret =3D get_ramblock_vfn_hash(info, info->sample_page_vfn[i], &md); + if (ret < 0) { + goto out; + } + + if (memcmp(md, info->hash_result + i * qcrypto_hash_len, qcrypto_h= ash_len) !=3D 0) { + info->sample_dirty_count++; + } + } + +out: + g_free(md); + return ret; +} + +static bool find_page_matched(RAMBlock *block, struct RamblockDirtyInfo *i= nfos, + int count, struct RamblockDirtyInfo **match= ed) +{ + 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) >> 12)) { + return false; + } + + *matched =3D &infos[i]; + return true; +} + +static int compare_page_hash_info(struct RamblockDirtyInfo *info, int bloc= k_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 (!dirty_stat.total_sample_count) { + return -1; + } + + return 0; +} + static void calculate_dirtyrate(struct DirtyRateConfig config) { /* todo */ --=20 1.8.3.1 From nobody Sun May 12 18:20:36 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=1597514757; cv=none; d=zohomail.com; s=zohoarc; b=jGurIanIO5nFnP4YRVoYt0OmQAfIiwZuTWT1ucBELiCUJTu2YYKnrEJMRm/HkUop9YNsHrmRXyFEOxzV8O9i36LmUt74X/pAt4Jst2fhv8UGMjcEDicAJUDfw6gXLOCRfoZs5rrx2ZE8ZIlkdIcEBjhjLWoMg3oiAExt6mduMJ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597514757; 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=IkRlMYI4eF12YYYdIcUAXOT8d9YIDdcBqcArilTZreQ=; b=kokk8tFFQls8WqXav+gMUbkG3FqLQnH3wp3L3rSSYARPAeKQfIu6EI2/sNsCmFrivSAydA1ScbJyo+6DLZocBuEyfLvskpDx6vgaP5qDUo+QnZwm+dzkFYU/23qH55Z3CP/Do091oL8uzichVTTZoSA0o1+pzYgeZiKAUGBOrf4= 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 1597514757858431.5573891317041; Sat, 15 Aug 2020 11:05:57 -0700 (PDT) Received: from localhost ([::1]:38924 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k70Z2-0005uo-I3 for importer@patchew.org; Sat, 15 Aug 2020 14:05:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51838) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k70VM-00010S-G4 for qemu-devel@nongnu.org; Sat, 15 Aug 2020 14:02:08 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:57598 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 1k70VI-0007E9-7w for qemu-devel@nongnu.org; Sat, 15 Aug 2020 14:02:08 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id F2CB275511DCECD4CEE2; Sat, 15 Aug 2020 10:11:16 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Sat, 15 Aug 2020 10:11:08 +0800 From: Chuan Zheng To: , , Subject: [PATCH v2 07/10] migration/dirtyrate: skip sampling ramblock with size below MIN_RAMBLOCK_SIZE Date: Sat, 15 Aug 2020 10:22:57 +0800 Message-ID: <1597458180-16945-8-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1597458180-16945-1-git-send-email-zhengchuan@huawei.com> References: <1597458180-16945-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.32; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/15 14:01:48 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, linyilu@huawei.com, qemu-devel@nongnu.org, 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" From: Zheng Chuan In order to sample real RAM, skip ramblock with size below MIN_RAMBLOCK_SIZE which is 128M as default. Signed-off-by: Zheng Chuan --- migration/dirtyrate.c | 24 ++++++++++++++++++++++++ migration/dirtyrate.h | 5 +++++ 2 files changed, 29 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index f136067..3dc9feb 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -179,6 +179,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) >> 20; + + /* + * 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 DirtyRateConfig config, struct RamblockDirtyInfo **block_dinf= o, int *block_index) { @@ -188,6 +206,9 @@ static int record_ramblock_hash_info(struct DirtyRateCo= nfig config, 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; @@ -263,6 +284,9 @@ static int compare_page_hash_info(struct RamblockDirtyI= nfo *info, int block_inde 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 0812b16..fce2e3b 100644 --- a/migration/dirtyrate.h +++ b/migration/dirtyrate.h @@ -31,6 +31,11 @@ =20 #define QCRYPTO_HASH_LEN 16 =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 12 18:20:36 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=1597514822; cv=none; d=zohomail.com; s=zohoarc; b=afFzL7nY1OhqI0q2JRKPjyWD762/wxCcay6RvNJ1sShqbSkhlIwXGBi0A/lpflE4f1dR57je5qYAN0JMyXK6yQsJI6PjUgTnVQH/goWbVx1v9WIlXCqL4aWrHGTyAKnsry03vjPBPx1S57xhFx+pZtJ6EX02x85CO/mW89BzG6g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597514822; 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=q/TBqRDpjKo/2JDHL/6Cp78TdDYL82Ta6WyxRv7/Nss=; b=SQdK8Jg057fZTRo3qfiQso2X0tKdhgHDFv7DbdxHyh/jfWcWFvdfkxu5w2nOwTvqr33s1H2YWFG/Vd+Cg8lr3eKG59GCobb3GM6VtrhkQi7mRgygRDXup0V+Dna6e+kmBwG5dCUoVvrHhg1vIinjLSMp8O/W1cc5fPtVdMNZrQg= 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 1597514822711579.2026238996365; Sat, 15 Aug 2020 11:07:02 -0700 (PDT) Received: from localhost ([::1]:44494 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k70a5-00089F-Iv for importer@patchew.org; Sat, 15 Aug 2020 14:07:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51786) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k70VH-0000qh-9S for qemu-devel@nongnu.org; Sat, 15 Aug 2020 14:02:03 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:57322 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 1k70VE-0007DW-KY for qemu-devel@nongnu.org; Sat, 15 Aug 2020 14:02:02 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 0BE1E4B46BF3E1E7C17E; Sat, 15 Aug 2020 10:11:17 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Sat, 15 Aug 2020 10:11:09 +0800 From: Chuan Zheng To: , , Subject: [PATCH v2 08/10] migration/dirtyrate: Implement get_sample_page_period() and block_sample_page_period() Date: Sat, 15 Aug 2020 10:22:58 +0800 Message-ID: <1597458180-16945-9-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1597458180-16945-1-git-send-email-zhengchuan@huawei.com> References: <1597458180-16945-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.32; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/15 14:01:48 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, linyilu@huawei.com, qemu-devel@nongnu.org, 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" From: Zheng Chuan Implement get_sample_page_period() and set_sample_page_period() to sleep specific time between sample actions. Signed-off-by: Zheng Chuan Signed-off-by: YanYing Zhuang --- migration/dirtyrate.c | 23 +++++++++++++++++++++++ migration/dirtyrate.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 3dc9feb..54b832a 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -28,6 +28,29 @@ CalculatingDirtyRateState CalculatingState =3D CAL_DIRTY= _RATE_INIT; static unsigned long int qcrypto_hash_len =3D QCRYPTO_HASH_LEN; static struct DirtyRateStat dirty_stat; =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 dirty_rate_set_state(int new_state) { int old_state =3D CalculatingState; diff --git a/migration/dirtyrate.h b/migration/dirtyrate.h index fce2e3b..86d8fa0 100644 --- a/migration/dirtyrate.h +++ b/migration/dirtyrate.h @@ -38,6 +38,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 12 18:20:36 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=1597514635; cv=none; d=zohomail.com; s=zohoarc; b=k1EyJ1v5DtemtOE7zdm6nD8h3FS+Hqa0RVP7vZ63D/u3/Zw5nsaUhEhDxSYb9DxEoKsTw+LfR33EHTyl9OQMtWsY2B6E3StpHjhzSzzom/pi8BWBXkeDU7bgiNJFSTBIiu/QU27oKm5fkFs72Pm5LkXj5vocGsZgyIwH4dNqxG4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597514635; 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=LW4gbhefGD0390RgPYV/jo9OmocbVWfHMSpl653FyNU=; b=hYSGo2iGiPhKPtzaOYsP9XWB3Vew5ykTA97TmaopPd0mYtjwAxAYVo78pdn1tlaZr/GgIcMMdUhphAHTHpn9DHOiahcJeArwWpiS14pFuRv5Wj3KRgKHEY2dXv3q0mftjyStZq1XU2uTWgZ8VyE6umE7pDFUdgqFkXfA/5XPGqQ= 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 159751463518056.55202574623479; Sat, 15 Aug 2020 11:03:55 -0700 (PDT) Received: from localhost ([::1]:58740 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k70X3-0002Sm-T7 for importer@patchew.org; Sat, 15 Aug 2020 14:03:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51784) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k70VG-0000pu-J8 for qemu-devel@nongnu.org; Sat, 15 Aug 2020 14:02:02 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:57320 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 1k70VE-0007DT-Ii for qemu-devel@nongnu.org; Sat, 15 Aug 2020 14:02:02 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 07955CC715B2438D88AC; Sat, 15 Aug 2020 10:11:17 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Sat, 15 Aug 2020 10:11:09 +0800 From: Chuan Zheng To: , , Subject: [PATCH v2 09/10] migration/dirtyrate: Implement calculate_dirtyrate() function Date: Sat, 15 Aug 2020 10:22:59 +0800 Message-ID: <1597458180-16945-10-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1597458180-16945-1-git-send-email-zhengchuan@huawei.com> References: <1597458180-16945-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.32; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/15 14:01:48 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, linyilu@huawei.com, qemu-devel@nongnu.org, 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" From: Zheng Chuan Implement calculate_dirtyrate() function. Signed-off-by: Zheng Chuan Signed-off-by: YanYing Zhuang --- migration/dirtyrate.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 54b832a..d487030 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -177,6 +177,21 @@ static void get_ramblock_dirty_info(RAMBlock *block, s= truct RamblockDirtyInfo *i 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) @@ -328,8 +343,35 @@ static int compare_page_hash_info(struct RamblockDirty= Info *info, int block_inde =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(config, &block_dinfo, &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 12 18:20:36 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=1597514753; cv=none; d=zohomail.com; s=zohoarc; b=nhYxRXCn6e8Hi1KT+LTfiX2zYyEzuWXC72Hw0L0/s+C+OfhetGY0KBABBcd+MGbg2AMRBBDNO32EoHvmREvi3Qm9vHH/Gg9Rz50peCL9Lo7M6Nhwnpq71zqHzGqTaTJdLwtl/Fnn7FtVN4621FpTMGhJo0ymkVcv0Gjv/0OpFYc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597514753; 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=yTXelBVypTDRF+Cnv4h0qzM5AySHJyeTD5V5GLEjb8E=; b=GtuxKIhWzM0awBqJN5JTiQK4AQ/7fhVHVVCt/+pI+R6SwfY/L2PHJSK4soJ2V4+KfzskBY0NOQGPJGyVMKs59HIFjSEesNTODDVIh0bib05OGtJLrGrq2w3LQpA/W6WjkVfpqOuDR3qTbH4/l6brx0f42ygHqeeoIMipNIwDmos= 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 1597514753963730.2233370418847; Sat, 15 Aug 2020 11:05:53 -0700 (PDT) Received: from localhost ([::1]:38692 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k70Yy-0005pI-KS for importer@patchew.org; Sat, 15 Aug 2020 14:05:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51758) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k70VF-0000pN-BO for qemu-devel@nongnu.org; Sat, 15 Aug 2020 14:02:01 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:57328 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 1k70VD-0007DU-6y for qemu-devel@nongnu.org; Sat, 15 Aug 2020 14:02:01 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 102351BFD4E5DDCEF8C1; Sat, 15 Aug 2020 10:11:17 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Sat, 15 Aug 2020 10:11:10 +0800 From: Chuan Zheng To: , , Subject: [PATCH v2 10/10] migration/dirtyrate: Implement qmp_cal_dirty_rate()/qmp_get_dirty_rate() function Date: Sat, 15 Aug 2020 10:23:00 +0800 Message-ID: <1597458180-16945-11-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1597458180-16945-1-git-send-email-zhengchuan@huawei.com> References: <1597458180-16945-1-git-send-email-zhengchuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.32; envelope-from=zhengchuan@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/15 14:01:48 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, linyilu@huawei.com, qemu-devel@nongnu.org, 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" From: Zheng Chuan Implement qmp_cal_dirty_rate()/qmp_get_dirty_rate() function which could be= called Signed-off-by: Zheng Chuan --- migration/dirtyrate.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ qapi/migration.json | 42 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index d487030..bf8fe9e 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -66,6 +66,39 @@ static int dirty_rate_set_state(int new_state) return 0; } =20 +static struct DirtyRateInfo *query_dirty_rate_info(void) +{ + int64_t dirty_rate =3D dirty_stat.dirty_rate; + struct DirtyRateInfo *info =3D g_malloc0(sizeof(DirtyRateInfo)); + + switch(CalculatingState) { + case CAL_DIRTY_RATE_INIT: + info->dirty_rate =3D -1; + info->status =3D g_strdup("Not start measuring"); + break; + case CAL_DIRTY_RATE_ACTIVE: + info->dirty_rate =3D -1; + info->status =3D g_strdup("Still measuring"); + break; + case CAL_DIRTY_RATE_END: + info->dirty_rate =3D dirty_rate; + info->status =3D g_strdup("Measured"); + break; + default: + info->dirty_rate =3D -1; + info->status =3D g_strdup("Unknown status"); + break; + } + + /* + * Only support query once for each calculation, + * reset as CAL_DIRTY_RATE_INIT after query + */ + (void)dirty_rate_set_state(CAL_DIRTY_RATE_INIT); + + return info; +} + static void reset_dirtyrate_stat(void) { dirty_stat.total_dirty_samples =3D 0; @@ -390,3 +423,26 @@ void *get_dirtyrate_thread(void *arg) =20 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 CAL_DIRTY_RATE_ACTIVE) { + 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 d500055..ccc7a4e 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -1621,3 +1621,45 @@ ## { 'event': 'UNPLUG_PRIMARY', 'data': { 'device-id': 'str' } } + +## +# @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 +# status with 'not start measuring' or +# 'Still measuring' or 'measured'(since 5.2) +## +{ 'struct': 'DirtyRateInfo', + 'data': {'dirty-rate': 'int64', + 'status': 'str'} } + +## +# @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