hw/acpi-build: build SRAT memory affinity structures for DIMM devices
v4 cover hw/acpi-build: build SRAT memory affinity structures for DIMM devices
(Patch 5 is only for reviewers to run test cases in patch 4)
ACPI 6.2A Table 5-129 "SPA Range Structure" requires the proximity domain of a NVDIMM SPA range must match with corresponding entry in SRAT table.
The address ranges of vNVDIMM in QEMU are allocated from the hot-pluggable address space, which is entirely covered by one SRAT memory affinity structure. However, users can set the vNVDIMM proximity domain in NFIT SPA range structure by the 'node' property of '-device nvdimm' to a value different than the one in the above SRAT memory affinity structure.
In order to solve such proximity domain mismatch, this patch builds one SRAT memory affinity structure for each DIMM device present at boot time, including both PC-DIMM and NVDIMM, with the proximity domain specified in '-device pc-dimm' or '-device nvdimm'.
The remaining hot-pluggable address space is covered by one or multiple SRAT memory affinity structures with the proximity domain of the last node as before.
Changes in v4:
* (Patch 1) Update the commit message and add R-b from Igor Mammedov.
* (Patch 2) Rebase on misc.json and update the commit message.
* (Patch 3) Directly use di-addr and di-node.
* (Patch 4) Drop the previous v3 patch 3 and add '-machine nvdimm=on' to parameters of test_acpi_one().
* (Patch 4) Put PC-DIMM and NVDIMM to different numa nodes.
* (Patch 4&5) Move binary blobs of ACPI tables to DO-NOT-APPLY patch 5.
Changes in v3:
* (Patch 1&2) Use qmp_pc_dimm_device_list to get information of DIMM devices and move it to separate patches.
* (Patch 3) Replace while loop by a more readable for loop.
* (Patch 3) Refactor the flag setting code.
* (Patch 3) s/'static-plugged'/'present at boot time' in commit message.
Changes in v2:
* Build SRAT memory affinity structures of PC-DIMM devices as well.
* Add test cases.
Haozhong Zhang (5):
pc-dimm: make qmp_pc_dimm_device_list() sort devices by address
qmp: distinguish PC-DIMM and NVDIMM in MemoryDeviceInfoList hw/acpi-build: build SRAT memory affinity structures for DIMM devices tests/bios-tables-test: add test cases for DIMM proximity [DO NOT APPLY] test/acpi-test-data: add ACPI tables for dimmpxm test
hmp.c | 14 +++-- hw/i386/acpi-build.c | 57 ++++++++++++++++++-- hw/mem/pc-dimm.c | 99 ++++++++++++++++++++-------------- hw/ppc/spapr.c | 3 +- include/hw/mem/pc-dimm.h | 2 +- numa.c | 23 ++++---- qapi/misc.json | 18 ++++++- qmp.c | 7 +-- stubs/qmp_pc_dimm.c | 4 +- tests/acpi-test-data/pc/APIC.dimmpxm | Bin 0 -> 144 bytes tests/acpi-test-data/pc/DSDT.dimmpxm | Bin 0 -> 6803 bytes tests/acpi-test-data/pc/NFIT.dimmpxm | Bin 0 -> 224 bytes tests/acpi-test-data/pc/SRAT.dimmpxm | Bin 0 -> 472 bytes tests/acpi-test-data/pc/SSDT.dimmpxm | Bin 0 -> 685 bytes tests/acpi-test-data/q35/APIC.dimmpxm | Bin 0 -> 144 bytes tests/acpi-test-data/q35/DSDT.dimmpxm | Bin 0 -> 9487 bytes tests/acpi-test-data/q35/NFIT.dimmpxm | Bin 0 -> 224 bytes tests/acpi-test-data/q35/SRAT.dimmpxm | Bin 0 -> 472 bytes tests/acpi-test-data/q35/SSDT.dimmpxm | Bin 0 -> 685 bytes tests/bios-tables-test.c | 38 +++++++++++++ 20 files changed, 198 insertions(+), 67 deletions(-) create mode 100644 tests/acpi-test-data/pc/APIC.dimmpxm create mode 100644 tests/acpi-test-data/pc/DSDT.dimmpxm create mode 100644 tests/acpi-test-data/pc/NFIT.dimmpxm create mode 100644 tests/acpi-test-data/pc/SRAT.dimmpxm create mode 100644 tests/acpi-test-data/pc/SSDT.dimmpxm create mode 100644 tests/acpi-test-data/q35/APIC.dimmpxm create mode 100644 tests/acpi-test-data/q35/DSDT.dimmpxm create mode 100644 tests/acpi-test-data/q35/NFIT.dimmpxm create mode 100644 tests/acpi-test-data/q35/SRAT.dimmpxm create mode 100644 tests/acpi-test-data/q35/SSDT.dimmpxm
Signature · 1 line
2.14.1
PATCH v4 1/5 pc-dimm: make qmp_pc_dimm_device_list() sort devices by address
Make qmp_pc_dimm_device_list() return sorted by start address list of devices so that it could be reused in places that would need sorted list*. Reuse existing pc_dimm_built_list() to get sorted list.
While at it hide recursive callbacks from callers, so that:
qmp_pc_dimm_device_list(qdev_get_machine(), &list);
could be replaced with simpler:
list = qmp_pc_dimm_device_list();
* follow up patch will use it in build_srat()
--- hw/mem/pc-dimm.c | 83 +++++++++++++++++++++++++----------------------- hw/ppc/spapr.c | 3 +- include/hw/mem/pc-dimm.h | 2 +- numa.c | 4 +-- qmp.c | 7 +--- stubs/qmp_pc_dimm.c | 4 +-- 6 files changed, 50 insertions(+), 53 deletions(-)
hw/mem/pc-dimm.c +44 -39
@@ -162,45 +162,6 @@ 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; - -if (object_dynamic_cast (obj,TYPE_PC_DIMM )) { -DeviceState *dev =DEVICE (obj); - -if (dev->realized) { -MemoryDeviceInfoList *elem =g_new0 (MemoryDeviceInfoList,1 ); -MemoryDeviceInfo *info =g_new0 (MemoryDeviceInfo,1 ); -PCDIMMDeviceInfo *di =g_new0 (PCDIMMDeviceInfo,1 ); -DeviceClass *dc =DEVICE_GET_CLASS (obj); -PCDIMMDevice *dimm =PC_DIMM (obj); - -if (dev->id) { - di->has_id = true; - di->id =g_strdup (dev->id); - } - di->hotplugged = dev->hotplugged; - di->hotpluggable = dc->hotpluggable; - di->addr = dimm->addr; - di->slot = dimm->slot; - di->node = dimm->node; - di->size =object_property_get_uint (OBJECT (dimm),PC_DIMM_SIZE_PROP , -NULL ); - di->memdev =object_get_canonical_path (OBJECT (dimm->hostmem)); - - info->u.dimm.data = di; - elem->value = info; - elem->next =NULL ; - **prev = elem; - *prev = &elem->next; - } - } - -object_child_foreach (obj, qmp_pc_dimm_device_list, opaque); -return 0 ; -} -static int pc_dimm_slot2bitmap (Object *obj,void *opaque) {unsigned long *bitmap = opaque;
@@ -276,6 +237,50 @@ static int pc_dimm_built_list(Object *obj, void *opaque)return 0 ; } +MemoryDeviceInfoList *qmp_pc_dimm_device_list (void ) +{ +GSList *dimms =NULL , *item; +MemoryDeviceInfoList *list =NULL , *prev =NULL ; + +object_child_foreach (qdev_get_machine (), pc_dimm_built_list, &dimms); + +for (item = dimms; item; item =g_slist_next (item)) { +PCDIMMDevice *dimm =PC_DIMM (item->data); +Object *obj =OBJECT (dimm); +MemoryDeviceInfoList *elem =g_new0 (MemoryDeviceInfoList,1 ); +MemoryDeviceInfo *info =g_new0 (MemoryDeviceInfo,1 ); +PCDIMMDeviceInfo *di =g_new0 (PCDIMMDeviceInfo,1 ); +DeviceClass *dc =DEVICE_GET_CLASS (obj); +DeviceState *dev =DEVICE (obj); + +if (dev->id) { + di->has_id = true; + di->id =g_strdup (dev->id); + } + di->hotplugged = dev->hotplugged; + di->hotpluggable = dc->hotpluggable; + di->addr = dimm->addr; + di->slot = dimm->slot; + di->node = dimm->node; + di->size =object_property_get_uint (obj,PC_DIMM_SIZE_PROP ,NULL ); + di->memdev =object_get_canonical_path (OBJECT (dimm->hostmem)); + + info->u.dimm.data = di; + elem->value = info; + elem->next =NULL ; +if (prev) { + prev->next = elem; + }else { + list = elem; + } + prev = elem; + } + +g_slist_free (dimms); + +return list; +} + uint64_t pc_dimm_get_free_addr(uint64_t address_space_start, uint64_t address_space_size, uint64_t *hint, uint64_t align, uint64_t size,
hw/ppc/spapr.c +1 -2
@@ -722,8 +722,7 @@ static int spapr_populate_drconf_memory(sPAPRMachineState *spapr, void *fdt) }if (hotplug_lmb_start) { -MemoryDeviceInfoList **prev = &dimms; -qmp_pc_dimm_device_list (qdev_get_machine (), &prev); + dimms =qmp_pc_dimm_device_list (); }/* ibm,dynamic-memory */
include/hw/mem/pc-dimm.h +1 -1
@@ -93,7 +93,7 @@ uint64_t pc_dimm_get_free_addr(uint64_t address_space_start,int pc_dimm_get_free_slot (const int *hint,int max_slots,Error **errp); -int qmp_pc_dimm_device_list (Object *obj,void *opaque); +MemoryDeviceInfoList *qmp_pc_dimm_device_list (void );uint64_t pc_existing_dimms_capacity (Error **errp);uint64_t get_plugged_memory_size (void ); void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState *hpms,
numa.c +1 -3
@@ -520,12 +520,10 @@ void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,static void numa_stat_memory_devices (NumaNodeMem node_mem[]) { -MemoryDeviceInfoList *info_list =NULL ; -MemoryDeviceInfoList **prev = &info_list; +MemoryDeviceInfoList *info_list =qmp_pc_dimm_device_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;
qmp.c +1 -6
@@ -731,12 +731,7 @@ void qmp_object_del(const char *id, Error **errp)MemoryDeviceInfoList *qmp_query_memory_devices (Error **errp) { -MemoryDeviceInfoList *head =NULL ; -MemoryDeviceInfoList **prev = &head; - -qmp_pc_dimm_device_list (qdev_get_machine (), &prev); - -return head; +return qmp_pc_dimm_device_list (); }ACPIOSTInfoList *qmp_query_acpi_ospm_status (Error **errp)
stubs/qmp_pc_dimm.c +2 -2
@@ -2,9 +2,9 @@#include "qom/object.h" #include "hw/mem/pc-dimm.h" -int qmp_pc_dimm_device_list (Object *obj,void *opaque) +MemoryDeviceInfoList *qmp_pc_dimm_device_list (void ) { -return 0 ; +return NULL ; }uint64_t get_plugged_memory_size (void )
Signature · 1 line
2.14.1
Re: [Qemu-devel] [PATCH v4 1/5] pc-dimm: make qmp_pc_dimm_device_list() sort devices by address
Quoted 13 lines · Haozhong Zhang
Make
qmp_pc_dimm_device_list()return sorted by start address list of devices so that it could be reused in places that would need sorted list*. Reuse existingpc_dimm_built_list()to get sorted list.While at it hide recursive callbacks from callers, so that:
qmp_pc_dimm_device_list(qdev_get_machine(), &list);could be replaced with simpler:
list = qmp_pc_dimm_device_list();
Quoted 7 lines
* follow up patch will use it in
build_srat()Signed-off-by Haozhong Zhang <[email protected]>Reviewed-by Igor Mammedov <[email protected]>--- hw/mem/pc-dimm.c | 83 +++++++++++++++++++++++++----------------------- hw/ppc/spapr.c | 3 +-
I have used this patch with SPAPR to implement the new device tree property ibm,dynamic-memory-v2 at http://patchwork.ozlabs.org/patch/882387/
Re: [Qemu-devel] [PATCH v4 1/5] pc-dimm: make qmp_pc_dimm_device_list() sort devices by address
In reply to Haozhong ZhangQuoted 9 lines · Haozhong Zhang
Make
qmp_pc_dimm_device_list()return sorted by start address list of devices so that it could be reused in places that would need sorted list*. Reuse existingpc_dimm_built_list()to get sorted list.While at it hide recursive callbacks from callers, so that:
qmp_pc_dimm_device_list(qdev_get_machine(), &list);
Quoted 8 lines
could be replaced with simpler:
list = qmp_pc_dimm_device_list();* follow up patch will use it in
build_srat()Signed-off-by Haozhong Zhang <[email protected]>Reviewed-by Igor Mammedov <[email protected]>
ppc part
Quoted 189 lines
--- hw/mem/pc-dimm.c | 83 +++++++++++++++++++++++++----------------------- hw/ppc/spapr.c | 3 +- include/hw/mem/pc-dimm.h | 2 +- numa.c | 4 +-- qmp.c | 7 +--- stubs/qmp_pc_dimm.c | 4 +-- 6 files changed, 50 insertions(+), 53 deletions(-)hw/mem/pc-dimm.c +44
-39@@ -162,45 +162,6 @@ 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; - -if (object_dynamic_cast (obj,TYPE_PC_DIMM )) { -DeviceState *dev =DEVICE (obj); - -if (dev->realized) { -MemoryDeviceInfoList *elem =g_new0 (MemoryDeviceInfoList,1 ); -MemoryDeviceInfo *info =g_new0 (MemoryDeviceInfo,1 ); -PCDIMMDeviceInfo *di =g_new0 (PCDIMMDeviceInfo,1 ); -DeviceClass *dc =DEVICE_GET_CLASS (obj); -PCDIMMDevice *dimm =PC_DIMM (obj); - -if (dev->id) { - di->has_id = true; - di->id =g_strdup (dev->id); - } - di->hotplugged = dev->hotplugged; - di->hotpluggable = dc->hotpluggable; - di->addr = dimm->addr; - di->slot = dimm->slot; - di->node = dimm->node; - di->size =object_property_get_uint (OBJECT (dimm),PC_DIMM_SIZE_PROP , -NULL ); - di->memdev =object_get_canonical_path (OBJECT (dimm->hostmem)); - - info->u.dimm.data = di; - elem->value = info; - elem->next =NULL ; - **prev = elem; - *prev = &elem->next; - } - } - -object_child_foreach (obj, qmp_pc_dimm_device_list, opaque); -return 0 ; -} -static int pc_dimm_slot2bitmap (Object *obj,void *opaque) {unsigned long *bitmap = opaque;@@ -276,6 +237,50 @@ static int pc_dimm_built_list(Object *obj, void *opaque)return 0 ; } +MemoryDeviceInfoList *qmp_pc_dimm_device_list (void ) +{ +GSList *dimms =NULL , *item; +MemoryDeviceInfoList *list =NULL , *prev =NULL ; + +object_child_foreach (qdev_get_machine (), pc_dimm_built_list, &dimms); + +for (item = dimms; item; item =g_slist_next (item)) { +PCDIMMDevice *dimm =PC_DIMM (item->data); +Object *obj =OBJECT (dimm); +MemoryDeviceInfoList *elem =g_new0 (MemoryDeviceInfoList,1 ); +MemoryDeviceInfo *info =g_new0 (MemoryDeviceInfo,1 ); +PCDIMMDeviceInfo *di =g_new0 (PCDIMMDeviceInfo,1 ); +DeviceClass *dc =DEVICE_GET_CLASS (obj); +DeviceState *dev =DEVICE (obj); + +if (dev->id) { + di->has_id = true; + di->id =g_strdup (dev->id); + } + di->hotplugged = dev->hotplugged; + di->hotpluggable = dc->hotpluggable; + di->addr = dimm->addr; + di->slot = dimm->slot; + di->node = dimm->node; + di->size =object_property_get_uint (obj,PC_DIMM_SIZE_PROP ,NULL ); + di->memdev =object_get_canonical_path (OBJECT (dimm->hostmem)); + + info->u.dimm.data = di; + elem->value = info; + elem->next =NULL ; +if (prev) { + prev->next = elem; + }else { + list = elem; + } + prev = elem; + } + +g_slist_free (dimms); + +return list; +} + uint64_t pc_dimm_get_free_addr(uint64_t address_space_start, uint64_t address_space_size, uint64_t *hint, uint64_t align, uint64_t size,hw/ppc/spapr.c +1
-2@@ -722,8 +722,7 @@ static int spapr_populate_drconf_memory(sPAPRMachineState *spapr, void *fdt) }if (hotplug_lmb_start) { -MemoryDeviceInfoList **prev = &dimms; -qmp_pc_dimm_device_list (qdev_get_machine (), &prev); + dimms =qmp_pc_dimm_device_list (); }/* ibm,dynamic-memory */ include/hw/mem/pc-dimm.h +1
-1@@ -93,7 +93,7 @@ uint64_t pc_dimm_get_free_addr(uint64_t address_space_start,int pc_dimm_get_free_slot (const int *hint,int max_slots,Error **errp); -int qmp_pc_dimm_device_list (Object *obj,void *opaque); +MemoryDeviceInfoList *qmp_pc_dimm_device_list (void );uint64_t pc_existing_dimms_capacity (Error **errp);uint64_t get_plugged_memory_size (void ); void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState *hpms,numa.c +1
-3@@ -520,12 +520,10 @@ void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,static void numa_stat_memory_devices (NumaNodeMem node_mem[]) { -MemoryDeviceInfoList *info_list =NULL ; -MemoryDeviceInfoList **prev = &info_list; +MemoryDeviceInfoList *info_list =qmp_pc_dimm_device_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;qmp.c +1
-6@@ -731,12 +731,7 @@ void qmp_object_del(const char *id, Error **errp)MemoryDeviceInfoList *qmp_query_memory_devices (Error **errp) { -MemoryDeviceInfoList *head =NULL ; -MemoryDeviceInfoList **prev = &head; - -qmp_pc_dimm_device_list (qdev_get_machine (), &prev); - -return head; +return qmp_pc_dimm_device_list (); }ACPIOSTInfoList *qmp_query_acpi_ospm_status (Error **errp)stubs/qmp_pc_dimm.c +2
-2@@ -2,9 +2,9 @@#include "qom/object.h" #include "hw/mem/pc-dimm.h" -int qmp_pc_dimm_device_list (Object *obj,void *opaque) +MemoryDeviceInfoList *qmp_pc_dimm_device_list (void ) { -return 0 ; +return NULL ; }uint64_t get_plugged_memory_size (void )
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
PATCH v4 2/5 qmp: distinguish PC-DIMM and NVDIMM in MemoryDeviceInfoList
In reply to Haozhong ZhangIt 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.
NVDIMMDeviceInfo, which inherits from PCDIMMDeviceInfo, is added to union type MemoryDeviceInfo to record information of NVDIMM devices. The NVDIMM-specific data is currently left empty and will be filled 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.
--- hmp.c | 14 +++++++++++--- hw/mem/pc-dimm.c | 20 ++++++++++++++++++-- numa.c | 19 +++++++++++++------ qapi/misc.json | 18 +++++++++++++++++- 4 files changed, 59 insertions(+), 12 deletions(-)
hmp.c +11 -3
@@ -2421,7 +2421,18 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)switch (value->type) {case MEMORY_DEVICE_INFO_KIND_DIMM : di = value->u.dimm.data; +break ; + +case MEMORY_DEVICE_INFO_KIND_NVDIMM : + di =qapi_NVDIMMDeviceInfo_base (value->u.nvdimm.data); +break ; + +default : + di =NULL ; +break ; + } +if (di) {monitor_printf (mon,"Memory device [%s]: \"%s\"\n" ,MemoryDeviceInfoKind_str (value->type), di->id ? di->id :"" );
@@ -2434,9 +2445,6 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *qdict) di->hotplugged ? "true" : "false");monitor_printf (mon," hotpluggable: %s\n" , di->hotpluggable ?"true" :"false" ); -break ; -default : -break ; } } }
hw/mem/pc-dimm.c +18 -2
@@ -20,6 +20,7 @@#include "qemu/osdep.h" #include "hw/mem/pc-dimm.h" +#include "hw/mem/nvdimm.h" #include "qapi/error.h" #include "qemu/config-file.h" #include "qapi/visitor.h"
@@ -249,10 +250,19 @@ MemoryDeviceInfoList *qmp_pc_dimm_device_list(void)Object *obj =OBJECT (dimm);MemoryDeviceInfoList *elem =g_new0 (MemoryDeviceInfoList,1 );MemoryDeviceInfo *info =g_new0 (MemoryDeviceInfo,1 ); -PCDIMMDeviceInfo *di =g_new0 (PCDIMMDeviceInfo,1 ); +PCDIMMDeviceInfo *di; +NVDIMMDeviceInfo *ndi; +bool is_nvdimm =object_dynamic_cast (obj,TYPE_NVDIMM );DeviceClass *dc =DEVICE_GET_CLASS (obj);DeviceState *dev =DEVICE (obj); +if (!is_nvdimm) { + di =g_new0 (PCDIMMDeviceInfo,1 ); + }else { + ndi =g_new0 (NVDIMMDeviceInfo,1 ); + di =qapi_NVDIMMDeviceInfo_base (ndi); + } +if (dev->id) { di->has_id = true; di->id =g_strdup (dev->id);
@@ -265,7 +275,13 @@ MemoryDeviceInfoList *qmp_pc_dimm_device_list(void) di->size =object_property_get_uint (obj,PC_DIMM_SIZE_PROP ,NULL ); 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 = ndi; + info->type =MEMORY_DEVICE_INFO_KIND_NVDIMM ; + } elem->value = info; elem->next =NULL ;if (prev) {
numa.c +13 -6
@@ -529,18 +529,25 @@ static void numa_stat_memory_devices(NumaNodeMem node_mem[])if (value) {switch (value->type) { -case MEMORY_DEVICE_INFO_KIND_DIMM : { +case MEMORY_DEVICE_INFO_KIND_DIMM : pcdimm_info = value->u.dimm.data; +break ; + +case MEMORY_DEVICE_INFO_KIND_NVDIMM : + pcdimm_info =qapi_NVDIMMDeviceInfo_base (value->u.nvdimm.data); +break ; + +default : + pcdimm_info =NULL ; +break ; + } + +if (pcdimm_info) { 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 ; } } }
qapi/misc.json +17 -1
@@ -2830,6 +2830,18 @@ } } +## +# @NVDIMMDeviceInfo: +# +# NVDIMMDevice state information +# +# Since: 2.12 +## +{ 'struct': 'NVDIMMDeviceInfo', + 'base': 'PCDIMMDeviceInfo', + 'data': {} +} + ## # @MemoryDeviceInfo: #
@@ -2837,7 +2849,11 @@ # # Since: 2.1 ## -{ 'union': 'MemoryDeviceInfo', 'data': {'dimm': 'PCDIMMDeviceInfo'} } +{ 'union': 'MemoryDeviceInfo', + 'data': { 'dimm': 'PCDIMMDeviceInfo', + 'nvdimm': 'NVDIMMDeviceInfo' + } +} ## # @query-memory-devices:
Signature · 1 line
2.14.1
Re: [Qemu-devel] [PATCH v4 2/5] qmp: distinguish PC-DIMM and NVDIMM in MemoryDeviceInfoList
Quoted 24 lines · Haozhong Zhang
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.
NVDIMMDeviceInfo, which inherits from PCDIMMDeviceInfo, is added to union type MemoryDeviceInfo to record information of NVDIMM devices. The NVDIMM-specific data is currently left empty and will be filled 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 toTYPE_PC_DIMMwhich it's been inherited from.Signed-off-by Haozhong Zhang <[email protected]>---
+++
b/qapi/misc.jsonqapi/misc.json +2
-0@@ -2830,6 +2830,18 @@ } } +## +# @NVDIMMDeviceInfo:
qapi/misc.json line 2844
Quoted 10 lines
qapi/misc.json +10
-0+# +# NVDIMMDevice state information +# +# Since: 2.12 +## +{ 'struct': 'NVDIMMDeviceInfo', + 'base': 'PCDIMMDeviceInfo', + 'data': {} +} +
As long as you don't have any data members to add, you could omit this type...
qapi/misc.json line 2855
Quoted 12 lines
qapi/misc.json +4
-1## # @MemoryDeviceInfo: #@@ -2837,7 +2849,11 @@ # # Since: 2.1 ## -{ 'union': 'MemoryDeviceInfo', 'data': {'dimm': 'PCDIMMDeviceInfo'} } +{ 'union': 'MemoryDeviceInfo', + 'data': { 'dimm': 'PCDIMMDeviceInfo', + 'nvdimm': 'NVDIMMDeviceInfo' + }
and just write this as
'data': { 'dimm': 'PCDIMMDeviceInfo',
'nvdimm': 'PCDIMMDeviceInfo' }
If, down the road, you want to add data members to one but not both of the branches, we can add a new (sub-)type at that time, and it won't break backwards compatibility.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH v4 2/5] qmp: distinguish PC-DIMM and NVDIMM in MemoryDeviceInfoList
Quoted 29 lines · Eric Blake
Quoted 28 lines · Haozhong Zhang
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.
NVDIMMDeviceInfo, which inherits from PCDIMMDeviceInfo, is added to union type MemoryDeviceInfo to record information of NVDIMM devices. The NVDIMM-specific data is currently left empty and will be filled 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 toTYPE_PC_DIMMwhich it's been inherited from.Signed-off-by Haozhong Zhang <[email protected]>---
+++
b/qapi/misc.jsonqapi/misc.json +7
-0@@ -2830,6 +2830,18 @@ } } +## +# @NVDIMMDeviceInfo: +# +# NVDIMMDevice state information +# +# Since: 2.12 +##
Quoted 8 lines
qapi/misc.json line 2844
Quoted 5 lines
qapi/misc.json +5
-0+{ 'struct': 'NVDIMMDeviceInfo', + 'base': 'PCDIMMDeviceInfo', + 'data': {} +} +As long as you don't have any data members to add, you could omit this type...
Sure, I'll change in the next version.
Haozhong
Quoted 27 lines
qapi/misc.json line 2855
Quoted 13 lines
qapi/misc.json +4
-1## # @MemoryDeviceInfo: #@@ -2837,7 +2849,11 @@ # # Since: 2.1 ## -{ 'union': 'MemoryDeviceInfo', 'data': {'dimm': 'PCDIMMDeviceInfo'} } +{ 'union': 'MemoryDeviceInfo', + 'data': { 'dimm': 'PCDIMMDeviceInfo', + 'nvdimm': 'NVDIMMDeviceInfo' + }and just write this as
'data': { 'dimm': 'PCDIMMDeviceInfo',
'nvdimm': 'PCDIMMDeviceInfo' }If, down the road, you want to add data members to one but not both of the branches, we can add a new (sub-)type at that time, and it won't break backwards compatibility.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
PATCH v4 3/5 hw/acpi-build: build SRAT memory affinity structures for DIMM devices
In reply to Haozhong ZhangACPI 6.2A Table 5-129 "SPA Range Structure" requires the proximity domain of a NVDIMM SPA range must match with corresponding entry in SRAT table.
The address ranges of vNVDIMM in QEMU are allocated from the hot-pluggable address space, which is entirely covered by one SRAT memory affinity structure. However, users can set the vNVDIMM proximity domain in NFIT SPA range structure by the 'node' property of '-device nvdimm' to a value different than the one in the above SRAT memory affinity structure.
In order to solve such proximity domain mismatch, this patch builds one SRAT memory affinity structure for each DIMM device present at boot time, including both PC-DIMM and NVDIMM, with the proximity domain specified in '-device pc-dimm' or '-device nvdimm'.
The remaining hot-pluggable address space is covered by one or multiple SRAT memory affinity structures with the proximity domain of the last node as before.
--- hw/i386/acpi-build.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 4 deletions(-)
hw/i386/acpi-build.c +53 -4
@@ -2323,6 +2323,56 @@ build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog)#define HOLE_640K_START (640 * 1024)#define HOLE_640K_END (1024 * 1024) +static void build_srat_hotpluggable_memory (GArray *table_data,uint64_t base, +uint64_t len,int default_node) +{ +MemoryDeviceInfoList *info_list =qmp_pc_dimm_device_list (); +MemoryDeviceInfoList *info; +MemoryDeviceInfo *mi; +PCDIMMDeviceInfo *di; +uint64_t end = base + len, cur, size; +bool is_nvdimm; +AcpiSratMemoryAffinity *numamem; +MemoryAffinityFlags flags; + +for (cur = base, info = info_list; + cur < end; + cur += size, info = info->next) { + numamem =acpi_data_push (table_data,sizeof *numamem); + +if (!info) { +build_srat_memory (numamem, cur, end - cur, default_node, +MEM_AFFINITY_HOTPLUGGABLE |MEM_AFFINITY_ENABLED ); +break ; + } + + mi = info->value; + is_nvdimm = (mi->type ==MEMORY_DEVICE_INFO_KIND_NVDIMM ); + di = !is_nvdimm ? mi->u.dimm.data : +qapi_NVDIMMDeviceInfo_base (mi->u.nvdimm.data); + +if (cur < di->addr) { +build_srat_memory (numamem, cur, di->addr - cur, default_node, +MEM_AFFINITY_HOTPLUGGABLE |MEM_AFFINITY_ENABLED ); + numamem =acpi_data_push (table_data,sizeof *numamem); + } + + size = di->size; + + flags =MEM_AFFINITY_ENABLED ; +if (di->hotpluggable) { + flags |=MEM_AFFINITY_HOTPLUGGABLE ; + } +if (is_nvdimm) { + flags |=MEM_AFFINITY_NON_VOLATILE ; + } + +build_srat_memory (numamem, di->addr, size, di->node, flags); + } + +qapi_free_MemoryDeviceInfoList (info_list); +} +static void build_srat (GArray *table_data,BIOSLinker *linker,MachineState *machine) {
@@ -2434,10 +2484,9 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)* providing _PXM method if necessary. */ if (hotplugabble_address_space_size) { - numamem =acpi_data_push (table_data,sizeof *numamem); -build_srat_memory (numamem, pcms->hotplug_memory.base, - hotplugabble_address_space_size, pcms->numa_nodes -1 , -MEM_AFFINITY_HOTPLUGGABLE |MEM_AFFINITY_ENABLED ); +build_srat_hotpluggable_memory (table_data, pcms->hotplug_memory.base, + hotplugabble_address_space_size, + pcms->numa_nodes -1 ); } build_header(linker, table_data,
Signature · 1 line
2.14.1
PATCH v4 4/5 tests/bios-tables-test: add test cases for DIMM proximity
In reply to Haozhong ZhangQEMU now builds one SRAT memory affinity structure for each PC-DIMM and NVDIMM device presented at boot time with the proximity domain specified in the device option 'node', rather than only one SRAT memory affinity structure covering the entire hotpluggable address space with the proximity domain of the last node.
Add test cases on PC and Q35 machines with 4 proximity domains, and one PC-DIMM and one NVDIMM attached to the 2nd and 3rd proximity domains respectively. Check whether the QEMU-built SRAT tables match with the expected ones.
The following ACPI tables need to be added for this test:
tests/acpi-test-data/pc/APIC.dimmpxm tests/acpi-test-data/pc/DSDT.dimmpxm tests/acpi-test-data/pc/NFIT.dimmpxm tests/acpi-test-data/pc/SRAT.dimmpxm tests/acpi-test-data/pc/SSDT.dimmpxm tests/acpi-test-data/q35/APIC.dimmpxm tests/acpi-test-data/q35/DSDT.dimmpxm tests/acpi-test-data/q35/NFIT.dimmpxm tests/acpi-test-data/q35/SRAT.dimmpxm tests/acpi-test-data/q35/SSDT.dimmpxm
New APIC and DSDT are needed because of the multiple processors configuration. New NFIT and SSDT are needed because of NVDIMM.
--- tests/bios-tables-test.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
tests/bios-tables-test.c +38 -0
@@ -869,6 +869,42 @@ static void test_acpi_piix4_tcg_numamem(void)free_test_data (&data); } +static void test_acpi_tcg_dimm_pxm (const char *machine) +{ +test_data data; + +memset (&data,0 ,sizeof (data)); + data.machine = machine; + data.variant =".dimmpxm" ; +test_acpi_one (" -machine nvdimm=on" +" -smp 4,sockets=4" +" -m 128M,slots=3,maxmem=1G" +" -numa node,mem=32M,nodeid=0" +" -numa node,mem=32M,nodeid=1" +" -numa node,mem=32M,nodeid=2" +" -numa node,mem=32M,nodeid=3" +" -numa cpu,node-id=0,socket-id=0" +" -numa cpu,node-id=1,socket-id=1" +" -numa cpu,node-id=2,socket-id=2" +" -numa cpu,node-id=3,socket-id=3" +" -object memory-backend-ram,id=ram0,size=128M" +" -object memory-backend-ram,id=nvm0,size=128M" +" -device pc-dimm,id=dimm0,memdev=ram0,node=1" +" -device nvdimm,id=dimm1,memdev=nvm0,node=2" , + &data); +free_test_data (&data); +} + +static void test_acpi_q35_tcg_dimm_pxm (void ) +{ +test_acpi_tcg_dimm_pxm (MACHINE_Q35 ); +} + +static void test_acpi_piix4_tcg_dimm_pxm (void ) +{ +test_acpi_tcg_dimm_pxm (MACHINE_PC ); +} +int main (int argc,char *argv[]) {const char *arch =qtest_get_arch ();
@@ -893,6 +929,8 @@ int main(int argc, char *argv[])qtest_add_func ("acpi/q35/memhp" , test_acpi_q35_tcg_memhp);qtest_add_func ("acpi/piix4/numamem" , test_acpi_piix4_tcg_numamem);qtest_add_func ("acpi/q35/numamem" , test_acpi_q35_tcg_numamem); +qtest_add_func ("acpi/piix4/dimmpxm" , test_acpi_piix4_tcg_dimm_pxm); +qtest_add_func ("acpi/q35/dimmpxm" , test_acpi_q35_tcg_dimm_pxm); } ret =g_test_run ();boot_sector_cleanup (disk);
Signature · 1 line
2.14.1
PATCH v4 5/5 test/acpi-test-data: add ACPI tables for dimmpxm test
In reply to Haozhong ZhangReviewers can use ACPI tables in this patch to run test_acpi_{piix4,q35}_tcg_dimm_pxm cases.
--- tests/acpi-test-data/pc/APIC.dimmpxm | Bin 0 -> 144 bytes tests/acpi-test-data/pc/DSDT.dimmpxm | Bin 0 -> 6803 bytes tests/acpi-test-data/pc/NFIT.dimmpxm | Bin 0 -> 224 bytes tests/acpi-test-data/pc/SRAT.dimmpxm | Bin 0 -> 472 bytes tests/acpi-test-data/pc/SSDT.dimmpxm | Bin 0 -> 685 bytes tests/acpi-test-data/q35/APIC.dimmpxm | Bin 0 -> 144 bytes tests/acpi-test-data/q35/DSDT.dimmpxm | Bin 0 -> 9487 bytes tests/acpi-test-data/q35/NFIT.dimmpxm | Bin 0 -> 224 bytes tests/acpi-test-data/q35/SRAT.dimmpxm | Bin 0 -> 472 bytes tests/acpi-test-data/q35/SSDT.dimmpxm | Bin 0 -> 685 bytes 10 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/acpi-test-data/pc/APIC.dimmpxm create mode 100644 tests/acpi-test-data/pc/DSDT.dimmpxm create mode 100644 tests/acpi-test-data/pc/NFIT.dimmpxm create mode 100644 tests/acpi-test-data/pc/SRAT.dimmpxm create mode 100644 tests/acpi-test-data/pc/SSDT.dimmpxm create mode 100644 tests/acpi-test-data/q35/APIC.dimmpxm create mode 100644 tests/acpi-test-data/q35/DSDT.dimmpxm create mode 100644 tests/acpi-test-data/q35/NFIT.dimmpxm create mode 100644 tests/acpi-test-data/q35/SRAT.dimmpxm create mode 100644 tests/acpi-test-data/q35/SSDT.dimmpxm
tests/acpi-test-data/pc/APIC.dimmpxm new file binary +0 -0
tests/acpi-test-data/pc/DSDT.dimmpxm new file binary +0 -0
tests/acpi-test-data/pc/NFIT.dimmpxm new file binary +0 -0
tests/acpi-test-data/pc/SRAT.dimmpxm new file binary +0 -0
tests/acpi-test-data/pc/SSDT.dimmpxm new file binary +0 -0
tests/acpi-test-data/q35/APIC.dimmpxm new file binary +0 -0
tests/acpi-test-data/q35/DSDT.dimmpxm new file binary +0 -0
tests/acpi-test-data/q35/NFIT.dimmpxm new file binary +0 -0
tests/acpi-test-data/q35/SRAT.dimmpxm new file binary +0 -0
tests/acpi-test-data/q35/SSDT.dimmpxm new file binary +0 -0
Signature · 1 line
2.14.1
Quoted 22 lines · Haozhong Zhang
(Patch 5 is only for reviewers to run test cases in patch 4)
ACPI 6.2A Table 5-129 "SPA Range Structure" requires the proximity domain of a NVDIMM SPA range must match with corresponding entry in SRAT table.
The address ranges of vNVDIMM in QEMU are allocated from the hot-pluggable address space, which is entirely covered by one SRAT memory affinity structure. However, users can set the vNVDIMM proximity domain in NFIT SPA range structure by the 'node' property of '-device nvdimm' to a value different than the one in the above SRAT memory affinity structure.
In order to solve such proximity domain mismatch, this patch builds one SRAT memory affinity structure for each DIMM device present at boot time, including both PC-DIMM and NVDIMM, with the proximity domain specified in '-device pc-dimm' or '-device nvdimm'.
The remaining hot-pluggable address space is covered by one or multiple SRAT memory affinity structures with the proximity domain of the last node as before.
Quoted 5 lines
Changes in v4:
* (Patch 1) Update the commit message and add R-b from Igor Mammedov.
* (Patch 2) Rebase on misc.json and update the commit message.
* (Patch 3) Directly use di-addr and di-node.
* (Patch 4) Drop the previous v3 patch 3 and add '-machine nvdimm=on'
^^^^^^^^^^ should be 'v3 patch 4'
Quoted 58 lines
to parameters of
test_acpi_one().
* (Patch 4) Put PC-DIMM and NVDIMM to different numa nodes.
* (Patch 4&5) Move binary blobs of ACPI tables to DO-NOT-APPLY patch 5.Changes in v3:
* (Patch 1&2) Useqmp_pc_dimm_device_listto get information of DIMM devices and move it to separate patches.
* (Patch 3) Replace while loop by a more readable for loop.
* (Patch 3) Refactor the flag setting code.
* (Patch 3) s/'static-plugged'/'present at boot time' in commit message.Changes in v2:
* Build SRAT memory affinity structures of PC-DIMM devices as well.
* Add test cases.Haozhong Zhang (5):
pc-dimm: makeqmp_pc_dimm_device_list()sort devices by address
qmp: distinguish PC-DIMM and NVDIMM in MemoryDeviceInfoList hw/acpi-build: build SRAT memory affinity structures for DIMM devices tests/bios-tables-test: add test cases for DIMM proximity [DO NOT APPLY] test/acpi-test-data: add ACPI tables for dimmpxm testhmp.c | 14 +++-- hw/i386/acpi-build.c | 57 ++++++++++++++++++-- hw/mem/pc-dimm.c | 99 ++++++++++++++++++++-------------- hw/ppc/spapr.c | 3 +- include/hw/mem/pc-dimm.h | 2 +- numa.c | 23 ++++---- qapi/misc.json | 18 ++++++- qmp.c | 7 +-- stubs/qmp_pc_dimm.c | 4 +- tests/acpi-test-data/pc/APIC.dimmpxm | Bin 0 -> 144 bytes tests/acpi-test-data/pc/DSDT.dimmpxm | Bin 0 -> 6803 bytes tests/acpi-test-data/pc/NFIT.dimmpxm | Bin 0 -> 224 bytes tests/acpi-test-data/pc/SRAT.dimmpxm | Bin 0 -> 472 bytes tests/acpi-test-data/pc/SSDT.dimmpxm | Bin 0 -> 685 bytes tests/acpi-test-data/q35/APIC.dimmpxm | Bin 0 -> 144 bytes tests/acpi-test-data/q35/DSDT.dimmpxm | Bin 0 -> 9487 bytes tests/acpi-test-data/q35/NFIT.dimmpxm | Bin 0 -> 224 bytes tests/acpi-test-data/q35/SRAT.dimmpxm | Bin 0 -> 472 bytes tests/acpi-test-data/q35/SSDT.dimmpxm | Bin 0 -> 685 bytes tests/bios-tables-test.c | 38 +++++++++++++ 20 files changed, 198 insertions(+), 67 deletions(-) create mode 100644 tests/acpi-test-data/pc/APIC.dimmpxm create mode 100644 tests/acpi-test-data/pc/DSDT.dimmpxm create mode 100644 tests/acpi-test-data/pc/NFIT.dimmpxm create mode 100644 tests/acpi-test-data/pc/SRAT.dimmpxm create mode 100644 tests/acpi-test-data/pc/SSDT.dimmpxm create mode 100644 tests/acpi-test-data/q35/APIC.dimmpxm create mode 100644 tests/acpi-test-data/q35/DSDT.dimmpxm create mode 100644 tests/acpi-test-data/q35/NFIT.dimmpxm create mode 100644 tests/acpi-test-data/q35/SRAT.dimmpxm create mode 100644 tests/acpi-test-data/q35/SSDT.dimmpxmSignature · 1 line
2.14.1