From nobody Fri Dec 19 06:16:29 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF009C00528 for ; Mon, 7 Aug 2023 13:57:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234644AbjHGN5S (ORCPT ); Mon, 7 Aug 2023 09:57:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232312AbjHGN45 (ORCPT ); Mon, 7 Aug 2023 09:56:57 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F20E74222 for ; Mon, 7 Aug 2023 06:54:31 -0700 (PDT) Message-ID: <20230807135029.166295656@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1691416435; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=gGPnBkTfW+8B5SQXJHv1hpNWRmiBwz+4UGwUc972rDw=; b=gUx+AJ4BNaJQrnonAOcot/xmdvpaOMg6OhvZ2XZ2EsQGYvVALa8wQyI1Rw7PAdCZy0qSwH Yqc4yKmozV6zAaG6CqeGst/MuASRp5t/yXP8b/g4NIFUkzmf6uXhuClATg9Fltv6Iz9ESR yEQJUeaFjKrXYAB6zQh96OwItVovZrcHyCmcg4vEy7Thp2numswApE+yDbUTftDkMIqAug Xi1GR1KNazhvbRagclkmiQRp2oaxi3wDcuelpyxpsyZd/9APWxZd3gMfbykBkT4XAthVCd lC1lBcnVt6AnRKfzAVXvR4jJ/kynSy4GSTAXQjHuNpmnD/0TsIcR4X4PhQ8D/Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1691416435; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=gGPnBkTfW+8B5SQXJHv1hpNWRmiBwz+4UGwUc972rDw=; b=jsdqZR++153ohXhEKjnvEMV/nlkzpS3n+K0Ps0yPvvZC2iOtFWrkmlbOJVUThtoYKP+S2d FKzyUz+C04J3vTAQ== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , Huang Rui , Juergen Gross , Dimitri Sivanich , Michael Kelley , Sohil Mehta , K Prateek Nayak , Kan Liang , Zhang Rui , "Paul E. McKenney" , Feng Tang , Andy Shevchenko Subject: [patch 52/53] x86/cpu/topology: Provide __num_[cores|threads]_per_package References: <20230807130108.853357011@linutronix.de> MIME-Version: 1.0 Date: Mon, 7 Aug 2023 15:53:55 +0200 (CEST) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Expose properly accounted information and accessors so the fiddling with other topology variables can be replaced. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/topology.h | 12 ++++++++++++ arch/x86/kernel/cpu/common.c | 6 ++++++ arch/x86/kernel/cpu/topology.c | 8 +++++++- 3 files changed, 25 insertions(+), 1 deletion(-) --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -146,6 +146,8 @@ extern const struct cpumask *cpu_cluster extern unsigned int __max_dies_per_package; extern unsigned int __max_logical_packages; extern unsigned int __max_threads_per_core; +extern unsigned int __num_threads_per_package; +extern unsigned int __num_cores_per_package; =20 static inline unsigned int topology_max_packages(void) { @@ -157,6 +159,16 @@ static inline unsigned int topology_max_ return __max_dies_per_package; } =20 +static inline unsigned int topology_num_cores_per_package(void) +{ + return __num_cores_per_package; +} + +static inline unsigned int topology_num_threads_per_package(void) +{ + return __num_threads_per_package; +} + int topology_get_logical_id(u32 apicid, enum x86_topology_domains at_level= ); =20 static inline int topology_phys_to_logical_pkg(unsigned int pkg) --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -81,6 +81,12 @@ EXPORT_SYMBOL(__max_dies_per_package); unsigned int __max_logical_packages __ro_after_init =3D 1; EXPORT_SYMBOL(__max_logical_packages); =20 +unsigned int __num_cores_per_package __ro_after_init =3D 1; +EXPORT_SYMBOL(__num_cores_per_package); + +unsigned int __num_threads_per_package __ro_after_init =3D 1; +EXPORT_SYMBOL(__num_threads_per_package); + static struct ppin_info { int feature; int msr_ppin_ctl; --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -391,7 +391,7 @@ void __init topology_init_possible_cpus( unsigned int disabled =3D topo_info.nr_disabled_cpus; unsigned int cnta, cntb, cpu, dom, allowed =3D 1; unsigned int total =3D assigned + disabled; - u32 apicid; + u32 apicid, firstid; =20 if (!restrict_to_up()) { if (total > 1) @@ -430,6 +430,12 @@ void __init topology_init_possible_cpus( __max_threads_per_core =3D 1U << (get_count_order(cntb) - get_count_order= (cnta)); pr_info("Max. threads per core: %3u\n", __max_threads_per_core); =20 + firstid =3D find_first_bit(apic_maps[TOPO_SMT_DOMAIN].map, MAX_LOCAL_APIC= ); + __num_cores_per_package =3D topology_unit_count(firstid, TOPO_CORE_DOMAIN= , TOPO_PKG_DOMAIN); + pr_info("Num. cores per package: %3u\n", __num_cores_per_package); + __num_threads_per_package =3D topology_unit_count(firstid, TOPO_SMT_DOMAI= N, TOPO_PKG_DOMAIN); + pr_info("Num. threads per package: %3u\n", __num_threads_per_package); + pr_info("Allowing %u present CPUs plus %u hotplug CPUs\n", assigned, disa= bled); if (topo_info.nr_rejected_cpus) pr_info("Rejected CPUs %u\n", topo_info.nr_rejected_cpus);