From patchwork Thu Mar 8 02:33:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 10265939 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id ECEF360247 for ; Thu, 8 Mar 2018 02:48:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE08729405 for ; Thu, 8 Mar 2018 02:48:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D26D52941A; Thu, 8 Mar 2018 02:48:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F2FF829405 for ; Thu, 8 Mar 2018 02:48:13 +0000 (UTC) Received: from localhost ([::1]:36564 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etlbI-0005x6-M9 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 07 Mar 2018 21:48:12 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40536) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etlNY-00071K-BK for qemu-devel@nongnu.org; Wed, 07 Mar 2018 21:34:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1etlNW-0000qj-Uu for qemu-devel@nongnu.org; Wed, 07 Mar 2018 21:34:00 -0500 Received: from mga07.intel.com ([134.134.136.100]:18809) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1etlNW-0000oc-Ih for qemu-devel@nongnu.org; Wed, 07 Mar 2018 21:33:58 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Mar 2018 18:33:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,438,1515484800"; d="scan'208";a="209769334" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.13.35]) by fmsmga006.fm.intel.com with ESMTP; 07 Mar 2018 18:33:55 -0800 From: Haozhong Zhang To: qemu-devel@nongnu.org Date: Thu, 8 Mar 2018 10:33:34 +0800 Message-Id: <20180308023337.21062-3-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180308023337.21062-1-haozhong.zhang@intel.com> References: <20180308023337.21062-1-haozhong.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.100 Subject: [Qemu-devel] [PATCH v4 2/5] qmp: distinguish PC-DIMM and NVDIMM in MemoryDeviceInfoList X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Haozhong Zhang , Xiao Guangrong , mst@redhat.com, Markus Armbruster , Eduardo Habkost , dgilbert@redhat.com, Stefan Hajnoczi , Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , Dan Williams , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 to TYPE_PC_DIMM which it's been inherited from. Signed-off-by: Haozhong Zhang --- hmp.c | 14 +++++++++++--- hw/mem/pc-dimm.c | 20 ++++++++++++++++++-- numa.c | 19 +++++++++++++------ qapi/misc.json | 18 +++++++++++++++++- 4 files changed, 59 insertions(+), 12 deletions(-) diff --git a/hmp.c b/hmp.c index 016cb5c4f1..692cb81868 100644 --- a/hmp.c +++ b/hmp.c @@ -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; } } } diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 4d050fe2cd..866ecc699a 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -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) { diff --git a/numa.c b/numa.c index 7ca2bef63f..5f291fc919 100644 --- a/numa.c +++ b/numa.c @@ -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; } } } diff --git a/qapi/misc.json b/qapi/misc.json index bd04469a4b..5bcabb0d7a 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -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: