Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp180549rdh; Tue, 13 Feb 2024 13:20:59 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXhyacSSgl9sVeuNuTCA0FICy4ysMFMEefrpxW4V0Z4SHv8ldyWoKxcR80GNlXSC86NYTGHcwZoYMa7wt5DAd/U+rPo6W3Hy2P3sZHZgQ== X-Google-Smtp-Source: AGHT+IGmHsAdqUzh66WsyZWLqyMdjTKF3adanHexluo7RjQhvuVJD2Kl/XeLF6ZaT7OKcozXY+vT X-Received: by 2002:a17:906:2614:b0:a3c:698:635f with SMTP id h20-20020a170906261400b00a3c0698635fmr28904ejc.28.1707859259120; Tue, 13 Feb 2024 13:20:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707859259; cv=pass; d=google.com; s=arc-20160816; b=oY1s2IyptA05VQXAOM18/o3JadOAXOs6i8lrsVCoUrgnvL3tki0KKKCnMtLbQlfXIG ry3PclhFmTdjALuNMxPtD1q0p+WMEc+DZSdkMfUaxHaapVkXKMrLtAGa9AOcxXIocxpT 3ZkUJmzLE1KRzaahaFJwW9A2q7lQahc79iG9nHe/O9bqmjAF4P8U7Iz+2fWV4qipHQ0/ Xn9ehyFMQu5uMRBlXIIz2CsGdn9+pkJbAfnYqo/WYx0zV6ywxlLAvVa/kp4xi6iLRciF kj9KRYsb4CixV/sO2a1Phpx0apizZj9xNNJYWG7I/JFFrkwZzCb52VBkT3nKHkhBB5hz f9zQ== 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=wvCBfg2jlU5pfZwZquiqaOzvl1tWWNyZNFyPP62Xkjs=; b=g292u5iaut/97L8MdOJKWqkDIdUWjlcCn8qsXal2dRex0UJc8qPusjOyWbUjH4mzvC PWgtwewJFEWBGEVXVzrtseumD+yBcm+Yd8i7yKH/WhQuJdxBcTaoMiax5qLQHCC5/1DA raDRO7LfyZHOAbXKXSfPhYuP7BuyZ0r01ryBRm3g+FrV5hIFMG3/uulJmwa2d0nbbqet iIMclZTd51E+fk8Yxk8aaFOMKp2yeItjmoqR0o6pz2f5zmIt+Ibt6huPT5MnQjIgbZCk Y0QqIj4U9ZjdFWsWYaAMKs2l1urQO3VsdAX/5IU8xxuV5fhJ2iA4mKG73GBrEXceTmq1 1isQ==; 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 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-64310-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64310-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=2; AJvYcCWr6mJIxvAgOXNwrHsBJjR2vvLLwVugoZixnGa8Vqia+OVFHucYDYyZI/nK0qIDyOPsu6o/YIxEZDNUH3wCY+F1Xpyjwh4ErjbNEovneA== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id jw9-20020a17090776a900b00a3d0f84f7dbsi739418ejc.410.2024.02.13.13.20.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 13:20:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64310-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; 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 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-64310-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64310-linux.lists.archive=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 am.mirrors.kernel.org (Postfix) with ESMTPS id D97891F2894D for ; Tue, 13 Feb 2024 21:20:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3403085949; Tue, 13 Feb 2024 21:06:12 +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 Content-Type: text/plain; charset=UTF-8 Date: Tue, 13 Feb 2024 22:06:07 +0100 (CET) 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