Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/dgilbert/tags/pull-hmp-20170914…
Browse files Browse the repository at this point in the history
…' into staging

HMP pull 2017-09-14

# gpg: Signature made Thu 14 Sep 2017 15:57:30 BST
# gpg:                using RSA key 0x0516331EBC5BFDE7
# gpg: Good signature from "Dr. David Alan Gilbert (RH2) <dgilbert@redhat.com>"
# gpg: WARNING: This key is not certified with sufficiently trusted signatures!
# gpg:          It is not certain that the signature belongs to the owner.
# Primary key fingerprint: 45F5 C71B 4A0C B7FB 977A  9FA9 0516 331E BC5B FDE7

* remotes/dgilbert/tags/pull-hmp-20170914:
  hmp: introduce 'info memory_size_summary' command
  qmp: introduce query-memory-size-summary command
  hmp: extend "info numa" with hotplugged memory information
  tests/hmp: test "none" machine with memory
  dump: do not dump non-existent guest memory
  hmp: fix "dump-quest-memory" segfault (arm)
  hmp: fix "dump-quest-memory" segfault (ppc)

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
  • Loading branch information
pm215 committed Sep 14, 2017
2 parents dae288d + d0f63c1 commit 3dabde1
Show file tree
Hide file tree
Showing 17 changed files with 146 additions and 14 deletions.
6 changes: 6 additions & 0 deletions dump.c
Expand Up @@ -1536,6 +1536,12 @@ static void dump_init(DumpState *s, int fd, bool has_format,
fprintf(stderr, "DUMP: total memory to dump: %lu\n", s->total_size);
#endif

/* it does not make sense to dump non-existent memory */
if (!s->total_size) {
error_setg(errp, "dump: no guest memory to dump");
goto cleanup;
}

s->start = get_start_block(s);
if (s->start == -1) {
error_setg(errp, QERR_INVALID_PARAMETER, "begin");
Expand Down
16 changes: 16 additions & 0 deletions hmp-commands-info.hx
Expand Up @@ -850,6 +850,22 @@ ETEXI
.cmd = hmp_info_vm_generation_id,
},

STEXI
@item info memory_size_summary
@findex memory_size_summary
Display the amount of initially allocated and present hotpluggable (if
enabled) memory in bytes.
ETEXI

{
.name = "memory_size_summary",
.args_type = "",
.params = "",
.help = "show the amount of initially allocated and "
"present hotpluggable (if enabled) memory in bytes.",
.cmd = hmp_info_memory_size_summary,
},

STEXI
@end table
ETEXI
Expand Down
18 changes: 18 additions & 0 deletions hmp.c
Expand Up @@ -2862,3 +2862,21 @@ void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
hmp_handle_error(mon, &err);
qapi_free_GuidInfo(info);
}

void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict)
{
Error *err = NULL;
MemoryInfo *info = qmp_query_memory_size_summary(&err);
if (info) {
monitor_printf(mon, "base memory: %" PRIu64 "\n",
info->base_memory);

if (info->has_plugged_memory) {
monitor_printf(mon, "plugged memory: %" PRIu64 "\n",
info->plugged_memory);
}

qapi_free_MemoryInfo(info);
}
hmp_handle_error(mon, &err);
}
1 change: 1 addition & 0 deletions hmp.h
Expand Up @@ -145,5 +145,6 @@ void hmp_info_dump(Monitor *mon, const QDict *qdict);
void hmp_info_ramblock(Monitor *mon, const QDict *qdict);
void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict);
void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict);
void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict);

#endif
5 changes: 5 additions & 0 deletions hw/mem/pc-dimm.c
Expand Up @@ -159,6 +159,11 @@ uint64_t pc_existing_dimms_capacity(Error **errp)
return cap.size;
}

uint64_t get_plugged_memory_size(void)
{
return pc_existing_dimms_capacity(&error_abort);
}

int qmp_pc_dimm_device_list(Object *obj, void *opaque)
{
MemoryDeviceInfoList ***prev = opaque;
Expand Down
1 change: 1 addition & 0 deletions include/hw/mem/pc-dimm.h
Expand Up @@ -95,6 +95,7 @@ int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp);

