From nobody Mon Feb 9 23:58:12 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=1623029379; cv=none; d=zohomail.com; s=zohoarc; b=QS/Ka8emUkUpQpcNV7jHOj8+CwzqPweLE1TRahvQGH1owr7M7LKTZFYBXLkZ0jv0Fo+JXB1RYUOLZGfkq40rigw6lFq5a3h/b9YX5PqRc2mRLV0WFaN9PP0vmu6XNeJ/u3UF1MWjLpZ1C3tVZbX0C0wp7rquCb28UGGmzyI/IDg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623029379; 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=yK0Z8UkQevB7qwB34wNUe/R318h71H7OeAjXjxs6Nsw=; b=V0MGbOtOw70W3xI1OL/y/Oa8cc4zKhNUObSjQzW6OTxrpuhJLyoB7IRjrffagtEOYZPc++96xPExc7bjUi14LYHDIeWZau3kyhNY9NsWqEH4gUP0KnttlANDH+Jbld+niQti6LV3ExkwjpptsKgmL4+BRcfkFlIfTiFnWPK61ZU= 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 1623029379289202.4951822465648; Sun, 6 Jun 2021 18:29:39 -0700 (PDT) Received: from localhost ([::1]:56300 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lq45C-0001Pl-B4 for importer@patchew.org; Sun, 06 Jun 2021 21:29:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49736) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lq408-0003Rb-Np for qemu-devel@nongnu.org; Sun, 06 Jun 2021 21:24:24 -0400 Received: from prt-mail.chinatelecom.cn ([42.123.76.220]:36077 helo=chinatelecom.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lq3pt-0004FN-36 for qemu-devel@nongnu.org; Sun, 06 Jun 2021 21:14:28 -0400 Received: from clientip-182.138.181.182?logid-e7583f06e12f448aa431b444b2fc2cc9 (unknown [172.18.0.218]) by chinatelecom.cn (HERMES) with SMTP id 1B1DA2800CC; Mon, 7 Jun 2021 09:13:00 +0800 (CST) Received: from ([172.18.0.218]) by app0025 with ESMTP id e7583f06e12f448aa431b444b2fc2cc9 for qemu-devel@nongnu.org; Mon Jun 7 09:12:59 2021 HMM_SOURCE_IP: 172.18.0.218:55792.962152414 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: +huangy81@chinatelecom.cn X-Transaction-ID: e7583f06e12f448aa431b444b2fc2cc9 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 5/7] migration/dirtyrate: adjust struct DirtyRateStat Date: Mon, 7 Jun 2021 09:12:54 +0800 Message-Id: <9be862eefa97e5e299dd26d4bf403d25ab317ee6.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.220; envelope-from=huangy81@chinatelecom.cn; helo=chinatelecom.cn X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, FORGED_SPF_HELO=1.997, KHOP_HELO_FCRDNS=0.398, SPF_HELO_PASS=-0.001, T_SPF_TEMPERROR=0.01 autolearn=no 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) 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 | 40 +++++++++++++++++++++------------------- migration/dirtyrate.h | 18 +++++++++++++++--- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 5947c688f6..055145c24c 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -88,33 +88,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, - uint64_t sample_pages) +static void init_dirtyrate_stat(int64_t start_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; - DirtyStat.sample_pages =3D sample_pages; + DirtyStat.calc_time =3D config.sample_period_seconds; + DirtyStat.sample_pages =3D config.sample_pages_per_gigabytes; + + if (config.per_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); @@ -327,7 +333,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 @@ -372,8 +378,6 @@ void *get_dirtyrate_thread(void *arg) struct DirtyRateConfig config =3D *(struct DirtyRateConfig *)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); @@ -383,9 +387,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; - sample_pages =3D config.sample_pages_per_gigabytes; - init_dirtyrate_stat(start_time, calc_time, sample_pages); + init_dirtyrate_stat(start_time, config); =20 calculate_dirtyrate(config); =20 diff --git a/migration/dirtyrate.h b/migration/dirtyrate.h index ec82716b40..af32e33d5d 100644 --- a/migration/dirtyrate.h +++ b/migration/dirtyrate.h @@ -59,17 +59,29 @@ 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= */ uint64_t sample_pages; /* sample pages per GB */ + union { + SampleVMStat vm; + VcpuStat vcpu; + } method; }; =20 void *get_dirtyrate_thread(void *arg); --=20 2.18.2