From patchwork Wed Mar 4 19:13:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 446386 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 336FE140146 for ; Thu, 5 Mar 2015 06:14:51 +1100 (AEDT) Received: from localhost ([::1]:46379 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTEkr-0004YA-2t for incoming@patchwork.ozlabs.org; Wed, 04 Mar 2015 14:14:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38331) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTEjp-0002q8-PZ for qemu-devel@nongnu.org; Wed, 04 Mar 2015 14:13:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YTEjk-00022h-S5 for qemu-devel@nongnu.org; Wed, 04 Mar 2015 14:13:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50134) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTEjk-00022G-Jk for qemu-devel@nongnu.org; Wed, 04 Mar 2015 14:13:40 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t24JDcqi018199 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 4 Mar 2015 14:13:38 -0500 Received: from localhost (ovpn-113-143.phx2.redhat.com [10.3.113.143]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t24JDbSW001742; Wed, 4 Mar 2015 14:13:38 -0500 From: Luiz Capitulino To: peter.maydell@linaro.org Date: Wed, 4 Mar 2015 14:13:31 -0500 Message-Id: <1425496415-6161-2-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1425496415-6161-1-git-send-email-lcapitulino@redhat.com> References: <1425496415-6161-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: qemu-devel@nongnu.org Subject: [Qemu-devel] [PULL 1/5] pc-dimm: add a function to calculate VM's current RAM size X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: zhanghailiang The global parameter 'ram_size' does not take into account the hotplugged memory. In some codes, we use 'ram_size' as current VM's real RAM size, which is not correct. Add function 'get_current_ram_size' to calculate VM's current RAM size, it will enumerate present memory devices and also plus ram_size. Signed-off-by: zhanghailiang Signed-off-by: Luiz Capitulino --- hw/mem/pc-dimm.c | 26 ++++++++++++++++++++++++++ include/exec/cpu-common.h | 1 + stubs/qmp_pc_dimm_device_list.c | 5 +++++ 3 files changed, 32 insertions(+) diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index f27a087..de81b9c 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -100,6 +100,32 @@ int qmp_pc_dimm_device_list(Object *obj, void *opaque) return 0; } +ram_addr_t get_current_ram_size(void) +{ + MemoryDeviceInfoList *info_list = NULL; + MemoryDeviceInfoList **prev = &info_list; + MemoryDeviceInfoList *info; + ram_addr_t size = ram_size; + + 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->kind) { + case MEMORY_DEVICE_INFO_KIND_DIMM: + size += value->dimm->size; + break; + default: + break; + } + } + } + qapi_free_MemoryDeviceInfoList(info_list); + + return size; +} + static int pc_dimm_slot2bitmap(Object *obj, void *opaque) { unsigned long *bitmap = opaque; diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index 427b851..fcc3162 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -52,6 +52,7 @@ typedef uintptr_t ram_addr_t; #endif extern ram_addr_t ram_size; +ram_addr_t get_current_ram_size(void); /* memory API */ diff --git a/stubs/qmp_pc_dimm_device_list.c b/stubs/qmp_pc_dimm_device_list.c index 5cb220c..b584bd8 100644 --- a/stubs/qmp_pc_dimm_device_list.c +++ b/stubs/qmp_pc_dimm_device_list.c @@ -5,3 +5,8 @@ int qmp_pc_dimm_device_list(Object *obj, void *opaque) { return 0; } + +ram_addr_t get_current_ram_size(void) +{ + return ram_size; +}