From nobody Thu Nov 6 20:34:48 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487746709848718.0627694360716; Tue, 21 Feb 2017 22:58:29 -0800 (PST) Received: from localhost ([::1]:50246 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgQse-0000sR-Ey for importer@patchew.org; Wed, 22 Feb 2017 01:58:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38049) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgQVB-00038p-S5 for qemu-devel@nongnu.org; Wed, 22 Feb 2017 01:34:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgQV9-0008C7-Po for qemu-devel@nongnu.org; Wed, 22 Feb 2017 01:34:13 -0500 Received: from ozlabs.org ([103.22.144.67]:57945) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgQV9-000882-Ax; Wed, 22 Feb 2017 01:34:11 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 3vSndM11nnz9sN5; Wed, 22 Feb 2017 17:33:56 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1487745239; bh=z4gv7FiBlfmYK2ShpqciCQHtoGXc4r0H4EvO+Yq+/Ys=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FLUMOW6icGwmXo18Lk2hFTn+GwzNnkI6PnpFINBHh1rkt3bAU2i5dyxAMvKs10wO3 tmqJXRcMkqOFLKZzkdEveyaYONKl/tONmcr6u2dBVF4sr3g04N7GVKJfvxarkb3PFn s6qEfFe+svPgI7D8Ptp32k86+jq0/zMRbzI7Lp30= From: David Gibson To: peter.maydell@linaro.org Date: Wed, 22 Feb 2017 17:33:38 +1100 Message-Id: <20170222063348.32176-34-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170222063348.32176-1-david@gibson.dropbear.id.au> References: <20170222063348.32176-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 103.22.144.67 Subject: [Qemu-devel] [PULL 33/43] pc: move pcms->possible_cpus init out of pc_cpus_init() 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: lvivier@redhat.com, thuth@redhat.com, qemu-devel@nongnu.org, mdroth@linux.vnet.ibm.com, agraf@suse.de, qemu-ppc@nongnu.org, imammedo@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Igor Mammedov possible_cpus could be initialized earlier then cpu objects, i.e. when -smp is parsed so move init code to possible_cpu_arch_ids() interface func and do initialization on the first call. it should help later with making -numa cpu/-smp parsing a machine state properties. Signed-off-by: Igor Mammedov Signed-off-by: David Gibson --- hw/i386/pc.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 04c6e59..a187748 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1144,7 +1144,9 @@ void pc_cpus_init(PCMachineState *pcms) ObjectClass *oc; const char *typename; gchar **model_pieces; + const CPUArchIdList *possible_cpus; MachineState *machine =3D MACHINE(pcms); + MachineClass *mc =3D MACHINE_GET_CLASS(pcms); =20 /* init CPUs */ if (machine->cpu_model =3D=3D NULL) { @@ -1179,14 +1181,9 @@ void pc_cpus_init(PCMachineState *pcms) * This is used for FW_CFG_MAX_CPUS. See comments on bochs_bios_init(). */ pcms->apic_id_limit =3D x86_cpu_apic_id_from_index(max_cpus - 1) + 1; - machine->possible_cpus =3D g_malloc0(sizeof(CPUArchIdList) + - sizeof(CPUArchId) * max_cpus); - for (i =3D 0; i < max_cpus; i++) { - machine->possible_cpus->cpus[i].arch_id =3D x86_cpu_apic_id_from_i= ndex(i); - machine->possible_cpus->len++; - if (i < smp_cpus) { - pc_new_cpu(typename, x86_cpu_apic_id_from_index(i), &error_fat= al); - } + possible_cpus =3D mc->possible_cpu_arch_ids(machine); + for (i =3D 0; i < smp_cpus; i++) { + pc_new_cpu(typename, possible_cpus->cpus[i].arch_id, &error_fatal); } } =20 @@ -2254,10 +2251,26 @@ static unsigned pc_cpu_index_to_socket_id(unsigned = cpu_index) return topo.pkg_id; } =20 -static const CPUArchIdList *pc_possible_cpu_arch_ids(MachineState *machine) +static const CPUArchIdList *pc_possible_cpu_arch_ids(MachineState *ms) { - assert(machine->possible_cpus); - return machine->possible_cpus; + int i; + + if (ms->possible_cpus) { + /* + * make sure that max_cpus hasn't changed since the first use, i.e. + * -smp hasn't been parsed after it + */ + assert(ms->possible_cpus->len =3D=3D max_cpus); + return ms->possible_cpus; + } + + ms->possible_cpus =3D g_malloc0(sizeof(CPUArchIdList) + + sizeof(CPUArchId) * max_cpus); + ms->possible_cpus->len =3D max_cpus; + for (i =3D 0; i < ms->possible_cpus->len; i++) { + ms->possible_cpus->cpus[i].arch_id =3D x86_cpu_apic_id_from_index(= i); + } + return ms->possible_cpus; } =20 static HotpluggableCPUList *pc_query_hotpluggable_cpus(MachineState *machi= ne) --=20 2.9.3