From nobody Fri May 10 05:35:01 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=1597633879; cv=none; d=zohomail.com; s=zohoarc; b=i2sI+YiWgAm6lb7rhHwsfLCkSQtHI8OkMkf7by7luR+inzLVmQv+WX6M+9fbc47IEpnuNa0+Z74fLMXkv8KpfwIq4RFyjSq0A0tjj66Gw6MCPi3ud0HTWJPiCW+96LO44zzibsMW7cAlNE3AHu3lD84tqHK+pxfZlpOERLuMRYI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597633879; 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=4cNv28Y5r7Z5dOm5FTZSdvRljSFbhWk9q72LeUX1QKA=; b=SHazA+wuncGY9HWehQMUnp5HnOwwwpDWy/yaj++Nbq4IuxB+wcbnQtzxL7yprpn0Ht6fQsnsDeWXm2fQxKnH6xx5J2b7ZNxwHIUDYOvGIAOlYbkqBdoZNRGH6fQ/2eGdj2lFFJbEZHH2D8ljJofSSDAGlY46xqYNP55Htv+UHGg= 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 1597633879392945.6955888709737; Sun, 16 Aug 2020 20:11:19 -0700 (PDT) Received: from localhost ([::1]:39156 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k7VYM-0002oP-4m for importer@patchew.org; Sun, 16 Aug 2020 23:11:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37202) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k7VWA-0006C8-BW for qemu-devel@nongnu.org; Sun, 16 Aug 2020 23:09:02 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:56670 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 1k7VW7-0008IW-R8 for qemu-devel@nongnu.org; Sun, 16 Aug 2020 23:09:02 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id B1789AF81AE59B1B1318; Mon, 17 Aug 2020 11:08:48 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Mon, 17 Aug 2020 11:08:42 +0800 From: Chuan Zheng To: , , Subject: [PATCH v3 01/10] migration/dirtyrate: Add get_dirtyrate_thread() function Date: Mon, 17 Aug 2020 11:20:24 +0800 Message-ID: <1597634433-18809-2-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1597634433-18809-1-git-send-email-zhengchuan@huawei.com> References: <1597634433-18809-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/16 23:08:49 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" Add get_dirtyrate_thread() functions Signed-off-by: Chuan Zheng 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 Fri May 10 05:35:01 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=1597633882; cv=none; d=zohomail.com; s=zohoarc; b=FgVLBpuXZp+qWVmLjievBATX7VgFTmsG0LX/wU9ogc4VL4wX3tX6wlVDumUfr8SCoPvcX3VKHDKhmD7PthIypp6gLXud94QcMLyUxju99lMSgqwK9kk7SK5lFcPjwxNgeRFrFzUN6bP54tCFLNcxLutPSA27amJ+5pBQmyX2bCg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597633882; 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=/GYdklFvIXNFtfETUQSmWoJSROgSru851v95NPiTT3U=; b=GTmMpbSr0Zz4bOVo0pr3AybcDYWqSOrmamVJTeUTabp4ODRq+Rab0dTW2CngCdo3FJXptOi1g/pAqVYGEacR+ZddtZ4h/+TgwIaJPMa4youQ3/SQXucVi/Sq+kYReEBcmnWFnnVPKwXNJxw6gOGMgTB5EwSr0+q+I+eS5GsNyL8= 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 1597633881901403.72010615110787; Sun, 16 Aug 2020 20:11:21 -0700 (PDT) Received: from localhost ([::1]:39432 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k7VYO-0002vA-Qe for importer@patchew.org; Sun, 16 Aug 2020 23:11:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37260) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k7VWF-0006Lj-0p for qemu-devel@nongnu.org; Sun, 16 Aug 2020 23:09:07 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:4257 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 1k7VWD-0008Nt-7H for qemu-devel@nongnu.org; Sun, 16 Aug 2020 23:09:06 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id E4CA65F7A3CFEA6F08B5; Mon, 17 Aug 2020 11:08:53 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Mon, 17 Aug 2020 11:08:43 +0800 From: Chuan Zheng To: , , Subject: [PATCH v3 02/10] migration/dirtyrate: Add RamlockDirtyInfo to store sampled page info Date: Mon, 17 Aug 2020 11:20:25 +0800 Message-ID: <1597634433-18809-3-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1597634433-18809-1-git-send-email-zhengchuan@huawei.com> References: <1597634433-18809-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/16 23:08:53 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" Add RamlockDirtyInfo to store sampled page info of each ramblock. Signed-off-by: Chuan Zheng Signed-off-by: YanYing Zhuang --- 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 Fri May 10 05:35:01 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=1597633805; cv=none; d=zohomail.com; s=zohoarc; b=en2NAFeB1RcSVAmSN2TIBnR48E6ijIWw+nMP5/AEbSqTMOIK8j+P8ZMW7TpGxaEojBYWL6acJvYUZrQ7sRLGCoqfIPWWOCKEZBfn16l2qlLobowuv2jj94wSIJ8e2Q0obxBuQ48aC4N8vmtmoov0CmB3lVmLhIv71+LloGwm3VY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597633805; 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=cFy1ok3JqAR8grIi0lDi8lAKXBAb6jbOT6LHWtWcELk=; b=JYXxQ5LI6UaEHJleDytfsI4bvyAlgMZSWQbACg4fghibdcbj9/RFuf6pXVoax6wBbVKz7EdRsXOIhIr4viz4Fa2XpcXmQsXKiKZEgwF3/BAw3Rw6I3FymncrQ32PbL9XRE7qE8E+wGkZR5kMuCRVKPt5BBMyFki7HTyqOH+/lws= 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 1597633805741928.5340219245933; Sun, 16 Aug 2020 20:10:05 -0700 (PDT) Received: from localhost ([::1]:60290 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k7VXA-0008AP-5C for importer@patchew.org; Sun, 16 Aug 2020 23:10:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37224) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k7VWB-0006Cv-BD for qemu-devel@nongnu.org; Sun, 16 Aug 2020 23:09:03 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:4252 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 1k7VW8-0008Lw-6K for qemu-devel@nongnu.org; Sun, 16 Aug 2020 23:09:03 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id C1136D4C214A9D7FD99A; Mon, 17 Aug 2020 11:08:53 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Mon, 17 Aug 2020 11:08:43 +0800 From: Chuan Zheng To: , , Subject: [PATCH v3 03/10] migration/dirtyrate: Add dirtyrate statistics series functions Date: Mon, 17 Aug 2020 11:20:26 +0800 Message-ID: <1597634433-18809-4-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1597634433-18809-1-git-send-email-zhengchuan@huawei.com> References: <1597634433-18809-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/16 23:08:53 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" Add dirtyrate statistics to record/update dirtyrate info. Signed-off-by: Chuan Zheng Signed-off-by: YanYing Zhuang --- 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 Fri May 10 05:35:01 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=1597634054; cv=none; d=zohomail.com; s=zohoarc; b=F5/gpR1zIKDf6HL071ghWJoim1lnCJJAtIQGf068erOcAQ9uFOFqP6ULQZdYIkXFOPr/qFVJp0tD//0BxwOrKfdyXZkPeztIKg5tIcdC6pZoPLdA2C7mpT7N9SdRguEyy2o2tQy/oTb2Zxv0ZcvWJsem74vW8HXwkJJbx4bneik= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597634054; 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=XuqYwuNs+U33F09Pj22ul2kHay66en9XG0YRjsB2+ao=; b=nr2TKAYuFjhkEOIDJgrpsmc9NUasexnHpYGycxNAaI9TI+x/vrkS5IAx4ler6AjjFS5xoczyj7MdbTs8elPE/ReOYSZFQqs9m0ET4Yz95PwBBzmwJ/V+NrVEIJWc768tEn0w/NKGyK1PzEldhm9jQJ4OEgCjiRGK02DGpgyxrI0= 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 1597634054632263.870817573998; Sun, 16 Aug 2020 20:14:14 -0700 (PDT) Received: from localhost ([::1]:48258 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k7VbB-0006Yl-Er for importer@patchew.org; Sun, 16 Aug 2020 23:14:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37290) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k7VWG-0006PR-Aj for qemu-devel@nongnu.org; Sun, 16 Aug 2020 23:09:08 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:4260 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 1k7VWD-0008O2-H2 for qemu-devel@nongnu.org; Sun, 16 Aug 2020 23:09:07 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 037B713E220501C35A81; Mon, 17 Aug 2020 11:08:54 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Mon, 17 Aug 2020 11:08:44 +0800 From: Chuan Zheng To: , , Subject: [PATCH v3 04/10] migration/dirtyrate: move RAMBLOCK_FOREACH_MIGRATABLE into ram.h Date: Mon, 17 Aug 2020 11:20:27 +0800 Message-ID: <1597634433-18809-5-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1597634433-18809-1-git-send-email-zhengchuan@huawei.com> References: <1597634433-18809-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/16 23:08:53 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" RAMBLOCK_FOREACH_MIGRATABLE is need in dirtyrate measure, move the existing definition up into migration/ram.h Signed-off-by: Chuan Zheng Signed-off-by: YanYing Zhuang Reviewed-by: Dr. David Alan Gilbert --- migration/dirtyrate.c | 1 + migration/ram.c | 11 +---------- migration/ram.h | 10 ++++++++++ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 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 Fri May 10 05:35:01 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=1597633996; cv=none; d=zohomail.com; s=zohoarc; b=VXbShhgHLmhf99XpVwC9TCydgQZoeD8guDbEbCxYT3ggiTLR/xYyAB1hwyC874zH7ZIqGTivTUCw3xdmNPeBp0q5115Es/pw3B+uo4q4oiI70KPQCqOZlPD/c3I0IhZ4P/0JPuD9dwMdYANU/qgOe8t6oRb8F5ZnSXSBbZfWjyk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597633996; 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=TlOSNHLWIbt1XK/CsefHb3DauiOMCNQOgBE4sYOIXcs=; b=grpyUM3vNfYjx94TJXoGGhGceLVY7xKJ4a0umwEvLB5SQ6jzRow5yyPHYaM0ui0/zaR7bfARVIEiQbKAfeSScbQpwF1kV8z/JuwBhYdE21iuF0OR+1S/3CKyz6cCoC9V35Mg2F4HN5IOlE7A0quxW8LnCoYXGLXxdR8Va+02MCM= 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 1597633996133735.9997101432856; Sun, 16 Aug 2020 20:13:16 -0700 (PDT) Received: from localhost ([::1]:45692 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k7VaF-0005Uv-1S for importer@patchew.org; Sun, 16 Aug 2020 23:13:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37262) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k7VWF-0006M9-6u for qemu-devel@nongnu.org; Sun, 16 Aug 2020 23:09:07 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:4258 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 1k7VWD-0008Ns-77 for qemu-devel@nongnu.org; Sun, 16 Aug 2020 23:09:06 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id EA8B2FB32EF2ADD94A56; Mon, 17 Aug 2020 11:08:53 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Mon, 17 Aug 2020 11:08:45 +0800 From: Chuan Zheng To: , , Subject: [PATCH v3 05/10] migration/dirtyrate: Record hash results for each sampled page Date: Mon, 17 Aug 2020 11:20:28 +0800 Message-ID: <1597634433-18809-6-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1597634433-18809-1-git-send-email-zhengchuan@huawei.com> References: <1597634433-18809-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/16 23:08:53 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" Record hash results for each sampled page. Signed-off-by: Chuan Zheng Signed-off-by: YanYing Zhuang --- migration/dirtyrate.c | 144 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ migration/dirtyrate.h | 7 +++ 2 files changed, 151 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index c4304ef..62b6f69 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,149 @@ 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; + size_t hash_len =3D qcrypto_hash_len; + + 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, &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(unsigned 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->ramblock_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 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) >> 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 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 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 Fri May 10 05:35:01 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=1597633944; cv=none; d=zohomail.com; s=zohoarc; b=Cdb0WKHFvGtlUF4718qzeVBSb2OJMN+3xotmg+2hwkze1wtyjDzIiqo0Q+GL8rGMEYfVM9WltYHegqz1nEY9hlpD3qqfofvDhl+9q8y7rlRs6vQzJwxhXmNRv+0JWjnLZhlaBwLp6Wk3tPl9cltbMV774hbeEyTcDuLw4TQd0TQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597633944; 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=Eds85pmKDsMrXPirQlSqAvTDZWTi5hecHZOJY4ir9Fo=; b=Qb5YecdFCyvJZm/ZRxEuQFt9kbCsOHu2TQ0x964pJQJdwfbVWPtdruphfyhFtADABhv1t/tSJeE0k+GapYKJdATzoHCKb3pxB4OLSnSA60sWB3dNJjf1DXioc0WKlyLAxHvIfcPz5EDg/R6XRB0XbykOmkoA7xBBE+gFBqvD5LI= 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 159763394488610.393563206517115; Sun, 16 Aug 2020 20:12:24 -0700 (PDT) Received: from localhost ([::1]:43592 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k7VZP-0004cE-Nk for importer@patchew.org; Sun, 16 Aug 2020 23:12:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37226) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k7VWB-0006DS-L9 for qemu-devel@nongnu.org; Sun, 16 Aug 2020 23:09:03 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:4256 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 1k7VW8-0008M0-LR for qemu-devel@nongnu.org; Sun, 16 Aug 2020 23:09:03 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id DD027E72928D3028BC1E; Mon, 17 Aug 2020 11:08:53 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Mon, 17 Aug 2020 11:08:45 +0800 From: Chuan Zheng To: , , Subject: [PATCH v3 06/10] migration/dirtyrate: Compare page hash results for recorded sampled page Date: Mon, 17 Aug 2020 11:20:29 +0800 Message-ID: <1597634433-18809-7-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1597634433-18809-1-git-send-email-zhengchuan@huawei.com> References: <1597634433-18809-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/16 23:08:53 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" Compare page hash results for recorded sampled page. Signed-off-by: Chuan Zheng Signed-off-by: YanYing Zhuang --- migration/dirtyrate.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 76 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 62b6f69..3ce25f5 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -215,6 +215,82 @@ static int record_ramblock_hash_info(struct RamblockDi= rtyInfo **block_dinfo, 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_hash_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 **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) >> 12)) { + 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 (!dirty_stat.total_sample_count) { + return -1; + } + + return 0; +} + static void calculate_dirtyrate(struct DirtyRateConfig config) { /* todo */ --=20 1.8.3.1 From nobody Fri May 10 05:35:01 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=1597633878; cv=none; d=zohomail.com; s=zohoarc; b=OrAj05oxffWWjFFS+2esLJ4MuSjjgy9wautpd+e5+LcKM1WnlNsrdrYWFeLXa10jBXb45bfKRkQapSY0L9L0QfhyHGI570ON5K9Y4qS3dr/HpXKqdvH56ESzGQrE3Wmz28Qb1tXYrYFIgUjQ/tXL1l3Uxlq44tvcOr8u7pv9CCI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597633878; 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=gZ76HwcCLgIAkTiC5SnzrubKW5Q5VtEqLfV/o6SS0kc=; b=F/w4/5hgSRzQLog9aks50E7Y/bhyvM4sCOlDeVsETF7DoZLk9DkK6pKX4KYK8jRulAF7MBhUKuOhoJQlYhWJsS/RZ7eqeDwnwLq97hr7nYizGTYmA9np/rZC4ur9mswJprD5qe2Rjt39pvj7X6rqBP7oS16RCkKHJJWcSajniaQ= 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 15976338788981018.4073913316346; Sun, 16 Aug 2020 20:11:18 -0700 (PDT) Received: from localhost ([::1]:39168 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k7VYL-0002od-PD for importer@patchew.org; Sun, 16 Aug 2020 23:11:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37232) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k7VWC-0006Fy-SY for qemu-devel@nongnu.org; Sun, 16 Aug 2020 23:09:04 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:4255 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 1k7VW8-0008Lz-6W for qemu-devel@nongnu.org; Sun, 16 Aug 2020 23:09:04 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id D61DD245FA2452E21830; Mon, 17 Aug 2020 11:08:53 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Mon, 17 Aug 2020 11:08:46 +0800 From: Chuan Zheng To: , , Subject: [PATCH v3 07/10] migration/dirtyrate: skip sampling ramblock with size below MIN_RAMBLOCK_SIZE Date: Mon, 17 Aug 2020 11:20:30 +0800 Message-ID: <1597634433-18809-8-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1597634433-18809-1-git-send-email-zhengchuan@huawei.com> References: <1597634433-18809-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/16 23:08:53 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" In order to sample real RAM, skip ramblock with size below Signed-off-by: Chuan Zheng Reviewed-by: Dr. David Alan Gilbert --- migration/dirtyrate.c | 24 ++++++++++++++++++++++++ migration/dirtyrate.h | 5 +++++ 2 files changed, 29 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 3ce25f5..6f30f67 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -186,6 +186,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 RamblockDirtyInfo **block_dinf= o, struct DirtyRateConfig config, int *block_index) @@ -196,6 +214,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; @@ -275,6 +296,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 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 Fri May 10 05:35:01 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=1597633802; cv=none; d=zohomail.com; s=zohoarc; b=M6V7Hg1ZtrNb2u8HBuGw/LPHE6sfW9b3kRiQxBRPvUKRzBerxz4DcuwZ681NrKIxjPUk+WqF2DfpsSU1RE+xuzPnITp1PXuUmkrpgwkDPK55WNGpW+LVJytVozOvwN3DMmH2qDj948pA9yhMBPyXZcqbeRNeyPMUQ6RnK3Oa8YY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597633802; 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=TevBsdEht/MEOZay1zQJVhuMjT2JnZEdvVXZ6FmWLuU=; b=PDQOXPoDCnXWf8qXBtXlEzntG/r3IRdC3KyI/r73VYDC5voQVXWPs18RikL+7l9wTIojsdEKv85RBz262MO1nHD0sdx+XZyyhrkFdszL88eKrYgN5Py0ciOYciFiwzGmDnj0C+8SSRVfSOwAK5x8Zx+0rkp+AmICvCR17qylCDg= 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 1597633802265344.2085713861809; Sun, 16 Aug 2020 20:10:02 -0700 (PDT) Received: from localhost ([::1]:59888 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k7VX5-000809-Sk for importer@patchew.org; Sun, 16 Aug 2020 23:09:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37218) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k7VWA-0006CR-T2 for qemu-devel@nongnu.org; Sun, 16 Aug 2020 23:09:02 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:4253 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 1k7VW8-0008Lx-05 for qemu-devel@nongnu.org; Sun, 16 Aug 2020 23:09:02 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id C81C5990C91F808F6A2D; Mon, 17 Aug 2020 11:08:53 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Mon, 17 Aug 2020 11:08:46 +0800 From: Chuan Zheng To: , , Subject: [PATCH v3 08/10] migration/dirtyrate: Implement get_sample_page_period() and block_sample_page_period() Date: Mon, 17 Aug 2020 11:20:31 +0800 Message-ID: <1597634433-18809-9-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1597634433-18809-1-git-send-email-zhengchuan@huawei.com> References: <1597634433-18809-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/16 23:08:53 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" Implement get_sample_page_period() and set_sample_page_period() to sleep specific time between sample actions. Signed-off-by: Chuan Zheng Signed-off-by: YanYing Zhuang Reviewed-by: Dr. David Alan Gilbert --- migration/dirtyrate.c | 24 ++++++++++++++++++++++++ migration/dirtyrate.h | 2 ++ 2 files changed, 26 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 6f30f67..4bbfcc3 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -28,6 +28,30 @@ 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 Fri May 10 05:35:01 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=1597633803; cv=none; d=zohomail.com; s=zohoarc; b=P4CbCWo65ayrcgD+4JI8GNS/41rWnXuycg2Tk1A4BrRu8YyY00bP8j9sP9mGpp2ItythQ91qJhgx+Vi2eiQLtq1i6IcMujqU66uPRsiXYHORrKc5BLDDQyqGjEh5n12h556FrDr2N7gdnEUon+66wka/kk74It5f6vFcrglG3Nk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597633803; 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=VsBefyzr65PVLbWRjPfoTM4z5q5Fmb6EsfR413ELRJA=; b=PZb9wIPiKxEy+T5zieWNYbkCNaspzPxrDM9Moz2AN5U9Zy1gv7ucPj7X/HQkZ79c3kEMniu0D8X2TcTSN3jDLPSTLEWbYM42KPrF+vzOqfuuYnq+OrQoky4gSIFMswgSpR4VD2tpcJeicmmr2jW96+ekbVYNiJBaBILwC69LzII= 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 1597633803627328.60531065749774; Sun, 16 Aug 2020 20:10:03 -0700 (PDT) Received: from localhost ([::1]:60086 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k7VX8-00085B-CA for importer@patchew.org; Sun, 16 Aug 2020 23:10:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37222) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k7VWB-0006Cg-5y for qemu-devel@nongnu.org; Sun, 16 Aug 2020 23:09:03 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:4254 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 1k7VW8-0008Ly-6G for qemu-devel@nongnu.org; Sun, 16 Aug 2020 23:09:02 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id CF076FF750B5AF333365; Mon, 17 Aug 2020 11:08:53 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Mon, 17 Aug 2020 11:08:47 +0800 From: Chuan Zheng To: , , Subject: [PATCH v3 09/10] migration/dirtyrate: Implement calculate_dirtyrate() function Date: Mon, 17 Aug 2020 11:20:32 +0800 Message-ID: <1597634433-18809-10-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1597634433-18809-1-git-send-email-zhengchuan@huawei.com> References: <1597634433-18809-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/16 23:08:53 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" Implement calculate_dirtyrate() function. Signed-off-by: Chuan Zheng Signed-off-by: YanYing Zhuang Reviewed-by: Dr. David Alan Gilbert --- migration/dirtyrate.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 4bbfcc3..041d0c6 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -184,6 +184,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) @@ -341,8 +356,35 @@ 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 Fri May 10 05:35:01 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=1597634125; cv=none; d=zohomail.com; s=zohoarc; b=K88TAqBG4OAEh1/5PqKNWj77JEXiIRG9GwH37YJ4b+eNhULYEkbjXQEt/WB2om42qDM/gstaBzgeNzdghbgSt7izX5XjEJiDcY9vFeFdQ29YMrUEu9oQTGTH28fIuuKBkFwzIIHJHAJZTddmrP2Nj5GuY7nhrtnD+ur7z5B26zY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597634125; 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=CnHy+1hnwR5SNJx/KUUJdfJS0OFxx70Vdv/N4BqsAD8=; b=erJp8lWwujdcvJ2r885CXiZuzsp78mYqeUBFlhpbeuI9W62zoqvz0NxpkLj5EyUhDEjzPK4Du1FBo8Wl/FuXDIVWHtD7tPE8G/erCYi9mkoW0Dw3cb1m4pfWXdwAhGSjxpS5DPFD94DndCs4C0HMJF+j5t0iYHbUhqNYur3V+yk= 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 1597634125656941.1014574615941; Sun, 16 Aug 2020 20:15:25 -0700 (PDT) Received: from localhost ([::1]:51964 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k7VcJ-00084d-A7 for importer@patchew.org; Sun, 16 Aug 2020 23:15:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37292) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k7VWG-0006Q4-Kn for qemu-devel@nongnu.org; Sun, 16 Aug 2020 23:09:08 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:4259 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 1k7VWD-0008O3-H6 for qemu-devel@nongnu.org; Sun, 16 Aug 2020 23:09:08 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id F1C4943269D3FFB1A9ED; Mon, 17 Aug 2020 11:08:53 +0800 (CST) Received: from huawei.com (10.175.101.6) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Mon, 17 Aug 2020 11:08:47 +0800 From: Chuan Zheng To: , , Subject: [PATCH v3 10/10] migration/dirtyrate: Implement qmp_cal_dirty_rate()/qmp_get_dirty_rate() function Date: Mon, 17 Aug 2020 11:20:33 +0800 Message-ID: <1597634433-18809-11-git-send-email-zhengchuan@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1597634433-18809-1-git-send-email-zhengchuan@huawei.com> References: <1597634433-18809-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/16 23:08:53 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" Implement qmp_cal_dirty_rate()/qmp_get_dirty_rate() function which could be= called Signed-off-by: Chuan Zheng --- migration/dirtyrate.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ qapi/migration.json | 42 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 041d0c6..0e8c9c5 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -67,6 +67,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; @@ -403,3 +436,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