From nobody Tue May 14 03:20:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1653297243744125.85826502094972; Mon, 23 May 2022 02:14:03 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.335623.559785 (Exim 4.92) (envelope-from ) id 1nt48E-0005jH-VL; Mon, 23 May 2022 09:13:42 +0000 Received: by outflank-mailman (output) from mailman id 335623.559785; Mon, 23 May 2022 09:13:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nt48E-0005jA-Sl; Mon, 23 May 2022 09:13:42 +0000 Received: by outflank-mailman (input) for mailman id 335623; Mon, 23 May 2022 09:13:41 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nt48D-0005j4-J8 for xen-devel@lists.xenproject.org; Mon, 23 May 2022 09:13:41 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id a244e8a8-da78-11ec-837e-e5687231ffcc; Mon, 23 May 2022 11:13:39 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 34C95ED1; Mon, 23 May 2022 02:13:39 -0700 (PDT) Received: from e129167.arm.com (unknown [10.57.7.84]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BDC263F73D; Mon, 23 May 2022 02:13:36 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: a244e8a8-da78-11ec-837e-e5687231ffcc From: Michal Orzel To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH] xen/arm: Allow setting the number of CPUs to activate at runtime Date: Mon, 23 May 2022 11:13:24 +0200 Message-Id: <20220523091324.137350-1-michal.orzel@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1653297245324100001 Content-Type: text/plain; charset="utf-8" Introduce a command line parameter "maxcpus" on Arm to allow adjusting the number of CPUs to activate. Currently the limit is defined by the config option CONFIG_NR_CPUS. Such parameter already exists on x86. Define a parameter "maxcpus" and a corresponding static variable max_cpus in Arm smpboot.c. Modify function smp_get_max_cpus to take max_cpus as a limit and to return proper unsigned int instead of int. Take the opportunity to remove redundant variable cpus from start_xen function and to directly assign the return value from smp_get_max_cpus to nr_cpu_ids (global variable in Xen used to store the number of CPUs actually activated). Signed-off-by: Michal Orzel Reviewed-by: Bertrand Marquis --- max_cpus is also defined in x86 setup.c. It would be possible to join these definitions in xen/common/cpu.c. However in that case, max_cpus would become global which is not really what we want. There is already global nr_cpu_ids used everywhere and max_cpus being used only in x86 start_xen and Arm smp_get_max_cpus should be kept local. Also there are already lots of places in Xen using max_cpus (local versions) and that would start to be hard to read (variable shadowing). --- docs/misc/xen-command-line.pandoc | 2 +- xen/arch/arm/include/asm/smp.h | 2 +- xen/arch/arm/setup.c | 10 ++++------ xen/arch/arm/smpboot.c | 18 ++++++++++++------ 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line= .pandoc index 1dc7e1ca07..a40d0ae2e8 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -1651,7 +1651,7 @@ with **crashinfo_maxaddr**. Specify the threshold below which Xen will inform dom0 that the quantity of free memory is getting low. Specifying `0` will disable this notification. =20 -### maxcpus (x86) +### maxcpus > `=3D ` =20 Specify the maximum number of CPUs that should be brought up. diff --git a/xen/arch/arm/include/asm/smp.h b/xen/arch/arm/include/asm/smp.h index 83c0cd6976..8133d5c295 100644 --- a/xen/arch/arm/include/asm/smp.h +++ b/xen/arch/arm/include/asm/smp.h @@ -33,7 +33,7 @@ extern void init_secondary(void); =20 extern void smp_init_cpus(void); extern void smp_clear_cpu_maps (void); -extern int smp_get_max_cpus (void); +extern unsigned int smp_get_max_cpus(void); =20 #define cpu_physical_id(cpu) cpu_logical_map(cpu) =20 diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index d5d0792ed4..b8d97950b7 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -862,11 +862,10 @@ void __init start_xen(unsigned long boot_phys_offset, unsigned long fdt_paddr) { size_t fdt_size; - int cpus, i; const char *cmdline; struct bootmodule *xen_bootmodule; struct domain *d; - int rc; + int rc, i; =20 dcache_line_bytes =3D read_dcache_line_bytes(); =20 @@ -942,9 +941,8 @@ void __init start_xen(unsigned long boot_phys_offset, processor_id(); =20 smp_init_cpus(); - cpus =3D smp_get_max_cpus(); - printk(XENLOG_INFO "SMP: Allowing %u CPUs\n", cpus); - nr_cpu_ids =3D cpus; + nr_cpu_ids =3D smp_get_max_cpus(); + printk(XENLOG_INFO "SMP: Allowing %u CPUs\n", nr_cpu_ids); =20 /* * Some errata relies on SMCCC version which is detected by psci_init() @@ -988,7 +986,7 @@ void __init start_xen(unsigned long boot_phys_offset, =20 for_each_present_cpu ( i ) { - if ( (num_online_cpus() < cpus) && !cpu_online(i) ) + if ( (num_online_cpus() < nr_cpu_ids) && !cpu_online(i) ) { int ret =3D cpu_up(i); if ( ret !=3D 0 ) diff --git a/xen/arch/arm/smpboot.c b/xen/arch/arm/smpboot.c index 9bb32a301a..22fede6600 100644 --- a/xen/arch/arm/smpboot.c +++ b/xen/arch/arm/smpboot.c @@ -43,6 +43,10 @@ cpumask_t cpu_possible_map; =20 struct cpuinfo_arm cpu_data[NR_CPUS]; =20 +/* maxcpus: maximum number of CPUs to activate. */ +static unsigned int __initdata max_cpus; +integer_param("maxcpus", max_cpus); + /* CPU logical map: map xen cpuid to an MPIDR */ register_t __cpu_logical_map[NR_CPUS] =3D { [0 ... NR_CPUS-1] =3D MPIDR_IN= VALID }; =20 @@ -277,16 +281,18 @@ void __init smp_init_cpus(void) "unless the cpu affinity of all domains is specified.\= n"); } =20 -int __init -smp_get_max_cpus (void) +unsigned int __init smp_get_max_cpus(void) { - int i, max_cpus =3D 0; + unsigned int i, cpus =3D 0; + + if ( ( !max_cpus ) || ( max_cpus > nr_cpu_ids ) ) + max_cpus =3D nr_cpu_ids; =20 - for ( i =3D 0; i < nr_cpu_ids; i++ ) + for ( i =3D 0; i < max_cpus; i++ ) if ( cpu_possible(i) ) - max_cpus++; + cpus++; =20 - return max_cpus; + return cpus; } =20 void __init --=20 2.25.1