From nobody Thu Nov 6 14:23:13 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489454883831727.0739625227819; Mon, 13 Mar 2017 18:28:03 -0700 (PDT) Received: from localhost ([::1]:55901 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnbFq-0002iF-3U for importer@patchew.org; Mon, 13 Mar 2017 21:28:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39798) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnbFO-0002hv-RU for qemu-devel@nongnu.org; Mon, 13 Mar 2017 21:27:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cnbFK-0003gX-T0 for qemu-devel@nongnu.org; Mon, 13 Mar 2017 21:27:34 -0400 Received: from [59.151.112.132] (port=39273 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnbFK-0003ar-2X for qemu-devel@nongnu.org; Mon, 13 Mar 2017 21:27:30 -0400 Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 14 Mar 2017 09:27:14 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id 5B21348A294D; Tue, 14 Mar 2017 09:27:16 +0800 (CST) Received: from localhost (10.167.226.75) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server id 14.3.319.2; Tue, 14 Mar 2017 09:27:14 +0800 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="16529339" From: Chao Fan To: , , , , Date: Tue, 14 Mar 2017 09:26:46 +0800 Message-ID: <20170314012646.30560-1-fanc.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.9.3 MIME-Version: 1.0 X-yoursite-MailScanner-ID: 5B21348A294D.AC094 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: fanc.fnst@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Subject: [Qemu-devel] [PATCH] Change the method to calculate dirty-pages-rate X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: douly.fnst@cn.fujitsu.com, caoj.fnst@cn.fujitsu.com, Chao Fan , maozy.fnst@cn.fujitsu.com, Li Zhijian Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In function cpu_physical_memory_sync_dirty_bitmap, file include/exec/ram_addr.h: if (src[idx][offset]) { unsigned long bits =3D atomic_xchg(&src[idx][offset], 0); unsigned long new_dirty; new_dirty =3D ~dest[k]; dest[k] |=3D bits; new_dirty &=3D bits; num_dirty +=3D ctpopl(new_dirty); } After these codes executed, only the pages not dirtied in bitmap(dest), but dirtied in dirty_memory[DIRTY_MEMORY_MIGRATION] will be calculated. For example: When ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] =3D 0b00001111, and atomic_rcu_read(&migration_bitmap_rcu)->bmap =3D 0b00000011, the new_dirty will be 0b00001100, and this function will return 2 but not 4 which is expected. the dirty pages in dirty_memory[DIRTY_MEMORY_MIGRATION] are all new, so these should be calculated also. Signed-off-by: Chao Fan Signed-off-by: Li Zhijian --- include/exec/ram_addr.h | 5 ++++- migration/ram.c | 7 +++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index cd432e7..b05dc84 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -355,7 +355,8 @@ static inline void cpu_physical_memory_clear_dirty_rang= e(ram_addr_t start, static inline uint64_t cpu_physical_memory_sync_dirty_bitmap(unsigned long *dest, ram_addr_t start, - ram_addr_t length) + ram_addr_t length, + int64_t *real_dirty_pages) { ram_addr_t addr; unsigned long page =3D BIT_WORD(start >> TARGET_PAGE_BITS); @@ -379,6 +380,7 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(unsigned= long *dest, if (src[idx][offset]) { unsigned long bits =3D atomic_xchg(&src[idx][offset], 0); unsigned long new_dirty; + *real_dirty_pages +=3D ctpopl(bits); new_dirty =3D ~dest[k]; dest[k] |=3D bits; new_dirty &=3D bits; @@ -398,6 +400,7 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(unsigned= long *dest, start + addr, TARGET_PAGE_SIZE, DIRTY_MEMORY_MIGRATION)) { + *real_dirty_pages +=3D 1; long k =3D (start + addr) >> TARGET_PAGE_BITS; if (!test_and_set_bit(k, dest)) { num_dirty++; diff --git a/migration/ram.c b/migration/ram.c index 719425b..fdf9a85 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -576,18 +576,18 @@ static inline bool migration_bitmap_clear_dirty(ram_a= ddr_t addr) return ret; } =20 +static int64_t num_dirty_pages_period; static void migration_bitmap_sync_range(ram_addr_t start, ram_addr_t lengt= h) { unsigned long *bitmap; bitmap =3D atomic_rcu_read(&migration_bitmap_rcu)->bmap; - migration_dirty_pages +=3D - cpu_physical_memory_sync_dirty_bitmap(bitmap, start, length); + migration_dirty_pages +=3D cpu_physical_memory_sync_dirty_bitmap(bitma= p, + start, length, &num_dirty_pages_period); } =20 /* Fix me: there are too many global variables used in migration process. = */ static int64_t start_time; static int64_t bytes_xfer_prev; -static int64_t num_dirty_pages_period; static uint64_t xbzrle_cache_miss_prev; static uint64_t iterations_prev; =20 @@ -648,7 +648,6 @@ static void migration_bitmap_sync(void) =20 trace_migration_bitmap_sync_end(migration_dirty_pages - num_dirty_pages_init); - num_dirty_pages_period +=3D migration_dirty_pages - num_dirty_pages_in= it; end_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); =20 /* more than 1 second =3D 1000 millisecons */ --=20 2.9.3