Patchwork [V2,3/5] exec: Introduce helper to set dirty flags.

login
register
mail settings
Submitter Anthony PERARD
Date July 20, 2012, 2:34 p.m.
Message ID <1342794882-30648-4-git-send-email-anthony.perard@citrix.com>
Download mbox | patch
Permalink /patch/172301/
State New
Headers show

Comments

Anthony PERARD - July 20, 2012, 2:34 p.m.
This new helper/hook is used in the next patch to add an extra call in a single
place.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
 exec.c |   42 ++++++++++++++----------------------------
 1 files changed, 14 insertions(+), 28 deletions(-)
Avi Kivity - July 29, 2012, 12:58 p.m.
On 07/20/2012 05:34 PM, Anthony PERARD wrote:
> This new helper/hook is used in the next patch to add an extra call in a single
> place.
> 
> Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
> ---
>  exec.c |   42 ++++++++++++++----------------------------
>  1 files changed, 14 insertions(+), 28 deletions(-)
> 
> diff --git a/exec.c b/exec.c
> index feb4795..b24a03a 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -3386,6 +3386,16 @@ int cpu_memory_rw_debug(CPUArchState *env, target_ulong addr,
>  }
>  
>  #else

<blank line>

> +static void set_dirty_helper(target_phys_addr_t addr, target_phys_addr_t length)

More meaningful name please.  Practically every function can be name
something_helper().

> +{
> +    if (!cpu_physical_memory_is_dirty(addr)) {
> +        /* invalidate code */
> +        tb_invalidate_phys_page_range(addr, addr + length, 0);
> +        /* set dirty bit */
> +        cpu_physical_memory_set_dirty_flags(addr, (0xff & ~CODE_DIRTY_FLAG));
> +    }
> +}
> +

Otherwise looks good; a nice cleanup in its own right.

Patch

diff --git a/exec.c b/exec.c
index feb4795..b24a03a 100644
--- a/exec.c
+++ b/exec.c
@@ -3386,6 +3386,16 @@  int cpu_memory_rw_debug(CPUArchState *env, target_ulong addr,
 }
 
 #else
+static void set_dirty_helper(target_phys_addr_t addr, target_phys_addr_t length)
+{
+    if (!cpu_physical_memory_is_dirty(addr)) {
+        /* invalidate code */
+        tb_invalidate_phys_page_range(addr, addr + length, 0);
+        /* set dirty bit */
+        cpu_physical_memory_set_dirty_flags(addr, (0xff & ~CODE_DIRTY_FLAG));
+    }
+}
+
 void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
                             int len, int is_write)
 {
@@ -3431,13 +3441,7 @@  void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
                 /* RAM case */
                 ptr = qemu_get_ram_ptr(addr1);
                 memcpy(ptr, buf, l);
-                if (!cpu_physical_memory_is_dirty(addr1)) {
-                    /* invalidate code */
-                    tb_invalidate_phys_page_range(addr1, addr1 + l, 0);
-                    /* set dirty bit */
-                    cpu_physical_memory_set_dirty_flags(
-                        addr1, (0xff & ~CODE_DIRTY_FLAG));
-                }
+                set_dirty_helper(addr1, l);
                 qemu_put_ram_ptr(ptr);
             }
         } else {
@@ -3628,13 +3632,7 @@  void cpu_physical_memory_unmap(void *buffer, target_phys_addr_t len,
                 l = TARGET_PAGE_SIZE;
                 if (l > access_len)
                     l = access_len;
-                if (!cpu_physical_memory_is_dirty(addr1)) {
-                    /* invalidate code */
-                    tb_invalidate_phys_page_range(addr1, addr1 + l, 0);
-                    /* set dirty bit */
-                    cpu_physical_memory_set_dirty_flags(
-                        addr1, (0xff & ~CODE_DIRTY_FLAG));
-                }
+                set_dirty_helper(addr1, l);
                 addr1 += l;
                 access_len -= l;
             }
@@ -3940,13 +3938,7 @@  static inline void stl_phys_internal(target_phys_addr_t addr, uint32_t val,
             stl_p(ptr, val);
             break;
         }
-        if (!cpu_physical_memory_is_dirty(addr1)) {
-            /* invalidate code */
-            tb_invalidate_phys_page_range(addr1, addr1 + 4, 0);
-            /* set dirty bit */
-            cpu_physical_memory_set_dirty_flags(addr1,
-                (0xff & ~CODE_DIRTY_FLAG));
-        }
+        set_dirty_helper(addr1, 4);
     }
 }
 
@@ -4013,13 +4005,7 @@  static inline void stw_phys_internal(target_phys_addr_t addr, uint32_t val,
             stw_p(ptr, val);
             break;
         }
-        if (!cpu_physical_memory_is_dirty(addr1)) {
-            /* invalidate code */
-            tb_invalidate_phys_page_range(addr1, addr1 + 2, 0);
-            /* set dirty bit */
-            cpu_physical_memory_set_dirty_flags(addr1,
-                (0xff & ~CODE_DIRTY_FLAG));
-        }
+        set_dirty_helper(addr1, 2);
     }
 }