From patchwork Fri Feb 16 15:16:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 202158 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp583449dyb; Fri, 16 Feb 2024 07:18:34 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWusZbE3E1BGEBE6LkZ87jd04+ZvawrzbRZI9XctqrfsdirCnBtAv/pog31RDDqwYRaBn7VwHtTUvoVbm1qOjkZzlr59A== X-Google-Smtp-Source: AGHT+IHOb3GpYpA/NhfPB4tiMeGBzP4g+4Tr7cYXADaotu7KxFXv+KuPH/pX2R/Cn3h7ZjdrZQSS X-Received: by 2002:a0c:cd02:0:b0:68f:2f2d:cfd with SMTP id b2-20020a0ccd02000000b0068f2f2d0cfdmr3272797qvm.53.1708096714197; Fri, 16 Feb 2024 07:18:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708096714; cv=pass; d=google.com; s=arc-20160816; b=TkBob/MD+A6fN0XqeDC3XQNGsMlfz24nufoCvNLoser2ht75lpDGmiIZLl2mjFA1jo 8uqEaiLY8G5Ttsaj4XdCPN7mLHOhTh2cmvRpT2LAog+C2LHA2VSqS4eRULr5Njx7XzD+ wICNXuUp4GVKTZSl76LZLo4EnCDZHP2ioFZmj9Q/C+e12dB95pLonibRSYeqvouZEfFX o5Ut7CXFTwlxBCFBFlaylhwZReQDbEDl2prEwh0r9ADPfvC+dbHU7H0tyigeHo4gzinF qvYyFA2yhKNxuypkLJhEIOGPuHBgtBYYjUg1YN/j+sZXyycmIqxBTr1Fh2AuTurDk97G XL6w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=KtWFXfkl1AGKFK+oSAjJDdxbIk0vfWtKmBtSsanyfDM=; fh=HfXWoIhgCc+vt39DMIJv/Ec0aAKnw0eFA8QxuIQTUoQ=; b=rdGIz/WjA6idIoWMJT8hN/G//orUM18ipIYqW+zpXobhju0u361KcDxk4745U3bd30 ecsyMxerMxE2RIiRW+ogt1HMaB/Qd1GP0HzKG0/gTMfNAXKsFWhnnE7MEWUz2mc/KgLY eSzdiXpLNhTWwiKd9snH6X8VVDskrJQ3R7N1Nt4Wpme6EgKTksgWJzEYlUkMmpDAGLFo kSQtxjcWfdS4pKfbcNzDG2vUkeZQyF+NvZ0Hc4ypGtPSUPct8wXSUv2THI/wajfOvNe7 xILFXTU77qdyKeh6TjG6BRWKRoPtzXyjtpu5n44zcJdG6qqCFPv6Cdr1eRzPMcDBRIVX zv8A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=uFrX6Yc9; 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-68796-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68796-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id e7-20020a0562141d0700b0068f34f52833si1171075qvd.107.2024.02.16.07.18.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 07:18:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-68796-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=uFrX6Yc9; 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-68796-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68796-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 012FB1C2121B for ; Fri, 16 Feb 2024 15:18:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E1463131E3D; Fri, 16 Feb 2024 15:16:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="uFrX6Yc9"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ECYwbaSj" 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 ACB0C12FB2D; Fri, 16 Feb 2024 15:16:52 +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=1708096614; cv=none; b=V7vN5xU52lPEHoRcghJXK/V/rSN2+sky83HlKGPk018hmVdg1pBC6Jn6CeW+6LFItYfDw23A//R22vtI9Qqdik2fapLjvKZycngfMqc9N5UCEx7NzDfxj6MbnfZq14fpwfnesCkfZxV0Nyl9f+XRJoRP3FC9RbWSi9gMVesHp9g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708096614; c=relaxed/simple; bh=ioe2GA/1+lcfLti+VlRk9lhT10z3QQ1cuSbotr0bXzY=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=UA1zFB9e5q4K5Hdf9i1/4MlzcUB8jnSQnsK7Zy/g3pVhsGoj3K9SxK4Lt8PJmGOzs6cofSU2VaNkIjwZVMzxBbP+g32XxwU18DZtkb/mQ3TGoT9GAtqpJR+EkA3QNxZKl7wyAeIM7/jEi2af9DG0HfiYWB3muyRvqyFDVMLijAI= 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=uFrX6Yc9; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ECYwbaSj; 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 Date: Fri, 16 Feb 2024 15:16:49 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708096610; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KtWFXfkl1AGKFK+oSAjJDdxbIk0vfWtKmBtSsanyfDM=; b=uFrX6Yc9qZNr5amXZOEtd2llG8AHi67w2pq2/bTxT2gJt7oAfhTJ8yt6uIlqL6fMO6RNiq wlB1wLqXszQSrGcOwXHxaROTWwj+ryg4y4X53WXjW8AT0ed/lDTihCQ6cGTzldJIalMdDI HUKVaN0BTPiuPMMTucekTnqP6J/IjCwkPLV01KMUYTif67mSmgdcuTWU01TchxmfHCOlbu ezGqTwL1BAv+2ruy54P9DUCRb3oLFduuvbsVZuyWLuc9gi8VbDigmqXVE8+XuBSrZjXEGO EtKz6i/OTFUVa48WZ+zJBbvQ0+ZwcF7j+JmUbv9d+ixLSsPFXBJHXZnVZRuWGg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708096610; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KtWFXfkl1AGKFK+oSAjJDdxbIk0vfWtKmBtSsanyfDM=; b=ECYwbaSjpI2KgQErkpKE9v0yIJiSMEK5VnJeF3SSriKRs5XIQ4N3dSS1JFcoOmy88I3CRn igjLZ3SHf9wTOiCg== From: "tip-bot2 for Thomas Gleixner" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/apic] x86/cpu/topology: Provide logical pkg/die mapping Cc: Thomas Gleixner , Michael Kelley , Sohil Mehta , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240213210252.846136196@linutronix.de> References: <20240213210252.846136196@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <170809660991.398.11224403618848319747.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790820263448130604 X-GMAIL-MSGID: 1791069219959822604 The following commit has been merged into the x86/apic branch of tip: Commit-ID: b7065f4f844c7876ed071b67e2ba57838152bd63 Gitweb: https://git.kernel.org/tip/b7065f4f844c7876ed071b67e2ba57838152bd63 Author: Thomas Gleixner AuthorDate: Tue, 13 Feb 2024 22:06:07 +01:00 Committer: Thomas Gleixner CommitterDate: Thu, 15 Feb 2024 22:07:44 +01:00 x86/cpu/topology: Provide logical pkg/die mapping 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 Tested-by: Michael Kelley Tested-by: Sohil Mehta Link: https://lore.kernel.org/r/20240213210252.846136196@linutronix.de --- arch/x86/include/asm/topology.h | 9 +++++++++ arch/x86/kernel/cpu/topology.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/arch/x86/include/asm/topology.h b/arch/x86/include/asm/topology.h index 94ef1a6..bdd6a98 100644 --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -156,6 +156,15 @@ static inline unsigned int topology_max_die_per_package(void) 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)) diff --git a/arch/x86/kernel/cpu/topology.c b/arch/x86/kernel/cpu/topology.c index aea408d..29759b4 100644 --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -229,6 +229,34 @@ void __init topology_register_boot_apic(u32 apic_id) 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