qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Glauber Costa <glommer@redhat.com>
To: qemu-devel@nongnu.org
Cc: avi@redhat.com, kvm@vger.kernel.org
Subject: [Qemu-devel] [PATCH 2/2] reduce code duplication
Date: Thu, 11 Dec 2008 09:11:50 -0500	[thread overview]
Message-ID: <1229004710-28331-3-git-send-email-glommer@redhat.com> (raw)
In-Reply-To: <1229004710-28331-2-git-send-email-glommer@redhat.com>

Code for all versions of notdirty_mem_write are quite alike.
Rewrite it as a generator macro.

Signed-off-by: Glauber Costa <glommer@redhat.com>
---
 exec.c |   66 ++++++++++++++++-----------------------------------------------
 1 files changed, 17 insertions(+), 49 deletions(-)

diff --git a/exec.c b/exec.c
index 35e0b8e..986c3b0 100644
--- a/exec.c
+++ b/exec.c
@@ -2455,43 +2455,27 @@ static CPUWriteMemoryFunc *unassigned_mem_write[3] = {
     unassigned_mem_writel,
 };
 
-static void notdirty_mem_writeb(void *opaque, target_phys_addr_t ram_addr,
-                                uint32_t val)
+static inline void store_size(target_phys_addr_t addr, uint32_t val, char siz)
 {
-    int dirty_flags;
-    dirty_flags = phys_ram_dirty[ram_addr >> TARGET_PAGE_BITS];
-    if (!(dirty_flags & CODE_DIRTY_FLAG)) {
-#if !defined(CONFIG_USER_ONLY)
-        tb_invalidate_phys_page_fast(ram_addr, 'b');
-        dirty_flags = phys_ram_dirty[ram_addr >> TARGET_PAGE_BITS];
-#endif
+    switch (siz) {
+    case 'b': stb_p(addr, val); break;
+    case 'w': stw_p(addr, val); break;
+    case 'l': stl_p(addr, val); break;
     }
-    stb_p(phys_ram_base + ram_addr, val);
-#ifdef USE_KQEMU
-    if (cpu_single_env->kqemu_enabled &&
-        (dirty_flags & KQEMU_MODIFY_PAGE_MASK) != KQEMU_MODIFY_PAGE_MASK)
-        kqemu_modify_page(cpu_single_env, ram_addr);
-#endif
-    dirty_flags |= (0xff & ~CODE_DIRTY_FLAG);
-    phys_ram_dirty[ram_addr >> TARGET_PAGE_BITS] = dirty_flags;
-    /* we remove the notdirty callback only if the code has been
-       flushed */
-    if (dirty_flags == 0xff)
-        tlb_set_dirty(cpu_single_env, cpu_single_env->mem_io_vaddr);
 }
 
-static void notdirty_mem_writew(void *opaque, target_phys_addr_t ram_addr,
-                                uint32_t val)
+static inline void notdirty_mem_write_size(void *opaque, target_phys_addr_t ram_addr,
+                                uint32_t val, char siz)
 {
     int dirty_flags;
     dirty_flags = phys_ram_dirty[ram_addr >> TARGET_PAGE_BITS];
     if (!(dirty_flags & CODE_DIRTY_FLAG)) {
 #if !defined(CONFIG_USER_ONLY)
-        tb_invalidate_phys_page_fast(ram_addr, 'w');
+        tb_invalidate_phys_page_fast(ram_addr, siz);
         dirty_flags = phys_ram_dirty[ram_addr >> TARGET_PAGE_BITS];
 #endif
     }
-    stw_p(phys_ram_base + ram_addr, val);
+    store_size((target_phys_addr_t)phys_ram_base + ram_addr, val, siz);
 #ifdef USE_KQEMU
     if (cpu_single_env->kqemu_enabled &&
         (dirty_flags & KQEMU_MODIFY_PAGE_MASK) != KQEMU_MODIFY_PAGE_MASK)
@@ -2505,30 +2489,14 @@ static void notdirty_mem_writew(void *opaque, target_phys_addr_t ram_addr,
         tlb_set_dirty(cpu_single_env, cpu_single_env->mem_io_vaddr);
 }
 
-static void notdirty_mem_writel(void *opaque, target_phys_addr_t ram_addr,
-                                uint32_t val)
-{
-    int dirty_flags;
-    dirty_flags = phys_ram_dirty[ram_addr >> TARGET_PAGE_BITS];
-    if (!(dirty_flags & CODE_DIRTY_FLAG)) {
-#if !defined(CONFIG_USER_ONLY)
-        tb_invalidate_phys_page_fast(ram_addr, 'l');
-        dirty_flags = phys_ram_dirty[ram_addr >> TARGET_PAGE_BITS];
-#endif
-    }
-    stl_p(phys_ram_base + ram_addr, val);
-#ifdef USE_KQEMU
-    if (cpu_single_env->kqemu_enabled &&
-        (dirty_flags & KQEMU_MODIFY_PAGE_MASK) != KQEMU_MODIFY_PAGE_MASK)
-        kqemu_modify_page(cpu_single_env, ram_addr);
-#endif
-    dirty_flags |= (0xff & ~CODE_DIRTY_FLAG);
-    phys_ram_dirty[ram_addr >> TARGET_PAGE_BITS] = dirty_flags;
-    /* we remove the notdirty callback only if the code has been
-       flushed */
-    if (dirty_flags == 0xff)
-        tlb_set_dirty(cpu_single_env, cpu_single_env->mem_io_vaddr);
-}
+#define gen_notdirty(s) static void notdirty_mem_write##s(void *opaque, \
+                                    target_phys_addr_t ram_addr, uint32_t val)\
+{   notdirty_mem_write_size(opaque, ram_addr, val, #s[0]); }
+
+gen_notdirty(b)
+gen_notdirty(w)
+gen_notdirty(l)
+#undef gen_notdirty
 
 static CPUReadMemoryFunc *error_mem_read[3] = {
     NULL, /* never used */
-- 
1.5.6.5

      reply	other threads:[~2008-12-11 14:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-11 14:11 [Qemu-devel] [PATCH 0/2] reduce code duplication Glauber Costa
2008-12-11 14:11 ` [Qemu-devel] [PATCH 1/2] pass parameter as char Glauber Costa
2008-12-11 14:11   ` Glauber Costa [this message]

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=1229004710-28331-3-git-send-email-glommer@redhat.com \
    --to=glommer@redhat.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --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).