From patchwork Thu Jan 12 17:53:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 9513777 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 73DAB60476 for ; Thu, 12 Jan 2017 18:07:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C30B286DD for ; Thu, 12 Jan 2017 18:07:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 610A4286FB; Thu, 12 Jan 2017 18:07:05 +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 EEA20286DD for ; Thu, 12 Jan 2017 18:07:04 +0000 (UTC) Received: from localhost ([::1]:35840 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cRjmC-0006Xo-1H for patchwork-qemu-devel@patchwork.kernel.org; Thu, 12 Jan 2017 13:07:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42056) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cRjen-0000iM-Bg for qemu-devel@nongnu.org; Thu, 12 Jan 2017 12:59:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cRjei-0000jO-FQ for qemu-devel@nongnu.org; Thu, 12 Jan 2017 12:59:25 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41216) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cRjei-0000j6-6c for qemu-devel@nongnu.org; Thu, 12 Jan 2017 12:59:20 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3C1D669CC3; Thu, 12 Jan 2017 17:59:20 +0000 (UTC) Received: from localhost (ovpn-116-4.gru2.redhat.com [10.97.116.4]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v0CHxINA013497; Thu, 12 Jan 2017 12:59:18 -0500 From: Eduardo Habkost To: Peter Maydell Date: Thu, 12 Jan 2017 15:53:55 -0200 Message-Id: <20170112175356.21701-6-ehabkost@redhat.com> In-Reply-To: <20170112175356.21701-1-ehabkost@redhat.com> References: <20170112175356.21701-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 12 Jan 2017 17:59:20 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 5/6] numa: make -numa parser dynamically allocate CPUs masks 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: Marcel Apfelbaum , Paolo Bonzini , Igor Mammedov , qemu-devel@nongnu.org, Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Igor Mammedov so it won't impose an additional limits on max_cpus limits supported by different targets. It removes global MAX_CPUMASK_BITS constant and need to bump it up whenever max_cpus is being increased for a target above MAX_CPUMASK_BITS value. Use runtime max_cpus value instead to allocate sufficiently sized node_cpu bitmasks in numa parser. Signed-off-by: Igor Mammedov Message-Id: <1479466974-249781-1-git-send-email-imammedo@redhat.com> Reviewed-by: Eduardo Habkost [ehabkost: Added asserts to ensure cpu_index < max_cpus] Signed-off-by: Eduardo Habkost --- include/sysemu/numa.h | 2 +- include/sysemu/sysemu.h | 7 ------- numa.c | 21 ++++++++++++++------- vl.c | 5 ----- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/include/sysemu/numa.h b/include/sysemu/numa.h index 4da808a6e9..8f09dcf918 100644 --- a/include/sysemu/numa.h +++ b/include/sysemu/numa.h @@ -17,7 +17,7 @@ struct numa_addr_range { typedef struct node_info { uint64_t node_mem; - DECLARE_BITMAP(node_cpu, MAX_CPUMASK_BITS); + unsigned long *node_cpu; struct HostMemoryBackend *node_memdev; bool present; QLIST_HEAD(, numa_addr_range) addr; /* List to store address ranges */ diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 66c6f1577e..cccde56454 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -168,13 +168,6 @@ extern int mem_prealloc; #define MAX_NODES 128 #define NUMA_NODE_UNASSIGNED MAX_NODES -/* The following shall be true for all CPUs: - * cpu->cpu_index < max_cpus <= MAX_CPUMASK_BITS - * - * Note that cpu->get_arch_id() may be larger than MAX_CPUMASK_BITS. - */ -#define MAX_CPUMASK_BITS 288 - #define MAX_OPTION_ROMS 16 typedef struct QEMUOptionRom { const char *name; diff --git a/numa.c b/numa.c index f5fc7da3e9..379bc8a140 100644 --- a/numa.c +++ b/numa.c @@ -266,20 +266,19 @@ static char *enumerate_cpus(unsigned long *cpus, int max_cpus) static void validate_numa_cpus(void) { int i; - DECLARE_BITMAP(seen_cpus, MAX_CPUMASK_BITS); + unsigned long *seen_cpus = bitmap_new(max_cpus); - bitmap_zero(seen_cpus, MAX_CPUMASK_BITS); for (i = 0; i < nb_numa_nodes; i++) { - if (bitmap_intersects(seen_cpus, numa_info[i].node_cpu, - MAX_CPUMASK_BITS)) { + if (bitmap_intersects(seen_cpus, numa_info[i].node_cpu, max_cpus)) { bitmap_and(seen_cpus, seen_cpus, - numa_info[i].node_cpu, MAX_CPUMASK_BITS); + numa_info[i].node_cpu, max_cpus); error_report("CPU(s) present in multiple NUMA nodes: %s", enumerate_cpus(seen_cpus, max_cpus)); + g_free(seen_cpus); exit(EXIT_FAILURE); } bitmap_or(seen_cpus, seen_cpus, - numa_info[i].node_cpu, MAX_CPUMASK_BITS); + numa_info[i].node_cpu, max_cpus); } if (!bitmap_full(seen_cpus, max_cpus)) { @@ -291,12 +290,17 @@ static void validate_numa_cpus(void) "in NUMA config"); g_free(msg); } + g_free(seen_cpus); } void parse_numa_opts(MachineClass *mc) { int i; + for (i = 0; i < MAX_NODES; i++) { + numa_info[i].node_cpu = bitmap_new(max_cpus); + } + if (qemu_opts_foreach(qemu_find_opts("numa"), parse_numa, NULL, NULL)) { exit(1); } @@ -362,7 +366,7 @@ void parse_numa_opts(MachineClass *mc) numa_set_mem_ranges(); for (i = 0; i < nb_numa_nodes; i++) { - if (!bitmap_empty(numa_info[i].node_cpu, MAX_CPUMASK_BITS)) { + if (!bitmap_empty(numa_info[i].node_cpu, max_cpus)) { break; } } @@ -397,6 +401,7 @@ void numa_post_machine_init(void) CPU_FOREACH(cpu) { for (i = 0; i < nb_numa_nodes; i++) { + assert(cpu->cpu_index < max_cpus); if (test_bit(cpu->cpu_index, numa_info[i].node_cpu)) { cpu->numa_node = i; } @@ -558,6 +563,8 @@ int numa_get_node_for_cpu(int idx) { int i; + assert(idx < max_cpus); + for (i = 0; i < nb_numa_nodes; i++) { if (test_bit(idx, numa_info[i].node_cpu)) { break; diff --git a/vl.c b/vl.c index a23de18fa9..c643d3ff3a 100644 --- a/vl.c +++ b/vl.c @@ -1277,11 +1277,6 @@ static void smp_parse(QemuOpts *opts) max_cpus = qemu_opt_get_number(opts, "maxcpus", cpus); - if (max_cpus > MAX_CPUMASK_BITS) { - error_report("unsupported number of maxcpus"); - exit(1); - } - if (max_cpus < cpus) { error_report("maxcpus must be equal to or greater than smp"); exit(1);