From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 450E5CAC5BB for ; Wed, 1 Oct 2025 17:58:58 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v414C-00039E-El; Wed, 01 Oct 2025 13:56:40 -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 1v413y-0002hX-Kt for qemu-devel@nongnu.org; Wed, 01 Oct 2025 13:56:26 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1v413N-00016f-E1 for qemu-devel@nongnu.org; Wed, 01 Oct 2025 13:56:25 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-46e37d10ed2so787865e9.2 for ; Wed, 01 Oct 2025 10:55:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1759341340; x=1759946140; darn=nongnu.org; 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=d4FpKgP4EA24JaZyt14rp8t6FdQHApouicK9Mpxbqsc=; b=OHfGS9VBxQwLopQOSSpKRlx+f4QDjAypAm53a+B1F83jr9ATLoJ8WscKaOOs5gjaiZ j++AZFyuwsEDMXW7b/vDPrisrni5h8MmAtLFMqIDDRi8bej/VgphJ9TfQyfIPj687v0b m64MJYcciDIGdGVGu9tOBHzkR2HeHT9YaZ91uKi+V9ttVTwLZ+qgzraDT2YdsITm1Cjf hTVRY5FDiHmOEsUxhZvW+8BBk3meU2sImAVGWddW4R5QhwrEOgLmD8s8yTsINyHJmuSU pQa0bgy+AvHUH8hUhtkgPty5NotTfBTw+Z2WDCofmn5gtyn9kQxXabUT5RGQ8K1sVSBp Q+6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759341340; x=1759946140; 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=d4FpKgP4EA24JaZyt14rp8t6FdQHApouicK9Mpxbqsc=; b=uL3wTKuUlSb767smSAajJZUATHpmrkH9UBd819d6Eq8Rup1FuUvwfo/b7Y0P35ocWb mK91SMJjKly1d/frsKfJOLsA+sZxJUwsbqDh8cca/J8j9dpbBGruk9zr32kMs2U3V5oR sPMU7Qso8gTbeNLj+67Sjjg99IftjNKObujUZrj2ZmqHQNZM14rFPMlw/QBrw29WgkWZ dQBM0SFcOIaEP7kQWrQfK581PYcpwEioVi5DZlHZLT3CQhrUuc4NMPawxs+gsofoXrDx VQfXz8zc4xlZAEc8pNfACuk5NyimE2I9brjKJUljiL8bzTVDH4owxAQiyG9msNadDT9H 0s8w== X-Gm-Message-State: AOJu0YxnFF/5Dihf+f6QQOFzyEIR6qK/AhlP+/SqEYDu+/DdtyqcEbmA oSS8WfHHiRRDRdhVjTJqYw5MGwWaylWd3c9/gU5hY2rl9XnpfNdJbxipHXKjctjNmD4ZJhs4Csh m05LfOB+UTQ== X-Gm-Gg: ASbGnctr4Ieh6Fsp/iz5ortSomwzna0ftYvqkghOgez1fFkIlqJLAa4gdQRLfd82Cj+ vmagYeLT+62hlFQqUi9xycGHS52VSvOpqjS800gkZS10ITgmnM7yN/XDTBQNUxPR8p6NGJOikzW ZSHR1IV3U7hbUugkR2P8TgCoTDZfbkE+6EhV+4BCdtYT/BbqdMJ4Cn3pmN71zBAg2oKvCpxsWmY Se5ARnAivWm9Tji5ijoF+Lhf7yTBUakBMtwIbz6iCzEweIAYmq6BKAsm7Op6siib6u9djSRZUzu FptwEmSLhHJlV98Oae/yxA98f38JIWWsJlXC+pRWgY+v1J0GU8csTipZMemg7zIJ2b6rtyJD+Gg VydpruhLwIlS0IKbHXHBDyLFUFG8HJ57/5p5tT266TIErlQXSRXUljJ8vGnkPBpCZBBHwasmp/i mFv79RFTUP70m0St35QtdrDOOLErHxd6r04LeV X-Google-Smtp-Source: AGHT+IF0xbC1IEd8QMB22IhbYKtfRZKDX/TCaConk1RKW1e7VjrGfmv9+PMY2JeZ2AZyw41zjVsNuw== X-Received: by 2002:a05:600c:620d:b0:46d:996b:828c with SMTP id 5b1f17b1804b1-46e61218f70mr40496535e9.10.1759341339699; Wed, 01 Oct 2025 10:55:39 -0700 (PDT) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-46e619b8507sm48708415e9.3.2025.10.01.10.55.38 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 01 Oct 2025 10:55:39 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Peter Maydell , Jagannathan Raman , qemu-ppc@nongnu.org, Ilya Leoshkevich , Thomas Huth , Jason Herne , Peter Xu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , kvm@vger.kernel.org, Christian Borntraeger , Halil Pasic , Matthew Rosato , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , "Michael S. Tsirkin" , Elena Ufimtseva , Richard Henderson , Harsh Prateek Bora , Fabiano Rosas , Eric Farman , qemu-arm@nongnu.org, qemu-s390x@nongnu.org, David Hildenbrand , Alex Williamson , Nicholas Piggin Subject: [PATCH v2 09/18] system/physmem: Un-inline cpu_physical_memory_range_includes_clean() Date: Wed, 1 Oct 2025 19:54:38 +0200 Message-ID: <20251001175448.18933-10-philmd@linaro.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251001175448.18933-1-philmd@linaro.org> References: <20251001175448.18933-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=philmd@linaro.org; helo=mail-wm1-x32d.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 autolearn=unavailable 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Avoid maintaining large functions in header, rely on the linker to optimize at linking time. cpu_physical_memory_all_dirty() doesn't involve any CPU, remove the 'cpu_' prefix. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- include/system/ram_addr.h | 62 ++------------------------------------- system/physmem.c | 60 +++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 59 deletions(-) diff --git a/include/system/ram_addr.h b/include/system/ram_addr.h index cdf25c315be..2dcca260b2b 100644 --- a/include/system/ram_addr.h +++ b/include/system/ram_addr.h @@ -142,69 +142,13 @@ static inline void qemu_ram_block_writeback(RAMBlock *block) #define DIRTY_CLIENTS_ALL ((1 << DIRTY_MEMORY_NUM) - 1) #define DIRTY_CLIENTS_NOCODE (DIRTY_CLIENTS_ALL & ~(1 << DIRTY_MEMORY_CODE)) -static inline bool cpu_physical_memory_all_dirty(ram_addr_t start, - ram_addr_t length, - unsigned client) -{ - DirtyMemoryBlocks *blocks; - unsigned long end, page; - unsigned long idx, offset, base; - bool dirty = true; - - assert(client < DIRTY_MEMORY_NUM); - - end = TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS; - page = start >> TARGET_PAGE_BITS; - - RCU_READ_LOCK_GUARD(); - - blocks = qatomic_rcu_read(&ram_list.dirty_memory[client]); - - idx = page / DIRTY_MEMORY_BLOCK_SIZE; - offset = page % DIRTY_MEMORY_BLOCK_SIZE; - base = page - offset; - while (page < end) { - unsigned long next = MIN(end, base + DIRTY_MEMORY_BLOCK_SIZE); - unsigned long num = next - base; - unsigned long found = find_next_zero_bit(blocks->blocks[idx], num, offset); - if (found < num) { - dirty = false; - break; - } - - page = next; - idx++; - offset = 0; - base += DIRTY_MEMORY_BLOCK_SIZE; - } - - return dirty; -} - bool cpu_physical_memory_get_dirty_flag(ram_addr_t addr, unsigned client); bool cpu_physical_memory_is_clean(ram_addr_t addr); -static inline uint8_t cpu_physical_memory_range_includes_clean(ram_addr_t start, - ram_addr_t length, - uint8_t mask) -{ - uint8_t ret = 0; - - if (mask & (1 << DIRTY_MEMORY_VGA) && - !cpu_physical_memory_all_dirty(start, length, DIRTY_MEMORY_VGA)) { - ret |= (1 << DIRTY_MEMORY_VGA); - } - if (mask & (1 << DIRTY_MEMORY_CODE) && - !cpu_physical_memory_all_dirty(start, length, DIRTY_MEMORY_CODE)) { - ret |= (1 << DIRTY_MEMORY_CODE); - } - if (mask & (1 << DIRTY_MEMORY_MIGRATION) && - !cpu_physical_memory_all_dirty(start, length, DIRTY_MEMORY_MIGRATION)) { - ret |= (1 << DIRTY_MEMORY_MIGRATION); - } - return ret; -} +uint8_t cpu_physical_memory_range_includes_clean(ram_addr_t start, + ram_addr_t length, + uint8_t mask); static inline void cpu_physical_memory_set_dirty_flag(ram_addr_t addr, unsigned client) diff --git a/system/physmem.c b/system/physmem.c index fb6a7378ff7..2667f289044 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -954,6 +954,66 @@ bool cpu_physical_memory_is_clean(ram_addr_t addr) return !(vga && code && migration); } +static bool physical_memory_all_dirty(ram_addr_t start, ram_addr_t length, + unsigned client) +{ + DirtyMemoryBlocks *blocks; + unsigned long end, page; + unsigned long idx, offset, base; + bool dirty = true; + + assert(client < DIRTY_MEMORY_NUM); + + end = TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS; + page = start >> TARGET_PAGE_BITS; + + RCU_READ_LOCK_GUARD(); + + blocks = qatomic_rcu_read(&ram_list.dirty_memory[client]); + + idx = page / DIRTY_MEMORY_BLOCK_SIZE; + offset = page % DIRTY_MEMORY_BLOCK_SIZE; + base = page - offset; + while (page < end) { + unsigned long next = MIN(end, base + DIRTY_MEMORY_BLOCK_SIZE); + unsigned long num = next - base; + unsigned long found = find_next_zero_bit(blocks->blocks[idx], + num, offset); + if (found < num) { + dirty = false; + break; + } + + page = next; + idx++; + offset = 0; + base += DIRTY_MEMORY_BLOCK_SIZE; + } + + return dirty; +} + +uint8_t cpu_physical_memory_range_includes_clean(ram_addr_t start, + ram_addr_t length, + uint8_t mask) +{ + uint8_t ret = 0; + + if (mask & (1 << DIRTY_MEMORY_VGA) && + !physical_memory_all_dirty(start, length, DIRTY_MEMORY_VGA)) { + ret |= (1 << DIRTY_MEMORY_VGA); + } + if (mask & (1 << DIRTY_MEMORY_CODE) && + !physical_memory_all_dirty(start, length, DIRTY_MEMORY_CODE)) { + ret |= (1 << DIRTY_MEMORY_CODE); + } + if (mask & (1 << DIRTY_MEMORY_MIGRATION) && + !physical_memory_all_dirty(start, length, DIRTY_MEMORY_MIGRATION)) { + ret |= (1 << DIRTY_MEMORY_MIGRATION); + } + return ret; +} + /* Note: start and end must be within the same ram block. */ bool cpu_physical_memory_test_and_clear_dirty(ram_addr_t start, ram_addr_t length, -- 2.51.0