int qmp_pc_dimm_device_list(Object *obj, void *opaque);
uint64_t pc_existing_dimms_capacity(Error **errp);
uint64_t get_plugged_memory_size(void);
void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState *hpms,
MemoryRegion *mr, uint64_t align, Error **errp);
void pc_dimm_memory_unplug(DeviceState *dev, MemoryHotplugState *hpms,
Expand Down
1 change: 1 addition & 0 deletions include/qemu/typedefs.h
Expand Up @@ -58,6 +58,7 @@ typedef struct MSIMessage MSIMessage;
typedef struct NetClientState NetClientState;
typedef struct NetFilterState NetFilterState;
typedef struct NICInfo NICInfo;
typedef struct NumaNodeMem NumaNodeMem;
typedef struct PcGuestInfo PcGuestInfo;
typedef struct PCIBridge PCIBridge;
typedef struct PCIBus PCIBus;
Expand Down
7 changes: 6 additions & 1 deletion include/sysemu/numa.h
Expand Up @@ -24,9 +24,14 @@ struct node_info {
uint8_t distance[MAX_NODES];
};

struct NumaNodeMem {
uint64_t node_mem;
uint64_t node_plugged_mem;
};

extern NodeInfo numa_info[MAX_NODES];
void parse_numa_opts(MachineState *ms);
void query_numa_node_mem(uint64_t node_mem[]);
void query_numa_node_mem(NumaNodeMem node_mem[]);
extern QemuOptsList qemu_numa_opts;
void numa_set_mem_node_id(ram_addr_t addr, uint64_t size, uint32_t node);
void numa_unset_mem_node_id(ram_addr_t addr, uint64_t size, uint32_t node);
Expand Down
9 changes: 6 additions & 3 deletions monitor.c
Expand Up @@ -1710,11 +1710,12 @@ static void hmp_info_mtree(Monitor *mon, const QDict *qdict)
static void hmp_info_numa(Monitor *mon, const QDict *qdict)
{
int i;
uint64_t *node_mem;
NumaNodeMem *node_mem;
CpuInfoList *cpu_list, *cpu;

cpu_list = qmp_query_cpus(&error_abort);
node_mem = g_new0(uint64_t, nb_numa_nodes);
node_mem = g_new0(NumaNodeMem, nb_numa_nodes);

query_numa_node_mem(node_mem);
monitor_printf(mon, "%d nodes\n", nb_numa_nodes);
for (i = 0; i < nb_numa_nodes; i++) {
Expand All @@ -1727,7 +1728,9 @@ static void hmp_info_numa(Monitor *mon, const QDict *qdict)
}
monitor_printf(mon, "\n");
monitor_printf(mon, "node %d size: %" PRId64 " MB\n", i,
node_mem[i] >> 20);
node_mem[i].node_mem >> 20);
monitor_printf(mon, "node %d plugged: %" PRId64 " MB\n", i,
node_mem[i].node_plugged_mem >> 20);
}
qapi_free_CpuInfoList(cpu_list);
g_free(node_mem);
Expand Down
18 changes: 13 additions & 5 deletions numa.c
Expand Up @@ -591,21 +591,29 @@ void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
}
}

static void numa_stat_memory_devices(uint64_t node_mem[])
static void numa_stat_memory_devices(NumaNodeMem node_mem[])
{
MemoryDeviceInfoList *info_list = NULL;
MemoryDeviceInfoList **prev = &info_list;
MemoryDeviceInfoList *info;
PCDIMMDeviceInfo *pcdimm_info;

qmp_pc_dimm_device_list(qdev_get_machine(), &prev);
for (info = info_list; info; info = info->next) {
MemoryDeviceInfo *value = info->value;

if (value) {
switch (value->type) {
case MEMORY_DEVICE_INFO_KIND_DIMM:
node_mem[value->u.dimm.data->node] += value->u.dimm.data->size;
case MEMORY_DEVICE_INFO_KIND_DIMM: {
pcdimm_info = value->u.dimm.data;
node_mem[pcdimm_info->node].node_mem += pcdimm_info->size;
if (pcdimm_info->hotpluggable && pcdimm_info->hotplugged) {
node_mem[pcdimm_info->node].node_plugged_mem +=
pcdimm_info->size;
}
break;
}

default:
break;
}
Expand All @@ -614,7 +622,7 @@ static void numa_stat_memory_devices(uint64_t node_mem[])
qapi_free_MemoryDeviceInfoList(info_list);
}

void query_numa_node_mem(uint64_t node_mem[])
void query_numa_node_mem(NumaNodeMem node_mem[])
{
int i;

Expand All @@ -624,7 +632,7 @@ void query_numa_node_mem(uint64_t node_mem[])

numa_stat_memory_devices(node_mem);
for (i = 0; i < nb_numa_nodes; i++) {
node_mem[i] += numa_info[i].node_mem;
node_mem[i].node_mem += numa_info[i].node_mem;
}
}

Expand Down
32 changes: 32 additions & 0 deletions qapi-schema.json
Expand Up @@ -1965,6 +1965,38 @@
'data': { 'name': 'str', '*migration-safe': 'bool', 'static': 'bool',
'*unavailable-features': [ 'str' ], 'typename': 'str' } }

##
# @MemoryInfo:
#
# Actual memory information in bytes.
#
# @base-memory: size of "base" memory specified with command line
# option -m.
#
# @plugged-memory: size of memory that can be hot-unplugged. This field
# is omitted if target doesn't support memory hotplug
# (i.e. CONFIG_MEM_HOTPLUG not defined on build time).
#
# Since: 2.11.0
##
{ 'struct': 'MemoryInfo',
'data' : { 'base-memory': 'size', '*plugged-memory': 'size' } }

##
# @query-memory-size-summary:
#
# Return the amount of initially allocated and present hotpluggable (if
# enabled) memory in bytes.
#
# Example:
#
# -> { "execute": "query-memory-size-summary" }
# <- { "return": { "base-memory": 4294967296, "plugged-memory": 0 } }
#
# Since: 2.11.0
##
{ 'command': 'query-memory-size-summary', 'returns': 'MemoryInfo' }

##
# @query-cpu-definitions:
#
Expand Down
13 changes: 13 additions & 0 deletions qmp.c
Expand Up @@ -709,3 +709,16 @@ ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **errp)

