Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp467325rdb; Tue, 23 Jan 2024 05:23:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IHJUq9Z/39eUDs9IYnEKoFFCmlaaFi45sztDc1CgLAvLi7hIlFfsEPZPb8ccOKO9qCjUpQx X-Received: by 2002:a05:6402:35c2:b0:55c:8d9f:997b with SMTP id z2-20020a05640235c200b0055c8d9f997bmr571726edc.30.1706016196892; Tue, 23 Jan 2024 05:23:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706016196; cv=pass; d=google.com; s=arc-20160816; b=QWeed0Tlqeuh9ttHp2I0WXqNvvP9yNJFe0YjKyqxXQRB46cd/K7iwaFgsuqvZyIEa3 qZ9vrW3Kwu6iiVQgUM4rLlqBgbWOFOeq3zVSDnGqx7zCrkSM7W9/FAaM3yaWpxZ+u7n+ Bz0+AYN6ZAuTcPSokG3lmJbtIgDPxWAZzfldTLZ/iMUToJq74RGpflzEWnIt3n0JEejx AusJn0iuH7+CCdNMMYub0YXd5efe5R2hVk6WbqXldYxbShEPSWlWEpcNT9tGQelLAeGP XqA7upboLcW+At8eKkZNnIKMK6ufanvH3vJlu88V+gbCEOqj0Cqzy62ymkLnq3p/FdjB lZ8Q== 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=6dhXYTos6w2yCRv5UATW39ekFguDcopd4GmFr46wLNc=; fh=Te0fDPJ/sd+7p881M6fa/oF213lBbJvGdEFWr/TLqNA=; b=vmI6S0prRsmvY2eGiBGAI/z8avt5p+elN3/CDavhCh7X6DQfv0cke9m0UmCF42rgsR 5s7FKyE0/ev8vgDNUYm63ROfFalxYx9hpmrbbOronr59uNlG9gxoM2qo9I/J9d7Ov4HW lRPKZlPKp1xOVEJz9FUJBReo6ub2kvMcBM6Ul3UQk7JwV0o3o8LCahqd1b9u2rd/ZrRV XwKSKWR/9MsF/UeN3F74MPUZwm/avVaICRTWPqXbLvx3YBzJNBnhKq/6H6NJn/srfhf8 qAMb03vyNoe4aXMS9Kn0R7hpqfnINzd0Rz/ryQG9oxpVVWIN7LDhkgFnHQJeCMHRXlbl HxKg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=uX7ei09C; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=VupscB6T; 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-35367-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35367-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id d3-20020a056402400300b0055a73178a1fsi4436784eda.107.2024.01.23.05.23.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 05:23:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-35367-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=uX7ei09C; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=VupscB6T; 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-35367-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35367-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 A3B771F217BB for ; Tue, 23 Jan 2024 13:23:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EDC8F5FBAB; Tue, 23 Jan 2024 13:11:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="uX7ei09C"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="VupscB6T" 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 BC7F6664D0 for ; Tue, 23 Jan 2024 13:11:31 +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=1706015493; cv=none; b=IrlW84IVAir9KDj/f2pWcdJWhlBwqTIZrfIOSs9JtrlAHqxsD72Po4XTveIjq4/vFW0zCJUSLrEEHnxLJHBH4aTxzESRU+FfFoolOmOZCwe8eVi64HIgQGapH4P26lNMDclzUiifHO/mhVaozxYbV4Y/n6eJG3xmnRW4FTNqc3Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015493; c=relaxed/simple; bh=Ct1lFW4Zt/3ZqqheSth0KhDYtCQXFpSWEQCu55WXYkw=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=bigcGeYAJNyVXHYIYWgJw5prH4iGFH34m9bVEDVJvPKngLRSkFQl0SQIj/Z60oQNDwowTe48NlqaK9J4dgaoSavwzB9DZy3Cc+O+wWl4KucKqUY2deIbTqONEltIosDBTcYp2+jTt169iwBBtKBp+V2X8fOlVol0OS9xVbcCFZw= 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=uX7ei09C; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=VupscB6T; 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: <20240118123649.915802822@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706015490; 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=6dhXYTos6w2yCRv5UATW39ekFguDcopd4GmFr46wLNc=; b=uX7ei09CmEb2eLpMfy2gC3gSHRHchP66lsJYQAt6PCqGtokPPQ+6SpykwWKm2iilmGd2/b we3INiR+R+4PjECbR9AITlaUa2W4z12zuirWewkule9D8qunYkYGR4vDu08ccYKDut60XD XeTc4DCNgediYHZH+oxQX/ZLJXxPKCR/3FHh/or3fiKuokDyoo7GZHQwVNKjZg3gZY57gU 7vJ0Vg0xmQH4ChZvi0uPJ6bSE/wNTa/ZT2g2wSDrJaXlDmcD88aFUL9xp/sdAhGfjNT0/O S2GNVW+AKM+/UUfmoFsOinb6OLpzn0LVklyrCCg46UW3nG3iycF9dGAanxsWKg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706015490; 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=6dhXYTos6w2yCRv5UATW39ekFguDcopd4GmFr46wLNc=; b=VupscB6TiZJvbX/r88yiwLAU9JMmN9+p80jDdh2UfuBQ3F12tKQs+qfR9A+MpPthaW/k72 dDKCL98TdIizKoCw== 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 v2 24/30] x86/cpu/topology: Provide logical pkg/die mapping References: <20240118123127.055361964@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, 23 Jan 2024 14:11:29 +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