qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gonglei <arei.gonglei@huawei.com>
Subject: [Qemu-devel] [PULL 09/24] memory: drop find_ram_block()
Date: Mon, 23 May 2016 17:09:44 +0200	[thread overview]
Message-ID: <1464016199-43768-10-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1464016199-43768-1-git-send-email-pbonzini@redhat.com>

From: Gonglei <arei.gonglei@huawei.com>

On the one hand, we have already qemu_get_ram_block() whose function
is similar. On the other hand, we can directly use mr->ram_block but
searching RAMblock by ram_addr which is a kind of waste.

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Message-Id: <1462845901-89716-2-git-send-email-arei.gonglei@huawei.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 exec.c                    | 34 +++++++---------------------------
 include/exec/cpu-common.h |  4 ++--
 include/exec/ram_addr.h   |  2 +-
 memory.c                  |  2 +-
 migration/ram.c           |  2 +-
 migration/savevm.c        |  4 ++--
 6 files changed, 14 insertions(+), 34 deletions(-)

diff --git a/exec.c b/exec.c
index 59aed17..e2966ce 100644
--- a/exec.c
+++ b/exec.c
@@ -1411,34 +1411,18 @@ static void qemu_ram_setup_dump(void *addr, ram_addr_t size)
     }
 }
 
-/* Called within an RCU critical section, or while the ramlist lock
- * is held.
- */
-static RAMBlock *find_ram_block(ram_addr_t addr)
-{
-    RAMBlock *block;
-
-    QLIST_FOREACH_RCU(block, &ram_list.blocks, next) {
-        if (block->offset == addr) {
-            return block;
-        }
-    }
-
-    return NULL;
-}
-
 const char *qemu_ram_get_idstr(RAMBlock *rb)
 {
     return rb->idstr;
 }
 
 /* Called with iothread lock held.  */
