* [Qemu-devel] [PATCH 0/2] reduce code duplication
@ 2008-12-11 14:11 Glauber Costa
2008-12-11 14:11 ` [Qemu-devel] [PATCH 1/2] pass parameter as char Glauber Costa
0 siblings, 1 reply; 3+ messages in thread
From: Glauber Costa @ 2008-12-11 14:11 UTC (permalink / raw)
To: qemu-devel; +Cc: avi, kvm
This is just a tiny nitpick I came across while hacking on other stuff.
It reduces the code duplication, hopefully in a good way for other eyes
too.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Qemu-devel] [PATCH 1/2] pass parameter as char.
2008-12-11 14:11 [Qemu-devel] [PATCH 0/2] reduce code duplication Glauber Costa
@ 2008-12-11 14:11 ` Glauber Costa
2008-12-11 14:11 ` [Qemu-devel] [PATCH 2/2] reduce code duplication Glauber Costa
0 siblings, 1 reply; 3+ messages in thread
From: Glauber Costa @ 2008-12-11 14:11 UTC (permalink / raw)
To: qemu-devel; +Cc: avi, kvm
pass parameter to tb_invalidate_phys_page_fast() as a char, that we'll
actually transform into an integer. It will make it easier for generator macros
to deal with it.
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
exec.c | 26 ++++++++++++++++++++++----
1 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/exec.c b/exec.c
index 105812f..35e0b8e 100644
--- a/exec.c
+++ b/exec.c
@@ -997,11 +997,29 @@ void tb_invalidate_phys_page_range(target_phys_addr_t start, target_phys_addr_t
#endif
}
+static inline int size2len(char size)
+{
+ switch (size) {
+ case 'b':
+ return 1;
+ case 'w':
+ return 2;
+ case 'l':
+ return 4;
+ }
+
+ /* should never happen */
+ fprintf(stderr, "%s: invalid size %d\n", __func__, size);
+ exit(1);
+ return -1;
+}
+
/* len must be <= 8 and start must be a multiple of len */
-static inline void tb_invalidate_phys_page_fast(target_phys_addr_t start, int len)
+static inline void tb_invalidate_phys_page_fast(target_phys_addr_t start, char size)
{
PageDesc *p;
int offset, b;
+ int len = size2len(size);
#if 0
if (1) {
if (loglevel) {
@@ -2444,7 +2462,7 @@ static void notdirty_mem_writeb(void *opaque, target_phys_addr_t ram_addr,
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, 1);
+ tb_invalidate_phys_page_fast(ram_addr, 'b');
dirty_flags = phys_ram_dirty[ram_addr >> TARGET_PAGE_BITS];
#endif
}
@@ -2469,7 +2487,7 @@ static void notdirty_mem_writew(void *opaque, target_phys_addr_t ram_addr,
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, 2);
+ tb_invalidate_phys_page_fast(ram_addr, 'w');
dirty_flags = phys_ram_dirty[ram_addr >> TARGET_PAGE_BITS];
#endif
}
@@ -2494,7 +2512,7 @@ static void notdirty_mem_writel(void *opaque, target_phys_addr_t ram_addr,
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, 4);
+ tb_invalidate_phys_page_fast(ram_addr, 'l');
dirty_flags = phys_ram_dirty[ram_addr >> TARGET_PAGE_BITS];
#endif
}
--
1.5.6.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [Qemu-devel] [PATCH 2/2] reduce code duplication
2008-12-11 14:11 ` [Qemu-devel] [PATCH 1/2] pass parameter as char Glauber Costa
@ 2008-12-11 14:11 ` Glauber Costa
0 siblings, 0 replies; 3+ messages in thread
From: Glauber Costa @ 2008-12-11 14:11 UTC (permalink / raw)
To: qemu-devel; +Cc: avi, kvm
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-12-11 14:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [Qemu-devel] [PATCH 2/2] reduce code duplication Glauber Costa
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).