From patchwork Tue Jun 13 09:38:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 691955 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d91:0:0:0:0:0 with SMTP id b17csp324084wru; Tue, 13 Jun 2023 02:51:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ciUTR0SXMSIhKO9MYJ2VzCP3A/Iz0qMFnDkcxjCIZQICzpryXLQ1kj1mkjzpLooYwZa34 X-Received: by 2002:a05:620a:24ca:b0:75e:c383:18a1 with SMTP id m10-20020a05620a24ca00b0075ec38318a1mr15592082qkn.7.1686649884800; Tue, 13 Jun 2023 02:51:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686649884; cv=none; d=google.com; s=arc-20160816; b=wHBW/9XF8sbgILbomeUdHNWE7jjKYq5fwt7kC+PNHRLrGKLsJAkYHqVeilByqd7tJt ULnwoR/ss2D3e5ltxzkON3LoT0zi9E6+m+S4YHPi5vX5I+bZ/V6LYgz3BbWUgpu5dX73 lWm4t9YC6ZlxqFgJ7h+tm4GubDwaqURix76pEsYJQfPPnAFfkHScR3HTF74UMzq9DXU+ IPsEXkpjMx6+2iCwROVBu5YZj5Qlwfr+Q7JfQk43HumvQ7/wSKMgFRZ+IReWkgtZSJKk LT1MJFJBLd36ATeln8Md8U05BeNKII9vn15ZWSARFtF7gYE0cYEIlnIgDzSH+3aA4X0I K4Bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=G228fEEG3KGPqTypnQQNKK4WYtjAfFhy5BxWLUD+e/U=; b=AYWuQ2fOw7WmVf0R6ehbvQ2fn31p9DKTU+4LF0n1vejlahBp/KxGpuSoUpWVfrTsgo xupEEUed/bgvQ6/wzKDb9kEjouM2BQ/CZ/7ubDwfCxQZPaA6y3PH5JoJ5L8j8COk2HRO RyyWZI1UqdqBPGreVpKIqdkSKnjOyW3WgX6uAMFs7mDUrixtYMBB53c+B8Q9wd6p476I BId0rBfHYzCY27CVr/p++Kyu+9YCoaMwEAfHAX3Cbc8+gfMMuU+WhAOHqeOP3TbzQ+Hf ++4u8kEQzE0755N/QoyXcqQVIYaaltwukqYZFLo1V4fn8UHPfvblty42zSU7HQFq2Ggs bMkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=R4rj8sg6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id oq23-20020a05620a611700b0074e014414b7si7272728qkn.775.2023.06.13.02.51.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 13 Jun 2023 02:51:24 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=R4rj8sg6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q90V8-0005km-Kq; Tue, 13 Jun 2023 05:39:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q90V6-0005kG-Qc for qemu-devel@nongnu.org; Tue, 13 Jun 2023 05:39:44 -0400 Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q90Uy-0005gc-Ku for qemu-devel@nongnu.org; Tue, 13 Jun 2023 05:39:44 -0400 Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-5147e8972a1so9235104a12.0 for ; Tue, 13 Jun 2023 02:39:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686649173; x=1689241173; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=G228fEEG3KGPqTypnQQNKK4WYtjAfFhy5BxWLUD+e/U=; b=R4rj8sg6Hi0kVUyzc1faFJ1L557UaQ0xAO9Hcf5jAjeQNBD0weg2dfiyBC/CWE3CuF YyiRdR253zu7VNRtRXEVkN08gzWpP3rcxmvCzd8Uj1JAcJah1F9ZbOK6rhXL/H7UzZrH b5ehSPregSQXwUfmwJ/k2yREToZMONAfs/8rntWN4nVV+oolcSSsm+sukGNyQNoLg68j hJ1gVCUEERKe6/RqpsDTjPv9A5JJ56P/pGC4cI/kX7thT0+VubPuDpnYGqw/1wovPbVV HiFaGv2BJb3rrcT+QNld8RBkK9cc3yb5f/VFIcYhe78q6a2dYRttBASU3FrrhMcO1VRS Esog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686649173; x=1689241173; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G228fEEG3KGPqTypnQQNKK4WYtjAfFhy5BxWLUD+e/U=; b=I1K8yjzF0vqpDHCWiBVUwdosaDNvKNcNn4J+p4Dy5aSUbAjtMfWuRSeA6b5xBhEJUd C5NyiSdNaHuSV+LrN46sH8LmBZuDizJqo8l101N3yQnqTAqKZhPrR/dTMTeoUXfh+Cxk duKZwSGiQqcdAR0HDKmV4kkCi8+uZVejdOV5w9EAlqYoIHUJaAbkt2lXxslRTCoy6iBU Ot9MrOCX1Yl0PxynhGuTnBihwGuHye0k1gmRTZV717yMuYY8gdI+jelKeb/nqGGeL7aE 1h6IM82nywJ/U36+rcO0mxVaG/KpC8/gDiTF0Mfh2w6uvctN67om+KR0g3p2N8Ty3MMP 805g== X-Gm-Message-State: AC+VfDx+D1FNGpjwnzgEVICuREL29Q5t+0f/NozBNHLPzKs+DqaxGGNU mqGknLmBcjH52xOc+GHt0xYRRNzEplkWl479wXCLrw== X-Received: by 2002:a05:6402:1487:b0:518:670a:7c57 with SMTP id e7-20020a056402148700b00518670a7c57mr2243685edv.14.1686649173369; Tue, 13 Jun 2023 02:39:33 -0700 (PDT) Received: from localhost.localdomain ([185.140.244.249]) by smtp.gmail.com with ESMTPSA id a25-20020aa7d919000000b00511aea132b9sm6198912edr.3.2023.06.13.02.39.32 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 13 Jun 2023 02:39:33 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Joao Martins , Peter Xu , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 15/17] exec/ram_addr: Return number of dirty pages in cpu_physical_memory_set_dirty_lebitmap() Date: Tue, 13 Jun 2023 11:38:20 +0200 Message-Id: <20230613093822.63750-16-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230613093822.63750-1-philmd@linaro.org> References: <20230613093822.63750-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::532; envelope-from=philmd@linaro.org; helo=mail-ed1-x532.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Joao Martins In preparation for including the number of dirty pages in the vfio_get_dirty_bitmap() tracepoint, return the number of dirty pages in cpu_physical_memory_set_dirty_lebitmap() similar to cpu_physical_memory_sync_dirty_bitmap(). To avoid counting twice when GLOBAL_DIRTY_RATE is enabled, stash the number of bits set per bitmap quad in a variable (@nbits) and reuse it there. Signed-off-by: Joao Martins Reviewed-by: Peter Xu Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20230530180556.24441-2-joao.m.martins@oracle.com> Signed-off-by: Philippe Mathieu-Daudé --- include/exec/ram_addr.h | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index 90a8269290..9f2e3893f5 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -334,14 +334,23 @@ static inline void cpu_physical_memory_set_dirty_range(ram_addr_t start, } #if !defined(_WIN32) -static inline void cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap, - ram_addr_t start, - ram_addr_t pages) + +/* + * Contrary to cpu_physical_memory_sync_dirty_bitmap() this function returns + * the number of dirty pages in @bitmap passed as argument. On the other hand, + * cpu_physical_memory_sync_dirty_bitmap() returns newly dirtied pages that + * weren't set in the global migration bitmap. + */ +static inline +uint64_t cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap, + ram_addr_t start, + ram_addr_t pages) { unsigned long i, j; - unsigned long page_number, c; + unsigned long page_number, c, nbits; hwaddr addr; ram_addr_t ram_addr; + uint64_t num_dirty = 0; unsigned long len = (pages + HOST_LONG_BITS - 1) / HOST_LONG_BITS; unsigned long hpratio = qemu_real_host_page_size() / TARGET_PAGE_SIZE; unsigned long page = BIT_WORD(start >> TARGET_PAGE_BITS); @@ -369,6 +378,7 @@ static inline void cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap, if (bitmap[k]) { unsigned long temp = leul_to_cpu(bitmap[k]); + nbits = ctpopl(temp); qatomic_or(&blocks[DIRTY_MEMORY_VGA][idx][offset], temp); if (global_dirty_tracking) { @@ -377,10 +387,12 @@ static inline void cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap, temp); if (unlikely( global_dirty_tracking & GLOBAL_DIRTY_DIRTY_RATE)) { - total_dirty_pages += ctpopl(temp); + total_dirty_pages += nbits; } } + num_dirty += nbits; + if (tcg_enabled()) { qatomic_or(&blocks[DIRTY_MEMORY_CODE][idx][offset], temp); @@ -409,9 +421,11 @@ static inline void cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap, for (i = 0; i < len; i++) { if (bitmap[i] != 0) { c = leul_to_cpu(bitmap[i]); + nbits = ctpopl(c); if (unlikely(global_dirty_tracking & GLOBAL_DIRTY_DIRTY_RATE)) { - total_dirty_pages += ctpopl(c); + total_dirty_pages += nbits; } + num_dirty += nbits; do { j = ctzl(c); c &= ~(1ul << j); @@ -424,6 +438,8 @@ static inline void cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap, } } } + + return num_dirty; } #endif /* not _WIN32 */