diff mbox

[24/38] memory: use find_next_bit() to find dirty bits

Message ID 1387293974-24718-25-git-send-email-quintela@redhat.com
State New
Headers show

Commit Message

Juan Quintela Dec. 17, 2013, 3:26 p.m. UTC
This operation is way faster than doing it bit by bit.

Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
 include/exec/memory-internal.h | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

Comments

Orit Wasserman Dec. 18, 2013, 11:48 a.m. UTC | #1
On 12/17/2013 05:26 PM, Juan Quintela wrote:
> This operation is way faster than doing it bit by bit.
>
> Signed-off-by: Juan Quintela <quintela@redhat.com>
> Reviewed-by: Eric Blake <eblake@redhat.com>
> ---
>   include/exec/memory-internal.h | 16 ++++++----------
>   1 file changed, 6 insertions(+), 10 deletions(-)
>
> diff --git a/include/exec/memory-internal.h b/include/exec/memory-internal.h
> index c04a92a..b017c2e 100644
> --- a/include/exec/memory-internal.h
> +++ b/include/exec/memory-internal.h
> @@ -44,19 +44,15 @@ static inline bool cpu_physical_memory_get_dirty(ram_addr_t start,
>                                                    ram_addr_t length,
>                                                    unsigned client)
>   {
> -    ram_addr_t addr, end;
> +    unsigned long end, page, next;
>
>       assert(client < DIRTY_MEMORY_NUM);
>
> -    end = TARGET_PAGE_ALIGN(start + length);
> -    start &= TARGET_PAGE_MASK;
> -    for (addr = start; addr < end; addr += TARGET_PAGE_SIZE) {
> -        if (test_bit(addr >> TARGET_PAGE_BITS,
> -                     ram_list.dirty_memory[client])) {
> -            return true;
> -        }
> -    }
> -    return false;
> +    end = TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS;
> +    page = start >> TARGET_PAGE_BITS;
> +    next = find_next_bit(ram_list.dirty_memory[client], end, page);
> +
> +    return next < end;
>   }
>
>   static inline bool cpu_physical_memory_get_dirty_flag(ram_addr_t addr,
>

Reviewed-by: Orit Wasserman <owasserm@redhat.com>
diff mbox

Patch

diff --git a/include/exec/memory-internal.h b/include/exec/memory-internal.h
index c04a92a..b017c2e 100644
--- a/include/exec/memory-internal.h
+++ b/include/exec/memory-internal.h
@@ -44,19 +44,15 @@  static inline bool cpu_physical_memory_get_dirty(ram_addr_t start,
                                                  ram_addr_t length,
                                                  unsigned client)
 {
-    ram_addr_t addr, end;
+    unsigned long end, page, next;

     assert(client < DIRTY_MEMORY_NUM);

-    end = TARGET_PAGE_ALIGN(start + length);
-    start &= TARGET_PAGE_MASK;
-    for (addr = start; addr < end; addr += TARGET_PAGE_SIZE) {
-        if (test_bit(addr >> TARGET_PAGE_BITS,
-                     ram_list.dirty_memory[client])) {
-            return true;
-        }
-    }
-    return false;
+    end = TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS;
+    page = start >> TARGET_PAGE_BITS;
+    next = find_next_bit(ram_list.dirty_memory[client], end, page);
+
+    return next < end;
 }

 static inline bool cpu_physical_memory_get_dirty_flag(ram_addr_t addr,