From nobody Sun May 19 19:10:09 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=1622480903; cv=none; d=zohomail.com; s=zohoarc; b=if0VrShPcOo3yyARQDlUPmL45br2W/ttnrEr+svLXQzEVQYF27OORmcwMqosv5xQuCaYA9e4+8qDfrjwmvvCmN1x9a5a2cwFNeVMLyb6f6pkbFZcUNJ2DD+FqnJ7OzmsYbrLmcCQ+f2Sf17mzkfXbivNl100WI0iFD0uIwWOIFY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622480903; 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=Jkf/U/7ltfxc/1GJ0Ppr+vEGnI81QrtyiQs5e7Amj3M=; b=RzWJnMZcLvLOWBzUJOLNwjm+elxrxGu/knEg7rRy2q461+XG8DHRHSe3VQyzJiVuQpHHS2TaQ+Ed/kP2ccm9QlJFIVtQXW/HjDAkUhcrVKqEmahIekDOqBK1a0+Sk9SCraaLQK+dwwxMctKuBLDtZ2OWQbAWZaUuNyzEaxNz5Vg= 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 1622480903915162.42315125193022; Mon, 31 May 2021 10:08:23 -0700 (PDT) Received: from localhost ([::1]:37552 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnlOo-0002oA-UL for importer@patchew.org; Mon, 31 May 2021 13:08:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55284) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnlKQ-00068U-CC for qemu-devel@nongnu.org; Mon, 31 May 2021 13:03:50 -0400 Received: from prt-mail.chinatelecom.cn ([42.123.76.228]:33168 helo=chinatelecom.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnlKK-0004aa-PN for qemu-devel@nongnu.org; Mon, 31 May 2021 13:03:50 -0400 Received: from clientip-202.80.192.39?logid-48afce8d3b6b4436b73d11f8304b4286 (unknown [172.18.0.48]) by chinatelecom.cn (HERMES) with SMTP id A730F2800E8; Tue, 1 Jun 2021 01:03:23 +0800 (CST) Received: from ([172.18.0.48]) by app0024 with ESMTP id 48afce8d3b6b4436b73d11f8304b4286 for qemu-devel@nongnu.org; Tue Jun 1 01:03:30 2021 HMM_SOURCE_IP: 172.18.0.48:58222.1682084387 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: +huangy81@chinatelecom.cn X-Transaction-ID: 48afce8d3b6b4436b73d11f8304b4286 X-filter-score: filter<0> X-Real-From: huangy81@chinatelecom.cn X-Receive-IP: 172.18.0.48 X-MEDUSA-Status: 0 From: huangy81@chinatelecom.cn To: Subject: [PATCH v1 1/6] KVM: add kvm_dirty_ring_enabled function Date: Tue, 1 Jun 2021 01:03:18 +0800 Message-Id: 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: kvm@vger.kernel.org, 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) introduce kvm_dirty_ring_enabled to show if kvm-reaper is working. dirtyrate thread could use it to check if calculation can base on dirty ring feature. Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) --- accel/kvm/kvm-all.c | 5 +++++ include/sysemu/kvm.h | 1 + 2 files changed, 6 insertions(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index c7ec538850..2e96b77b31 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2293,6 +2293,11 @@ bool kvm_vcpu_id_is_valid(int vcpu_id) return vcpu_id >=3D 0 && vcpu_id < kvm_max_vcpu_id(s); } =20 +bool kvm_dirty_ring_enabled(void) +{ + return kvm_state->kvm_dirty_ring_size ? true : false; +} + static int kvm_init(MachineState *ms) { MachineClass *mc =3D MACHINE_GET_CLASS(ms); diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index a1ab1ee12d..7b22aeb6ae 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -547,4 +547,5 @@ bool kvm_cpu_check_are_resettable(void); =20 bool kvm_arch_cpu_check_are_resettable(void); =20 +bool kvm_dirty_ring_enabled(void); #endif --=20 2.24.3 From nobody Sun May 19 19:10:09 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=1622481156; cv=none; d=zohomail.com; s=zohoarc; b=KESbV5MnuTCSlbAd/egBoVqeS/hUPW4tywaX0RwC0UP2UFN4zJk1lGzapV2GAXHaCoWoc6VBxISR4NkC+xz3Y3Yu083UaCpBkrEuxKoiA717sZrMol80NfbQ1yQKWuw/hddZD6na/9ich/kLqRDh65uiL0QnloK1HonKN8b+fb4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622481156; 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=sbT/OBc+6REBR6rqyz3voaibjpEWFvKhi1dlpkpPpj4=; b=JsbxkwgQM7JYOAoNdG223XbzkXxzs6CVAu98lM5qgl3hA0BreGCg9Gtr8sioyay62zjHv9K2Gtzf/bLttP+vh+s5CKtCa59ZDmINJwNLenKUdCyPCn85MfqxR2gtuHh3XS73o9PDCuVR8ty/fnKzAhJDvdz1Tt488TdARLyFOnU= 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 1622481156150463.5726836561281; Mon, 31 May 2021 10:12:36 -0700 (PDT) Received: from localhost ([::1]:45170 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnlSt-00088w-3M for importer@patchew.org; Mon, 31 May 2021 13:12:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55470) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnlLG-0007Sp-9m for qemu-devel@nongnu.org; Mon, 31 May 2021 13:04:42 -0400 Received: from prt-mail.chinatelecom.cn ([42.123.76.228]:33210 helo=chinatelecom.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnlLC-0004zx-DL for qemu-devel@nongnu.org; Mon, 31 May 2021 13:04:42 -0400 Received: from clientip-202.80.192.38?logid-29ae52c8a85445e99aab72860cfd77f0 (unknown [172.18.0.218]) by chinatelecom.cn (HERMES) with SMTP id 4D8B52800F6; Tue, 1 Jun 2021 01:04:12 +0800 (CST) Received: from ([172.18.0.218]) by app0025 with ESMTP id 29ae52c8a85445e99aab72860cfd77f0 for qemu-devel@nongnu.org; Tue Jun 1 01:04:30 2021 HMM_SOURCE_IP: 172.18.0.218:47064.1907396775 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: +huangy81@chinatelecom.cn X-Transaction-ID: 29ae52c8a85445e99aab72860cfd77f0 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: Subject: [PATCH v1 2/6] KVM: introduce dirty_pages into CPUState Date: Tue, 1 Jun 2021 01:04:06 +0800 Message-Id: <78cc154863754a93d88070d1fae9fed6a1ec5f01.1622479161.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: kvm@vger.kernel.org, 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) dirty_pages is used to calculate dirtyrate via dirty ring, when enabled, kvm-reaper will increase the dirty pages after gfns being dirtied. Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) --- accel/kvm/kvm-all.c | 6 ++++++ include/hw/core/cpu.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 2e96b77b31..52cba1b094 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -506,6 +506,9 @@ int kvm_init_vcpu(CPUState *cpu, Error **errp) } } =20 + cpu->dirty_pages =3D 0; + cpu->stat_dirty_pages =3D false; + ret =3D kvm_arch_init_vcpu(cpu); if (ret < 0) { error_setg_errno(errp, -ret, @@ -739,6 +742,9 @@ static uint32_t kvm_dirty_ring_reap_one(KVMState *s, CP= UState *cpu) cur->offset); dirty_gfn_set_collected(cur); trace_kvm_dirty_ring_page(cpu->cpu_index, fetch, cur->offset); + if (cpu->stat_dirty_pages) { + cpu->dirty_pages++; + } fetch++; count++; } diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 044f668a6e..973c193501 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -375,6 +375,8 @@ struct CPUState { struct kvm_run *kvm_run; struct kvm_dirty_gfn *kvm_dirty_gfns; uint32_t kvm_fetch_index; + uint64_t dirty_pages; + bool stat_dirty_pages; =20 /* Used for events with 'vcpu' and *without* the 'disabled' properties= */ DECLARE_BITMAP(trace_dstate_delayed, CPU_TRACE_DSTATE_MAX_EVENTS); --=20 2.24.3 From nobody Sun May 19 19:10:09 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=1622480901; cv=none; d=zohomail.com; s=zohoarc; b=BWh48AZ6HJwHAu7Hh664PiBudBQ1Z4un729Gepa4cJJ3/H1IuI2oRSdb3uW9WbLYnEhvr9XA57RbWGRrp5Aq+xwycdpvPXVtpxd+zcdNdWbnX6dLD4ibdKtBEbdMtp5LqyzxICppuPjeOuXM0VzTHDKHLFp8IndHHAmEkfD5+7U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622480901; 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=eKPqlazZuLW1eded5C04HNoAOzzI6jIXcXzegMZx+Ig=; b=OnloqfgD4ZrqXdK3Ij3/e6rbBfjK+tLUJU65vvR+TAiKQ/4gHwVf8X7ljgpHJ+D5O3crUp6+2dZTAEDhZ/oQRpQqPb21EgYybPO5cSHNYT2zIZuTrcMmo1PlxBDc/zn9ojvbMwvVvWsb+sxr4pQLmy7FGX/U22C2Qog0X56ac1U= 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 1622480901248903.3305449635106; Mon, 31 May 2021 10:08:21 -0700 (PDT) Received: from localhost ([::1]:37212 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnlOm-0002Zo-6Z for importer@patchew.org; Mon, 31 May 2021 13:08:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55572) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnlLf-00080A-QW for qemu-devel@nongnu.org; Mon, 31 May 2021 13:05:07 -0400 Received: from prt-mail.chinatelecom.cn ([42.123.76.219]:51878 helo=chinatelecom.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnlLd-0005A8-Ip for qemu-devel@nongnu.org; Mon, 31 May 2021 13:05:07 -0400 Received: from clientip-202.80.192.39?logid-4a3d34afc9d14b97a5e6c1a5d502adc7 (unknown [172.18.0.218]) by chinatelecom.cn (HERMES) with SMTP id D220D2800B0; Tue, 1 Jun 2021 01:04:59 +0800 (CST) Received: from ([172.18.0.218]) by app0025 with ESMTP id 4a3d34afc9d14b97a5e6c1a5d502adc7 for qemu-devel@nongnu.org; Tue Jun 1 01:04:59 2021 HMM_SOURCE_IP: 172.18.0.218:37984.253484957 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: +huangy81@chinatelecom.cn X-Transaction-ID: 4a3d34afc9d14b97a5e6c1a5d502adc7 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: Subject: [PATCH v1 3/6] migration/dirtyrate: add vcpu option for qmp calc-dirty-rate Date: Tue, 1 Jun 2021 01:05:00 +0800 Message-Id: <28111cd734b1b6e76f7cd8f2f6ad1d4c54f12842.1622479162.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.219; 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: kvm@vger.kernel.org, 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 | 5 ++++- migration/dirtyrate.h | 1 + qapi/migration.json | 28 ++++++++++++++++++++++++++-- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index ccb98147e8..3c1a824a41 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -383,7 +383,10 @@ 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_vcpu, + bool vcpu, + Error **errp) { static struct DirtyRateConfig config; QemuThread thread; diff --git a/migration/dirtyrate.h b/migration/dirtyrate.h index 6ec429534d..f20dd52d77 100644 --- a/migration/dirtyrate.h +++ b/migration/dirtyrate.h @@ -38,6 +38,7 @@ struct DirtyRateConfig { uint64_t sample_pages_per_gigabytes; /* sample pages per GB */ int64_t sample_period_seconds; /* time duration between two sampling */ + bool vcpu; /* calculate dirtyrate for each vcpu using dirty ring */ }; =20 /* diff --git a/qapi/migration.json b/qapi/migration.json index 7a5bdf9a0d..896ebcb93b 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: # @@ -1740,6 +1755,10 @@ # # @calc-time: time in units of second for sample dirty pages # +# @vcpu: calculate dirtyrate for each vcpu (Since 6.1) +# +# @vcpu-dirty-rate: dirtyrate for each vcpu (Since 6.1) +# # Since: 5.2 # ## @@ -1747,7 +1766,9 @@ 'data': {'*dirty-rate': 'int64', 'status': 'DirtyRateStatus', 'start-time': 'int64', - 'calc-time': 'int64'} } + 'calc-time': 'int64', + '*vcpu': 'bool', + '*vcpu-dirty-rate': [ 'DirtyRateVcpu' ] } } =20 ## # @calc-dirty-rate: @@ -1756,13 +1777,16 @@ # # @calc-time: time in units of second for sample dirty pages # +# @vcpu: calculate vcpu dirty rate if true, the default value is +# false (since 6.1) +# # Since: 5.2 # # Example: # {"command": "calc-dirty-rate", "data": {"calc-time": 1} } # ## -{ 'command': 'calc-dirty-rate', 'data': {'calc-time': 'int64'} } +{ 'command': 'calc-dirty-rate', 'data': {'calc-time': 'int64', '*vcpu': 'b= ool'} } =20 ## # @query-dirty-rate: --=20 2.24.3 From nobody Sun May 19 19:10:09 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=1622481099; cv=none; d=zohomail.com; s=zohoarc; b=RrirulLV03S05cv+Jb5YIl/kx7cc/ygGuAe8bM+BjxINh3nqfcc7GvxY+XBx1DB+d/uoZAlYmt01SbfOudyTaRrRmizpIBZSu3Og7ce8tfxbrMS2bDvCZjsZwUxICF7SG9RRNki9EVkjQ6fz8sEab0X7gjolpb/CmSWadgvEIWk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622481099; 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=ERNo2Vg+gSkZl2zf2BQpvLlJz9tfqMMoeeDOiFHjBWo=; b=fUP+al8P8BjiJYKCjpslMmziM925gIkNIm2PnTClWIltUNAjW4oAh1Bbng8EmWg3IhqODOiveHh2i3+bkYxB5QecbsVFs3I394e4XF92bSob2n9qlUaaXdTns53hLDxtwpVj1t7o+3NjFi6OIcMFuEY0dyQFXFhnT5Ht63fgXFI= 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 1622481099128777.3006651900484; Mon, 31 May 2021 10:11:39 -0700 (PDT) Received: from localhost ([::1]:43336 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnlRx-0006of-U1 for importer@patchew.org; Mon, 31 May 2021 13:11:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55662) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnlM5-000059-SD for qemu-devel@nongnu.org; Mon, 31 May 2021 13:05:38 -0400 Received: from prt-mail.chinatelecom.cn ([42.123.76.227]:57779 helo=chinatelecom.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnlM1-0005QO-3J for qemu-devel@nongnu.org; Mon, 31 May 2021 13:05:33 -0400 Received: from clientip-202.80.192.39?logid-262a242008784dafb9db8682f1ad8717 (unknown [172.18.0.218]) by chinatelecom.cn (HERMES) with SMTP id 525342800B2; Tue, 1 Jun 2021 01:05:28 +0800 (CST) Received: from ([172.18.0.218]) by app0025 with ESMTP id 262a242008784dafb9db8682f1ad8717 for qemu-devel@nongnu.org; Tue Jun 1 01:05:27 2021 HMM_SOURCE_IP: 172.18.0.218:60136.529866758 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: +huangy81@chinatelecom.cn X-Transaction-ID: 262a242008784dafb9db8682f1ad8717 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: Subject: [PATCH v1 4/6] migration/dirtyrate: adjust struct DirtyRateStat Date: Tue, 1 Jun 2021 01:05:29 +0800 Message-Id: <16e0e8f50b3b83f809187dcfed5693026bea0caa.1622479162.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.227; 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: kvm@vger.kernel.org, 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) use union to store stat data of two mutual exclusive methods. Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) --- migration/dirtyrate.c | 32 ++++++++++++++++++++------------ migration/dirtyrate.h | 18 +++++++++++++++--- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 3c1a824a41..7952eb6117 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -78,31 +78,39 @@ static struct DirtyRateInfo *query_dirty_rate_info(void) 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, + struct DirtyRateConfig config) { - DirtyStat.total_dirty_samples =3D 0; - DirtyStat.total_sample_count =3D 0; - DirtyStat.total_block_mem_MB =3D 0; DirtyStat.dirty_rate =3D -1; DirtyStat.start_time =3D start_time; DirtyStat.calc_time =3D calc_time; + + if (config.vcpu) { + DirtyStat.method.vcpu.nvcpu =3D -1; + DirtyStat.method.vcpu.rates =3D NULL; + } else { + DirtyStat.method.vm.total_dirty_samples =3D 0; + DirtyStat.method.vm.total_sample_count =3D 0; + DirtyStat.method.vm.total_block_mem_MB =3D 0; + } } =20 static void update_dirtyrate_stat(struct RamblockDirtyInfo *info) { - DirtyStat.total_dirty_samples +=3D info->sample_dirty_count; - DirtyStat.total_sample_count +=3D info->sample_pages_count; + DirtyStat.method.vm.total_dirty_samples +=3D info->sample_dirty_count; + DirtyStat.method.vm.total_sample_count +=3D info->sample_pages_count; /* size of total pages in MB */ - DirtyStat.total_block_mem_MB +=3D (info->ramblock_pages * + DirtyStat.method.vm.total_block_mem_MB +=3D (info->ramblock_pages * TARGET_PAGE_SIZE) >> 20; } =20 static void update_dirtyrate(uint64_t msec) { uint64_t dirtyrate; - uint64_t total_dirty_samples =3D DirtyStat.total_dirty_samples; - uint64_t total_sample_count =3D DirtyStat.total_sample_count; - uint64_t total_block_mem_MB =3D DirtyStat.total_block_mem_MB; + uint64_t total_dirty_samples =3D DirtyStat.method.vm.total_dirty_sampl= es; + uint64_t total_sample_count =3D DirtyStat.method.vm.total_sample_count; + uint64_t total_block_mem_MB =3D DirtyStat.method.vm.total_block_mem_MB; =20 dirtyrate =3D total_dirty_samples * total_block_mem_MB * 1000 / (total_sample_count * msec); @@ -315,7 +323,7 @@ static bool compare_page_hash_info(struct RamblockDirty= Info *info, update_dirtyrate_stat(block_dinfo); } =20 - if (DirtyStat.total_sample_count =3D=3D 0) { + if (DirtyStat.method.vm.total_sample_count =3D=3D 0) { return false; } =20 @@ -371,7 +379,7 @@ 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); + init_dirtyrate_stat(start_time, calc_time, config); =20 calculate_dirtyrate(config); =20 diff --git a/migration/dirtyrate.h b/migration/dirtyrate.h index f20dd52d77..3ab8e81f42 100644 --- a/migration/dirtyrate.h +++ b/migration/dirtyrate.h @@ -54,16 +54,28 @@ struct RamblockDirtyInfo { uint32_t *hash_result; /* array of hash result for sampled pages */ }; =20 +typedef struct SampleVMStat { + uint64_t total_dirty_samples; /* total dirty sampled page */ + uint64_t total_sample_count; /* total sampled pages */ + uint64_t total_block_mem_MB; /* size of total sampled pages in MB */ +} SampleVMStat; + +typedef struct VcpuStat { + int nvcpu; /* number of vcpu */ + DirtyRateVcpu *rates; /* array of dirty rate for each vcpu */ +} VcpuStat; + /* * Store calculation statistics for each measure. */ struct DirtyRateStat { - uint64_t total_dirty_samples; /* total dirty sampled page */ - uint64_t total_sample_count; /* total sampled pages */ - uint64_t total_block_mem_MB; /* size of total sampled pages in MB */ 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= */ + union { + SampleVMStat vm; + VcpuStat vcpu; + } method; }; =20 void *get_dirtyrate_thread(void *arg); --=20 2.24.3 From nobody Sun May 19 19:10:09 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=1622481082; cv=none; d=zohomail.com; s=zohoarc; b=kvyV73SFMW2HSM5x7Wsgq1tP1ClEeIuNBPmBX+wOUooWx3S5tJc0WSnKbS/7aTu+Cfdvfo7p+F1rvicxxne8BXw9j7m6Cjuv1nmxtZhE6uzpEljzKOdMpFHoAvwW1I6r6DBAL+2mmUERz/f188d5+9xmMNGGrSDA8zEesULB7h8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622481082; 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=zZKMPVn5x5zL6/eINSPz+f6vy9eo+L7Dhg4AiLU4M+0=; b=QYOVdaIU/3doTxWdscmQrCptvG7ERbfaUz+MID07DYXvan3Bs1F0WZTb6HOiNR0dU3FwYqYxU0eMuOrG7lqtmYkeGdfg9TAR/6U5gWmcchXhgVs6qZ2irCFqJGz/GAPh2lAIycoR9JP27DWaMY/3CNZq2IVfpKwsVFj5Dbdp1u0= 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 1622481082072999.5517070925217; Mon, 31 May 2021 10:11:22 -0700 (PDT) Received: from localhost ([::1]:42352 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnlRg-00065D-Tw for importer@patchew.org; Mon, 31 May 2021 13:11:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55770) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnlMc-0000gI-4R for qemu-devel@nongnu.org; Mon, 31 May 2021 13:06:06 -0400 Received: from prt-mail.chinatelecom.cn ([42.123.76.228]:33244 helo=chinatelecom.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnlMX-0005aC-Mk for qemu-devel@nongnu.org; Mon, 31 May 2021 13:06:05 -0400 Received: from clientip-202.80.192.38?logid-ed481103dcf04c7799310e542c3cbd82 (unknown [172.18.0.218]) by chinatelecom.cn (HERMES) with SMTP id ED4F72800FA; Tue, 1 Jun 2021 01:05:57 +0800 (CST) Received: from ([172.18.0.218]) by app0025 with ESMTP id ed481103dcf04c7799310e542c3cbd82 for qemu-devel@nongnu.org; Tue Jun 1 01:05:58 2021 HMM_SOURCE_IP: 172.18.0.218:53114.1639123736 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: +huangy81@chinatelecom.cn X-Transaction-ID: ed481103dcf04c7799310e542c3cbd82 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: Subject: [PATCH v1 5/6] migration/dirtyrate: check support of calculation for vcpu Date: Tue, 1 Jun 2021 01:05:58 +0800 Message-Id: <8c48e41e38c31827f305806704e6e23faef848c3.1622479162.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: kvm@vger.kernel.org, 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) vcpu method only works when kvm dirty ring is enabled, use kvm_dirty_ring_enabled to probe if dirty ring is enabled. Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) --- migration/dirtyrate.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 7952eb6117..da6500c8ec 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -16,6 +16,7 @@ #include "cpu.h" #include "exec/ramblock.h" #include "qemu/rcu_queue.h" +#include "sysemu/kvm.h" #include "qapi/qapi-commands-migration.h" #include "ram.h" #include "trace.h" @@ -415,6 +416,14 @@ void qmp_calc_dirty_rate(int64_t calc_time, return; } =20 + /* + * Vcpu method only works when kvm dirty ring is enabled. + */ + if (has_vcpu && vcpu && !kvm_dirty_ring_enabled()) { + error_setg(errp, "kvm dirty ring is disabled, use sample method."); + return; + } + /* * Init calculation state as unstarted. */ @@ -427,6 +436,7 @@ void qmp_calc_dirty_rate(int64_t calc_time, =20 config.sample_period_seconds =3D calc_time; config.sample_pages_per_gigabytes =3D DIRTYRATE_DEFAULT_SAMPLE_PAGES; + config.vcpu =3D has_vcpu ? vcpu : false; qemu_thread_create(&thread, "get_dirtyrate", get_dirtyrate_thread, (void *)&config, QEMU_THREAD_DETACHED); } --=20 2.24.3 From nobody Sun May 19 19:10:09 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=1622481296; cv=none; d=zohomail.com; s=zohoarc; b=EvZTQr8lMMRpi58BQZwXIZQiSDqprV7feOo/KrmZH7pzskohmrEMUTV99MtuqmKvfNbX7Fe5NnNv7S8JLIvSmyls+7ihIcJaLl8E6kSkjv9yLn9F9VcetDC9or5fZU+AjNvicMqba24CSTtwNwVSI2UdB3/IM7Tv6KoBgtvVWIM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622481296; 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=Rq+ssmYJgD1KrPVlszT0KyJEpjWUdw4bmwWabvnnEwc=; b=L6jR0cZuk6FCSHW+/dLO6id/aurtnYC8p6UIKoGzMkt7PU/5pbZS6eqDIC/4PlKPnoPahDG/MxDwg3RzyZKKIRrFOAfSm+CVBOs+BfejKYJ/71YmjkM2AaRcjqsW+Wcf7dqWKMaR8vot5G9yhBMRLOk1wTEE7waS4tgwBUPSziI= 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 1622481296905940.2546861987396; Mon, 31 May 2021 10:14:56 -0700 (PDT) Received: from localhost ([::1]:51226 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnlV8-0003lY-Sy for importer@patchew.org; Mon, 31 May 2021 13:14:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55900) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnlN5-0001bp-Js for qemu-devel@nongnu.org; Mon, 31 May 2021 13:06:36 -0400 Received: from prt-mail.chinatelecom.cn ([42.123.76.219]:51924 helo=chinatelecom.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnlN0-0005rU-22 for qemu-devel@nongnu.org; Mon, 31 May 2021 13:06:35 -0400 Received: from clientip-202.80.192.39?logid-8790cfef0ba147a299cbd8acf210f1a0 (unknown [172.18.0.218]) by chinatelecom.cn (HERMES) with SMTP id 5A2E42800B2; Tue, 1 Jun 2021 01:06:29 +0800 (CST) Received: from ([172.18.0.218]) by app0025 with ESMTP id 8790cfef0ba147a299cbd8acf210f1a0 for qemu-devel@nongnu.org; Tue Jun 1 01:06:27 2021 HMM_SOURCE_IP: 172.18.0.218:42706.1466219582 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: +huangy81@chinatelecom.cn X-Transaction-ID: 8790cfef0ba147a299cbd8acf210f1a0 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: Subject: [PATCH v1 6/6] migration/dirtyrate: implement dirty-ring dirtyrate calculation Date: Tue, 1 Jun 2021 01:06:29 +0800 Message-Id: <27607e12038273706273203b2146c5d4a40ac487.1622479162.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.219; 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: kvm@vger.kernel.org, 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) use dirty ring feature to implement dirtyrate calculation. to enable it, set vcpu option as true in qmp calc-dirty-rate. Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) --- migration/dirtyrate.c | 146 ++++++++++++++++++++++++++++++++++++++--- migration/trace-events | 1 + 2 files changed, 139 insertions(+), 8 deletions(-) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index da6500c8ec..028c11d117 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -16,14 +16,22 @@ #include "cpu.h" #include "exec/ramblock.h" #include "qemu/rcu_queue.h" +#include "qemu/main-loop.h" #include "sysemu/kvm.h" #include "qapi/qapi-commands-migration.h" #include "ram.h" #include "trace.h" #include "dirtyrate.h" =20 +typedef enum { + CALC_NONE =3D 0, + CALC_DIRTY_RING, + CALC_SAMPLE_PAGES, +} CalcMethod; + static int CalculatingState =3D DIRTY_RATE_STATUS_UNSTARTED; static struct DirtyRateStat DirtyStat; +static CalcMethod last_method =3D CALC_NONE; =20 static int64_t set_sample_page_period(int64_t msec, int64_t initial_time) { @@ -64,6 +72,7 @@ static struct DirtyRateInfo *query_dirty_rate_info(void) { int64_t dirty_rate =3D DirtyStat.dirty_rate; struct DirtyRateInfo *info =3D g_malloc0(sizeof(DirtyRateInfo)); + DirtyRateVcpuList *head =3D NULL, **tail =3D &head; =20 if (qatomic_read(&CalculatingState) =3D=3D DIRTY_RATE_STATUS_MEASURED)= { info->has_dirty_rate =3D true; @@ -73,6 +82,22 @@ 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->has_vcpu =3D true; + + if (last_method =3D=3D CALC_DIRTY_RING) { + int i =3D 0; + info->vcpu =3D true; + info->has_vcpu_dirty_rate =3D true; + for (i =3D 0; i < DirtyStat.method.vcpu.nvcpu; i++) { + DirtyRateVcpu *rate =3D g_malloc0(sizeof(DirtyRateVcpu)); + rate->id =3D DirtyStat.method.vcpu.rates[i].id; + rate->dirty_rate =3D DirtyStat.method.vcpu.rates[i].dirty_rate; + QAPI_LIST_APPEND(tail, rate); + } + info->vcpu_dirty_rate =3D head; + } else { + info->vcpu =3D false; + } =20 trace_query_dirty_rate_info(DirtyRateStatus_str(CalculatingState)); =20 @@ -87,13 +112,29 @@ static void init_dirtyrate_stat(int64_t start_time, DirtyStat.start_time =3D start_time; DirtyStat.calc_time =3D calc_time; =20 - if (config.vcpu) { - DirtyStat.method.vcpu.nvcpu =3D -1; - DirtyStat.method.vcpu.rates =3D NULL; - } else { - DirtyStat.method.vm.total_dirty_samples =3D 0; - DirtyStat.method.vm.total_sample_count =3D 0; - DirtyStat.method.vm.total_block_mem_MB =3D 0; + switch (last_method) { + case CALC_NONE: + case CALC_SAMPLE_PAGES: + if (config.vcpu) { + DirtyStat.method.vcpu.nvcpu =3D -1; + DirtyStat.method.vcpu.rates =3D NULL; + } else { + DirtyStat.method.vm.total_dirty_samples =3D 0; + DirtyStat.method.vm.total_sample_count =3D 0; + DirtyStat.method.vm.total_block_mem_MB =3D 0; + } + break; + case CALC_DIRTY_RING: + if (!config.vcpu) { + g_free(DirtyStat.method.vcpu.rates); + DirtyStat.method.vcpu.rates =3D NULL; + DirtyStat.method.vm.total_dirty_samples =3D 0; + DirtyStat.method.vm.total_sample_count =3D 0; + DirtyStat.method.vm.total_block_mem_MB =3D 0; + } + break; + default: + break; } } =20 @@ -331,7 +372,84 @@ static bool compare_page_hash_info(struct RamblockDirt= yInfo *info, return true; } =20 -static void calculate_dirtyrate(struct DirtyRateConfig config) +static void stat_dirtypages(CPUState *cpu, bool start) +{ + cpu->stat_dirty_pages =3D start; +} + +static void start_kvm_dirty_log(void) +{ + qemu_mutex_lock_iothread(); + memory_global_dirty_log_start(); + qemu_mutex_unlock_iothread(); +} + +static void stop_kvm_dirty_log(void) +{ + qemu_mutex_lock_iothread(); + memory_global_dirty_log_stop(); + qemu_mutex_unlock_iothread(); +} + +static int64_t do_calculate_dirtyrate_vcpu(CPUState *cpu) +{ + uint64_t memory_size_MB; + int64_t time_s; + + memory_size_MB =3D (cpu->dirty_pages * TARGET_PAGE_SIZE) >> 20; + time_s =3D DirtyStat.calc_time; + + return memory_size_MB / time_s; +} + +static void calculate_dirtyrate_vcpu(struct DirtyRateConfig config) +{ + CPUState *cpu; + int64_t msec =3D 0; + int64_t start_time; + uint64_t dirtyrate =3D 0; + uint64_t dirtyrate_sum =3D 0; + int nvcpu, i =3D 0; + + CPU_FOREACH(cpu) { + stat_dirtypages(cpu, true); + nvcpu++; + } + + DirtyStat.method.vcpu.nvcpu =3D nvcpu; + + if (last_method !=3D CALC_DIRTY_RING) { + DirtyStat.method.vcpu.rates =3D + g_malloc0(sizeof(DirtyRateVcpu) * nvcpu); + } + + start_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); + DirtyStat.start_time =3D start_time / 1000; + + start_kvm_dirty_log(); + + msec =3D config.sample_period_seconds * 1000; + msec =3D set_sample_page_period(msec, start_time); + DirtyStat.calc_time =3D msec / 1000; + + CPU_FOREACH(cpu) { + stat_dirtypages(cpu, false); + } + + stop_kvm_dirty_log(); + + CPU_FOREACH(cpu) { + dirtyrate =3D do_calculate_dirtyrate_vcpu(cpu); + DirtyStat.method.vcpu.rates[i].id =3D cpu->cpu_index; + DirtyStat.method.vcpu.rates[i].dirty_rate =3D dirtyrate; + dirtyrate_sum +=3D dirtyrate; + i++; + } + + DirtyStat.dirty_rate =3D dirtyrate_sum / nvcpu; +} + +static void calculate_dirtyrate_sample_vm(struct DirtyRateConfig config) { struct RamblockDirtyInfo *block_dinfo =3D NULL; int block_count =3D 0; @@ -364,6 +482,18 @@ out: rcu_unregister_thread(); } =20 +static void calculate_dirtyrate(struct DirtyRateConfig config) +{ + if (config.vcpu) { + calculate_dirtyrate_vcpu(config); + last_method =3D CALC_DIRTY_RING; + } else { + calculate_dirtyrate_sample_vm(config); + last_method =3D CALC_SAMPLE_PAGES; + } + trace_calculate_dirtyrate(DirtyStat.dirty_rate); +} + void *get_dirtyrate_thread(void *arg) { struct DirtyRateConfig config =3D *(struct DirtyRateConfig *)arg; diff --git a/migration/trace-events b/migration/trace-events index 668c562fed..5a80b39a62 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -330,6 +330,7 @@ get_ramblock_vfn_hash(const char *idstr, uint64_t vfn, = uint32_t crc) "ramblock n calc_page_dirty_rate(const char *idstr, uint32_t new_crc, uint32_t old_crc= ) "ramblock name: %s, new crc: %" PRIu32 ", old crc: %" PRIu32 skip_sample_ramblock(const char *idstr, uint64_t ramblock_size) "ramblock = name: %s, ramblock size: %" PRIu64 find_page_matched(const char *idstr) "ramblock %s addr or size changed" +calculate_dirtyrate(int64_t dirtyrate) "dirty rate: %" PRIi64 =20 # block.c migration_block_init_shared(const char *blk_device_name) "Start migration = for %s with shared base image" --=20 2.24.3