qmp: distinguish PC-DIMM and NVDIMM in MemoryDeviceInfoList

It may need to treat PC-DIMM and NVDIMM differently, e.g., when
deciding the necessity of non-volatile flag bit in SRAT memory
affinity structures.

A new field 'nvdimm' is added to the union type MemoryDeviceInfo for
such purpose. Its type is currently PCDIMMDeviceInfo and will be
updated when necessary in the future.

It also fixes "info memory-devices"/query-memory-devices which
currently show nvdimm devices as dimm devices since
object_dynamic_cast(obj, TYPE_PC_DIMM) happily cast nvdimm to
TYPE_PC_DIMM which it's been inherited from.

Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
Haozhong Zhang 2018-03-11 11:02:12 +08:00 committed by Michael S. Tsirkin
parent 52c95cae4e
commit 6388e18de9
4 changed files with 38 additions and 11 deletions

14
hmp.c
View File

@ -2423,7 +2423,18 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
switch (value->type) { switch (value->type) {
case MEMORY_DEVICE_INFO_KIND_DIMM: case MEMORY_DEVICE_INFO_KIND_DIMM:
di = value->u.dimm.data; di = value->u.dimm.data;
break;
case MEMORY_DEVICE_INFO_KIND_NVDIMM:
di = value->u.nvdimm.data;
break;
default:
di = NULL;
break;
}
if (di) {
monitor_printf(mon, "Memory device [%s]: \"%s\"\n", monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
MemoryDeviceInfoKind_str(value->type), MemoryDeviceInfoKind_str(value->type),
di->id ? di->id : ""); di->id ? di->id : "");
@ -2436,9 +2447,6 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
di->hotplugged ? "true" : "false"); di->hotplugged ? "true" : "false");
monitor_printf(mon, " hotpluggable: %s\n", monitor_printf(mon, " hotpluggable: %s\n",
di->hotpluggable ? "true" : "false"); di->hotpluggable ? "true" : "false");
break;
default:
break;
} }
} }
} }

View File

@ -20,6 +20,7 @@
#include "qemu/osdep.h" #include "qemu/osdep.h"
#include "hw/mem/pc-dimm.h" #include "hw/mem/pc-dimm.h"
#include "hw/mem/nvdimm.h"
#include "qapi/error.h" #include "qapi/error.h"
#include "qemu/config-file.h" #include "qemu/config-file.h"
#include "qapi/visitor.h" #include "qapi/visitor.h"
@ -250,6 +251,7 @@ MemoryDeviceInfoList *qmp_pc_dimm_device_list(void)
MemoryDeviceInfoList *elem = g_new0(MemoryDeviceInfoList, 1); MemoryDeviceInfoList *elem = g_new0(MemoryDeviceInfoList, 1);
MemoryDeviceInfo *info = g_new0(MemoryDeviceInfo, 1); MemoryDeviceInfo *info = g_new0(MemoryDeviceInfo, 1);
PCDIMMDeviceInfo *di = g_new0(PCDIMMDeviceInfo, 1); PCDIMMDeviceInfo *di = g_new0(PCDIMMDeviceInfo, 1);
bool is_nvdimm = object_dynamic_cast(obj, TYPE_NVDIMM);
DeviceClass *dc = DEVICE_GET_CLASS(obj); DeviceClass *dc = DEVICE_GET_CLASS(obj);
DeviceState *dev = DEVICE(obj); DeviceState *dev = DEVICE(obj);
@ -265,7 +267,13 @@ MemoryDeviceInfoList *qmp_pc_dimm_device_list(void)
di->size = object_property_get_uint(obj, PC_DIMM_SIZE_PROP, NULL); di->size = object_property_get_uint(obj, PC_DIMM_SIZE_PROP, NULL);
di->memdev = object_get_canonical_path(OBJECT(dimm->hostmem)); di->memdev = object_get_canonical_path(OBJECT(dimm->hostmem));
info->u.dimm.data = di; if (!is_nvdimm) {
info->u.dimm.data = di;
info->type = MEMORY_DEVICE_INFO_KIND_DIMM;
} else {
info->u.nvdimm.data = di;
info->type = MEMORY_DEVICE_INFO_KIND_NVDIMM;
}
elem->value = info; elem->value = info;
elem->next = NULL; elem->next = NULL;
if (prev) { if (prev) {

19
numa.c
View File

@ -529,18 +529,25 @@ static void numa_stat_memory_devices(NumaNodeMem node_mem[])
if (value) { if (value) {
switch (value->type) { switch (value->type) {
case MEMORY_DEVICE_INFO_KIND_DIMM: { case MEMORY_DEVICE_INFO_KIND_DIMM:
pcdimm_info = value->u.dimm.data; pcdimm_info = value->u.dimm.data;
break;
case MEMORY_DEVICE_INFO_KIND_NVDIMM:
pcdimm_info = value->u.nvdimm.data;
break;
default:
pcdimm_info = NULL;
break;
}
if (pcdimm_info) {
node_mem[pcdimm_info->node].node_mem += pcdimm_info->size; node_mem[pcdimm_info->node].node_mem += pcdimm_info->size;
if (pcdimm_info->hotpluggable && pcdimm_info->hotplugged) { if (pcdimm_info->hotpluggable && pcdimm_info->hotplugged) {
node_mem[pcdimm_info->node].node_plugged_mem += node_mem[pcdimm_info->node].node_plugged_mem +=
pcdimm_info->size; pcdimm_info->size;
} }
break;
}
default:
break;
} }
} }
} }

View File

@ -2852,7 +2852,11 @@
# #
# Since: 2.1 # Since: 2.1
## ##
{ 'union': 'MemoryDeviceInfo', 'data': {'dimm': 'PCDIMMDeviceInfo'} } { 'union': 'MemoryDeviceInfo',
'data': { 'dimm': 'PCDIMMDeviceInfo',
'nvdimm': 'PCDIMMDeviceInfo'
}
}
## ##
# @query-memory-devices: # @query-memory-devices: