be9b23c4a5
To dump information about ramblocks. It looks like: (qemu) info ramblock Block Name PSize Offset Used Total /objects/mem 2 MiB 0x0000000000000000 0x0000000080000000 0x0000000080000000 vga.vram 4 KiB 0x0000000080060000 0x0000000001000000 0x0000000001000000 /rom@etc/acpi/tables 4 KiB 0x00000000810b0000 0x0000000000020000 0x0000000000200000 pc.bios 4 KiB 0x0000000080000000 0x0000000000040000 0x0000000000040000 0000:00:03.0/e1000.rom 4 KiB 0x0000000081070000 0x0000000000040000 0x0000000000040000 pc.rom 4 KiB 0x0000000080040000 0x0000000000020000 0x0000000000020000 0000:00:02.0/vga.rom 4 KiB 0x0000000081060000 0x0000000000010000 0x0000000000010000 /rom@etc/table-loader 4 KiB 0x00000000812b0000 0x0000000000001000 0x0000000000001000 /rom@etc/acpi/rsdp 4 KiB 0x00000000812b1000 0x0000000000001000 0x0000000000001000 Ramblock is something hidden internally in QEMU implementation, and this command should only be used by mostly QEMU developers on RAM stuff. It is not a command suitable for QMP interface. So only HMP interface is provided for it. Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Signed-off-by: Peter Xu <peterx@redhat.com> Message-Id: <1494562661-9063-4-git-send-email-peterx@redhat.com> Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
79 lines
2.6 KiB
C
79 lines
2.6 KiB
C
#ifndef RAMLIST_H
|
|
#define RAMLIST_H
|
|
|
|
#include "qemu/queue.h"
|
|
#include "qemu/thread.h"
|
|
#include "qemu/rcu.h"
|
|
#include "qemu/rcu_queue.h"
|
|
|
|
typedef struct RAMBlockNotifier RAMBlockNotifier;
|
|
|
|
#define DIRTY_MEMORY_VGA 0
|
|
#define DIRTY_MEMORY_CODE 1
|
|
#define DIRTY_MEMORY_MIGRATION 2
|
|
#define DIRTY_MEMORY_NUM 3 /* num of dirty bits */
|
|
|
|
/* The dirty memory bitmap is split into fixed-size blocks to allow growth
|
|
* under RCU. The bitmap for a block can be accessed as follows:
|
|
*
|
|
* rcu_read_lock();
|
|
*
|
|
* DirtyMemoryBlocks *blocks =
|
|
* atomic_rcu_read(&ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION]);
|
|
*
|
|
* ram_addr_t idx = (addr >> TARGET_PAGE_BITS) / DIRTY_MEMORY_BLOCK_SIZE;
|
|
* unsigned long *block = blocks.blocks[idx];
|
|
* ...access block bitmap...
|
|
*
|
|
* rcu_read_unlock();
|
|
*
|
|
* Remember to check for the end of the block when accessing a range of
|
|
* addresses. Move on to the next block if you reach the end.
|
|
*
|
|
* Organization into blocks allows dirty memory to grow (but not shrink) under
|
|
* RCU. When adding new RAMBlocks requires the dirty memory to grow, a new
|
|
* DirtyMemoryBlocks array is allocated with pointers to existing blocks kept
|
|
* the same. Other threads can safely access existing blocks while dirty
|
|
* memory is being grown. When no threads are using the old DirtyMemoryBlocks
|
|
* anymore it is freed by RCU (but the underlying blocks stay because they are
|
|
* pointed to from the new DirtyMemoryBlocks).
|
|
*/
|
|
#define DIRTY_MEMORY_BLOCK_SIZE ((ram_addr_t)256 * 1024 * 8)
|
|
typedef struct {
|
|
struct rcu_head rcu;
|
|
unsigned long *blocks[];
|
|
} DirtyMemoryBlocks;
|
|
|
|
typedef struct RAMList {
|
|
QemuMutex mutex;
|
|
RAMBlock *mru_block;
|
|
/* RCU-enabled, writes protected by the ramlist lock. */
|
|
QLIST_HEAD(, RAMBlock) blocks;
|
|
DirtyMemoryBlocks *dirty_memory[DIRTY_MEMORY_NUM];
|
|
uint32_t version;
|
|
QLIST_HEAD(, RAMBlockNotifier) ramblock_notifiers;
|
|
} RAMList;
|
|
extern RAMList ram_list;
|
|
|
|
/* Should be holding either ram_list.mutex, or the RCU lock. */
|
|
#define RAMBLOCK_FOREACH(block) \
|
|
QLIST_FOREACH_RCU(block, &ram_list.blocks, next)
|
|
|
|
void qemu_mutex_lock_ramlist(void);
|
|
void qemu_mutex_unlock_ramlist(void);
|
|
|
|
struct RAMBlockNotifier {
|
|
void (*ram_block_added)(RAMBlockNotifier *n, void *host, size_t size);
|
|
void (*ram_block_removed)(RAMBlockNotifier *n, void *host, size_t size);
|
|
QLIST_ENTRY(RAMBlockNotifier) next;
|
|
};
|
|
|
|
void ram_block_notifier_add(RAMBlockNotifier *n);
|
|
void ram_block_notifier_remove(RAMBlockNotifier *n);
|
|
void ram_block_notify_add(void *host, size_t size);
|
|
void ram_block_notify_remove(void *host, size_t size);
|
|
|
|
void ram_block_dump(Monitor *mon);
|
|
|
|
#endif /* RAMLIST_H */
|