return head;
}

MemoryInfo *qmp_query_memory_size_summary(Error **errp)
{
MemoryInfo *mem_info = g_malloc0(sizeof(MemoryInfo));

mem_info->base_memory = ram_size;

mem_info->plugged_memory = get_plugged_memory_size();
mem_info->has_plugged_memory =
mem_info->plugged_memory != (uint64_t)-1;

return mem_info;
}
2 changes: 1 addition & 1 deletion stubs/Makefile.objs
Expand Up @@ -33,7 +33,7 @@ stub-obj-y += uuid.o
stub-obj-y += vm-stop.o
stub-obj-y += vmstate.o
stub-obj-$(CONFIG_WIN32) += fd-register.o
stub-obj-y += qmp_pc_dimm_device_list.o
stub-obj-y += qmp_pc_dimm.o
stub-obj-y += target-monitor-defs.o
stub-obj-y += target-get-monitor-def.o
stub-obj-y += pc_madt_cpu_entry.o
Expand Down
5 changes: 5 additions & 0 deletions stubs/qmp_pc_dimm_device_list.c → stubs/qmp_pc_dimm.c
Expand Up @@ -6,3 +6,8 @@ int qmp_pc_dimm_device_list(Object *obj, void *opaque)
{
return 0;
}

uint64_t get_plugged_memory_size(void)
{
return (uint64_t)-1;
}
11 changes: 9 additions & 2 deletions target/arm/arch_dump.c
Expand Up @@ -273,11 +273,18 @@ int arm_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs,
int cpu_get_dump_info(ArchDumpInfo *info,
const GuestPhysBlockList *guest_phys_blocks)
{
ARMCPU *cpu = ARM_CPU(first_cpu);
CPUARMState *env = &cpu->env;
ARMCPU *cpu;
CPUARMState *env;
GuestPhysBlock *block;
hwaddr lowest_addr = ULLONG_MAX;

if (first_cpu == NULL) {
return -1;
}

cpu = ARM_CPU(first_cpu);
env = &cpu->env;

/* Take a best guess at the phys_base. If we get it wrong then crash
* will need '--machdep phys_offset=<phys-offset>' added to its command
* line, which isn't any worse than assuming we can use zero, but being
Expand Down
11 changes: 9 additions & 2 deletions target/ppc/arch_dump.c
Expand Up @@ -224,8 +224,15 @@ typedef struct NoteFuncDescStruct NoteFuncDesc;
int cpu_get_dump_info(ArchDumpInfo *info,
const struct GuestPhysBlockList *guest_phys_blocks)
{
PowerPCCPU *cpu = POWERPC_CPU(first_cpu);
PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu);
PowerPCCPU *cpu;
PowerPCCPUClass *pcc;

if (first_cpu == NULL) {
return -1;
}

cpu = POWERPC_CPU(first_cpu);
pcc = POWERPC_CPU_GET_CLASS(cpu);

info->d_machine = PPC_ELF_MACHINE;
info->d_class = ELFCLASS;
Expand Down
4 changes: 4 additions & 0 deletions tests/test-hmp.c
Expand Up @@ -35,6 +35,7 @@ static const char *hmp_cmds[] = {
"mouse_button 0",
"device_del mouse1",
"dump-guest-memory /dev/null 0 4096",
"dump-guest-memory /dev/null",
"gdbserver",
"host_net_add user id=net0",
"hostfwd_add tcp::43210-:43210",
Expand Down Expand Up @@ -159,5 +160,8 @@ int main(int argc, char **argv)

qtest_cb_for_every_machine(add_machine_test_case);

/* as none machine has no memory by default, add a test case with memory */
qtest_add_data_func("hmp/none+2MB", g_strdup("none -m 2"), test_machine);

return g_test_run();
}

0 comments on commit 3dabde1

Please sign in to comment.