memory: split dirty bitmap into three

After all the previous patches, spliting the bitmap gets direct.

Note: For some reason, I have to move DIRTY_MEMORY_* definitions to
the beginning of memory.h to make compilation work.

Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Orit Wasserman <owasserm@redhat.com>
This commit is contained in:
Juan Quintela 2013-10-08 16:14:39 +02:00
parent 164590a60f
commit 1ab4c8ceaa
4 changed files with 16 additions and 15 deletions

9
exec.c
View File

@ -1277,9 +1277,12 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
new_ram_size = last_ram_offset() >> TARGET_PAGE_BITS; new_ram_size = last_ram_offset() >> TARGET_PAGE_BITS;
if (new_ram_size > old_ram_size) { if (new_ram_size > old_ram_size) {
ram_list.phys_dirty = g_realloc(ram_list.phys_dirty, new_ram_size); int i;
memset(ram_list.phys_dirty + (new_block->offset >> TARGET_PAGE_BITS), for (i = 0; i < DIRTY_MEMORY_NUM; i++) {
0, size >> TARGET_PAGE_BITS); ram_list.dirty_memory[i] =
bitmap_zero_extend(ram_list.dirty_memory[i],
old_ram_size, new_ram_size);
}
} }
cpu_physical_memory_set_dirty_range(new_block->offset, size); cpu_physical_memory_set_dirty_range(new_block->offset, size);

View File

@ -21,6 +21,7 @@
#include "qemu-common.h" #include "qemu-common.h"
#include "exec/cpu-common.h" #include "exec/cpu-common.h"
#include "exec/memory.h"
#include "qemu/thread.h" #include "qemu/thread.h"
#include "qom/cpu.h" #include "qom/cpu.h"
@ -459,7 +460,7 @@ typedef struct RAMBlock {
typedef struct RAMList { typedef struct RAMList {
QemuMutex mutex; QemuMutex mutex;
/* Protected by the iothread lock. */ /* Protected by the iothread lock. */
uint8_t *phys_dirty; unsigned long *dirty_memory[DIRTY_MEMORY_NUM];
RAMBlock *mru_block; RAMBlock *mru_block;
/* Protected by the ramlist lock. */ /* Protected by the ramlist lock. */
QTAILQ_HEAD(, RAMBlock) blocks; QTAILQ_HEAD(, RAMBlock) blocks;

View File

@ -44,7 +44,7 @@ static inline bool cpu_physical_memory_get_dirty_flag(ram_addr_t addr,
unsigned client) unsigned client)
{ {
assert(client < DIRTY_MEMORY_NUM); assert(client < DIRTY_MEMORY_NUM);
return ram_list.phys_dirty[addr >> TARGET_PAGE_BITS] & (1 << client); return test_bit(addr >> TARGET_PAGE_BITS, ram_list.dirty_memory[client]);
} }
/* read dirty bit (return 0 or 1) */ /* read dirty bit (return 0 or 1) */
@ -76,7 +76,7 @@ static inline void cpu_physical_memory_set_dirty_flag(ram_addr_t addr,
unsigned client) unsigned client)
{ {
assert(client < DIRTY_MEMORY_NUM); assert(client < DIRTY_MEMORY_NUM);
ram_list.phys_dirty[addr >> TARGET_PAGE_BITS] |= (1 << client); set_bit(addr >> TARGET_PAGE_BITS, ram_list.dirty_memory[client]);
} }
static inline void cpu_physical_memory_set_dirty(ram_addr_t addr) static inline void cpu_physical_memory_set_dirty(ram_addr_t addr)
@ -89,11 +89,8 @@ static inline void cpu_physical_memory_set_dirty(ram_addr_t addr)
static inline void cpu_physical_memory_clear_dirty_flag(ram_addr_t addr, static inline void cpu_physical_memory_clear_dirty_flag(ram_addr_t addr,
unsigned client) unsigned client)
{ {
int mask = ~(1 << client);
assert(client < DIRTY_MEMORY_NUM); assert(client < DIRTY_MEMORY_NUM);
clear_bit(addr >> TARGET_PAGE_BITS, ram_list.dirty_memory[client]);
ram_list.phys_dirty[addr >> TARGET_PAGE_BITS] &= mask;
} }
static inline void cpu_physical_memory_set_dirty_range(ram_addr_t start, static inline void cpu_physical_memory_set_dirty_range(ram_addr_t start,

View File

@ -16,6 +16,11 @@
#ifndef CONFIG_USER_ONLY #ifndef CONFIG_USER_ONLY
#define DIRTY_MEMORY_VGA 0
#define DIRTY_MEMORY_CODE 1
#define DIRTY_MEMORY_MIGRATION 2
#define DIRTY_MEMORY_NUM 3 /* num of dirty bits */
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include "qemu-common.h" #include "qemu-common.h"
@ -33,11 +38,6 @@
typedef struct MemoryRegionOps MemoryRegionOps; typedef struct MemoryRegionOps MemoryRegionOps;
typedef struct MemoryRegionMmio MemoryRegionMmio; typedef struct MemoryRegionMmio MemoryRegionMmio;
#define DIRTY_MEMORY_VGA 0
#define DIRTY_MEMORY_CODE 1
#define DIRTY_MEMORY_MIGRATION 2
#define DIRTY_MEMORY_NUM 3 /* num of dirty bits */
struct MemoryRegionMmio { struct MemoryRegionMmio {
CPUReadMemoryFunc *read[3]; CPUReadMemoryFunc *read[3];
CPUWriteMemoryFunc *write[3]; CPUWriteMemoryFunc *write[3];