From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O9DXZ-00060k-Cs for qemu-devel@nongnu.org; Tue, 04 May 2010 04:31:41 -0400 Received: from [140.186.70.92] (port=53560 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O9DXW-00060c-GI for qemu-devel@nongnu.org; Tue, 04 May 2010 04:31:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O9DXU-00065l-5V for qemu-devel@nongnu.org; Tue, 04 May 2010 04:31:38 -0400 Received: from mail-pw0-f45.google.com ([209.85.160.45]:52727) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O9DXT-00065O-RA for qemu-devel@nongnu.org; Tue, 04 May 2010 04:31:36 -0400 Received: by pwi6 with SMTP id 6so1616830pwi.4 for ; Tue, 04 May 2010 01:31:34 -0700 (PDT) MIME-Version: 1.0 Sender: tamura.yoshiaki@gmail.com In-Reply-To: <4BDF2C26.40406@codemonkey.ws> References: <1271734843-24231-1-git-send-email-tamura.yoshiaki@lab.ntt.co.jp> <1271734843-24231-2-git-send-email-tamura.yoshiaki@lab.ntt.co.jp> <4BDF2C26.40406@codemonkey.ws> Date: Tue, 4 May 2010 17:31:34 +0900 Message-ID: Subject: Re: [Qemu-devel] [PATCH v4 1/4] Modify DIRTY_FLAG value and introduce DIRTY_IDX to use as indexes of bit-based phys_ram_dirty. From: Yoshiaki Tamura Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: ohmura.kei@lab.ntt.co.jp, Marcelo Tosatti , qemu-devel@nongnu.org, avi@redhat.com Sure. Submitted as v5. Thanks, Yoshi 2010/5/4 Anthony Liguori : > Hi Yoshi, > > Could you rebase this series and resubmit? =A0It conflicts with the lates= t > HEAD. > > Regards, > > Anthony Liguori > > On 04/19/2010 10:40 PM, Yoshiaki Tamura wrote: >> >> Replaces byte-based phys_ram_dirty bitmap with four (MASTER, VGA, CODE, >> MIGRATION) bit-based phys_ram_dirty bitmap. =A0On allocation, it sets al= l >> bits in >> the bitmap. =A0It uses ffs() to convert DIRTY_FLAG to DIRTY_IDX. >> >> Modifies wrapper functions for byte-based phys_ram_dirty bitmap to >> bit-based >> phys_ram_dirty bitmap. =A0MASTER works as a buffer, and upon get_diry() = or >> get_dirty_flags(), it calls cpu_physical_memory_sync_master() to update >> VGA and >> MIGRATION. >> >> Signed-off-by: Yoshiaki Tamura >> --- >> =A0cpu-all.h =A0 =A0 | =A0127 >> ++++++++++++++++++++++++++++++++++++++++++++++++--------- >> =A0exec.c =A0 =A0 =A0 =A0| =A0 15 +++++-- >> =A0qemu-common.h | =A0 =A03 + >> =A03 files changed, 121 insertions(+), 24 deletions(-) >> >> diff --git a/cpu-all.h b/cpu-all.h >> index f8bfa66..b6a2d91 100644 >> --- a/cpu-all.h >> +++ b/cpu-all.h >> @@ -37,6 +37,9 @@ >> >> =A0#include "softfloat.h" >> >> +/* to use ffs in flag_to_idx() */ >> +#include >> + >> =A0#if defined(HOST_WORDS_BIGENDIAN) !=3D defined(TARGET_WORDS_BIGENDIAN= ) >> =A0#define BSWAP_NEEDED >> =A0#endif >> @@ -853,7 +856,6 @@ target_phys_addr_t cpu_get_phys_page_debug(CPUState >> *env, target_ulong addr); >> =A0/* memory API */ >> >> =A0extern int phys_ram_fd; >> -extern uint8_t *phys_ram_dirty; >> =A0extern ram_addr_t ram_size; >> =A0extern ram_addr_t last_ram_offset; >> >> @@ -878,50 +880,137 @@ extern int mem_prealloc; >> =A0/* Set if TLB entry is an IO callback. =A0*/ >> =A0#define TLB_MMIO =A0 =A0 =A0 =A0(1<< =A05) >> >> -#define VGA_DIRTY_FLAG =A0 =A0 =A0 0x01 >> -#define CODE_DIRTY_FLAG =A0 =A0 =A00x02 >> -#define MIGRATION_DIRTY_FLAG 0x08 >> +/* Use DIRTY_IDX as indexes of bit-based phys_ram_dirty. */ >> +#define MASTER_DIRTY_IDX =A0 =A00 >> +#define VGA_DIRTY_IDX =A0 =A0 =A0 1 >> +#define CODE_DIRTY_IDX =A0 =A0 =A02 >> +#define MIGRATION_DIRTY_IDX 3 >> +#define NUM_DIRTY_IDX =A0 =A0 =A0 4 >> + >> +#define MASTER_DIRTY_FLAG =A0 =A0(1<< =A0MASTER_DIRTY_IDX) >> +#define VGA_DIRTY_FLAG =A0 =A0 =A0 (1<< =A0VGA_DIRTY_IDX) >> +#define CODE_DIRTY_FLAG =A0 =A0 =A0(1<< =A0CODE_DIRTY_IDX) >> +#define MIGRATION_DIRTY_FLAG (1<< =A0MIGRATION_DIRTY_IDX) >> + >> +extern unsigned long *phys_ram_dirty[NUM_DIRTY_IDX]; >> + >> +static inline int dirty_flag_to_idx(int flag) >> +{ >> + =A0 =A0return ffs(flag) - 1; >> +} >> + >> +static inline int dirty_idx_to_flag(int idx) >> +{ >> + =A0 =A0return 1<< =A0idx; >> +} >> >> =A0/* read dirty bit (return 0 or 1) */ >> =A0static inline int cpu_physical_memory_is_dirty(ram_addr_t addr) >> =A0{ >> - =A0 =A0return phys_ram_dirty[addr>> =A0TARGET_PAGE_BITS] =3D=3D 0xff; >> + =A0 =A0unsigned long mask; >> + =A0 =A0ram_addr_t index =3D (addr>> =A0TARGET_PAGE_BITS) / HOST_LONG_B= ITS; >> + =A0 =A0int offset =3D (addr>> =A0TARGET_PAGE_BITS)& =A0(HOST_LONG_BITS= - 1); >> + >> + =A0 =A0mask =3D 1UL<< =A0offset; >> + =A0 =A0return (phys_ram_dirty[MASTER_DIRTY_IDX][index]& =A0mask) =3D= =3D mask; >> +} >> + >> +static inline void cpu_physical_memory_sync_master(ram_addr_t index) >> +{ >> + =A0 =A0if (phys_ram_dirty[MASTER_DIRTY_IDX][index]) { >> + =A0 =A0 =A0 =A0phys_ram_dirty[VGA_DIRTY_IDX][index] >> + =A0 =A0 =A0 =A0 =A0 =A0|=3D =A0phys_ram_dirty[MASTER_DIRTY_IDX][index]= ; >> + =A0 =A0 =A0 =A0phys_ram_dirty[MIGRATION_DIRTY_IDX][index] >> + =A0 =A0 =A0 =A0 =A0 =A0|=3D =A0phys_ram_dirty[MASTER_DIRTY_IDX][index]= ; >> + =A0 =A0 =A0 =A0phys_ram_dirty[MASTER_DIRTY_IDX][index] =3D 0UL; >> + =A0 =A0} >> =A0} >> >> =A0static inline int cpu_physical_memory_get_dirty_flags(ram_addr_t addr= ) >> =A0{ >> - =A0 =A0return phys_ram_dirty[addr>> =A0TARGET_PAGE_BITS]; >> + =A0 =A0 unsigned long mask; >> + =A0 =A0 ram_addr_t index =3D (addr>> =A0TARGET_PAGE_BITS) / HOST_LONG_= BITS; >> + =A0 =A0 int offset =3D (addr>> =A0TARGET_PAGE_BITS)& =A0(HOST_LONG_BIT= S - 1); >> + =A0 =A0 int ret =3D 0, i; >> + >> + =A0 =A0 mask =3D 1UL<< =A0offset; >> + =A0 =A0 cpu_physical_memory_sync_master(index); >> + >> + =A0 =A0 for (i =3D VGA_DIRTY_IDX; i<=3D MIGRATION_DIRTY_IDX; i++) { >> + =A0 =A0 =A0 =A0 if (phys_ram_dirty[i][index]& =A0mask) { >> + =A0 =A0 =A0 =A0 =A0 =A0 ret |=3D dirty_idx_to_flag(i); >> + =A0 =A0 =A0 =A0 } >> + =A0 =A0 } >> + >> + =A0 =A0 return ret; >> +} >> + >> +static inline int cpu_physical_memory_get_dirty_idx(ram_addr_t addr, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0int dirty_idx) >> +{ >> + =A0 =A0unsigned long mask; >> + =A0 =A0ram_addr_t index =3D (addr>> =A0TARGET_PAGE_BITS) / HOST_LONG_B= ITS; >> + =A0 =A0int offset =3D (addr>> =A0TARGET_PAGE_BITS)& =A0(HOST_LONG_BITS= - 1); >> + >> + =A0 =A0mask =3D 1UL<< =A0offset; >> + =A0 =A0cpu_physical_memory_sync_master(index); >> + =A0 =A0return (phys_ram_dirty[dirty_idx][index]& =A0mask) =3D=3D mask; >> =A0} >> >> =A0static inline int cpu_physical_memory_get_dirty(ram_addr_t addr, >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0int dirty_flags) >> =A0{ >> - =A0 =A0return phys_ram_dirty[addr>> =A0TARGET_PAGE_BITS]& =A0dirty_fla= gs; >> + =A0 =A0return cpu_physical_memory_get_dirty_idx(addr, >> + >> dirty_flag_to_idx(dirty_flags)); >> =A0} >> >> =A0static inline void cpu_physical_memory_set_dirty(ram_addr_t addr) >> =A0{ >> - =A0 =A0phys_ram_dirty[addr>> =A0TARGET_PAGE_BITS] =3D 0xff; >> + =A0 =A0unsigned long mask; >> + =A0 =A0ram_addr_t index =3D (addr>> =A0TARGET_PAGE_BITS) / HOST_LONG_B= ITS; >> + =A0 =A0int offset =3D (addr>> =A0TARGET_PAGE_BITS)& =A0(HOST_LONG_BITS= - 1); >> + >> + =A0 =A0mask =3D 1UL<< =A0offset; >> + =A0 =A0phys_ram_dirty[MASTER_DIRTY_IDX][index] |=3D mask; >> +} >> + >> +static inline void cpu_physical_memory_set_dirty_range(ram_addr_t addr, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 unsigned long >> mask) >> +{ >> + =A0 =A0ram_addr_t index =3D (addr>> =A0TARGET_PAGE_BITS) / HOST_LONG_B= ITS; >> + >> + =A0 =A0phys_ram_dirty[MASTER_DIRTY_IDX][index] |=3D mask; >> =A0} >> >> -static inline int cpu_physical_memory_set_dirty_flags(ram_addr_t addr, >> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0int dirty_flags) >> +static inline void cpu_physical_memory_set_dirty_flags(ram_addr_t addr, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int dirty_flags) >> =A0{ >> - =A0 =A0return phys_ram_dirty[addr>> =A0TARGET_PAGE_BITS] |=3D dirty_fl= ags; >> + =A0 =A0unsigned long mask; >> + =A0 =A0ram_addr_t index =3D (addr>> =A0TARGET_PAGE_BITS) / HOST_LONG_B= ITS; >> + =A0 =A0int offset =3D (addr>> =A0TARGET_PAGE_BITS)& =A0(HOST_LONG_BITS= - 1); >> + >> + =A0 =A0mask =3D 1UL<< =A0offset; >> + =A0 =A0phys_ram_dirty[MASTER_DIRTY_IDX][index] |=3D mask; >> + >> + =A0 =A0if (dirty_flags& =A0CODE_DIRTY_FLAG) { >> + =A0 =A0 =A0 =A0phys_ram_dirty[CODE_DIRTY_IDX][index] |=3D mask; >> + =A0 =A0} >> =A0} >> >> =A0static inline void cpu_physical_memory_mask_dirty_range(ram_addr_t st= art, >> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0int length, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0unsigned long >> length, >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0int dirty_flags) >> =A0{ >> - =A0 =A0int i, mask, len; >> - =A0 =A0uint8_t *p; >> + =A0 =A0ram_addr_t addr =3D start, index; >> + =A0 =A0unsigned long mask; >> + =A0 =A0int offset, i; >> >> - =A0 =A0len =3D length>> =A0TARGET_PAGE_BITS; >> - =A0 =A0mask =3D ~dirty_flags; >> - =A0 =A0p =3D phys_ram_dirty + (start>> =A0TARGET_PAGE_BITS); >> - =A0 =A0for (i =3D 0; i< =A0len; i++) >> - =A0 =A0 =A0 =A0p[i]&=3D mask; >> + =A0 =A0for (i =3D 0; =A0i< =A0length; i +=3D TARGET_PAGE_SIZE) { >> + =A0 =A0 =A0 =A0index =3D ((addr + i)>> =A0TARGET_PAGE_BITS) / HOST_LON= G_BITS; >> + =A0 =A0 =A0 =A0offset =3D ((addr + i)>> =A0TARGET_PAGE_BITS)& =A0(HOST= _LONG_BITS - 1); >> + =A0 =A0 =A0 =A0mask =3D ~(1UL<< =A0offset); >> + =A0 =A0 =A0 =A0phys_ram_dirty[dirty_flag_to_idx(dirty_flags)][index]&= =3D mask; >> + =A0 =A0 } >> =A0} >> >> =A0void cpu_physical_memory_reset_dirty(ram_addr_t start, ram_addr_t end= , >> diff --git a/exec.c b/exec.c >> index c74b0a4..82b7c32 100644 >> --- a/exec.c >> +++ b/exec.c >> @@ -110,7 +110,7 @@ uint8_t *code_gen_ptr; >> >> =A0#if !defined(CONFIG_USER_ONLY) >> =A0int phys_ram_fd; >> -uint8_t *phys_ram_dirty; >> +unsigned long *phys_ram_dirty[NUM_DIRTY_IDX]; >> =A0static int in_migration; >> >> =A0typedef struct RAMBlock { >> @@ -2793,6 +2793,7 @@ static void *file_ram_alloc(ram_addr_t memory, con= st >> char *path) >> =A0ram_addr_t qemu_ram_alloc(ram_addr_t size) >> =A0{ >> =A0 =A0 =A0RAMBlock *new_block; >> + =A0 =A0int i; >> >> =A0 =A0 =A0size =3D TARGET_PAGE_ALIGN(size); >> =A0 =A0 =A0new_block =3D qemu_malloc(sizeof(*new_block)); >> @@ -2825,10 +2826,14 @@ ram_addr_t qemu_ram_alloc(ram_addr_t size) >> =A0 =A0 =A0new_block->next =3D ram_blocks; >> =A0 =A0 =A0ram_blocks =3D new_block; >> >> - =A0 =A0phys_ram_dirty =3D qemu_realloc(phys_ram_dirty, >> - =A0 =A0 =A0 =A0(last_ram_offset + size)>> =A0TARGET_PAGE_BITS); >> - =A0 =A0memset(phys_ram_dirty + (last_ram_offset>> =A0TARGET_PAGE_BITS)= , >> - =A0 =A0 =A0 =A0 =A0 0xff, size>> =A0TARGET_PAGE_BITS); >> + =A0 =A0for (i =3D MASTER_DIRTY_IDX; i< =A0NUM_DIRTY_IDX; i++) { >> + =A0 =A0 =A0 =A0phys_ram_dirty[i] >> + =A0 =A0 =A0 =A0 =A0 =A0=3D qemu_realloc(phys_ram_dirty[i], >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 BITMAP_SIZE(last_r= am_offset + size)); >> + =A0 =A0 =A0 =A0memset((uint8_t *)phys_ram_dirty[i] + >> BITMAP_SIZE(last_ram_offset), >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 0xff, BITMAP_SIZE(last_ram_offset + size) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 - BITMAP_SIZE(last_ram_offset)); >> + =A0 =A0} >> >> =A0 =A0 =A0last_ram_offset +=3D size; >> >> diff --git a/qemu-common.h b/qemu-common.h >> index 4ba0cda..efe5b1f 100644 >> --- a/qemu-common.h >> +++ b/qemu-common.h >> @@ -285,6 +285,9 @@ static inline uint8_t from_bcd(uint8_t val) >> =A0 =A0 =A0return ((val>> =A04) * 10) + (val& =A00x0f); >> =A0} >> >> +#define ALIGN(x, y) =A0(((x)+(y)-1)& =A0~((y)-1)) >> +#define BITMAP_SIZE(m) (ALIGN(((m)>>TARGET_PAGE_BITS), HOST_LONG_BITS) = / >> 8) >> + >> =A0#include "module.h" >> >> =A0#endif /* dyngen-exec.h hack */ >> > > > >