[Qemu-devel] [PATCH 42/51] ram: Pass RAMBlock to bitmap_sync

Juan Quintela posted 51 patches 8 years, 10 months ago
There is a newer version of this series
[Qemu-devel] [PATCH 42/51] ram: Pass RAMBlock to bitmap_sync
Posted by Juan Quintela 8 years, 10 months ago
We change the meaning of start to be the offset from the beggining of
the block.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 include/exec/ram_addr.h | 2 ++
 migration/ram.c         | 8 ++++----
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
index b05dc84..d50c970 100644
--- a/include/exec/ram_addr.h
+++ b/include/exec/ram_addr.h
@@ -354,11 +354,13 @@ static inline void cpu_physical_memory_clear_dirty_range(ram_addr_t start,
 
 static inline
 uint64_t cpu_physical_memory_sync_dirty_bitmap(unsigned long *dest,
+                                               RAMBlock *rb,
                                                ram_addr_t start,
                                                ram_addr_t length,
                                                int64_t *real_dirty_pages)
 {
     ram_addr_t addr;
+    start = rb->offset + start;
     unsigned long page = BIT_WORD(start >> TARGET_PAGE_BITS);
     uint64_t num_dirty = 0;
 
diff --git a/migration/ram.c b/migration/ram.c
index 064b2c0..9772fd8 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -648,13 +648,13 @@ static inline bool migration_bitmap_clear_dirty(RAMState *rs, ram_addr_t addr)
     return ret;
 }
 
-static void migration_bitmap_sync_range(RAMState *rs, ram_addr_t start,
-                                        ram_addr_t length)
+static void migration_bitmap_sync_range(RAMState *rs, RAMBlock *rb,
+                                        ram_addr_t start, ram_addr_t length)
 {
     unsigned long *bitmap;
     bitmap = atomic_rcu_read(&rs->ram_bitmap)->bmap;
     rs->migration_dirty_pages +=
-        cpu_physical_memory_sync_dirty_bitmap(bitmap, start, length,
+        cpu_physical_memory_sync_dirty_bitmap(bitmap, rb, start, length,
                                               &rs->num_dirty_pages_period);
 }
 
@@ -701,7 +701,7 @@ static void migration_bitmap_sync(RAMState *rs)
     qemu_mutex_lock(&rs->bitmap_mutex);
     rcu_read_lock();
     QLIST_FOREACH_RCU(block, &ram_list.blocks, next) {
-        migration_bitmap_sync_range(rs, block->offset, block->used_length);
+        migration_bitmap_sync_range(rs, block, 0, block->used_length);
     }
     rcu_read_unlock();
     qemu_mutex_unlock(&rs->bitmap_mutex);
-- 
2.9.3


Re: [Qemu-devel] [PATCH 42/51] ram: Pass RAMBlock to bitmap_sync
Posted by Yang Hongyang 8 years, 10 months ago
On 2017/3/24 4:45, Juan Quintela wrote:
> We change the meaning of start to be the offset from the beggining of
> the block.
> 
> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
>  include/exec/ram_addr.h | 2 ++
>  migration/ram.c         | 8 ++++----
>  2 files changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
> index b05dc84..d50c970 100644
> --- a/include/exec/ram_addr.h
> +++ b/include/exec/ram_addr.h
> @@ -354,11 +354,13 @@ static inline void cpu_physical_memory_clear_dirty_range(ram_addr_t start,
>  
>  static inline
>  uint64_t cpu_physical_memory_sync_dirty_bitmap(unsigned long *dest,
> +                                               RAMBlock *rb,
>                                                 ram_addr_t start,
>                                                 ram_addr_t length,
>                                                 int64_t *real_dirty_pages)
>  {
>      ram_addr_t addr;
> +    start = rb->offset + start;
>      unsigned long page = BIT_WORD(start >> TARGET_PAGE_BITS);
>      uint64_t num_dirty = 0;
>  
> diff --git a/migration/ram.c b/migration/ram.c
> index 064b2c0..9772fd8 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -648,13 +648,13 @@ static inline bool migration_bitmap_clear_dirty(RAMState *rs, ram_addr_t addr)
>      return ret;
>  }
>  
> -static void migration_bitmap_sync_range(RAMState *rs, ram_addr_t start,
> -                                        ram_addr_t length)
> +static void migration_bitmap_sync_range(RAMState *rs, RAMBlock *rb,
> +                                        ram_addr_t start, ram_addr_t length)
>  {
>      unsigned long *bitmap;
>      bitmap = atomic_rcu_read(&rs->ram_bitmap)->bmap;
>      rs->migration_dirty_pages +=
> -        cpu_physical_memory_sync_dirty_bitmap(bitmap, start, length,
> +        cpu_physical_memory_sync_dirty_bitmap(bitmap, rb, start, length,
>                                                &rs->num_dirty_pages_period);
>  }
>  
> @@ -701,7 +701,7 @@ static void migration_bitmap_sync(RAMState *rs)
>      qemu_mutex_lock(&rs->bitmap_mutex);
>      rcu_read_lock();
>      QLIST_FOREACH_RCU(block, &ram_list.blocks, next) {
> -        migration_bitmap_sync_range(rs, block->offset, block->used_length);
> +        migration_bitmap_sync_range(rs, block, 0, block->used_length);

Since RAMBlock been passed to bitmap_sync, could we remove
param 'block->used_length' either?

>      }
>      rcu_read_unlock();
>      qemu_mutex_unlock(&rs->bitmap_mutex);
> 

-- 
Thanks,
Yang


Re: [Qemu-devel] [PATCH 42/51] ram: Pass RAMBlock to bitmap_sync
Posted by Dr. David Alan Gilbert 8 years, 10 months ago
* Juan Quintela (quintela@redhat.com) wrote:
> We change the meaning of start to be the offset from the beggining of
> the block.

s/beggining/beginning/

Why do this?
We have:
   migration_bitmap_sync (all blocks)
   migration_bitmap_sync_range - called per block
   cpu_physical_memory_sync_dirty_bitmap

Why keep migration_bitmap_sync_range having start/length as well as the block
if you could just rename it to migration_bitmap_sync_block and just give it the rb?
And since cpu_physical_memory_clear_dirty_range is lower level, why give it
the rb?

Dave


> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
>  include/exec/ram_addr.h | 2 ++
>  migration/ram.c         | 8 ++++----
>  2 files changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
> index b05dc84..d50c970 100644
> --- a/include/exec/ram_addr.h
> +++ b/include/exec/ram_addr.h
> @@ -354,11 +354,13 @@ static inline void cpu_physical_memory_clear_dirty_range(ram_addr_t start,
>  
>  static inline
>  uint64_t cpu_physical_memory_sync_dirty_bitmap(unsigned long *dest,
> +                                               RAMBlock *rb,
>                                                 ram_addr_t start,
>                                                 ram_addr_t length,
>                                                 int64_t *real_dirty_pages)
>  {
>      ram_addr_t addr;
> +    start = rb->offset + start;
>      unsigned long page = BIT_WORD(start >> TARGET_PAGE_BITS);
>      uint64_t num_dirty = 0;
>  
> diff --git a/migration/ram.c b/migration/ram.c
> index 064b2c0..9772fd8 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -648,13 +648,13 @@ static inline bool migration_bitmap_clear_dirty(RAMState *rs, ram_addr_t addr)
>      return ret;
>  }
>  
> -static void migration_bitmap_sync_range(RAMState *rs, ram_addr_t start,
> -                                        ram_addr_t length)
> +static void migration_bitmap_sync_range(RAMState *rs, RAMBlock *rb,
> +                                        ram_addr_t start, ram_addr_t length)
>  {
>      unsigned long *bitmap;
>      bitmap = atomic_rcu_read(&rs->ram_bitmap)->bmap;
>      rs->migration_dirty_pages +=
> -        cpu_physical_memory_sync_dirty_bitmap(bitmap, start, length,
> +        cpu_physical_memory_sync_dirty_bitmap(bitmap, rb, start, length,
>                                                &rs->num_dirty_pages_period);
>  }
>  
> @@ -701,7 +701,7 @@ static void migration_bitmap_sync(RAMState *rs)
>      qemu_mutex_lock(&rs->bitmap_mutex);
>      rcu_read_lock();
>      QLIST_FOREACH_RCU(block, &ram_list.blocks, next) {
> -        migration_bitmap_sync_range(rs, block->offset, block->used_length);
> +        migration_bitmap_sync_range(rs, block, 0, block->used_length);
>      }
>      rcu_read_unlock();
>      qemu_mutex_unlock(&rs->bitmap_mutex);
> -- 
> 2.9.3
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK