All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Dr . David Alan Gilbert" <dgilbert@redhat.com>,
	Peter Xu <peterx@redhat.com>
Subject: [PULL 09/28] memory: Introduce log_sync_global() to memory listener
Date: Mon, 24 May 2021 18:41:12 +0200	[thread overview]
Message-ID: <20210524164131.383778-10-pbonzini@redhat.com> (raw)
In-Reply-To: <20210524164131.383778-1-pbonzini@redhat.com>

From: Peter Xu <peterx@redhat.com>

Some of the memory listener may want to do log synchronization without
being able to specify a range of memory to sync but always globally.
Such a memory listener should provide this new method instead of the
log_sync() method.

Obviously we can also achieve similar thing when we put the global
sync logic into a log_sync() handler. However that's not efficient
enough because otherwise memory_global_dirty_log_sync() may do the
global sync N times, where N is the number of flat ranges in the
address space.

Make this new method be exclusive to log_sync().

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
Message-Id: <20210506160549.130416-2-peterx@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 include/exec/memory.h | 12 ++++++++++++
 softmmu/memory.c      | 33 +++++++++++++++++++++++----------
 2 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/include/exec/memory.h b/include/exec/memory.h
index c8b9088924..e38b7e3dce 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -616,6 +616,18 @@ struct MemoryListener {
      */
     void (*log_sync)(MemoryListener *listener, MemoryRegionSection *section);
 
+    /**
+     * @log_sync_global:
+     *
+     * This is the global version of @log_sync when the listener does
+     * not have a way to synchronize the log with finer granularity.
+     * When the listener registers with @log_sync_global defined, then
+     * its @log_sync must be NULL.  Vice versa.
+     *
+     * @listener: The #MemoryListener.
+     */
+    void (*log_sync_global)(MemoryListener *listener);
+
     /**
      * @log_clear:
      *
diff --git a/softmmu/memory.c b/softmmu/memory.c
index 3bb533c0bc..c19b0be6b1 100644
--- a/softmmu/memory.c
+++ b/softmmu/memory.c
@@ -2055,6 +2055,10 @@ void memory_region_set_dirty(MemoryRegion *mr, hwaddr addr,
                                         memory_region_get_dirty_log_mask(mr));
 }
 
+/*
+ * If memory region `mr' is NULL, do global sync.  Otherwise, sync
+ * dirty bitmap for the specified memory region.
+ */
 static void memory_region_sync_dirty_bitmap(MemoryRegion *mr)
 {
     MemoryListener *listener;
@@ -2068,18 +2072,24 @@ static void memory_region_sync_dirty_bitmap(MemoryRegion *mr)
      * address space once.
      */
     QTAILQ_FOREACH(listener, &memory_listeners, link) {
-        if (!listener->log_sync) {
-            continue;
-        }
-        as = listener->address_space;
-        view = address_space_get_flatview(as);
-        FOR_EACH_FLAT_RANGE(fr, view) {
-            if (fr->dirty_log_mask && (!mr || fr->mr == mr)) {
-                MemoryRegionSection mrs = section_from_flat_range(fr, view);
-                listener->log_sync(listener, &mrs);
+        if (listener->log_sync) {
+            as = listener->address_space;
+            view = address_space_get_flatview(as);
+            FOR_EACH_FLAT_RANGE(fr, view) {
+                if (fr->dirty_log_mask && (!mr || fr->mr == mr)) {
+                    MemoryRegionSection mrs = section_from_flat_range(fr, view);
+                    listener->log_sync(listener, &mrs);
+                }
             }
+            flatview_unref(view);
+        } else if (listener->log_sync_global) {
+            /*
+             * No matter whether MR is specified, what we can do here
+             * is to do a global sync, because we are not capable to
+             * sync in a finer granularity.
+             */
+            listener->log_sync_global(listener);
         }
-        flatview_unref(view);
     }
 }
 
@@ -2767,6 +2777,9 @@ void memory_listener_register(MemoryListener *listener, AddressSpace *as)
 {
     MemoryListener *other = NULL;
 
+    /* Only one of them can be defined for a listener */
+    assert(!(listener->log_sync && listener->log_sync_global));
+
     listener->address_space = as;
     if (QTAILQ_EMPTY(&memory_listeners)
         || listener->priority >= QTAILQ_LAST(&memory_listeners)->priority) {
-- 
2.31.1




  parent reply	other threads:[~2021-05-24 17:20 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-24 16:41 [PULL 00/28] Misc patches for 2021-05-24 Paolo Bonzini
2021-05-24 16:41 ` [PULL 01/28] configure: Only clone softfloat-3 repositories if TCG is enabled Paolo Bonzini
2021-05-24 16:41 ` [PULL 02/28] configure: check for submodules if --with-git-submodules=ignore Paolo Bonzini
2021-05-24 16:41 ` [PULL 03/28] configure: simplify assignment to GIT_SUBMODULES Paolo Bonzini
2021-05-24 16:41 ` [PULL 04/28] hw/mem/nvdimm: Use Kconfig 'imply' instead of 'depends on' Paolo Bonzini
2021-05-24 16:41 ` [PULL 05/28] i386/cpu: Expose AVX_VNNI instruction to guest Paolo Bonzini
2021-05-24 16:41 ` [PULL 06/28] object: add more commands to preconfig mode Paolo Bonzini
2021-05-24 16:41 ` [PULL 07/28] qtest: add a QOM object for qtest Paolo Bonzini
2021-06-04 15:37   ` Eric Blake
2021-06-04 15:45     ` Philippe Mathieu-Daudé
2021-06-04 15:48       ` Philippe Mathieu-Daudé
2021-05-24 16:41 ` [PULL 08/28] KVM: do not allow setting properties at runtime Paolo Bonzini
2021-05-24 16:41 ` Paolo Bonzini [this message]
2021-05-24 16:41 ` [PULL 10/28] KVM: Use a big lock to replace per-kml slots_lock Paolo Bonzini
2021-05-24 16:41 ` [PULL 11/28] KVM: Create the KVMSlot dirty bitmap on flag changes Paolo Bonzini
2021-05-24 16:41 ` [PULL 12/28] KVM: Provide helper to get kvm dirty log Paolo Bonzini
2021-05-24 16:41 ` [PULL 13/28] KVM: Provide helper to sync dirty bitmap from slot to ramblock Paolo Bonzini
2021-05-24 16:41 ` [PULL 14/28] KVM: Simplify dirty log sync in kvm_set_phys_mem Paolo Bonzini
2021-05-24 16:41 ` [PULL 15/28] KVM: Cache kvm slot dirty bitmap size Paolo Bonzini
2021-05-24 16:41 ` [PULL 16/28] KVM: Add dirty-ring-size property Paolo Bonzini
2021-05-24 16:41 ` [PULL 17/28] KVM: Disable manual dirty log when dirty ring enabled Paolo Bonzini
2021-05-24 16:41 ` [PULL 18/28] KVM: Dirty ring support Paolo Bonzini
2021-05-24 16:41 ` [PULL 19/28] tests/qtest/fuzz: Fix build failure Paolo Bonzini
2021-05-24 16:41 ` [PULL 20/28] meson: Set implicit_include_directories to false Paolo Bonzini
2021-05-24 16:41 ` [PULL 21/28] remove qemu-options* from root directory Paolo Bonzini
2021-05-24 16:41 ` [PULL 22/28] replication: move include out of " Paolo Bonzini
2021-05-24 16:41 ` [PULL 23/28] vl: allow not specifying size in -m when using -M memory-backend Paolo Bonzini
2021-05-24 16:41 ` [PULL 24/28] qemu-config: load modules when instantiating option groups Paolo Bonzini
2021-05-24 16:41 ` [PULL 25/28] doc: Add notes about -mon option mode=control argument Paolo Bonzini
2021-05-24 16:41 ` [PULL 26/28] configure: Avoid error messages about missing *-config-*.h files Paolo Bonzini
2021-05-24 16:41 ` [PULL 27/28] hw/scsi: Fix sector translation bug in scsi_unmap_complete_noio Paolo Bonzini
2021-05-24 16:41 ` [PULL 28/28] gitlab-ci: use --meson=git for CFI jobs Paolo Bonzini
2021-05-24 17:39 ` [PULL 00/28] Misc patches for 2021-05-24 no-reply
2021-05-24 18:02 ` Peter Maydell

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=20210524164131.383778-10-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=peterx@redhat.com \
    --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.