From nobody Sat Jul 12 04:31:44 2025 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1623250277; cv=none; d=zohomail.com; s=zohoarc; b=idc8J7vz7Ic5Gdue0cs56wwwjbqr4lE/AihckXt205Sb/whMpbdTVLUws5g2PrEUODCHWzlVSUhdjtg6b5GyjnISb9hxMrpCLYMQOSS8ZqV86bA/Gg+TkfgJ6ilUtfUcYa5m1j/3avCGeQ1quNkZ+E2I83gytQ0oOmjdymi80Tk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623250277; h=Content-Type:Content-Transfer-Encoding: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=5BEx2+s+dEa5eKj92PIDgwGF7hnX67z4SFsPH9sRzU8=; b=PaBLwoJba78IAXt4knbqeP0cRdIArX1o0cExmdn6q1WIyh9lE7N5P5L/uobkKJJrX2p1K1V6IoBzjO3GDC6Ubg0SymHu6fEBH7fK7cTmX4CTSecCW/AdNYyOqbqoZoxRsLEunM1HDra1hvcM2d+/tfK2z3LDUk+OpnKeOpecAeI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162325027715486.01038141855531; Wed, 9 Jun 2021 07:51:17 -0700 (PDT) Received: from localhost ([::1]:54428 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqzY4-00067u-5O for importer2@patchew.org; Wed, 09 Jun 2021 10:51:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44640) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqzT0-0003p0-4n for qemu-devel@nongnu.org; Wed, 09 Jun 2021 10:46:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:20181) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqzSw-0005Zw-Qf for qemu-devel@nongnu.org; Wed, 09 Jun 2021 10:46:00 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-451-Jlc9W2g5NvuKcYJ-jGlQeA-1; Wed, 09 Jun 2021 10:45:51 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 50482100C66F; Wed, 9 Jun 2021 14:45:50 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-113-168.ams2.redhat.com [10.36.113.168]) by smtp.corp.redhat.com (Postfix) with ESMTP id ABA8710016FE; Wed, 9 Jun 2021 14:45:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623249958; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5BEx2+s+dEa5eKj92PIDgwGF7hnX67z4SFsPH9sRzU8=; b=hlAszijwqunPQ3YJGRGlbg00LbsUGfBDHLmR0NHs1Mvz34iBtJcqYMKQjfeGDsxC0EhMci A15QdPAe48vMF1nenenWlN8xpbjX7/LC8v6AAYuLsDLQnJGQdzhyritg98FZuMohvHrh7A vMA30wRjLdvFfzvV6nSfrXBLORWZ6Jk= X-MC-Unique: Jlc9W2g5NvuKcYJ-jGlQeA-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, huangy81@chinatelecom.cn, peterx@redhat.com, lizhijian@cn.fujitsu.com, leobras.c@gmail.com, pabeni@redhat.com Subject: [PULL 8/9] migration/dirtyrate: make sample page count configurable Date: Wed, 9 Jun 2021 15:45:11 +0100 Message-Id: <20210609144512.211746-9-dgilbert@redhat.com> In-Reply-To: <20210609144512.211746-1-dgilbert@redhat.com> References: <20210609144512.211746-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.199, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) From: Hyman Huang(=E9=BB=84=E5=8B=87) introduce optional sample-pages argument in calc-dirty-rate, making sample page count per GB configurable so that more accurate dirtyrate can be calculated. Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) Message-Id: <3103453a3b2796f929269c99a6ad81a9a7f1f405.1623027729.git.huangy= 81@chinatelecom.cn> Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Dr. David Alan Gilbert Wrapped a couple of long lines --- migration/dirtyrate.c | 31 +++++++++++++++++++++++++++---- migration/dirtyrate.h | 8 +++++++- qapi/migration.json | 15 ++++++++++++--- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index ccb98147e8..2ee3890721 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -48,6 +48,12 @@ static bool is_sample_period_valid(int64_t sec) return true; } =20 +static bool is_sample_pages_valid(int64_t pages) +{ + return pages >=3D MIN_SAMPLE_PAGE_COUNT && + pages <=3D MAX_SAMPLE_PAGE_COUNT; +} + static int dirtyrate_set_state(int *state, int old_state, int new_state) { assert(new_state < DIRTY_RATE_STATUS__MAX); @@ -72,13 +78,15 @@ static struct DirtyRateInfo *query_dirty_rate_info(void) info->status =3D CalculatingState; info->start_time =3D DirtyStat.start_time; info->calc_time =3D DirtyStat.calc_time; + info->sample_pages =3D DirtyStat.sample_pages; =20 trace_query_dirty_rate_info(DirtyRateStatus_str(CalculatingState)); =20 return info; } =20 -static void init_dirtyrate_stat(int64_t start_time, int64_t calc_time) +static void init_dirtyrate_stat(int64_t start_time, int64_t calc_time, + uint64_t sample_pages) { DirtyStat.total_dirty_samples =3D 0; DirtyStat.total_sample_count =3D 0; @@ -86,6 +94,7 @@ static void init_dirtyrate_stat(int64_t start_time, int64= _t calc_time) DirtyStat.dirty_rate =3D -1; DirtyStat.start_time =3D start_time; DirtyStat.calc_time =3D calc_time; + DirtyStat.sample_pages =3D sample_pages; } =20 static void update_dirtyrate_stat(struct RamblockDirtyInfo *info) @@ -361,6 +370,7 @@ void *get_dirtyrate_thread(void *arg) int ret; int64_t start_time; int64_t calc_time; + uint64_t sample_pages; =20 ret =3D dirtyrate_set_state(&CalculatingState, DIRTY_RATE_STATUS_UNSTA= RTED, DIRTY_RATE_STATUS_MEASURING); @@ -371,7 +381,8 @@ void *get_dirtyrate_thread(void *arg) =20 start_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME) / 1000; calc_time =3D config.sample_period_seconds; - init_dirtyrate_stat(start_time, calc_time); + sample_pages =3D config.sample_pages_per_gigabytes; + init_dirtyrate_stat(start_time, calc_time, sample_pages); =20 calculate_dirtyrate(config); =20 @@ -383,7 +394,8 @@ void *get_dirtyrate_thread(void *arg) return NULL; } =20 -void qmp_calc_dirty_rate(int64_t calc_time, Error **errp) +void qmp_calc_dirty_rate(int64_t calc_time, bool has_sample_pages, + int64_t sample_pages, Error **errp) { static struct DirtyRateConfig config; QemuThread thread; @@ -404,6 +416,17 @@ void qmp_calc_dirty_rate(int64_t calc_time, Error **er= rp) return; } =20 + if (has_sample_pages) { + if (!is_sample_pages_valid(sample_pages)) { + error_setg(errp, "sample-pages is out of range[%d, %d].", + MIN_SAMPLE_PAGE_COUNT, + MAX_SAMPLE_PAGE_COUNT); + return; + } + } else { + sample_pages =3D DIRTYRATE_DEFAULT_SAMPLE_PAGES; + } + /* * Init calculation state as unstarted. */ @@ -415,7 +438,7 @@ void qmp_calc_dirty_rate(int64_t calc_time, Error **err= p) } =20 config.sample_period_seconds =3D calc_time; - config.sample_pages_per_gigabytes =3D DIRTYRATE_DEFAULT_SAMPLE_PAGES; + config.sample_pages_per_gigabytes =3D sample_pages; qemu_thread_create(&thread, "get_dirtyrate", get_dirtyrate_thread, (void *)&config, QEMU_THREAD_DETACHED); } diff --git a/migration/dirtyrate.h b/migration/dirtyrate.h index 6ec429534d..e1fd29089e 100644 --- a/migration/dirtyrate.h +++ b/migration/dirtyrate.h @@ -15,7 +15,6 @@ =20 /* * Sample 512 pages per GB as default. - * TODO: Make it configurable. */ #define DIRTYRATE_DEFAULT_SAMPLE_PAGES 512 =20 @@ -35,6 +34,12 @@ #define MIN_FETCH_DIRTYRATE_TIME_SEC 1 #define MAX_FETCH_DIRTYRATE_TIME_SEC 60 =20 +/* + * Take 1/16 pages in 1G as the maxmum sample page count + */ +#define MIN_SAMPLE_PAGE_COUNT 128 +#define MAX_SAMPLE_PAGE_COUNT 16384 + struct DirtyRateConfig { uint64_t sample_pages_per_gigabytes; /* sample pages per GB */ int64_t sample_period_seconds; /* time duration between two sampling */ @@ -63,6 +68,7 @@ struct DirtyRateStat { int64_t dirty_rate; /* dirty rate in MB/s */ int64_t start_time; /* calculation start time in units of second */ int64_t calc_time; /* time duration of two sampling in units of second= */ + uint64_t sample_pages; /* sample pages per GB */ }; =20 void *get_dirtyrate_thread(void *arg); diff --git a/qapi/migration.json b/qapi/migration.json index 7a5bdf9a0d..1124a2dda8 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -1740,6 +1740,9 @@ # # @calc-time: time in units of second for sample dirty pages # +# @sample-pages: page count per GB for sample dirty pages +# the default value is 512 (since 6.1) +# # Since: 5.2 # ## @@ -1747,7 +1750,8 @@ 'data': {'*dirty-rate': 'int64', 'status': 'DirtyRateStatus', 'start-time': 'int64', - 'calc-time': 'int64'} } + 'calc-time': 'int64', + 'sample-pages': 'uint64'} } =20 ## # @calc-dirty-rate: @@ -1756,13 +1760,18 @@ # # @calc-time: time in units of second for sample dirty pages # +# @sample-pages: page count per GB for sample dirty pages +# the default value is 512 (since 6.1) +# # Since: 5.2 # # Example: -# {"command": "calc-dirty-rate", "data": {"calc-time": 1} } +# {"command": "calc-dirty-rate", "data": {"calc-time": 1, +# 'sample-pages': 512} } # ## -{ 'command': 'calc-dirty-rate', 'data': {'calc-time': 'int64'} } +{ 'command': 'calc-dirty-rate', 'data': {'calc-time': 'int64', + '*sample-pages': 'int'} } =20 ## # @query-dirty-rate: --=20 2.31.1