-void qemu_ram_set_idstr(ram_addr_t addr, const char *name, DeviceState *dev)
+void qemu_ram_set_idstr(RAMBlock *new_block, const char *name, DeviceState *dev)
 {
-    RAMBlock *new_block, *block;
+    RAMBlock *block;
 
     rcu_read_lock();
-    new_block = find_ram_block(addr);
+
     assert(new_block);
     assert(!new_block->idstr[0]);
 
@@ -1452,7 +1436,8 @@ void qemu_ram_set_idstr(ram_addr_t addr, const char *name, DeviceState *dev)
     pstrcat(new_block->idstr, sizeof(new_block->idstr), name);
 
     QLIST_FOREACH_RCU(block, &ram_list.blocks, next) {
-        if (block != new_block && !strcmp(block->idstr, new_block->idstr)) {
+        if (block != new_block &&
+            !strcmp(block->idstr, new_block->idstr)) {
             fprintf(stderr, "RAMBlock \"%s\" already registered, abort!\n",
                     new_block->idstr);
             abort();
@@ -1462,17 +1447,14 @@ void qemu_ram_set_idstr(ram_addr_t addr, const char *name, DeviceState *dev)
 }
 
 /* Called with iothread lock held.  */
-void qemu_ram_unset_idstr(ram_addr_t addr)
+void qemu_ram_unset_idstr(RAMBlock *block)
 {
-    RAMBlock *block;
-
     /* FIXME: arch_init.c assumes that this is not called throughout
      * migration.  Ignore the problem since hot-unplug during migration
      * does not work anyway.
      */
 
     rcu_read_lock();
-    block = find_ram_block(addr);
     if (block) {
         memset(block->idstr, 0, sizeof(block->idstr));
     }
@@ -1496,10 +1478,8 @@ static int memory_try_enable_merging(void *addr, size_t len)
  * resize callback to update device state and/or add assertions to detect
  * misuse, if necessary.
  */
-int qemu_ram_resize(ram_addr_t base, ram_addr_t newsize, Error **errp)
+int qemu_ram_resize(RAMBlock *block, ram_addr_t newsize, Error **errp)
 {
-    RAMBlock *block = find_ram_block(base);
-
     assert(block);
 
     newsize = HOST_PAGE_ALIGN(newsize);
diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index 04eade5..a2c3b92 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -61,8 +61,8 @@ MemoryRegion *qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr);
 RAMBlock *qemu_ram_block_by_name(const char *name);
 RAMBlock *qemu_ram_block_from_host(void *ptr, bool round_offset,
                                    ram_addr_t *ram_addr, ram_addr_t *offset);
-void qemu_ram_set_idstr(ram_addr_t addr, const char *name, DeviceState *dev);
-void qemu_ram_unset_idstr(ram_addr_t addr);
+void qemu_ram_set_idstr(RAMBlock *block, const char *name, DeviceState *dev);
+void qemu_ram_unset_idstr(RAMBlock *block);
 const char *qemu_ram_get_idstr(RAMBlock *rb);
 
 void cpu_physical_memory_rw(hwaddr addr, uint8_t *buf,
diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
index 5adf7a4..5b6e1b8 100644
--- a/include/exec/ram_addr.h
+++ b/include/exec/ram_addr.h
@@ -110,7 +110,7 @@ void qemu_set_ram_fd(ram_addr_t addr, int fd);
 void *qemu_get_ram_block_host_ptr(ram_addr_t addr);
 void qemu_ram_free(RAMBlock *block);
 
-int qemu_ram_resize(ram_addr_t base, ram_addr_t newsize, Error **errp);
+int qemu_ram_resize(RAMBlock *block, ram_addr_t newsize, Error **errp);
 
 #define DIRTY_CLIENTS_ALL     ((1 << DIRTY_MEMORY_NUM) - 1)
 #define DIRTY_CLIENTS_NOCODE  (DIRTY_CLIENTS_ALL & ~(1 << DIRTY_MEMORY_CODE))
diff --git a/memory.c b/memory.c
index a8ef852..9daac5e 100644
--- a/memory.c
+++ b/memory.c
@@ -1673,7 +1673,7 @@ void memory_region_ram_resize(MemoryRegion *mr, ram_addr_t newsize, Error **errp
 {
     assert(mr->ram_block);
 
-    qemu_ram_resize(memory_region_get_ram_addr(mr), newsize, errp);
+    qemu_ram_resize(mr->ram_block, newsize, errp);
 }
 
 static void memory_region_update_coalesced_range_as(MemoryRegion *mr, AddressSpace *as)
diff --git a/migration/ram.c b/migration/ram.c
index 5e88080..6b6900e 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -2478,7 +2478,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
                     if (length != block->used_length) {
                         Error *local_err = NULL;
 
-                        ret = qemu_ram_resize(block->offset, length,
+                        ret = qemu_ram_resize(block, length,
                                               &local_err);
                         if (local_err) {
                             error_report_err(local_err);
diff --git a/migration/savevm.c b/migration/savevm.c
index bfb3d91..9bc362a 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -2229,13 +2229,13 @@ void hmp_info_snapshots(Monitor *mon, const QDict *qdict)
 
 void vmstate_register_ram(MemoryRegion *mr, DeviceState *dev)
 {
-    qemu_ram_set_idstr(memory_region_get_ram_addr(mr) & TARGET_PAGE_MASK,
+    qemu_ram_set_idstr(mr->ram_block,
                        memory_region_name(mr), dev);
 }
 
 void vmstate_unregister_ram(MemoryRegion *mr, DeviceState *dev)
 {
-    qemu_ram_unset_idstr(memory_region_get_ram_addr(mr) & TARGET_PAGE_MASK);
+    qemu_ram_unset_idstr(mr->ram_block);
 }
 
 void vmstate_register_ram_global(MemoryRegion *mr)
-- 
1.8.3.1

  parent reply	other threads:[~2016-05-23 15:10 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-23 15:09 [Qemu-devel] [PULL 00/24] Misc patches for 2016-05-23 Paolo Bonzini
2016-05-23 15:09 ` [Qemu-devel] [PULL 01/24] exec.c: Ensure right alignment also for file backed ram Paolo Bonzini
2016-05-23 15:09 ` [Qemu-devel] [PULL 02/24] docs/atomics.txt: Update pointer to linux macro Paolo Bonzini
2016-05-23 15:09 ` [Qemu-devel] [PULL 03/24] i386: kvmvapic: initialise imm32 variable Paolo Bonzini
2016-05-23 15:09 ` [Qemu-devel] [PULL 04/24] configure: Allow builds with extra warnings Paolo Bonzini
2016-05-23 15:09 ` [Qemu-devel] [PULL 05/24] target-i386: key sfence availability on CPUID_SSE, not CPUID_SSE2 Paolo Bonzini
2016-05-23 15:09 ` [Qemu-devel] [PULL 06/24] ioapic: keep RO bits for IOAPIC entry Paolo Bonzini
2016-05-23 15:09 ` [Qemu-devel] [PULL 07/24] ioapic: clear remote irr bit for edge-triggered interrupts Paolo Bonzini
2016-05-23 15:09 ` [Qemu-devel] [PULL 08/24] vl: change runstate only if new state is different from current state Paolo Bonzini
2016-05-23 15:09 ` Paolo Bonzini [this message]
2016-05-23 15:09 ` [Qemu-devel] [PULL 10/24] exec: adjust rcu_read_lock requirement Paolo Bonzini
2016-05-23 15:09 ` [Qemu-devel] [PULL 11/24] memory: Remove code for mr->may_overlap Paolo Bonzini
2016-05-23 15:09 ` [Qemu-devel] [PULL 12/24] memory: Drop FlatRange.romd_mode Paolo Bonzini
2016-05-23 15:09 ` [Qemu-devel] [PULL 13/24] memory: remove unnecessary masking of MemoryRegion ram_addr Paolo Bonzini
2016-05-23 15:09 ` [Qemu-devel] [PULL 14/24] cpus.c: Use pthread_sigmask() rather than sigprocmask() Paolo Bonzini
2016-05-23 15:09 ` [Qemu-devel] [PULL 15/24] Remove config-devices.mak on 'make clean' Paolo Bonzini
2016-05-23 15:09 ` [Qemu-devel] [PULL 16/24] scripts/signrom.py: Allow option ROM checksum script to write the size header Paolo Bonzini
2016-05-23 15:09 ` [Qemu-devel] [PULL 17/24] scripts/signrom.py: Check for magic in option ROMs Paolo Bonzini
2016-05-23 15:09 ` [Qemu-devel] [PULL 18/24] esp: check command buffer length before write(CVE-2016-4439) Paolo Bonzini
2016-05-23 15:09 ` [Qemu-devel] [PULL 19/24] esp: check dma length before reading scsi command(CVE-2016-4441) Paolo Bonzini
2016-05-23 15:09 ` [Qemu-devel] [PULL 20/24] iscsi: pass SCSI status back for SG_IO Paolo Bonzini
2016-05-23 15:09 ` [Qemu-devel] [PULL 21/24] coccinelle: add g_assert_cmp* to macro file Paolo Bonzini
2016-05-23 15:09 ` [Qemu-devel] [PULL 22/24] target-i386: add a generic x86 nmi handler Paolo Bonzini
2016-05-23 15:09 ` [Qemu-devel] [PULL 23/24] nmi: remove x86 specific nmi handling Paolo Bonzini
2016-05-23 15:09 ` [Qemu-devel] [PULL 24/24] cpus: call the core nmi injection function Paolo Bonzini
2016-05-23 16:16 ` [Qemu-devel] [PULL 00/24] Misc patches for 2016-05-23 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=1464016199-43768-10-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=arei.gonglei@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).