From nobody Tue Feb 10 08:04:49 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=1623028978; cv=none; d=zohomail.com; s=zohoarc; b=cvyzH+ODLtWvtzbXggPk/L9DZAGvh8Z6ZtXZ7Un726hsCoDVoYQxJ07wEHgFzVJRb16gzkFvxXcLznUt8LjcWwo2Py3VhsG3bNfFYeJLE2EhymJGJhnCDizU0aLqWZuHK+QHnm6m8JSXq3+Ep0VjWZI2fRlU+a0/9/V7P6RVofI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623028978; h=Content-Type:Content-Transfer-Encoding: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=hogVn23sVHtnAI/0SoiFK7BN7NqG/Vat9Rf3E3qwCH0=; b=W4oMi9CW9t+Vt3HYYV/cCu/a029MlTUoFyBcmnLMcg49TZ5pgLcwJDKfftpGFICGJ2R5gdz7yVxvh4qz1gsWJQygr1UzSb6k0gxkM1KMYzTcpYjly3YCa1dzeUVcEzu90nkA8F5uEdGa+quZlpWDTBb0Om1fCC+HKEqLWRbTF7E= 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 1623028978281460.22479207206095; Sun, 6 Jun 2021 18:22:58 -0700 (PDT) Received: from localhost ([::1]:39188 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lq3yj-0006ra-4h for importer@patchew.org; Sun, 06 Jun 2021 21:22:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45198) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lq3wa-0004dC-Sg for qemu-devel@nongnu.org; Sun, 06 Jun 2021 21:20:44 -0400 Received: from prt-mail.chinatelecom.cn ([42.123.76.228]:49309 helo=chinatelecom.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lq3wY-0000Wn-6S for qemu-devel@nongnu.org; Sun, 06 Jun 2021 21:20:44 -0400 Received: from clientip-182.138.181.182?logid-0124981a5a3c45efa7eb3d3c061ab6a6 (unknown [172.18.0.218]) by chinatelecom.cn (HERMES) with SMTP id 4E8E1280137; Mon, 7 Jun 2021 09:12:43 +0800 (CST) Received: from ([172.18.0.218]) by app0025 with ESMTP id 0124981a5a3c45efa7eb3d3c061ab6a6 for qemu-devel@nongnu.org; Mon Jun 7 09:12:42 2021 HMM_SOURCE_IP: 172.18.0.218:41712.897474470 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: +huangy81@chinatelecom.cn X-Transaction-ID: 0124981a5a3c45efa7eb3d3c061ab6a6 X-filter-score: filter<0> X-Real-From: huangy81@chinatelecom.cn X-Receive-IP: 172.18.0.218 X-MEDUSA-Status: 0 From: huangy81@chinatelecom.cn To: qemu-devel@nongnu.org Subject: [PATCH v3 4/7] migration/dirtyrate: add per-vcpu option for calc-dirty-rate Date: Mon, 7 Jun 2021 09:12:36 +0800 Message-Id: <19ad91782f5798844c42e34683fda833f9d1928a.1623027729.git.huangy81@chinatelecom.cn> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: MIME-Version: 1.0 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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=42.123.76.228; envelope-from=huangy81@chinatelecom.cn; helo=chinatelecom.cn X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, 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: Eduardo Habkost , Juan Quintela , Hyman , "Dr. David Alan Gilbert" , Peter Xu , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" From: Hyman Huang(=E9=BB=84=E5=8B=87) calculate dirtyrate for each vcpu if vcpu is true, add the dirtyrate of each vcpu to the return value also. Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) --- migration/dirtyrate.c | 45 ++++++++++++++++++++++++++++++++++++++----- migration/dirtyrate.h | 1 + qapi/migration.json | 29 ++++++++++++++++++++++++++-- 3 files changed, 68 insertions(+), 7 deletions(-) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 320c56ba2c..5947c688f6 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -397,8 +397,11 @@ void *get_dirtyrate_thread(void *arg) return NULL; } =20 -void qmp_calc_dirty_rate(int64_t calc_time, bool has_sample_pages, - int64_t sample_pages, Error **errp) +void qmp_calc_dirty_rate(int64_t calc_time, + bool per_vcpu, + bool has_sample_pages, + int64_t sample_pages, + Error **errp) { static struct DirtyRateConfig config; QemuThread thread; @@ -419,6 +422,12 @@ void qmp_calc_dirty_rate(int64_t calc_time, bool has_s= ample_pages, return; } =20 + if (has_sample_pages && per_vcpu) { + error_setg(errp, "per-vcpu and sample-pages are mutually exclusive= , " + "only one of then can be specified!\n"); + return; + } + if (has_sample_pages) { if (!is_sample_pages_valid(sample_pages)) { error_setg(errp, "sample-pages is out of range[%d, %d].", @@ -430,6 +439,15 @@ void qmp_calc_dirty_rate(int64_t calc_time, bool has_s= ample_pages, sample_pages =3D DIRTYRATE_DEFAULT_SAMPLE_PAGES; } =20 + /* + * Vcpu method only works when kvm dirty ring is enabled. + */ + if (per_vcpu && !kvm_dirty_ring_enabled()) { + error_setg(errp, "dirty ring is disabled or conflict with migratio= n" + "use sample method or remeasure later."); + return; + } + /* * Init calculation state as unstarted. */ @@ -442,6 +460,7 @@ void qmp_calc_dirty_rate(int64_t calc_time, bool has_sa= mple_pages, =20 config.sample_period_seconds =3D calc_time; config.sample_pages_per_gigabytes =3D sample_pages; + config.per_vcpu =3D per_vcpu; qemu_thread_create(&thread, "get_dirtyrate", get_dirtyrate_thread, (void *)&config, QEMU_THREAD_DETACHED); } @@ -459,13 +478,22 @@ void hmp_info_dirty_rate(Monitor *mon, const QDict *q= dict) DirtyRateStatus_str(info->status)); monitor_printf(mon, "Start Time: %"PRIi64" (ms)\n", info->start_time); - monitor_printf(mon, "Sample Pages: %"PRIu64" (per GB)\n", - info->sample_pages); monitor_printf(mon, "Period: %"PRIi64" (sec)\n", info->calc_time); + if (info->has_sample_pages) { + monitor_printf(mon, "Sample Pages: %"PRIu64" (per GB)\n", + info->sample_pages); + } monitor_printf(mon, "Dirty rate: "); if (info->has_dirty_rate) { monitor_printf(mon, "%"PRIi64" (MB/s)\n", info->dirty_rate); + if (info->per_vcpu && info->has_vcpu_dirty_rate) { + DirtyRateVcpuList *rate, *head =3D info->vcpu_dirty_rate; + for (rate =3D head; rate !=3D NULL; rate =3D rate->next) { + monitor_printf(mon, "vcpu[%"PRIi64"], Dirty rate: %"PRIi64= "\n", + rate->value->id, rate->value->dirty_rate); + } + } } else { monitor_printf(mon, "(not ready)\n"); } @@ -477,6 +505,7 @@ void hmp_calc_dirty_rate(Monitor *mon, const QDict *qdi= ct) int64_t sec =3D qdict_get_try_int(qdict, "second", 0); int64_t sample_pages =3D qdict_get_try_int(qdict, "sample_pages_per_GB= ", -1); bool has_sample_pages =3D (sample_pages !=3D -1); + bool per_vcpu =3D qdict_get_try_bool(qdict, "per_vcpu", false); Error *err =3D NULL; =20 if (!sec) { @@ -484,7 +513,13 @@ void hmp_calc_dirty_rate(Monitor *mon, const QDict *qd= ict) return; } =20 - qmp_calc_dirty_rate(sec, has_sample_pages, sample_pages, &err); + if (has_sample_pages && per_vcpu) { + monitor_printf(mon, "per_vcpu and sample_pages are mutually exclus= ive, " + "only one of then can be specified!\n"); + return; + } + + qmp_calc_dirty_rate(sec, per_vcpu, has_sample_pages, sample_pages, &er= r); if (err) { hmp_handle_error(mon, err); return; diff --git a/migration/dirtyrate.h b/migration/dirtyrate.h index e1fd29089e..ec82716b40 100644 --- a/migration/dirtyrate.h +++ b/migration/dirtyrate.h @@ -43,6 +43,7 @@ struct DirtyRateConfig { uint64_t sample_pages_per_gigabytes; /* sample pages per GB */ int64_t sample_period_seconds; /* time duration between two sampling */ + bool per_vcpu; /* calculate dirtyrate for each vcpu using dirty ring */ }; =20 /* diff --git a/qapi/migration.json b/qapi/migration.json index 770ae54c17..7eef988182 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -1708,6 +1708,21 @@ { 'event': 'UNPLUG_PRIMARY', 'data': { 'device-id': 'str' } } =20 +## +# @DirtyRateVcpu: +# +# Dirty rate of vcpu. +# +# @id: vcpu index. +# +# @dirty-rate: dirty rate. +# +# Since: 6.1 +# +## +{ 'struct': 'DirtyRateVcpu', + 'data': { 'id': 'int', 'dirty-rate': 'int64' } } + ## # @DirtyRateStatus: # @@ -1743,6 +1758,10 @@ # @sample-pages: page count per GB for sample dirty pages # the default value is 512 (since 6.1) # +# @per-vcpu: calculate dirtyrate for each vcpu (Since 6.1) +# +# @vcpu-dirty-rate: dirtyrate for each vcpu (Since 6.1) +# # Since: 5.2 # ## @@ -1751,7 +1770,9 @@ 'status': 'DirtyRateStatus', 'start-time': 'int64', 'calc-time': 'int64', - 'sample-pages': 'uint64'} } + '*sample-pages': 'uint64', + 'per-vcpu': 'bool', + '*vcpu-dirty-rate': [ 'DirtyRateVcpu' ] } } =20 ## # @calc-dirty-rate: @@ -1760,6 +1781,10 @@ # # @calc-time: time in units of second for sample dirty pages # +# @per-vcpu: calculate vcpu dirty rate if true, the default value is +# false, note that the per-vcpu and sample-pages are mutually +# exclusive (since 6.1) +# # @sample-pages: page count per GB for sample dirty pages # the default value is 512 (since 6.1) # @@ -1769,7 +1794,7 @@ # {"command": "calc-dirty-rate", "data": {"calc-time": 1, 'sample-pages'= : 512} } # ## -{ 'command': 'calc-dirty-rate', 'data': {'calc-time': 'int64', '*sample-pa= ges': 'int'} } +{ 'command': 'calc-dirty-rate', 'data': {'calc-time': 'int64', 'per-vcpu':= 'bool', '*sample-pages': 'int'} } =20 ## # @query-dirty-rate: --=20 2.18.2