From nobody Tue Feb 10 13:17:20 2026 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