From nobody Mon Feb 9 20:36:29 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=1623008934; cv=none; d=zohomail.com; s=zohoarc; b=d87weIBGw7t9/amSCTl3v87AlCnNYNMhZ8Y1WTnK1blFFLu9Pe0keBqS2ccoRYNI5Dqdc3wiE6xBzFaCjM/1l1EjK26zCkgVTJua7x+jXu7ZllyH4h565oue49xiemGF/ktfwyKaUQiCooTNBakyIJLotGXbm69vTb5Bf+DA2wE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623008934; 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=YiI+41P9FOwV5SiCFiXI4U7K53k++D7dnveFmhJffFoHky7mxNM9ngRbBNh0pAlVozSeyfreOXnBfCjS3w+2f1jjFJPw1ZsKXjY6LrS7PG8OQpz5E9Kg+sAL2fr6qrFkvaI1rL4M3bydU7z710+Le545r657qauSn9Ie0bXovVE= 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 1623008934514442.1546721655684; Sun, 6 Jun 2021 12:48:54 -0700 (PDT) Received: from localhost ([::1]:40402 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lpylR-00088H-A5 for importer@patchew.org; Sun, 06 Jun 2021 15:48:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39336) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lpyka-0006Eg-Nj for qemu-devel@nongnu.org; Sun, 06 Jun 2021 15:48:00 -0400 Received: from prt-mail.chinatelecom.cn ([42.123.76.223]:48424 helo=chinatelecom.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lpykY-0001yz-Bb for qemu-devel@nongnu.org; Sun, 06 Jun 2021 15:48:00 -0400 Received: from clientip-182.138.181.182?logid-3baf8edfb7cb4197920492887b8f9e01 (unknown [172.18.0.48]) by chinatelecom.cn (HERMES) with SMTP id 6025E2800A8; Mon, 7 Jun 2021 03:47:56 +0800 (CST) Received: from ([172.18.0.48]) by app0024 with ESMTP id 3baf8edfb7cb4197920492887b8f9e01 for qemu-devel@nongnu.org; Mon Jun 7 03:47:57 2021 HMM_SOURCE_IP: 172.18.0.48:45766.974914747 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: +huangy81@chinatelecom.cn X-Transaction-ID: 3baf8edfb7cb4197920492887b8f9e01 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: qemu-devel@nongnu.org Subject: [PATCH v2 4/6] migration/dirtyrate: adjust struct DirtyRateStat Date: Mon, 7 Jun 2021 03:47:51 +0800 Message-Id: <9be862eefa97e5e299dd26d4bf403d25ab317ee6.1623007591.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.223; 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) 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