From patchwork Mon Feb 4 02:27:54 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liguang X-Patchwork-Id: 217817 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6BFEF2C0099 for ; Mon, 4 Feb 2013 13:42:14 +1100 (EST) Received: from localhost ([::1]:55122 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U2Bog-0006Xd-2N for incoming@patchwork.ozlabs.org; Sun, 03 Feb 2013 21:29:54 -0500 Received: from eggs.gnu.org ([208.118.235.92]:35050) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U2BnQ-0003or-9M for qemu-devel@nongnu.org; Sun, 03 Feb 2013 21:28:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U2BnL-0002xZ-MC for qemu-devel@nongnu.org; Sun, 03 Feb 2013 21:28:36 -0500 Received: from [222.73.24.84] (port=35143 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U2BnL-0002wu-69 for qemu-devel@nongnu.org; Sun, 03 Feb 2013 21:28:31 -0500 X-IronPort-AV: E=Sophos;i="4.84,596,1355068800"; d="scan'208";a="6683544" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 04 Feb 2013 10:26:12 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id r142SN7K013673; Mon, 4 Feb 2013 10:28:24 +0800 Received: from liguang.fnst.cn.fujitsu.com ([10.167.225.128]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2013020410270965-263196 ; Mon, 4 Feb 2013 10:27:09 +0800 From: liguang To: qemu-devel@nongnu.org, seabios@seabios.org Date: Mon, 4 Feb 2013 10:27:54 +0800 Message-Id: <1359944880-6039-3-git-send-email-lig.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1359944880-6039-1-git-send-email-lig.fnst@cn.fujitsu.com> References: <1359944880-6039-1-git-send-email-lig.fnst@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/02/04 10:27:09, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/02/04 10:27:09, Serialize complete at 2013/02/04 10:27:09 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 222.73.24.84 Cc: aliguori@us.ibm.com, kevin@koconnor.net, dwmw2@infradead.org, stefanha@linux.vnet.ibm.com, liguang Subject: [Qemu-devel] [PATCH 2/6] pc/numa: refactor bios_init function 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 orginally, numa data was packed into an array, which was implicit and hard to maintain, we define a struct for this data, hope to be as clear as enough. also, we only pass cpumask of corresponding nodes to seabios, and leave the paring work for it. Signed-off-by: liguang --- hw/pc.c | 40 ++++++++++++++++++---------------------- 1 files changed, 18 insertions(+), 22 deletions(-) diff --git a/hw/pc.c b/hw/pc.c index d010c75..893c930 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -562,13 +562,21 @@ static unsigned int pc_apic_id_limit(unsigned int max_cpus) return x86_cpu_apic_id_from_index(max_cpus - 1) + 1; } +struct srat_data { + uint64_t apic_map; /* size is MAX_NODES */ + uint64_t memory_size; +}; + static void *bios_init(void) { void *fw_cfg; uint8_t *smbios_table; size_t smbios_len; - uint64_t *numa_fw_cfg; - int i, j; + struct fw_numa_cfg { + uint32_t nr_node; + struct srat_data *srat_data; + } fw_cfg_numa; + int i; unsigned int apic_id_limit = pc_apic_id_limit(max_cpus); fw_cfg = fw_cfg_init(FW_CFG_CTL_IOPORT, FW_CFG_DATA_IOPORT, 0, 0); @@ -601,28 +609,16 @@ static void *bios_init(void) &e820_table, sizeof(e820_table)); fw_cfg_add_bytes(fw_cfg, FW_CFG_HPET, &hpet_cfg, sizeof(hpet_cfg)); - /* allocate memory for the NUMA channel: one (64bit) word for the number - * of nodes, one word for each VCPU->node and one word for each node to - * hold the amount of memory. - */ - numa_fw_cfg = g_new0(uint64_t, 1 + apic_id_limit + nb_numa_nodes); - numa_fw_cfg[0] = cpu_to_le64(nb_numa_nodes); - for (i = 0; i < max_cpus; i++) { - unsigned int apic_id = x86_cpu_apic_id_from_index(i); - assert(apic_id < apic_id_limit); - for (j = 0; j < nb_numa_nodes; j++) { - if (test_bit(i, node_cpumask[j])) { - numa_fw_cfg[apic_id + 1] = cpu_to_le64(j); - break; - } - } - } + + fw_cfg_numa.srat_data = g_new0(struct srat_data, nb_numa_nodes); + fw_cfg_numa.nr_node = cpu_to_le64(nb_numa_nodes); + for (i = 0; i < nb_numa_nodes; i++) { - numa_fw_cfg[apic_id_limit + 1 + i] = cpu_to_le64(node_mem[i]); + fw_cfg_numa.srat_data[i].apic_map = *node_cpumask[i]; + fw_cfg_numa.srat_data[i].memory_size = cpu_to_le64(node_mem[i]); } - fw_cfg_add_bytes(fw_cfg, FW_CFG_NUMA, numa_fw_cfg, - (1 + apic_id_limit + nb_numa_nodes) * - sizeof(*numa_fw_cfg)); + + fw_cfg_add_bytes(fw_cfg, FW_CFG_NUMA, &fw_cfg_numa, sizeof(fw_cfg_numa)); return fw_cfg; }