From patchwork Tue Feb 13 21:06:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 200654 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp815194dyb; Tue, 13 Feb 2024 13:21:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUf2EaD/qMbkgJg308eYE5hhvws9ID2z4901TFtKGnovnJFTsFBOuzywnhZ/s3Q/2jtgRkfCb4nPYywK2AGtBX0cBsqvA== X-Google-Smtp-Source: AGHT+IHFAwLxb5QgVXbgc6vw4kHP1MjjKsy5hgY6NQqrD80/OneEt6p3PoPF1eUrqhwh0FmGHjCP X-Received: by 2002:ac8:5852:0:b0:42d:adde:95d5 with SMTP id h18-20020ac85852000000b0042dadde95d5mr111107qth.5.1707859290343; Tue, 13 Feb 2024 13:21:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707859290; cv=pass; d=google.com; s=arc-20160816; b=dlYQ6AP/1cBKgnt43EQouHumHLpaGvrigzf1LywiW48pSy1rFyfqYZN+2H7eZ19EFZ KNS9wwbBikHCNmwSuLHKuQ/oQYwNuY5p80SWz1ViBmbg4R8sKQWCdzpaKtK3ZdM6PRmU Yj98QE2XmKUEPETYgbp9OKfgQHN9BojdRrwggGDEGZBor2tptUOM97b+kPQCmBtVyL2A Ct4w/MNaKdJi2Tymw52Te2yY+2KoOisg8/g39CQILJdY43jrJEgkiViBeL4OfaBOJ3yV b1LUEVPtOWocdeq+ubcD5ex7Lf9LPJB0vgTncvTrmhM5s+g2Jxz29XRrjy6616l2JKBZ Ztcg== 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=VSt0e/pJgXOuwhWfq+S+zmb74FzHu/CZzfV9Bz+FkzQ=; fh=/ByvPGpe09fsf4Ok4pWV0ktrUgEXYL1T5YxEQeZqTvQ=; b=0Mi04iz488qUBzaUS7w5ojxZb0/vHwnc7goxxGzNX+hMxdTg1LoHWW73N9j0SvojpT n3EAJd3y3nHgL/TH6cvKSqxpGVgvo2GcWlqHsTLqwmyrSEe52EbkNAm2o1RRP64v1wdI kSzQM3cl3CxU9Y6dQdzSZ88y4FeSQXR18dEwVj41BfU2FhfTG0RDPCurt7dc+z0hdIaP HVnP/g39Vdr/wklnTp2f9H0WJAMdVvPK6C0EVzIlsYHeSVAZj9VvfySNtq4TpLTDVfHf Id28/JKTCf2ixgcIBsNquGClWq193wZlTWefgPIq3zm5lGxjjeURHguWgaAw6Y+oi/Fm ltSQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=0JUjk1Nb; dkim=neutral (no key) header.i=@linutronix.de; 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-64310-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64310-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=2; AJvYcCX/Lm3831pDh1cGVjRF4ZtwsBl9t2333N9T7/oDIFC8N5HAyDsXVSBxkOvxzKsKHZWzfFFZWKgfTG12AwtaUFeCsBQZOA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id c7-20020ac85187000000b0042c6cd08430si3564060qtn.284.2024.02.13.13.21.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 13:21:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64310-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=0JUjk1Nb; dkim=neutral (no key) header.i=@linutronix.de; 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-64310-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64310-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 EF38F1C268C7 for ; Tue, 13 Feb 2024 21:21:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E621986629; Tue, 13 Feb 2024 21:06:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="0JUjk1Nb"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="pKyhgdLo" 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 E71558562F for ; Tue, 13 Feb 2024 21:06:09 +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=1707858371; cv=none; b=GVhuYRMm3Fxec2SzpDeQbY7Msfi1QUaormJp37i3u/ks8s3mlWSkKTKMFsjlddTH7QTwhR1TeH1jeud2QbwapDXYdzq2LDUKd+0KoHxL7K0Hb0A14CpI2FwoiO2NDp4DNymXq/j+054NPLRQYRXRLvDDM++ldlSweWusVS9olcA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707858371; c=relaxed/simple; bh=dzZg/qbHJvAs2UTwP+S3YTraj0xonaKUEUGBDYOq4Ys=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=hO7KoINDvHMilB8U+zE4chCXRkRgGLBwQ7A5pEbmOMcOetzP7GH2agG0nudYQ8ZwYHiGoO3mLZdkyRO+5EREIgZaL6vNIM8zGq/tAlbRrURSLSYvh6Hr4HnhG3MBR0AZavyzJXRntmfwoXzbRQWZsR0fUlm9Ok64KLIJJ7QMUr4= 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=0JUjk1Nb; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=pKyhgdLo; 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: <20240213210252.846136196@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1707858368; 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=VSt0e/pJgXOuwhWfq+S+zmb74FzHu/CZzfV9Bz+FkzQ=; b=0JUjk1NbcZdKyEcWK408QIMwYUEaGUYAKKNJ74i87P8E8w6szqsv7OePZ3tcOXQ94++mbV eDbPHX75r9nyjMFwpD2GZiQqJxDfZfudq+iEtNggN5pHOci/VKhTOJgKtZ7rm9NmUQHsb2 XqU8bbKeZ3dA0iJXH9xlflyBcN2zMY7kDrpKQZ+Dzi1vSi7i9698g/FF9PEOSycCsuPRO3 BwQLTgCfmszEhtfHRa/EJEX/RstNFKEotR1xE901wAxx8YetfATEr+XbCuKQd5B5PEAe/1 XgtCnnWgJUCYECm7Xzz7RjY81FX54JZcaD1PjTPfwBSbj5yXXdi6UKZ2TExmoQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1707858368; 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=VSt0e/pJgXOuwhWfq+S+zmb74FzHu/CZzfV9Bz+FkzQ=; b=pKyhgdLod3f79cGRjJsb3nBPliUbF3C9bSowopxEVo5WMqdabcozXoC10wIa7UCUQno3M3 F4zfClkK9ZstF8AQ== 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 24/30] x86/cpu/topology: Provide logical pkg/die mapping 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:07 +0100 (CET) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790820263448130604 X-GMAIL-MSGID: 1790820263448130604 From: Thomas Gleixner With the topology bitmaps in place the logical package and die IDs can trivially be retrieved by determining the bitmap weight of the relevant topology domain level up to and including the physical ID in question. Provide a function to that effect. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/topology.h | 9 +++++++++ arch/x86/kernel/cpu/topology.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) --- --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -156,6 +156,15 @@ static inline unsigned int topology_max_ return __max_dies_per_package; } +#ifdef CONFIG_X86_LOCAL_APIC +int topology_get_logical_id(u32 apicid, enum x86_topology_domains at_level); +#else +static inline int topology_get_logical_id(u32 apicid, enum x86_topology_domains at_level) +{ + return 0; +} +#endif + #ifdef CONFIG_SMP #define topology_cluster_id(cpu) (cpu_data(cpu).topo.l2c_id) #define topology_die_cpumask(cpu) (per_cpu(cpu_die_map, cpu)) --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -230,6 +230,34 @@ void __init topology_register_boot_apic( topo_register_apic(apic_id, CPU_ACPIID_INVALID, true); } +/** + * topology_get_logical_id - Retrieve the logical ID at a given topology domain level + * @apicid: The APIC ID for which to lookup the logical ID + * @at_level: The topology domain level to use + * + * @apicid must be a full APIC ID, not the normalized variant. It's valid to have + * all bits below the domain level specified by @at_level to be clear. So both + * real APIC IDs and backshifted normalized APIC IDs work correctly. + * + * Returns: + * - >= 0: The requested logical ID + * - -ERANGE: @apicid is out of range + * - -ENODEV: @apicid is not registered + */ +int topology_get_logical_id(u32 apicid, enum x86_topology_domains at_level) +{ + /* Remove the bits below @at_level to get the proper level ID of @apicid */ + unsigned int lvlid = topo_apicid(apicid, at_level); + + if (lvlid >= MAX_LOCAL_APIC) + return -ERANGE; + if (!test_bit(lvlid, apic_maps[at_level].map)) + return -ENODEV; + /* Get the number of set bits before @lvlid. */ + return bitmap_weight(apic_maps[at_level].map, lvlid); +} +EXPORT_SYMBOL_GPL(topology_get_logical_id); + #ifdef CONFIG_ACPI_HOTPLUG_CPU /** * topology_hotplug_apic - Handle a physical hotplugged APIC after boot