4 #include "qemu/queue.h"
5 #include "qemu/thread.h"
8 typedef struct RAMBlockNotifier RAMBlockNotifier
;
10 #define DIRTY_MEMORY_VGA 0
11 #define DIRTY_MEMORY_CODE 1
12 #define DIRTY_MEMORY_MIGRATION 2
13 #define DIRTY_MEMORY_NUM 3 /* num of dirty bits */
15 /* The dirty memory bitmap is split into fixed-size blocks to allow growth
16 * under RCU. The bitmap for a block can be accessed as follows:
20 * DirtyMemoryBlocks *blocks =
21 * atomic_rcu_read(&ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION]);
23 * ram_addr_t idx = (addr >> TARGET_PAGE_BITS) / DIRTY_MEMORY_BLOCK_SIZE;
24 * unsigned long *block = blocks.blocks[idx];
25 * ...access block bitmap...
29 * Remember to check for the end of the block when accessing a range of
30 * addresses. Move on to the next block if you reach the end.
32 * Organization into blocks allows dirty memory to grow (but not shrink) under
33 * RCU. When adding new RAMBlocks requires the dirty memory to grow, a new
34 * DirtyMemoryBlocks array is allocated with pointers to existing blocks kept
35 * the same. Other threads can safely access existing blocks while dirty
36 * memory is being grown. When no threads are using the old DirtyMemoryBlocks
37 * anymore it is freed by RCU (but the underlying blocks stay because they are
38 * pointed to from the new DirtyMemoryBlocks).
40 #define DIRTY_MEMORY_BLOCK_SIZE ((ram_addr_t)256 * 1024 * 8)
43 unsigned long *blocks
[];
46 typedef struct RAMList
{
49 /* RCU-enabled, writes protected by the ramlist lock. */
50 QLIST_HEAD(, RAMBlock
) blocks
;
51 DirtyMemoryBlocks
*dirty_memory
[DIRTY_MEMORY_NUM
];
53 QLIST_HEAD(, RAMBlockNotifier
) ramblock_notifiers
;
55 extern RAMList ram_list
;
57 void qemu_mutex_lock_ramlist(void);
58 void qemu_mutex_unlock_ramlist(void);
60 struct RAMBlockNotifier
{
61 void (*ram_block_added
)(RAMBlockNotifier
*n
, void *host
, size_t size
);
62 void (*ram_block_removed
)(RAMBlockNotifier
*n
, void *host
, size_t size
);
63 QLIST_ENTRY(RAMBlockNotifier
) next
;
66 void ram_block_notifier_add(RAMBlockNotifier
*n
);
67 void ram_block_notifier_remove(RAMBlockNotifier
*n
);
68 void ram_block_notify_add(void *host
, size_t size
);
69 void ram_block_notify_remove(void *host
, size_t size
);
72 #endif /* RAMLIST_H */