From patchwork Tue Feb 13 21:06:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 200658 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp815566dyb; Tue, 13 Feb 2024 13:22:26 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXt/Gi2x7/ilnhpbo44NcbPpd+jSsfak13sfjFNYKsP4ejRVzKFZIgbu0emAsF8ox0mAtsI4MFcICLQuYzWiF1qk4NyxA== X-Google-Smtp-Source: AGHT+IHGr8N8HJeLDxPEXPLNkxvjO2uWpuixlbteLqTZSybZNz/atBraJTspuj9ydAUpQnjkDD0Y X-Received: by 2002:ae9:e01a:0:b0:785:becb:7b86 with SMTP id m26-20020ae9e01a000000b00785becb7b86mr882132qkk.34.1707859345793; Tue, 13 Feb 2024 13:22:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707859345; cv=pass; d=google.com; s=arc-20160816; b=FGwOVtTGeJprWFb/q+UQwtPBdCNxUC8Qejp0o6r/AouHN1wzBQiJnwdYTxPJu9rKQo Pwcy69JL3lcT8Y40FFplAcDY8Bbnq/cpSIrbAo0C7Xd5nQUbOVv9AInbe489vZB7T/fM LJQO/rxPYS2BJFyTPPeHiZxvnAiezY2yuZi3/BaaHAi+QngNyPZzIxt39l2ZrQTNi8Z4 VXvjiQI/UUJppwARAjKAIHAXPcF8vc/WQ9R3vuu+sXxtA71Htxa4BsMl06xCCU30L3EG Y130Ifj2mv9qHXwUp1F17cGFl4vIhzBycoZ42jZu90g1+Qhzb/jGoght+e6RvH3H8kgS NVIg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:subject:cc:to:from:dkim-signature :dkim-signature:message-id; bh=C480USuDHEN1DJ+mKCDr2IgHfoW7jqhf18boy4k9tqM=; fh=kihWAYR4GDQSuOGfJcaRbj4o8HnGzEbq7g3pJUZib4U=; b=GSXUNTdbwiGi1QCnSRZ8ihAI54wryePG2X/wW2PBbcMhYMWTo9nWyT6ehGJJ0camlg 0BL9k5Bl30owZtHTuALOAtPZuOp1CgwlVd37M5VDNPqUhEQosjjsRIwdaAkF2Wm2rndv OBhAAyE1GkfDRI4KsaVqsykraIS7rBCiqgomcpfl/cAVM80PYF8I5vMChd3jyly+7Bp5 9tuSuJv0YGfBEGG9oFMhCAyq4jBIp3pTq/gb0Zu54xVzgTQHjNVilJpYx7jdc4o6joG9 7Bbi2Rq8+mTxKD+7Gde7Dg5OpqLOOfhl6suOsHuojXJ+EaxVJQbm610eGDKN1Jnq1zv2 HuHw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="hYaOnL/2"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-64315-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64315-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=2; AJvYcCVESsYA3igNe4RY6j/c8FrNzMZBu9dLfIbkFeybd4b3JsoBcbHowz/xqjvrrgxDf5GnyWJnJr28klj3mP2Bhi8bLBOUVQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d13-20020a05620a136d00b00785d5dbc115si5631276qkl.147.2024.02.13.13.22.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 13:22:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64315-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="hYaOnL/2"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-64315-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64315-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 94F9D1C26411 for ; Tue, 13 Feb 2024 21:22:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ED5F81272D4; Tue, 13 Feb 2024 21:06:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="hYaOnL/2"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="3J2b59gv" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F68186656 for ; Tue, 13 Feb 2024 21:06:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707858378; cv=none; b=Zhkg53Nlotm8jb3tBWM1OOKKurlAoOrNqTpY3+/FkVneC+TEYEobGW2oENXMAjQM3kNQsulMJLzMCKlHuMrdTYD14BRSqSJeZD1//A3Zm3Tebqk4MGdSo+tsGJxVz2bWOGPfxme1TQ+JCG7CmIpA54Zp64Axzx4HyEI3T3qmgZU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707858378; c=relaxed/simple; bh=BYCek0/+KoSqfQdbi1lbVUiGFjTm1kaHkGsteLGoGIE=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=X+6pSAoa9PBlwKuIwtWwgOmpCxP8m+SkzI5/OyR2UZNLM1Y2JtaYkqqZBGs9djaNGxGDVIhuMDxIO7dpZi48x55qGe5LtI5ZXPSA4Tutzy5RYgIg7hxPV6jH5uBCYlRsB7aFrjE/cD1h5zuZbxvjV1CwM5FeHoWa/LjZPJZtXoY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=hYaOnL/2; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=3J2b59gv; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Message-ID: <20240213210253.120958987@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1707858375; 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=C480USuDHEN1DJ+mKCDr2IgHfoW7jqhf18boy4k9tqM=; b=hYaOnL/2Ivox9nGn6t1XhqdZYSeR367afVMDfPkVKYBkupJXWsIv3t0KB/M60YAmcRbtRQ GJsQ9TsdWBQ0Vh9i0vc3pHz5awnxMJRYE52WHDqwaFl7o1rVeSWAWiki82qlR/o1uMaABo qdyAHDgFOPDOehXMgCsc5nHiptunDWV3ZolodYWeKNAE0a1jLz8Zi6bHAUb4U3TVqkLJ1H iOlNyc0JfnU4lA9/HGWBXd0hIsMqHnCg1X1LNKCk24Hrb4dGiO5TOXSgw1mgI3Ar8uSDBJ Mi7UF6MD2hLVhMeIOcDL9iyKr9q480hyTWcVLVGxd+5BaoOL9wATQtP5tQ2NVA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1707858375; 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=C480USuDHEN1DJ+mKCDr2IgHfoW7jqhf18boy4k9tqM=; b=3J2b59gvV8IAF6w5DQ21L0W8SAgnPLSrBqG0IGpzra53FVKM3SBvvgt86wGk+3SkkW/qRy NKCjFWVmism2MOAA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , Huang Rui , Juergen Gross , Dimitri Sivanich , Sohil Mehta , K Prateek Nayak , Kan Liang , Zhang Rui , "Paul E. McKenney" , Feng Tang , Andy Shevchenko , Michael Kelley , "Peter Zijlstra (Intel)" Subject: [patch 29/30] x86/cpu/topology: Provide __num_[cores|threads]_per_package References: <20240213205415.307029033@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Tue, 13 Feb 2024 22:06:14 +0100 (CET) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790820321010439551 X-GMAIL-MSGID: 1790820321010439551 From: Thomas Gleixner 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; static inline unsigned int topology_max_packages(void) { @@ -157,6 +159,16 @@ static inline unsigned int topology_max_ return __max_dies_per_package; } +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; +} + #ifdef CONFIG_X86_LOCAL_APIC int topology_get_logical_id(u32 apicid, enum x86_topology_domains at_level); #else --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -82,6 +82,12 @@ EXPORT_SYMBOL(__max_dies_per_package); unsigned int __max_logical_packages __ro_after_init = 1; EXPORT_SYMBOL(__max_logical_packages); +unsigned int __num_cores_per_package __ro_after_init = 1; +EXPORT_SYMBOL(__num_cores_per_package); + +unsigned int __num_threads_per_package __ro_after_init = 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 @@ -392,7 +392,7 @@ void __init topology_init_possible_cpus( unsigned int disabled = topo_info.nr_disabled_cpus; unsigned int cnta, cntb, cpu, allowed = 1; unsigned int total = assigned + disabled; - u32 apicid; + u32 apicid, firstid; if (!restrict_to_up()) { if (WARN_ON_ONCE(assigned > nr_cpu_ids)) { @@ -432,6 +432,12 @@ void __init topology_init_possible_cpus( __max_threads_per_core = DIV_ROUND_UP(cntb, cnta); pr_info("Max. threads per core: %3u\n", __max_threads_per_core); + firstid = find_first_bit(apic_maps[TOPO_SMT_DOMAIN].map, MAX_LOCAL_APIC); + __num_cores_per_package = 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 = topology_unit_count(firstid, TOPO_SMT_DOMAIN, 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, disabled); if (topo_info.nr_rejected_cpus) pr_info("Rejected CPUs %u\n", topo_info.nr_rejected_cpus);