All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Subject: [PULL 34/48] physmem: Simplify dirty memory type checks with loop
Date: Wed, 22 Apr 2026 21:57:32 +0200	[thread overview]
Message-ID: <20260422195746.88865-35-philmd@linaro.org> (raw)
In-Reply-To: <20260422195746.88865-1-philmd@linaro.org>

From: Bin Guo <guobin@linux.alibaba.com>

In physical_memory_range_includes_clean(), we have three nearly identical
if-statements checking different DIRTY_MEMORY types (VGA, CODE, MIGRATION).
This code duplication makes maintenance harder and increases the risk of
inconsistencies when adding new dirty memory types.

Replace the repetitive checks with a simple loop that iterates through
all DIRTY_MEMORY_NUM types, checking only those specified in the mask.
This reduces code size and makes it easier to add new dirty memory types
in the future.

Signed-off-by: Bin Guo <guobin@linux.alibaba.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20260401100005.20651-1-guobin@linux.alibaba.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 system/physmem.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/system/physmem.c b/system/physmem.c
index 4e26f1a1d42..c58d940e807 100644
--- a/system/physmem.c
+++ b/system/physmem.c
@@ -981,17 +981,11 @@ uint8_t physical_memory_range_includes_clean(ram_addr_t start,
 {
     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);
+    for (int i = 0; i < DIRTY_MEMORY_NUM; i++) {
+        if ((mask & (1 << i)) &&
+            !physical_memory_all_dirty(start, length, i)) {
+            ret |= (1 << i);
+        }
     }
     return ret;
 }
-- 
2.53.0



  parent reply	other threads:[~2026-04-22 20:03 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-22 19:56 [PULL 00/49] Misc HW patches for 2026-04-22 Philippe Mathieu-Daudé
2026-04-22 19:56 ` [PULL 01/48] hw/avr: Build as common unit files Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 02/48] hw/misc/cpc: Include missing 'hw/core/cpu.h' header Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 03/48] hw/alpha: Include full path to target 'cpu.h' header Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 04/48] hw/arm: " Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 05/48] hw/avr: " Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 06/48] hw/hppa: " Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 07/48] hw/i386: " Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 08/48] hw/m68k: " Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 09/48] hw/microblaze: " Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 10/48] hw/mips: " Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 11/48] hw/or1k: " Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 12/48] hw/ppc: " Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 13/48] hw/riscv: " Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 14/48] hw/s390x: " Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 15/48] hw/sh4: " Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 16/48] hw/sparc: " Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 17/48] hw/tricore: " Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 18/48] hw/xtensa: " Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 19/48] hw/tpm: Factor tpm_ppi_enabled() out Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 20/48] hw/tpm: Add TPMIfClass::ppi_enabled field Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 21/48] hw/tpm: Remove CRBState::ppi_enabled field Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 22/48] hw/tpm: Propagate @ppi_enabled to tpm_tis_reset() and remove in TPMState Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 23/48] hw/tpm: Simplify tpm_ppi_enabled() Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 24/48] hw/ppc/spapr: Un-inline rtas_load/store() helpers Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 25/48] hw/hyperv: Replace legacy ld_phys() -> address_space_ld() Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 26/48] system/memory: Constify various AddressSpace arguments (flatview) Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 27/48] hw/core: Move compat_props_add() to 'hw/core/boards.h' Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 28/48] qom: Declare GlobalProperty structure in 'qom/compat-properties.h' Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 29/48] qom: Declare compat properties API " Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 30/48] qom: Restrict compat properties API to system emulation Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 31/48] docs/specs/tpm: document PPI support on ARM64 virt Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 32/48] hw/acpi/tpm: parameterize PPI base address in tpm_build_ppi_acpi Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 33/48] hw/tpm: add PPI support to tpm-tis-device for ARM64 virt Philippe Mathieu-Daudé
2026-04-22 19:57 ` Philippe Mathieu-Daudé [this message]
2026-04-22 19:57 ` [PULL 35/48] hw/arm/smmuv3: Have smmuv3_accel_init() take an Error* parameter Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 36/48] hw/arm/smmuv3: Avoid including CONFIG_DEVICES in hw/ header Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 37/48] hw/ppc/e500: fix bus-frequency property hardcoded to zero in CPU FDT node Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 38/48] ati-vga: fix unsigned integer overflow in cursor bounds checks Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 39/48] ati-vga: mask out lock bit from CUR_OFFSET in cursor offset calculation Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 40/48] hw/virtio/virtio-iommu: remove duplicate include Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 41/48] hw/hyperv: " Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 42/48] hw/ppc/amigaone: " Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 43/48] hw/misc: Fix the valid access size to the avr-power device Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 44/48] hw/sh4/sh7750: Remove forgotten abort() in the MM_ITLB_DATA handler Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 45/48] MAINTAINERS: Remove my unused git tree locations Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 46/48] MAINTAINERS: Remove my disfunctional emails Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 47/48] MAINTAINERS: Remove PhilMD from NVMe Block Driver Philippe Mathieu-Daudé
2026-04-22 19:57 ` [PULL 48/48] MAINTAINERS: Transfer CI maintenance to Pierrick Philippe Mathieu-Daudé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260422195746.88865-35-philmd@linaro.org \
    --to=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.