From nobody Thu Sep 24 20:27:56 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=valinux.co.jp); dmarc=pass(p=none dis=none) header.from=valinux.co.jp ARC-Seal: i=2; a=rsa-sha256; t=1785027366; cv=pass; d=zohomail.com; s=zohoarc; b=YV6yy/uQqidt3rLwrlV7DitFEQjHvbrnHyoPlYfr2M3k+lMz44CfVdzkNROc840r+Qu9QGXlpTJzoaYUPEzOrwNgkcX2Q0TJ+mpbPHr3VhxxvuoDlKAVhWzOEZaxh0LTrGUsPZtAhfGacEB67cCcAMO/9Hu3uloL3YQEbwjS648= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1785027366; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=4Q4Sn6ZvbDxStJSJKmYRZ8YWSBhcchVL9I57LeHdLTQ=; b=SSAJ4QgNemVMR/iflUsDQ2OUHqbULMDXtxnWMWrmOSXEwf7TShm+ni4gXOrQ67C6iXuU3gxs7zbjAUEkd3Nb3Afm+Psq1lX1sb8LOAinH8mB3WFazb82cbzZlhUazFHHR8OytUpY4ANBHuhxbgPwld+4xCdhFVsAl+pbV9krNTA= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=valinux.co.jp); dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1785027366184510.9938328254575; Sat, 25 Jul 2026 17:56:06 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1370879.1618747 (Exim 4.92) (envelope-from ) id 1wnn9T-0006gR-M4; Sun, 26 Jul 2026 00:55:35 +0000 Received: by outflank-mailman (output) from mailman id 1370879.1618747; Sun, 26 Jul 2026 00:55:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wnn9T-0006gI-GO; Sun, 26 Jul 2026 00:55:35 +0000 Received: by outflank-mailman (input) for mailman id 1370879; Sun, 26 Jul 2026 00:55:33 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wnn9Q-0006fz-RU for xen-devel@lists.xenproject.org; Sun, 26 Jul 2026 00:55:33 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wnn9Q-007Oo9-8T for xen-devel@lists.xenproject.org; Sun, 26 Jul 2026 02:55:32 +0200 Received: from [10.42.69.9] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a6559e3-e002-0a2a0a5209dd-0a2a4509e574-48 for ; Sun, 26 Jul 2026 02:55:32 +0200 Received: from [52.101.228.97] (helo=OS0P286CU011.outbound.protection.outlook.com) by tlsNG-bad1c0.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a655aff-be1a-0a2a45090019-3465e461c552-4 for ; Sun, 26 Jul 2026 02:55:31 +0200 Received: from OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:458::18) by OS7P286MB5490.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:397::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.245.12; Sun, 26 Jul 2026 00:55:27 +0000 Received: from OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM ([fe80::c8c9:25cd:8d13:96d6]) by OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM ([fe80::c8c9:25cd:8d13:96d6%6]) with mapi id 15.21.0245.012; Sun, 26 Jul 2026 00:55:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=valinux.co.jp header.i="@valinux.co.jp" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cBg49bQqnAS3G1T7M7RsVJ900z/jRdzAro8vpIe5Boy6JWsfCV+Y4kbcSAZACTYr+9Fas8wSIhRpCTWtesdHlJLOE+H05hIr5avU+P890RmSGYMccEAI/jV7kWGhps3Pw0QmKNxkCG+81t74bRSFIvgpfpFYwtJuFxZiWNL+drDPi7aEVpQZrpYSu1fdtbBuGtg7HyxK+ctVaSftQoHLHO/4vcvj8PKCgxqNy0+j/Z1KONM9vnA3j/Ra53+b6PSm1FVjzekZJNb/6jvm4kWxpfUl4gEc5QVTM1EaE2thRMosA3QXW7jTGFQq9xhW1r/287ZxK/w+dLSiWLpvZR10LA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4Q4Sn6ZvbDxStJSJKmYRZ8YWSBhcchVL9I57LeHdLTQ=; b=SNMh9G0LXyB04ueMbsZJmc7taIgLwZdATKj0rSjXbc3Te5wmvJ9yLh6fp8kkMQQcAm/a3tvoOedOvUe7VqufyM8YJpHCoelnkqqP1HcuMJlsOeE+tLYnuLW0MyLqSrYt7Y7vVrrU7SQlm87RaxdXZpsINASrFABzZ3YNclnIzjL7tY4K4LY3kaLim/mwDwXjAZe+XAe+hiAf24Q8ZAU2RqZawedzLvXTQ8eKkr7U0kGQmonb3C+ZVTU87ItRza6ISJuC/FBbU7pdouyRw/uLo1do6Vqqddn1Ol/84LDioa/6PUtE6ZgA6nwwkF4ZA5jbQAnRTrPhIBT74gYdte3TDQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=valinux.co.jp; dmarc=pass action=none header.from=valinux.co.jp; dkim=pass header.d=valinux.co.jp; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=valinux.co.jp; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4Q4Sn6ZvbDxStJSJKmYRZ8YWSBhcchVL9I57LeHdLTQ=; b=M2rRz/RQgW19UDHvbVK0mx/lrpuaDh99qOT7QJqny2mnFAt/xBGSbYHDDcu7sxUBh1tptrz43m1VPREbOR4iwsLPt65+wILLT0SlO6G9TLIe2df1bYFg4W3WhsK/qiz1aNBW9mzk4KAj/3Fxfxp8uqUFE2SBZNrL+bJCEvsYTGQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=valinux.co.jp; From: Hirokazu Takahashi To: xen-devel@lists.xenproject.org Cc: Mykyta_Poturai@epam.com, Hirokazu Takahashi , Jan Beulich , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , Anthony PERARD , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v8 1/4] xen/device-tree: Parse 'cpu-map' node for CPU topology exploration Date: Sun, 26 Jul 2026 09:55:14 +0900 Message-ID: <20260726005517.379267-2-taka@valinux.co.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260726005517.379267-1-taka@valinux.co.jp> References: <20260726005517.379267-1-taka@valinux.co.jp> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: TY6P301CA0020.JPNP301.PROD.OUTLOOK.COM (2603:1096:405:3bf::10) To OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:458::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OS9P286MB7222:EE_|OS7P286MB5490:EE_ X-MS-Office365-Filtering-Correlation-Id: 0c6200f9-3386-4592-3776-08deeab0955d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|23010399003|366016|7416014|376014|10070799003|56012099006|10067099003|6133799003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: 4DCqLUpwzeAjxQSCg4Y2MhTk3wJpEvRanypax0tM3t0Mt+o0xEWqrMhrmEtuR4dLyHfQgtMeAcoiY2WPI+OgP/94JmN/RWQFT8H6NjTDZyVxjhT5HHsVzBEmFS9te2OaiP84L/wedGFEy56euBwzAvuQ44GFJhAu6TTNeoEfKMzrC27mQJX2CQoXdqCZviDIdEzRTqfD/JJNJLJC7p0lyFxjsmg5CtfsoDCoGosws8EWmmHnHHEXaZWmS3n97JIy/OnInOgLbF5pgEpFkRRa1OCwOWFHx8LN5H9s1cwXosQIHLlLmiq4gES6jKSczum7kkM1CFy041m5eRrTGaQrt0daas2PcbS62i92ansxDL1iSKy/H1YVWRatI3wddwRAgqB6WKgIe1bXfeQtCBUB+7kVmmk6G+lG4YqMpKThWpAN0N+3KvfzglAUWt2XApoFGDB8Big0uJW+cxbtIUAOCKq/fQls6k8UOS/m1vLBeGzBKPifbmLSIzSuANjU3+2B+vj49Y05852qKYHrGA0/ZikyIVn1zq5bIk2sGknQ0s6HgfAgFNE+J0n+3NM/EE/bDwf3Lspa+OS7gG7E996wt4ukoXbHFqbIMlDrgHRusirftoiIGIh5bMJbgFW0cz3oY8PMkQ8zqon6XJI4spDJDNxbyRhTPw+KVLGv6V0fMy0= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(23010399003)(366016)(7416014)(376014)(10070799003)(56012099006)(10067099003)(6133799003)(18002099003)(22082099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?Xk4Sj/yJ3+AgfupMDqO6tFxstpOfuQXAa2jCt1BSD86sUZRAy30dQeWq6ZUA?= =?us-ascii?Q?3mlzj/OxotkfY/Qf2zH0ETx0/jNJgMRSnuwUjM1+uD4pxvoV/v+E2Gv7mFrK?= =?us-ascii?Q?AeifSuN6o1ooZo1TcEH6zD4o3hcfIefIywVjgBtL/c4kJAiFPyhegMqdv87o?= =?us-ascii?Q?hlP2S6lmM9SF72dRlZgNpcPDvXOPVnmMW6JdlGt0gL8NpEnqoVlTOmyJjXIJ?= =?us-ascii?Q?VZs0l0Q44RKv/SeGaW8IR1J+RS9fGpr/HUyQrWSweLLuiSuyla+w2UOnxGUp?= =?us-ascii?Q?fAFx5zouZuKy58mNf7z/wHrqW/TOuMSTBLcXXlWC9WzkvzTtr4X405NXlECd?= =?us-ascii?Q?CV/4HGklUkeoxdOWxI3QMjK9OU2tx9U6HQn0xMTWPi/kt0AyZHNtWzjR01FP?= =?us-ascii?Q?vZHP4TzHSfzouWCFcIrcu/gqIM3FgaWk6ySk7FCHUSBS0vFmlGQgIPghaGX+?= =?us-ascii?Q?+ppU7d8JQBYOxmy3jtQn/cgzvrpBPhpD8JR/Z2Dw/r3bvbSlwmzP6TnqHV16?= =?us-ascii?Q?n1gqFz++eQR6SXByLh5/yJw4qnFsdmgkT/M1S4xMeyjKXyZC8erEAAzEYeCA?= =?us-ascii?Q?k6FrU0agRwUuL+SPT5WLYQ2cKLK4NM1Ugj6cdFFg0+O1LvFv9PQUmt7m3ed8?= =?us-ascii?Q?hBhGkq9Ay/U0rheBdGnpREE6r6Qj3ktJYdFqsgR8gO65/b7uB2WT7VhEc5t4?= =?us-ascii?Q?UZQyA5uebjjKn+10ZhKrrhJsCJvsecn7rxgtysXHr7TS0szbFJmoXUuyVoRj?= =?us-ascii?Q?d7ehlw0MwV3PmIrg4PCgzE7z1TIrQT6U9KtT2PqnBtY+0XCERNCIR8AGsGhj?= =?us-ascii?Q?gvl29vYqEoemoUdFQ43saZbRZBykWfotnS/HnQupRI0uVe5bXFnde2Kbs9Gc?= =?us-ascii?Q?lAgjPReNIWbzy3wjgbnQTmpSj6SKiC2SQTitqbyUrpmx4b52PnUFejiPEDkb?= =?us-ascii?Q?X7+PGq9dIuuAv8Fs1QKirKGp8KWVf59MwmtNRFKpqBhgYx+zUva8DRHExaIi?= =?us-ascii?Q?aMijk3z4/RTd/uRDfKuNblR+48f5Slf6c05UDavh0CqAbgCaU45cgFcTMOEp?= =?us-ascii?Q?IeQPbLgl3RwEbxeoDGBSvTFRi6cET+uwKB5nbzAlteTCYQ0fX6DOEwaBNzMX?= =?us-ascii?Q?qhoUg+F8hCralomCg8AAbo+2+zrYceq5gLrYvR2QMPhn0IlmI6gTNrsUOAnx?= =?us-ascii?Q?M2Y5M7rcsruF65SZ/5DiwvtZzmSumj0G1GkWknMRlaib+6Dr5VxvrJoBCYeC?= =?us-ascii?Q?2gDu3dMLgE+1SP+TO+gM12EAKGg9WL19Is6ENDIBGiXWOxbsjZZVxiP4PkeN?= =?us-ascii?Q?MBDLl6mU83yfXCxWvK0jQ2SXt1dPCnCe4VgYmc3SlS0IisSy2Hv2KOTw80Gx?= =?us-ascii?Q?AS1QQ5a64kCgyQJhQ0EscLR1zFTanzB2PH0aELazPdKKb6YjH2S3sUmUbRFl?= =?us-ascii?Q?T8QS5DfkI0Q9hRY3Vpt4T4O7plfZDSYTmDzMONsJkIr8o0yy89yzwLnlySsJ?= =?us-ascii?Q?tq0LPtKj8bbGu0fk/Se2CrwLouWjlfCDPfz9x4IgEFnuhEbDKKCckoemLVG9?= =?us-ascii?Q?GskzYlp17cwZdY54Xdr0CFj81K/lwlhRFYQEBGYolM8+fpbyuBacdKWigyOe?= =?us-ascii?Q?/b341R2g6gjyJOVPMKD5Ipt0UI+bO8gQmqS3ffmwgpPXV1kKGyF4PhHfD6tr?= =?us-ascii?Q?szvonf1o7A1n5Wr904Z/z1myLtxzkXHm62VzV4AvfETTJ5s6OBXdOgwYS9zp?= =?us-ascii?Q?QusqiYF1q8UvAcMg0HCnxE9FbCiKey8iz92I0UCkqyx4whMDTtVPDmjKs6O9?= X-MS-Exchange-AntiSpam-MessageData-1: kA5IhUOuPJWWLg== X-OriginatorOrg: valinux.co.jp X-MS-Exchange-CrossTenant-Network-Message-Id: 0c6200f9-3386-4592-3776-08deeab0955d X-MS-Exchange-CrossTenant-AuthSource: OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jul 2026 00:55:27.4798 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 7a57bee8-f73d-4c5f-a4f7-d72c91c8c111 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: RmsNJ6jLTsMdM67kctMdM+QasxtwSLxMJAFJLO4QfwksHjvY7hMS8JHkC3e/jossDyQEhLCUKzQycxGkl0MIZA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: OS7P286MB5490 X-purgate-ID: tlsNG-bad1c0/1785027332-FD06B034-5BFCBC92/0/0 X-purgate-type: clean X-purgate-size: 21786 X-ZohoMail-DKIM: pass (identity @valinux.co.jp) X-ZM-MESSAGEID: 1785027367343154100 Content-Type: text/plain; charset="utf-8" Parse the 'cpu-map' node in the Device Tree to extract CPU topology information. If the 'cpu-map' node is absent, fall back to generating the topology data from the NUMA information. This generation assumes exactly one socket per NUMA node and that SMT is unsupported. Signed-off-by: Hirokazu Takahashi Reviewed-by: Jan Beulich # common, acpi --- Changes in v8: * Placed binary logical operators (||, &&) at the end of lines when splitting conditional statements. * Explicitly included in xen/common/cpu.c. * Removed leftovers of ACPI_CPU_TOPOLOGY definition from xen/drivers/acpi/Kconfig. xen/arch/arm/Kconfig | 1 + xen/arch/arm/smpboot.c | 7 + xen/common/Kconfig | 22 ++ xen/common/Makefile | 1 + xen/common/cpu-topology.c | 62 +++++ xen/common/cpu.c | 5 + xen/common/device-tree/Makefile | 1 + xen/common/device-tree/cpu-topology.c | 344 ++++++++++++++++++++++++++ xen/drivers/acpi/Makefile | 1 + xen/drivers/acpi/topology.c | 41 +++ xen/include/xen/acpi.h | 13 + xen/include/xen/cpu-topology.h | 34 +++ xen/include/xen/dt-cpu-topology.h | 35 +++ 13 files changed, 567 insertions(+) create mode 100644 xen/common/cpu-topology.c create mode 100644 xen/common/device-tree/cpu-topology.c create mode 100644 xen/drivers/acpi/topology.c create mode 100644 xen/include/xen/cpu-topology.h create mode 100644 xen/include/xen/dt-cpu-topology.h diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index 843a43897e..1e0fd4957e 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -19,6 +19,7 @@ config ARM select HAS_ALTERNATIVE if HAS_VMAP select HAS_DEVICE_TREE_DISCOVERY select HAS_DOM0LESS + select HAS_GENERIC_CPU_TOPOLOGY select HAS_GRANT_CACHE_FLUSH if GRANT_TABLE select HAS_STACK_PROTECTOR select HAS_STATIC_MEMORY diff --git a/xen/arch/arm/smpboot.c b/xen/arch/arm/smpboot.c index ba5fd2dd52..d957553a44 100644 --- a/xen/arch/arm/smpboot.c +++ b/xen/arch/arm/smpboot.c @@ -9,10 +9,12 @@ =20 #include #include +#include #include #include #include #include +#include #include #include #include @@ -244,6 +246,9 @@ static void __init dt_smp_init_cpus(void) } else tmp_map[i] =3D hwid; + + /* Pass the info to dt_init_cpu_topology() */ + map_cpu_to_dt_node(i, cpu); } =20 if ( !bootcpu_valid ) @@ -280,6 +285,8 @@ void __init smp_init_cpus(void) else acpi_smp_init_cpus(); =20 + init_cpu_topology(); + if ( opt_hmp_unsafe ) warning_add("WARNING: HMP COMPUTING HAS BEEN ENABLED.\n" "It has implications on the security and stability of = the system,\n" diff --git a/xen/common/Kconfig b/xen/common/Kconfig index da80fdba84..29879a9131 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -140,6 +140,9 @@ config HAS_EX_TABLE config HAS_FAST_MULTIPLY bool =20 +config HAS_GENERIC_CPU_TOPOLOGY + bool + config HAS_IOPORTS bool =20 @@ -191,6 +194,25 @@ config VM_EVENT config NEEDS_LIBELF bool =20 +config GENERIC_CPU_TOPOLOGY + bool + +config DT_CPU_TOPOLOGY + bool "Device tree based CPU topology support (UNSUPPORTED)" + depends on HAS_GENERIC_CPU_TOPOLOGY && DEVICE_TREE_PARSE && UNSUPPORTED + select GENERIC_CPU_TOPOLOGY + help + Retrieve CPU topology information from the device tree to optimize + vCPU scheduling. + +config ACPI_CPU_TOPOLOGY + bool "ACPI based CPU topology support (UNSUPPORTED)" + depends on HAS_GENERIC_CPU_TOPOLOGY && ACPI && UNSUPPORTED + select GENERIC_CPU_TOPOLOGY + help + Retrieve CPU topology information from the ACPI PPTT to optimize + vCPU scheduling. + config NUMA bool =20 diff --git a/xen/common/Makefile b/xen/common/Makefile index 6018e25614..901bb37925 100644 --- a/xen/common/Makefile +++ b/xen/common/Makefile @@ -5,6 +5,7 @@ obj-$(CONFIG_GENERIC_BUG_FRAME) +=3D bug.o obj-$(CONFIG_HYPFS_CONFIG) +=3D config_data.o obj-$(CONFIG_CORE_PARKING) +=3D core_parking.o obj-y +=3D cpu.o +obj-$(CONFIG_GENERIC_CPU_TOPOLOGY) +=3D cpu-topology.init.o obj-$(CONFIG_DEBUG_TRACE) +=3D debugtrace.o obj-$(CONFIG_HAS_DEVICE_TREE_DISCOVERY) +=3D device.o obj-$(filter-out $(CONFIG_X86),$(CONFIG_ACPI)) +=3D device.o diff --git a/xen/common/cpu-topology.c b/xen/common/cpu-topology.c new file mode 100644 index 0000000000..52e31ef518 --- /dev/null +++ b/xen/common/cpu-topology.c @@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include +#include +#include +#include +#include +#include + +static void __init free_topology_table(void) +{ + unsigned int cpu; + + for ( cpu =3D 0; cpu < nr_cpu_ids; cpu++ ) + { + free_cpumask_var(cpu_topology[cpu].thread_sibling); + free_cpumask_var(cpu_topology[cpu].core_sibling); + free_cpumask_var(cpu_topology[cpu].cluster_sibling); + } + + XVFREE(cpu_topology); +} + +void __init init_cpu_topology(void) +{ + unsigned int cpu; + int ret; + + cpu_topology =3D xvzalloc_array(struct cpu_topology, nr_cpu_ids); + if ( !cpu_topology ) + return; + + for ( cpu =3D 0; cpu < nr_cpu_ids; cpu++ ) + { + if ( !zalloc_cpumask_var(&cpu_topology[cpu].thread_sibling) || + !zalloc_cpumask_var(&cpu_topology[cpu].core_sibling) || + !zalloc_cpumask_var(&cpu_topology[cpu].cluster_sibling) ) + { + free_topology_table(); + return; + } + } + + if ( acpi_disabled ) + ret =3D dt_init_cpu_topology(); + else + ret =3D acpi_init_cpu_topology(); + + /* Free the CPU topology table if initialization fails. */ + if ( ret !=3D 0 ) + free_topology_table(); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/common/cpu.c b/xen/common/cpu.c index f09af0444b..9591ada60a 100644 --- a/xen/common/cpu.c +++ b/xen/common/cpu.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -46,6 +47,10 @@ const unsigned long cpu_bit_bitmap[BITS_PER_LONG+1][BITS= _TO_LONGS(NR_CPUS)] =3D { #undef MASK_DECLARE_2 #undef MASK_DECLARE_1 =20 +#ifdef CONFIG_GENERIC_CPU_TOPOLOGY +struct cpu_topology *__ro_after_init cpu_topology; +#endif /* CONFIG_GENERIC_CPU_TOPOLOGY */ + static DEFINE_RWLOCK(cpu_add_remove_lock); =20 bool get_cpu_maps(void) diff --git a/xen/common/device-tree/Makefile b/xen/common/device-tree/Makef= ile index 9036e455d6..6ee670b5f4 100644 --- a/xen/common/device-tree/Makefile +++ b/xen/common/device-tree/Makefile @@ -1,6 +1,7 @@ obj-y +=3D bootfdt.init.o obj-$(CONFIG_HAS_DEVICE_TREE_DISCOVERY) +=3D bootinfo-fdt.init.o obj-$(CONFIG_HAS_DEVICE_TREE_DISCOVERY) +=3D bootinfo.init.o +obj-$(CONFIG_DT_CPU_TOPOLOGY) +=3D cpu-topology.init.o obj-y +=3D device-tree.o obj-$(CONFIG_DOMAIN_BUILD_HELPERS) +=3D domain-build.init.o obj-$(filter $(CONFIG_DOM0LESS_BOOT),$(CONFIG_HAS_DEVICE_TREE_DISCOVERY)) = +=3D dom0less-build.init.o diff --git a/xen/common/device-tree/cpu-topology.c b/xen/common/device-tree= /cpu-topology.c new file mode 100644 index 0000000000..9259be73bc --- /dev/null +++ b/xen/common/device-tree/cpu-topology.c @@ -0,0 +1,344 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Derived from Linux kernel 7.0's $drivers/base/arch_topology.c + * Parse cpu topology information. + */ + +#include +#include +#include +#include +#include +#include + +#define INVALID_TOPO_ID (~0U) + +struct cpu_map { + unsigned int thread_id; + unsigned int core_id; + unsigned int cluster_id; + unsigned int package_id; +}; + +static struct cpu_map __initdata cpu_map[NR_CPUS] =3D { + [0 ... NR_CPUS - 1] =3D { + .thread_id =3D INVALID_TOPO_ID, + .core_id =3D INVALID_TOPO_ID, + .cluster_id =3D INVALID_TOPO_ID, + .package_id =3D INVALID_TOPO_ID, + }, +}; +static struct dt_device_node *__initdata dt_cpu_table[NR_CPUS]; + +static void __init setup_siblings_masks(unsigned int target_cpu) +{ + const struct cpu_topology *target_topo =3D &cpu_topology[target_cpu]; + const struct cpu_map *target_map =3D &cpu_map[target_cpu]; + unsigned int cpu; + + /* Update cluster, core and thread sibling masks */ + for_each_possible_cpu(cpu) + { + const struct cpu_topology *cpu_topo =3D &cpu_topology[cpu]; + const struct cpu_map *map =3D &cpu_map[cpu]; + + if ( target_cpu > cpu ) + continue; + + if ( target_map->package_id !=3D map->package_id ) + continue; + + cpumask_set_cpu(target_cpu, cpu_topo->core_sibling); + cpumask_set_cpu(cpu, target_topo->core_sibling); + + if ( target_map->cluster_id !=3D map->cluster_id ) + continue; + + if ( target_map->cluster_id !=3D INVALID_TOPO_ID ) + { + cpumask_set_cpu(target_cpu, cpu_topo->cluster_sibling); + cpumask_set_cpu(cpu, target_topo->cluster_sibling); + } + + if ( target_map->core_id !=3D map->core_id ) + continue; + + cpumask_set_cpu(target_cpu, cpu_topo->thread_sibling); + cpumask_set_cpu(cpu, target_topo->thread_sibling); + } +} + +static const struct dt_device_node *__init dt_find_child_node_by_name( + const struct dt_device_node *dt, + const char *name) +{ + const struct dt_device_node *np; + + dt_for_each_child_node(dt, np) + if ( np->name && (dt_node_cmp(np->name, name) =3D=3D 0) ) + return np; + + return NULL; +} + +void __init map_cpu_to_dt_node(unsigned int cpu, + struct dt_device_node *cpu_node) +{ + if ( cpu < ARRAY_SIZE(dt_cpu_table) ) + dt_cpu_table[cpu] =3D cpu_node; + else + printk(XENLOG_WARNING + "cpu %u exceeds the max cpus %zu\n", + cpu, ARRAY_SIZE(dt_cpu_table)); +} + +static unsigned int __init cpu_node_to_id( + const struct dt_device_node *cpu_node) +{ + unsigned int cpu; + + for_each_possible_cpu(cpu) + if ( cpu_node =3D=3D dt_cpu_table[cpu] ) + return cpu; + + return INVALID_TOPO_ID; +} + +/* + * This function returns the Xen cpu number of the DT node. + */ +static unsigned int __init get_cpu_for_node( + const struct dt_device_node *dt_node) +{ + const struct dt_device_node *cpu_node =3D + dt_parse_phandle(dt_node, "cpu", 0); + + if ( !cpu_node ) + return INVALID_TOPO_ID; + + return cpu_node_to_id(cpu_node); +} + +static int __init parse_core(const struct dt_device_node *core, + unsigned int package_id, + unsigned int cluster_id, + unsigned int core_id) +{ + bool leaf =3D true; + unsigned int thread_id; + unsigned int cpu; + + for ( thread_id =3D 0; ; thread_id++ ) + { + const struct dt_device_node *thread; + char name[20]; + + snprintf(name, sizeof(name), "thread%u", thread_id); + thread =3D dt_find_child_node_by_name(core, name); + + if ( !thread ) + break; + + leaf =3D false; + cpu =3D get_cpu_for_node(thread); + + if ( cpu =3D=3D INVALID_TOPO_ID ) + { + printk(XENLOG_ERR + "ERROR: %s: Can't get CPU for thread\n", dt_node_name(t= hread)); + return -EINVAL; + } + + ASSERT(cpu_map[cpu].package_id =3D=3D INVALID_TOPO_ID); + ASSERT(cpu_map[cpu].cluster_id =3D=3D INVALID_TOPO_ID); + ASSERT(cpu_map[cpu].core_id =3D=3D INVALID_TOPO_ID); + ASSERT(cpu_map[cpu].thread_id =3D=3D INVALID_TOPO_ID); + + cpu_map[cpu].package_id =3D package_id; + cpu_map[cpu].cluster_id =3D cluster_id; + cpu_map[cpu].core_id =3D core_id; + cpu_map[cpu].thread_id =3D thread_id; + } + + cpu =3D get_cpu_for_node(core); + + if ( cpu !=3D INVALID_TOPO_ID ) + { + if ( !leaf ) + { + printk(XENLOG_ERR "ERROR: %s: Core has both threads and CPU\n", + dt_node_name(core)); + return -EINVAL; + } + + ASSERT(cpu_map[cpu].package_id =3D=3D INVALID_TOPO_ID); + ASSERT(cpu_map[cpu].cluster_id =3D=3D INVALID_TOPO_ID); + ASSERT(cpu_map[cpu].core_id =3D=3D INVALID_TOPO_ID); + ASSERT(cpu_map[cpu].thread_id =3D=3D INVALID_TOPO_ID); + + cpu_map[cpu].package_id =3D package_id; + cpu_map[cpu].cluster_id =3D cluster_id; + cpu_map[cpu].core_id =3D core_id; + cpu_map[cpu].thread_id =3D 0; + } + else if ( leaf ) + { + printk(XENLOG_ERR + "ERROR: %s: Can't get CPU for leaf core\n", dt_node_name(co= re)); + return -EINVAL; + } + + return 0; +} + +static int __init parse_cluster(const struct dt_device_node *cluster, + unsigned int package_id, + unsigned int cluster_id, + unsigned int depth) +{ + bool leaf =3D true; + bool has_cores =3D false; + unsigned int core_id; + unsigned int child_cluster_id; + + /* + * First check for child clusters; we currently ignore any + * information about the nesting of clusters and present the + * scheduler with a flat list of them. + */ + for ( child_cluster_id =3D 0; ; child_cluster_id++ ) + { + const struct dt_device_node *child_cluster; + char name[20]; + int ret; + + snprintf(name, sizeof(name), "cluster%u", child_cluster_id); + child_cluster =3D dt_find_child_node_by_name(cluster, name); + + if ( !child_cluster ) + break; + + leaf =3D false; + ret =3D parse_cluster(child_cluster, package_id, child_cluster_id, + depth + 1); + if ( depth > 0 ) + printk(XENLOG_WARNING + "WARNING: Topology for clusters of clusters not yet sup= ported\n"); + if ( ret !=3D 0 ) + return ret; + } + + /* Now check for cores */ + for ( core_id =3D 0; ; core_id++ ) + { + const struct dt_device_node *core; + char name[20]; + int ret; + + snprintf(name, sizeof(name), "core%u", core_id); + core =3D dt_find_child_node_by_name(cluster, name); + + if ( !core ) + break; + + has_cores =3D true; + + if ( depth =3D=3D 0 ) + { + printk(XENLOG_ERR + "ERROR: %s: cpu-map children should be clusters\n", + dt_node_name(core)); + return -EINVAL; + } + + if ( leaf ) + { + ret =3D parse_core(core, package_id, cluster_id, core_id); + if ( ret !=3D 0 ) + return ret; + } + else + { + printk(XENLOG_ERR "ERROR: %s: Non-leaf cluster with core %s\n", + dt_node_name(cluster), name); + return -EINVAL; + } + } + + if ( leaf && !has_cores ) + printk(XENLOG_WARNING "WARNING: %s: empty cluster\n", + dt_node_name(cluster)); + + return 0; +} + +static int __init parse_socket(const struct dt_device_node *socket) +{ + bool has_socket =3D false; + unsigned int package_id; + int ret; + + for ( package_id =3D 0; ; package_id++ ) + { + const struct dt_device_node *cluster; + char name[20]; + + snprintf(name, sizeof(name), "socket%u", package_id); + cluster =3D dt_find_child_node_by_name(socket, name); + + if ( !cluster ) + break; + + has_socket =3D true; + ret =3D parse_cluster(cluster, package_id, INVALID_TOPO_ID, 0); + if ( ret !=3D 0 ) + return ret; + } + + if ( !has_socket ) + ret =3D parse_cluster(socket, 0, INVALID_TOPO_ID, 0); + + return ret; +} + +static int __init parse_dt_topology(void) +{ + const struct dt_device_node *cpus; + const struct dt_device_node *map; + + cpus =3D dt_find_node_by_path("/cpus"); + if ( !cpus ) + return -ENOENT; + + map =3D dt_find_child_node_by_name(cpus, "cpu-map"); + if ( !map ) + return -ENOENT; + + return parse_socket(map); +} + +int __init dt_init_cpu_topology(void) +{ + unsigned int cpu; + int ret; + + BUG_ON(!acpi_disabled); + BUG_ON(!cpu_topology); + + ret =3D parse_dt_topology(); + if ( ret =3D=3D 0 ) + for_each_possible_cpu(cpu) + setup_siblings_masks(cpu); + + return ret; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/drivers/acpi/Makefile b/xen/drivers/acpi/Makefile index 477408afbe..6d676e91d4 100644 --- a/xen/drivers/acpi/Makefile +++ b/xen/drivers/acpi/Makefile @@ -7,6 +7,7 @@ obj-$(CONFIG_ACPI_NUMA) +=3D numa.o obj-y +=3D osl.o obj-$(CONFIG_PM_STATS) +=3D pmstat.o obj-$(CONFIG_PM_OP) +=3D pm-op.o +obj-$(CONFIG_ACPI_CPU_TOPOLOGY) +=3D topology.init.o =20 obj-$(CONFIG_X86) +=3D hwregs.o obj-$(CONFIG_X86) +=3D reboot.o diff --git a/xen/drivers/acpi/topology.c b/xen/drivers/acpi/topology.c new file mode 100644 index 0000000000..45d1f2c5be --- /dev/null +++ b/xen/drivers/acpi/topology.c @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include +#include +#include +#include + +/* + * TODO: Populate the topology information by scanning the ACPI + * PPTT (Processor Properties Topology Table). + */ +int __init acpi_init_cpu_topology(void) +{ + unsigned int cpu; + + /* + * Generate temporary cpu topology information for now. + * It assumes that the cpu doesn't have SMT and all CPUs + * belong to the same socket. + */ + for_each_possible_cpu(cpu) + { + struct cpu_topology *topo =3D &cpu_topology[cpu]; + + cpumask_set_cpu(cpu, topo->thread_sibling); + cpumask_copy(topo->core_sibling, &cpu_possible_map); + cpumask_copy(topo->cluster_sibling, &cpu_possible_map); + } + + return 0; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/xen/acpi.h b/xen/include/xen/acpi.h index 2fdf38cf74..cbb02e0f35 100644 --- a/xen/include/xen/acpi.h +++ b/xen/include/xen/acpi.h @@ -135,6 +135,19 @@ static inline int acpi_boot_table_init(void) =20 #endif /*!CONFIG_ACPI*/ =20 +#ifdef CONFIG_ACPI_CPU_TOPOLOGY + +int acpi_init_cpu_topology(void); + +#else /* CONFIG_ACPI_CPU_TOPOLOGY */ + +static inline int acpi_init_cpu_topology(void) +{ + return -EOPNOTSUPP; +} + +#endif /* CONFIG_ACPI_CPU_TOPOLOGY */ + int get_cpu_id(u32 acpi_id); =20 unsigned int acpi_register_gsi (u32 gsi, int edge_level, int active_high_l= ow); diff --git a/xen/include/xen/cpu-topology.h b/xen/include/xen/cpu-topology.h new file mode 100644 index 0000000000..7cfe3752cd --- /dev/null +++ b/xen/include/xen/cpu-topology.h @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef XEN_CPU_TOPOLOGY_H +#define XEN_CPU_TOPOLOGY_H + +#include + +#ifdef CONFIG_GENERIC_CPU_TOPOLOGY + +struct cpu_topology { + cpumask_var_t thread_sibling; + cpumask_var_t core_sibling; + cpumask_var_t cluster_sibling; +}; + +extern struct cpu_topology *cpu_topology; +void init_cpu_topology(void); + +#else /* CONFIG_GENERIC_CPU_TOPOLOGY */ + +static inline void init_cpu_topology(void) {} + +#endif /* CONFIG_GENERIC_CPU_TOPOLOGY */ + +#endif /* XEN_CPU_TOPOLOGY_H */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/xen/dt-cpu-topology.h b/xen/include/xen/dt-cpu-top= ology.h new file mode 100644 index 0000000000..72b35b3cf2 --- /dev/null +++ b/xen/include/xen/dt-cpu-topology.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef XEN_DT_CPU_TOPOLOGY_H +#define XEN_DT_CPU_TOPOLOGY_H + +#include + +struct dt_device_node; + +#ifdef CONFIG_DT_CPU_TOPOLOGY + +void map_cpu_to_dt_node(unsigned int cpu, struct dt_device_node *cpu_node); +int dt_init_cpu_topology(void); + +#else /* CONFIG_DT_CPU_TOPOLOGY */ + +static inline void map_cpu_to_dt_node(unsigned int cpu, + struct dt_device_node *cpu_node) {} +static inline int dt_init_cpu_topology(void) +{ + return -EOPNOTSUPP; +} + +#endif /* CONFIG_DT_CPU_TOPOLOGY */ + +#endif /* XEN_DT_CPU_TOPOLOGY_H */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ --=20 2.43.0 From nobody Thu Sep 24 20:27:56 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=valinux.co.jp); dmarc=pass(p=none dis=none) header.from=valinux.co.jp ARC-Seal: i=2; a=rsa-sha256; t=1785027366; cv=pass; d=zohomail.com; s=zohoarc; b=Yrqg9Aw3bDSRA+6T17i9RDT7TQcl2mWM41VIu86x8ZuA7DP9tUsl9XaVzG3k28bSU7zS+B/kWGHNqz2hHunrso4Ltgq/aOmgKt+rgUpffJXEmCW0qIyKqwZZWyCOOTrALkJNAaMOFIBHAi6jpiCP6KEgBaIOyq2EG6WvViyfYrg= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1785027366; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=KMShCBGc4W5KYknagjI2BL0mNG7v+HoatGWhYaSmHkc=; b=mto2K9RKzjcr7AG9Y/XbfoaPLZBhz3v9Ly26z0pPKalX1d2prsXQYT2GyWkgSUUWbVAM2vr1M897fto+dtUpaq+vNqn3sqYvFgQPIYUhmn7x/BPH10hgH6oDiCjpcyKFgKfL9yYFMrUzy36YdXBeVbTP/dnmN54xvzQdM5tqwOM= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=valinux.co.jp); dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1785027366320870.2338324561803; Sat, 25 Jul 2026 17:56:06 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1370881.1618757 (Exim 4.92) (envelope-from ) id 1wnn9U-0006qF-8B; Sun, 26 Jul 2026 00:55:36 +0000 Received: by outflank-mailman (output) from mailman id 1370881.1618757; Sun, 26 Jul 2026 00:55:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wnn9U-0006oo-4Z; Sun, 26 Jul 2026 00:55:36 +0000 Received: by outflank-mailman (input) for mailman id 1370881; Sun, 26 Jul 2026 00:55:34 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wnn9S-0006gB-D4 for xen-devel@lists.xenproject.org; Sun, 26 Jul 2026 00:55:34 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wnn9R-0081V3-8b for xen-devel@lists.xenproject.org; Sun, 26 Jul 2026 02:55:33 +0200 Received: from [10.42.69.9] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a655b05-5cb7-0a2a0a5109dd-0a2a4509e00a-0 for ; Sun, 26 Jul 2026 02:55:33 +0200 Received: from [52.101.228.97] (helo=OS0P286CU011.outbound.protection.outlook.com) by tlsNG-bad1c0.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a655aff-be1a-0a2a45090019-3465e461c552-5 for ; Sun, 26 Jul 2026 02:55:32 +0200 Received: from OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:458::18) by OS7P286MB5490.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:397::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.245.12; Sun, 26 Jul 2026 00:55:31 +0000 Received: from OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM ([fe80::c8c9:25cd:8d13:96d6]) by OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM ([fe80::c8c9:25cd:8d13:96d6%6]) with mapi id 15.21.0245.012; Sun, 26 Jul 2026 00:55:31 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=valinux.co.jp header.i="@valinux.co.jp" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=hLM5z8Zbrhf64HEbJlll29O8EnKGutztpwg+Si9DC/LMEOJh4/xd/HTJzOQekl2N2pWZNF6MA7Mn3/V7wZReZWV69j6CrP4UgBNc7CnZ7M/cYzG++rIRdmPfiunFwnIKPrceKPAHI/SEh93OZUQzrJKTFxQIsAxv3VxzSO4i3+wUYxK/ynP/PaaJSQOX7C1eiA/GVtIHbWO14QgSQt7bq8ALPiMI7C28F/mmQzNt0IJXYpdojY+NnGND5jModGzd7wL397mPhY1JuCkEQ7cXHPCuFUrxxwPSYQyqpCYX9Bv8Uciq8doG1mfP0U1lhGsIIbQLMEFUw7D2bGT4oCKvrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=KMShCBGc4W5KYknagjI2BL0mNG7v+HoatGWhYaSmHkc=; b=jtI7TW2RRF9BliD1aZkQljgMmWaL0t0ZAynv2kBkJ49GuqCDzCtsWuK4CcUUUWuadMlRL6XpZZ2D8vahMV1Gim4FzSLWwrmtKAO7UjWyvvYbQhmfyaBeo4tU0Sh85PEJmaZeCa/9sTPd6XoMJjJ0/IoUXgWycO1UN74zIvZjyKEmsPjW9WM2nCvjZg7WE3KK83gyS0nZV8PdhsIOR4t5MOVJzZwmh/Jyr6rfZ2kUtQPBo/nOVjaRlw8+PbQLiYOd+sQ36rgM0X8U3PjW+2he8F1ojiEbAXzHf5CiPqOtbB4dIJX6b55KTtg1aelkoLX3i8WN1eOk3QN3LqrnO9lRag== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=valinux.co.jp; dmarc=pass action=none header.from=valinux.co.jp; dkim=pass header.d=valinux.co.jp; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=valinux.co.jp; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KMShCBGc4W5KYknagjI2BL0mNG7v+HoatGWhYaSmHkc=; b=WPJXinkHugLwRhQpcmiBOy723OXL2cVNtHbY/bn8lKN1aqAJkgmNPMw72xGde6jgagBQbi+gLfXKnXzwlyR3JpT32oSL7KSW7HhLkvYEv5aezspvkMSjxp5uNYmnlGC40bEjZev5XP6Xcp0JfNtW88BQopAr8By1lNhs76JQHk4= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=valinux.co.jp; From: Hirokazu Takahashi To: xen-devel@lists.xenproject.org Cc: Mykyta_Poturai@epam.com, Hirokazu Takahashi , Jan Beulich , Juergen Gross , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , Anthony PERARD , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Timothy Pearson , Alistair Francis , Connor Davis , Oleksii Kurochko , Dario Faggioli , George Dunlap Subject: [PATCH v8 2/4] xen/sched: Link CPU topology to scheduler Date: Sun, 26 Jul 2026 09:55:15 +0900 Message-ID: <20260726005517.379267-3-taka@valinux.co.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260726005517.379267-1-taka@valinux.co.jp> References: <20260726005517.379267-1-taka@valinux.co.jp> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: TY6P301CA0028.JPNP301.PROD.OUTLOOK.COM (2603:1096:405:3bf::18) To OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:458::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OS9P286MB7222:EE_|OS7P286MB5490:EE_ X-MS-Office365-Filtering-Correlation-Id: efbe40ab-6bd3-466d-a1fd-08deeab097a9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|23010399003|366016|7416014|376014|10070799003|56012099006|10067099003|6133799003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: ue4m0+C+frD0jlEpTY9KDMhqLu8nHI5qWfHvVBKhm+aKxSk3PJoj/oaebeXl66T//GmZi7uYfdRIR3JvGcjYhaOpEFje5wp9hpjCHVRJScpcJlgQSZhFAtV/qhOChAnI5cvcOss7zHmohwt+HO0CTPymKyTGUkBAzv5UvA0lAQ6L/0yP+xOk1ncYwy6ch9uCu+AlfWK4OZYwceSeq1vEmmu+Ssiyuqfb+utVzxffjpevLTRdmn1SjL4HHnYhX2WFXIEGTn5tePOH1qzq+8MF74vQDXyarPCzbb7AsEiLqaCsG8sdCOblRDT1ozY3V/PiZ94AdzI76IF0xEhYOLSgrONIDtBx5Bea7r79TiZcXdfPc/OZgq6H1ujeY+lI/EDvfXj/0pHRV5ICyjVBFhKLI6WH6m5MQvdSDloAkMC65Uchh5HKusYcW3ICbUUZ2AxNMriyUTkmzNNtNwXRLp1l4NU7XtZZZUN6+722JkHI2WfLoZwKxRX3sOmudfaYzWaPMl3jTNWt9InxNWXTt5OTQhpaC71ze8Y64rT6jSoM9Mr8GVrh5n1CbfEjtKWEUfKa2gdw2TS4KTyeLDJimt/IL2YamHGnkGkqi3WJMJq+CYGRsLxaT8Kmufo8ERepjubNnQHHrRax0DULAp4jrKFdBIzEP/G3TwveXDXz4STtgrw= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(23010399003)(366016)(7416014)(376014)(10070799003)(56012099006)(10067099003)(6133799003)(18002099003)(22082099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?LRtZNQT3YdLLM8fgG/ggJnKOZMAQO9R5U2syct/IB+BCJdzvYEFP9cJ8gi6Z?= =?us-ascii?Q?OAV45j0oTw4ykf0JKo6L1WoF3Ls8ftzpAn5O3ih2o5ICrc3TeSmfQyZih9iU?= =?us-ascii?Q?CHXdY8kVIJJA9qXVehHqNb2zsorf4ph8ZDVG/HXEjvWzu9aMjnAjixfCET5d?= =?us-ascii?Q?deZOnR7qjcrlLPfzfQb7pRglnLeGPNd1thmcRkOsqr+HDG04AmuV58eNtNZx?= =?us-ascii?Q?dcGdlz4Z3RldkcC816t4mxgluXoZA4MiDLDhJzqR+30jEBi8NpOQ2aM/r7DH?= =?us-ascii?Q?1axLhjuZ7KeNsa2866JeCRq0cd/h6WHGyQiRnGsl6sulI9IsQKzoy5DcvcNa?= =?us-ascii?Q?OMgEU0aZP6IAmV4PuBCK2V3XLjnQ1PV9vtBhwUclJsaFA4qY/3h0p5JT/yRI?= =?us-ascii?Q?Q+4wbQd8WDwUpbh4FFVBjzFF3O0ybL00a9yrPNHGMFrOPeoBHVT8Bk7ZWByi?= =?us-ascii?Q?QG3FNHWo1EP0nyGSBdFjSfRdy+Wu5B355o5pa01RSd60wSY37OIgqqyZjb4N?= =?us-ascii?Q?fpnhP8QN6Y7F7fK5QuANqhK+p6Gbtkd4n3a45GciVzHO07ZskiDlyye2T9OU?= =?us-ascii?Q?mUA0sp8OfKlc6btgaOoYedWiP+g2EVzl7MhKbrgGU28BrUvbIqwDGKAC+L+B?= =?us-ascii?Q?KQqld8CVKxrTqDsefoqEFsLim4Uu7xFg94TX8lp/R4rvQY2PGXSQramIC0hh?= =?us-ascii?Q?SoUBq5oCGiWuJqzXmRq2+nA5EfRzYUBWmkrmq8vZBQulDTqHFlqjnI2fWFcC?= =?us-ascii?Q?HF2esEelwoKEmYksNrVwRcN81kKkZjgDSVbonKEh1X090Nw+FXm6tpXdrzjx?= =?us-ascii?Q?9UggLo5gMmCyrQ0A1R/ftmwLfigNmZ3ADhGoKAQtPBl03K8lCHxZjFB4zukc?= =?us-ascii?Q?R/hzCBY1x5TEqwZiVMxUgAKPVAF4z4DHtP289aWFELvXo67S2Gx1MYiY5Y6t?= =?us-ascii?Q?9bc8U072xOlO8LmqSxBcxj3G4KyOVcIjvpx7TnIpLNLg6w/j8jBV1iTpsUlu?= =?us-ascii?Q?2jGMjsfW66UQGfg3tnpi3Vndwb7peC1lGJx0CZ9/eACYtsb0vVRJsU6Kjue7?= =?us-ascii?Q?p7Mi9HjZx5WslIOuvu7m4OtdisoFF0Pj9U4knHcn9hFW9V4VChBoU7AFUKeF?= =?us-ascii?Q?wq7Asq6xF9oO7xAFbks2aFN2bqxsphAxPQXbj3dqVwoEGS4Y79fS63kOex+x?= =?us-ascii?Q?Qg/h+MMIkMko/ebIxvFlL0FyREMuio/A5zQ8zni1ydnDkacSxDsVmsuxd2NP?= =?us-ascii?Q?19hS7VJG/6u5Mh+iha97KV+Hja6GCTCPrOW7MjX5tlfpIHY0TU4P9UwiYC/N?= =?us-ascii?Q?Ec/2sCToBYFJulaMXQ+h7EHPjvoMXGAOh2zwbekA4AIM60pO11/JmdDux+uQ?= =?us-ascii?Q?LZlnFJnsahZteTZ3v8CWKdpvU0n8ypkbosWE3UOX6mGT/3YkJ6Cwctj/37e0?= =?us-ascii?Q?23aRoBLKGeAk0nZn6SAK28YtlGNHa0U7CPT4zl2hp2W6rdLPcub4/ioB4zy2?= =?us-ascii?Q?y7AGPiko71kqhW4gM8BsH0mvhDO2K6mulGEHSTgrnsUS9NWBTUpLgrERLcyD?= =?us-ascii?Q?aPZxaRJyVvT5cmgDn5KGxJ0Umd8nhHeMCG4zl57vyvykAnZzM+6u5IRXAaaG?= =?us-ascii?Q?nTMBi7pL2mkAekG3D1VTKayD5e6Cq8iPwu1DjGUWKaNNOT68jGVjDPmx49Yd?= =?us-ascii?Q?dqql3qDH+CacuEoDjCFOVGbxWTC7N5xgjbAu2LK5MpQzwzw4KefCzqHt8kX2?= =?us-ascii?Q?XtA39FbvIl6pO8er5csJc99dRmFE+uCQPo/bmRA+BRf3cndLPAsDjTpGIngU?= X-MS-Exchange-AntiSpam-MessageData-1: pNmSAjxFN6K+hA== X-OriginatorOrg: valinux.co.jp X-MS-Exchange-CrossTenant-Network-Message-Id: efbe40ab-6bd3-466d-a1fd-08deeab097a9 X-MS-Exchange-CrossTenant-AuthSource: OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jul 2026 00:55:31.3370 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 7a57bee8-f73d-4c5f-a4f7-d72c91c8c111 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: YI8E3YBnEo6mKfku5d/ZIorhmVaoQZ6b1ji9f+qttpuNu4wK/1iJLirwD7hR9cd6BDfoByvecGJbIebpNRsV+A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: OS7P286MB5490 X-purgate-ID: tlsNG-bad1c0/1785027333-BF4D3034-091A738E/0/0 X-purgate-type: clean X-purgate-size: 9046 X-ZohoMail-DKIM: pass (identity @valinux.co.jp) X-ZM-MESSAGEID: 1785027367255154101 Content-Type: text/plain; charset="utf-8" Make CPU topology information available to the Xen scheduler. Additionally, ensure that this topology information is displayed when executing the 'xl info -n' command. Signed-off-by: Hirokazu Takahashi Acked-by: Jan Beulich Reviewed-by: Juergen Gross # scheduler part --- xen/arch/arm/include/asm/processor.h | 4 -- xen/arch/arm/smpboot.c | 8 +--- xen/arch/ppc/include/asm/processor.h | 4 -- xen/arch/riscv/include/asm/processor.h | 4 -- xen/common/device-tree/cpu-topology.c | 65 ++++++++++++++++++++++++++ xen/common/sched/credit2.c | 6 +++ xen/common/sysctl.c | 1 + xen/drivers/acpi/topology.c | 3 ++ xen/include/xen/cpu-topology.h | 39 +++++++++++++++- 9 files changed, 114 insertions(+), 20 deletions(-) diff --git a/xen/arch/arm/include/asm/processor.h b/xen/arch/arm/include/as= m/processor.h index a3753c317f..41fa73cfc4 100644 --- a/xen/arch/arm/include/asm/processor.h +++ b/xen/arch/arm/include/asm/processor.h @@ -613,10 +613,6 @@ void show_stack(const struct cpu_user_regs *regs); =20 #define cpu_relax() barrier() /* Could yield? */ =20 -/* All a bit UP for the moment */ -#define cpu_to_core(_cpu) (0) -#define cpu_to_socket(_cpu) (0) - struct vcpu; void vcpu_regs_hyp_to_user(const struct vcpu *vcpu, struct vcpu_guest_core_regs *regs); diff --git a/xen/arch/arm/smpboot.c b/xen/arch/arm/smpboot.c index d957553a44..88b01bcfd2 100644 --- a/xen/arch/arm/smpboot.c +++ b/xen/arch/arm/smpboot.c @@ -92,13 +92,7 @@ static int setup_cpu_sibling_map(int cpu) !zalloc_cpumask_var(&per_cpu(cpu_core_mask, cpu)) ) return -ENOMEM; =20 - /* - * Currently we assume there is no multithread and NUMA, so - * a CPU is a sibling with itself, and the all possible CPUs - * are supposed to belong to the same socket (NUMA node). - */ - cpumask_set_cpu(cpu, per_cpu(cpu_sibling_mask, cpu)); - cpumask_copy(per_cpu(cpu_core_mask, cpu), &cpu_possible_map); + init_cpu_sibling_map(cpu); =20 return 0; } diff --git a/xen/arch/ppc/include/asm/processor.h b/xen/arch/ppc/include/as= m/processor.h index 242346cab9..1bf6f6c66c 100644 --- a/xen/arch/ppc/include/asm/processor.h +++ b/xen/arch/ppc/include/asm/processor.h @@ -141,10 +141,6 @@ /* Macro to adjust thread priority for hardware multithreading */ #define HMT_very_low() asm volatile ( "or %r31, %r31, %r31" ) =20 -/* TODO: This isn't correct */ -#define cpu_to_core(cpu) (0) -#define cpu_to_socket(cpu) (0) - /* * User-accessible registers: most of these need to be saved/restored * for every nested Xen invocation. diff --git a/xen/arch/riscv/include/asm/processor.h b/xen/arch/riscv/includ= e/asm/processor.h index 6b89df4a2d..d478ffb76b 100644 --- a/xen/arch/riscv/include/asm/processor.h +++ b/xen/arch/riscv/include/asm/processor.h @@ -54,10 +54,6 @@ struct cpu_user_regs unsigned long pregs; }; =20 -/* TODO: need to implement */ -#define cpu_to_core(cpu) 0 -#define cpu_to_socket(cpu) 0 - static inline void cpu_relax(void) { #ifdef __riscv_zihintpause diff --git a/xen/common/device-tree/cpu-topology.c b/xen/common/device-tree= /cpu-topology.c index 9259be73bc..36560dc228 100644 --- a/xen/common/device-tree/cpu-topology.c +++ b/xen/common/device-tree/cpu-topology.c @@ -317,6 +317,67 @@ static int __init parse_dt_topology(void) return parse_socket(map); } =20 +static void __init setup_cpu_topology_ids(void) +{ + unsigned int cpu; + unsigned int next_core_id =3D 0; + unsigned int next_cluster_id =3D 0; + unsigned int next_socket_id =3D 0; + + for_each_possible_cpu(cpu) + { + unsigned int first_cpu; + struct cpu_topology *topo =3D &cpu_topology[cpu]; + + first_cpu =3D cpumask_first(topo->thread_sibling); + ASSERT(first_cpu < nr_cpu_ids); + + if ( first_cpu =3D=3D cpu ) + { + topo->phys_core_id =3D next_core_id; + next_core_id++; + } + else + { + topo->phys_core_id =3D cpu_topology[first_cpu].phys_core_id; + } + + first_cpu =3D cpumask_first(topo->cluster_sibling); + if ( first_cpu >=3D nr_cpu_ids ) + { + /* Clustering is not supported */ + topo->phys_cluster_id =3D 0; + } + else + { + if ( first_cpu =3D=3D cpu ) + { + topo->phys_cluster_id =3D next_cluster_id; + next_cluster_id++; + } + else + { + topo->phys_cluster_id =3D cpu_topology[first_cpu].phys_clu= ster_id; + } + } + + first_cpu =3D cpumask_first(topo->core_sibling); + ASSERT(first_cpu < nr_cpu_ids); + + if ( first_cpu =3D=3D cpu ) + { + topo->phys_socket_id =3D next_socket_id; + next_socket_id++; + } + else + { + topo->phys_socket_id =3D cpu_topology[first_cpu].phys_socket_i= d; + } + + topo->num_siblings =3D cpumask_weight(topo->thread_sibling); + } +} + int __init dt_init_cpu_topology(void) { unsigned int cpu; @@ -327,9 +388,13 @@ int __init dt_init_cpu_topology(void) =20 ret =3D parse_dt_topology(); if ( ret =3D=3D 0 ) + { for_each_possible_cpu(cpu) setup_siblings_masks(cpu); =20 + setup_cpu_topology_ids(); + } + return ret; } =20 diff --git a/xen/common/sched/credit2.c b/xen/common/sched/credit2.c index 95946634d1..b4a3b59601 100644 --- a/xen/common/sched/credit2.c +++ b/xen/common/sched/credit2.c @@ -9,6 +9,7 @@ * Based on an earlier verson by Emmanuel Ackaouy. */ =20 +#include #include #include #include @@ -35,6 +36,11 @@ */ static unsigned int cpu_nr_siblings(unsigned int cpu) { +#ifdef CONFIG_GENERIC_CPU_TOPOLOGY + if ( cpu_topology ) + return cpu_topology[cpu].num_siblings; +#endif + #ifdef CONFIG_X86 return cpu_data[cpu].x86_num_siblings; #else diff --git a/xen/common/sysctl.c b/xen/common/sysctl.c index 5207664252..81a68fe24c 100644 --- a/xen/common/sysctl.c +++ b/xen/common/sysctl.c @@ -28,6 +28,7 @@ #include #include #include +#include =20 long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) { diff --git a/xen/drivers/acpi/topology.c b/xen/drivers/acpi/topology.c index 45d1f2c5be..56fcfa4945 100644 --- a/xen/drivers/acpi/topology.c +++ b/xen/drivers/acpi/topology.c @@ -22,6 +22,9 @@ int __init acpi_init_cpu_topology(void) { struct cpu_topology *topo =3D &cpu_topology[cpu]; =20 + topo->phys_core_id =3D cpu; + topo->num_siblings =3D 1; + cpumask_set_cpu(cpu, topo->thread_sibling); cpumask_copy(topo->core_sibling, &cpu_possible_map); cpumask_copy(topo->cluster_sibling, &cpu_possible_map); diff --git a/xen/include/xen/cpu-topology.h b/xen/include/xen/cpu-topology.h index 7cfe3752cd..52ee93d4d0 100644 --- a/xen/include/xen/cpu-topology.h +++ b/xen/include/xen/cpu-topology.h @@ -4,22 +4,59 @@ #define XEN_CPU_TOPOLOGY_H =20 #include +#include =20 -#ifdef CONFIG_GENERIC_CPU_TOPOLOGY +#include +#include =20 struct cpu_topology { cpumask_var_t thread_sibling; cpumask_var_t core_sibling; cpumask_var_t cluster_sibling; + unsigned int phys_core_id; + unsigned int phys_cluster_id; + unsigned int phys_socket_id; + unsigned int num_siblings; }; =20 extern struct cpu_topology *cpu_topology; + +static inline void init_cpu_sibling_map(unsigned int cpu) +{ + if ( IS_ENABLED(CONFIG_GENERIC_CPU_TOPOLOGY) && cpu_topology ) + { + cpumask_copy(per_cpu(cpu_sibling_mask, cpu), + cpu_topology[cpu].thread_sibling); + cpumask_copy(per_cpu(cpu_core_mask, cpu), + cpu_topology[cpu].core_sibling); + } + else + { + /* Assume all CPUs reside in the same socket and no threading. */ + cpumask_set_cpu(cpu, per_cpu(cpu_sibling_mask, cpu)); + cpumask_copy(per_cpu(cpu_core_mask, cpu), &cpu_possible_map); + } +} + +#ifdef CONFIG_GENERIC_CPU_TOPOLOGY + void init_cpu_topology(void); =20 +#define cpu_to_core(cpu) (cpu_topology ? cpu_topology[cpu].phys_core_id : = 0) +#define cpu_to_socket(cpu) (cpu_topology ? cpu_topology[cpu].phys_socket_i= d : 0) + #else /* CONFIG_GENERIC_CPU_TOPOLOGY */ =20 static inline void init_cpu_topology(void) {} =20 +#ifndef cpu_to_core +#define cpu_to_core(cpu) (0) +#endif + +#ifndef cpu_to_socket +#define cpu_to_socket(cpu) (0) +#endif + #endif /* CONFIG_GENERIC_CPU_TOPOLOGY */ =20 #endif /* XEN_CPU_TOPOLOGY_H */ --=20 2.43.0 From nobody Thu Sep 24 20:27:56 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=valinux.co.jp); dmarc=pass(p=none dis=none) header.from=valinux.co.jp ARC-Seal: i=2; a=rsa-sha256; t=1785027368; cv=pass; d=zohomail.com; s=zohoarc; b=NCtNCwEIXZtFygodqt7qbHqGc144756jxaUmVOpbUOhFLJDuif4Qh/Fd7KjUTZFQCP1ewGpP5EWZJCvRZ7HCPVm9l9i+Bk3ejs9Vly7tx0eA2jVK1TS1i98zlp4vt0KvChVv1GggOjSsGzwvbVNvwMMsX5wn5waJWHoQA10B+TU= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1785027368; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XK1cLDx6Xq4Pa7KAEXAzG6KDMbfPkr/rPHIGR/XkH3U=; b=nfGU2NhETckNAtQRcv0AgXjGXH47fsNNZ9S0rGkwkADzgRd+SvnehIYzjFThtJI1OHsCH9a22+z79foHY6/Vcq4c8pAPuecjH5o+KcnZhuSdFyKCdPMfKzuwPBKM8sG1kltLR0050ivEsCQIlByLxBUxxek8J/xNc0hPIbodx5o= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=valinux.co.jp); dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 178502736868567.93581863167606; Sat, 25 Jul 2026 17:56:08 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1370882.1618774 (Exim 4.92) (envelope-from ) id 1wnn9b-0007MU-JC; Sun, 26 Jul 2026 00:55:43 +0000 Received: by outflank-mailman (output) from mailman id 1370882.1618774; Sun, 26 Jul 2026 00:55:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wnn9b-0007MD-FM; Sun, 26 Jul 2026 00:55:43 +0000 Received: by outflank-mailman (input) for mailman id 1370882; Sun, 26 Jul 2026 00:55:42 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wnn9a-0007LC-8w for xen-devel@lists.xenproject.org; Sun, 26 Jul 2026 00:55:42 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wnn9Z-0081V3-MD for xen-devel@lists.xenproject.org; Sun, 26 Jul 2026 02:55:41 +0200 Received: from [10.42.69.8] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a655996-5cb7-0a2a0a5109dd-0a2a4508b87a-26 for ; Sun, 26 Jul 2026 02:55:41 +0200 Received: from [40.107.74.120] (helo=OS0P286CU010.outbound.protection.outlook.com) by tlsNG-c1860d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a655b0b-f659-0a2a45080019-286b4a78f062-3 for ; Sun, 26 Jul 2026 02:55:41 +0200 Received: from OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:458::18) by OS7P286MB5490.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:397::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.245.12; Sun, 26 Jul 2026 00:55:37 +0000 Received: from OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM ([fe80::c8c9:25cd:8d13:96d6]) by OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM ([fe80::c8c9:25cd:8d13:96d6%6]) with mapi id 15.21.0245.012; Sun, 26 Jul 2026 00:55:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=valinux.co.jp header.i="@valinux.co.jp" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tSjRKyKqMDqgH0597bkduhO8Ch9CW0mDor3V9qcu2orsfftkt4Vqn1TaAx+dBR0FTumsCdfDaIoiLKTBIdxXYN2uD8+4Hn+SedI5HYL/1VfzfPIazmlAOh2rkaRtXvgx7uCtwWskZKUeOhljt8l5KKXiAwBVuVhZU0bK9aI6NPmktVpr8z2V/XgtCo3iwfz0sEXblRjV1Rs9E25QL2H4usJ41hCUsk/yhwV8Z9cOfBuweK4DUuKtjC2VD54FGDXMgx7pFWDn6obEm1HjxasnI5fUz9yM3ocBmkqiwTr3rmizObpcushzBJ44qsgoinP12hOhkzBmvsKAwvh5RGt+NA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=XK1cLDx6Xq4Pa7KAEXAzG6KDMbfPkr/rPHIGR/XkH3U=; b=EtQuP+GmAD6NR+1xMhSaxGjOdgLzJ3aC1VOoPd845KxuwnDtTFEG2uknTg4U9lXCAbFKeEPvNT+mG4Jo9JV9WKoi/vh4cZKza/lhiyFcTVWQMgpW3QHCpGXmcAztbiGhI9sEgJ4kxVTzh2Aia/yYBNPC7K8NGGC8z+0tXgTxZzee0hXSiB2mBVNpyj2zaW3MmEwmhkWAnzTttChygDdikgfchHbPWLtqDR6OPBT/lOAMS0/MbKEA0fclkQHJyNENIqnRNJjaqvV4HEo4XQalOwqurMR003i9UeZmcV759x2m6sVTK19naxkG2haF0qrTzDjVi59Ho657fPDDSs+CzQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=valinux.co.jp; dmarc=pass action=none header.from=valinux.co.jp; dkim=pass header.d=valinux.co.jp; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=valinux.co.jp; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XK1cLDx6Xq4Pa7KAEXAzG6KDMbfPkr/rPHIGR/XkH3U=; b=uNhgWhGDgIiPfXFuVYb5+OMGm7w6FP/LNvCRW2YLH56YVppLEqCOOI5lt1QaiLHq8T77zgss3PXYCkpOJW2nOYTnrQ0x322p3UvKAL/Ya4tr8w2VeY1Xp2sMH1xcqnOwxYjrpxhPVYWdDu0oNLhdXZZe4p9HZ8K5vvfzrFvczRI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=valinux.co.jp; From: Hirokazu Takahashi To: xen-devel@lists.xenproject.org Cc: Mykyta_Poturai@epam.com, Hirokazu Takahashi , Jan Beulich , Juergen Gross , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Michal Orzel , Julien Grall , Stefano Stabellini , Dario Faggioli , George Dunlap Subject: [PATCH v8 3/4] xen/sched: Make cpu_nr_siblings() architecture-specific Date: Sun, 26 Jul 2026 09:55:16 +0900 Message-ID: <20260726005517.379267-4-taka@valinux.co.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260726005517.379267-1-taka@valinux.co.jp> References: <20260726005517.379267-1-taka@valinux.co.jp> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: TYCP286CA0094.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:2b4::8) To OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:458::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OS9P286MB7222:EE_|OS7P286MB5490:EE_ X-MS-Office365-Filtering-Correlation-Id: 4e9984e9-eaad-4216-7747-08deeab09b13 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|23010399003|366016|7416014|376014|10070799003|56012099006|10067099003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: pG920k+kiZRMv9N9SXdahkt9c4g0ykzQJnbAOHNmRDDRNGFyJaedqOdWYOnHtBNz7i0Lj5T9JuP5KuZrwmxadmVu4HjKl2TUl862BWvpOKXgdjQGK4h8BNEFb4ww7bqj3eFu3ntZzvKE8QRNDeXM3/QSDjd7NiS/xHKc7OilwyEm2vk+P8p/3Mf0D/VH233zXSHFwSObs5GBe0N2Up35KJXhmpqn/33QfstVtd/Imx9wVNEtwmzVrfGqA2HIEokkpaaLln8cPWfEJIGn9XPFybSbnb4KfrXpQ333Mp6SYEEX8RbXqfn7Z4Iascji02MJcSDsiFZnt+bCPS9UE31kvj6NXMMIRO0vjJznu3fw9FknkPFeAspwuy2JtWYOpm70o9idf+V5H8eDkelT5Jn6eF4I57vNlAVzhGs2xg3rws79ADch0qCqQ0pbYxVq7mD6KyV7kzvEwv4Kr4qkBCrxxD0gUmy1uqziouvIhQh7LrZko/sl+93wNKUh50+OJqxGIn6bxEH12wNOmtPAFF4N7lTCpUge3J/KA5w+4bsZ3MkNiL5Od8rdQ1//v18k0PwZQTz6WOeCCxKOQVLlahwMGytvAATiFQecHkz72P7t8bdK/ZrD7uzs31tPVBckLxameV09GEh1DvjcqBw0jWtgwmpK85gQvZx29ioyBJWggcs= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(23010399003)(366016)(7416014)(376014)(10070799003)(56012099006)(10067099003)(18002099003)(22082099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?0Fo3gkpCQxCQu+dFya7UU7lt5de2nJMWpkoqI08578oDN4qVfqrMtqNQ0fqg?= =?us-ascii?Q?q6pJAR4Qcg1Fc6MiAyUJqQaCQYR3TW5edgRtjWV6aPLzFwHUb8FdoOjn9zlr?= =?us-ascii?Q?YOgzRYUIq4WmmVCdRjak85umrv2Yk+RgRzoBn5UD/1Yo0vxt9Z4rkCeGwk2g?= =?us-ascii?Q?si/UnOGiL0HhW2aYpndtow2Zzs/Trm6HSwcKLnrmE7kiDmBPLLVhDsnTJaGi?= =?us-ascii?Q?C9Pbd6eWST76gVf5By5REV9GCanfMndIpZhiBWfKQin/9T2WzidL3DPALQuJ?= =?us-ascii?Q?KoHsYAgzQmPuYJvj02v1NK21xCzg7YtAt+6YkVUBcFNhNkLGaPPe7Y8w7MRB?= =?us-ascii?Q?gVNc7VwRNOtA0/CidW70T2EFJAwUdxMQa27cidW9uhxqngt8dZXucrplrUY5?= =?us-ascii?Q?e4QSFKruzXKb6AK0MWuC7RZrHXnlhNQXL+h/y/Bh3eQKyUIgbi/R6Fe9Fq5K?= =?us-ascii?Q?zPsYQZxiHtilCZ3BL4Vwk7ZxdWp9dqptmqACtSHHJefDCunoSjJS4Nhxim4y?= =?us-ascii?Q?PDVOR29k1vwqxM62Xq9uGg9QWKtp33ZK9It1FXkckssrft6s4h848S7F4KM+?= =?us-ascii?Q?n/nW5akSffCJOHIHiYTfk+NO/+PnTREa22FV7HR/hwSfIVN1+hSikuhowzVR?= =?us-ascii?Q?TXlXhVKnAmHOwth1emchjOAI9/rKEYbdB6hOl16xmfyqTVVKbMY4oJhwidW4?= =?us-ascii?Q?wtT4XLWVNK9w0LbWGufI8clDuRF2Dh+mrekNdLIONn3KCUGxNVWdR0XmhEVb?= =?us-ascii?Q?SYPTFOc+VnUfPQU5RIkss3vH0HQ/JZBb3Dik14XSpwyJX4RmXxUPyqrkv5Fr?= =?us-ascii?Q?W847CjDBmQZlPqPDkh3uKLNMs1ZhWfcx2LVl38/AcV5d10l9zZVaFq280sbw?= =?us-ascii?Q?r0jVNpmwhTTPD5WDJqI0z9j8HbdBnwZ9ePizX+xHCgpyLQ7JdP4fuOK3QSQ9?= =?us-ascii?Q?6FobdWoL/e0ShZg7EDPpYTwdDOPc4YGqoe5jOV+PfNVyGb3gOtXJxVmgfQJW?= =?us-ascii?Q?BaaIfZPUtpwuOEpDtMLDyxtNUdO3klAn2QvVLzcVSeDpos2dSG/vS+eyF1Rg?= =?us-ascii?Q?lMy64BYgegrP7F3aMY4GIhXjEr1oGBSflWvp1Oqksy7bQIib/uzhkrliaKhl?= =?us-ascii?Q?xrdBmhGn9OcEO50ZqWYP+iPtC4CARzkKxbOZg0kUlGWF9/aDxCvzyZ6yXx1Y?= =?us-ascii?Q?+X8c7LntOuLKm7H0FwjJ3pVIPOOVA/0yrToQxgohwfm+I8hMEZ4pUp6a28NK?= =?us-ascii?Q?4Y1yMAWmwiY4BKbP0q9LfLPW2szoJq7EtjRhSowiQ+M0fBBoyGvAQEUJFV2k?= =?us-ascii?Q?nc8tCdZaeoOrwsaemtOaQcv1Lf35mZEkz/SbGy/+nKSY/O3qZlAvWJlbLLZD?= =?us-ascii?Q?FK9f4/8wQKQjIz/kWOzCXmTlhH0XKHNubKCS+xRsexMFvZ741l5qrocclysM?= =?us-ascii?Q?oifM/n8cOFhhg0qFc1CyXzqvAn9/EL14MVS7xxJcZmguXhQWnWB7EiDPPbam?= =?us-ascii?Q?KnY3QOfwyft5+1QZuGTvwext8fk1fgsDDwRfdNKjHjwbYl+ediC4pUgygxbB?= =?us-ascii?Q?TNJZBvaEMi170G43//UtykQe2RL85PrrwDXXI4FPyaDSG1z/bPUe9O0sgDoc?= =?us-ascii?Q?DYK/0vGX1kl9Gisf6lC8RxkjFsOBHiyt5CHdOeILekk11AqgO3FkpnGONtiw?= =?us-ascii?Q?AmD3pR3pN4t8Xoij3E/3IrU5gOVz5MPAbBdL7Yw0Fg19QRDYHiJsmcCGbJbd?= =?us-ascii?Q?A97wbYqv+PmxwymWUjSjHE9QbnBdEzswbCBjDsXQt/Uua65vdCT7GDPg+js2?= X-MS-Exchange-AntiSpam-MessageData-1: 5ZOdnMH54+Bb1w== X-OriginatorOrg: valinux.co.jp X-MS-Exchange-CrossTenant-Network-Message-Id: 4e9984e9-eaad-4216-7747-08deeab09b13 X-MS-Exchange-CrossTenant-AuthSource: OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jul 2026 00:55:37.0558 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 7a57bee8-f73d-4c5f-a4f7-d72c91c8c111 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: jRs3ZLiHDgktbz/9nVfPPmcUclKnLf7Y9/ytILe7di5nE6a7aAX0r40QDrke7ZkxiLZT1EzHuO7ycMGsV54yhw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: OS7P286MB5490 X-purgate-ID: tlsNG-c1860d/1785027341-D6D4087B-B97BB96C/0/0 X-purgate-type: clean X-purgate-size: 3435 X-ZohoMail-DKIM: pass (identity @valinux.co.jp) X-ZM-MESSAGEID: 1785027370975154100 Content-Type: text/plain; charset="utf-8" Make cpu_nr_siblings() an architecture-specific function. This patch provides the implementation for x86 and a common version for Device Tree-based architectures. Signed-off-by: Hirokazu Takahashi Acked-by: Jan Beulich Reviewed-by: Juergen Gross # scheduler part --- xen/arch/x86/include/asm/processor.h | 1 + xen/common/sched/credit2.c | 25 +++---------------------- xen/include/xen/cpu-topology.h | 5 +++++ 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/xen/arch/x86/include/asm/processor.h b/xen/arch/x86/include/as= m/processor.h index 8ca6799a81..9758060129 100644 --- a/xen/arch/x86/include/asm/processor.h +++ b/xen/arch/x86/include/asm/processor.h @@ -106,6 +106,7 @@ extern void intel_init_arat(void); =20 #define cpu_to_core(_cpu) (cpu_data[_cpu].cpu_core_id) #define cpu_to_socket(_cpu) (cpu_data[_cpu].phys_proc_id) +#define cpu_nr_siblings(_cpu) (cpu_data[_cpu].x86_num_siblings) =20 unsigned int apicid_to_socket(unsigned int apicid); =20 diff --git a/xen/common/sched/credit2.c b/xen/common/sched/credit2.c index b4a3b59601..6c645f0e21 100644 --- a/xen/common/sched/credit2.c +++ b/xen/common/sched/credit2.c @@ -29,25 +29,6 @@ /* #define d2printk printk */ #define d2printk(x...) =20 -/* - * TODO: Abstract this properly, and figure out what Credit2 wants to do w= ith - * the fact that x86_num_siblings doesn't even have the same meaning - * between x86 vendors. - */ -static unsigned int cpu_nr_siblings(unsigned int cpu) -{ -#ifdef CONFIG_GENERIC_CPU_TOPOLOGY - if ( cpu_topology ) - return cpu_topology[cpu].num_siblings; -#endif - -#ifdef CONFIG_X86 - return cpu_data[cpu].x86_num_siblings; -#else - return 1; -#endif -} - /* * Credit2 tracing events ("only" 512 available!). Check * include/public/trace.h for more details. @@ -885,9 +866,9 @@ cpu_runqueue_match(const struct csched2_runqueue_data *= rqd, unsigned int cpu) =20 /* * Additional checks, to avoid separating siblings in different runqueues. - * This deals with both Intel's HTs and AMD's CUs. An arch that does not h= ave - * any similar concept will just have cpu_nr_siblings() always return 1, a= nd - * setup the cpu_sibling_mask-s acordingly (as currently does ARM), and th= ings + * This deals with Intel's HTs, AMD's CUs and ARM's SMT. An arch that + * does not have similar concept will just have cpu_nr_siblings() always + * return 1, and setup the cpu_sibling_mask-s accordingly, and things * will just work as well. */ static bool diff --git a/xen/include/xen/cpu-topology.h b/xen/include/xen/cpu-topology.h index 52ee93d4d0..fccc9cd316 100644 --- a/xen/include/xen/cpu-topology.h +++ b/xen/include/xen/cpu-topology.h @@ -44,6 +44,7 @@ void init_cpu_topology(void); =20 #define cpu_to_core(cpu) (cpu_topology ? cpu_topology[cpu].phys_core_id : = 0) #define cpu_to_socket(cpu) (cpu_topology ? cpu_topology[cpu].phys_socket_i= d : 0) +#define cpu_nr_siblings(cpu) (cpu_topology ? cpu_topology[cpu].num_sibling= s : 1) =20 #else /* CONFIG_GENERIC_CPU_TOPOLOGY */ =20 @@ -57,6 +58,10 @@ static inline void init_cpu_topology(void) {} #define cpu_to_socket(cpu) (0) #endif =20 +#ifndef cpu_nr_siblings +#define cpu_nr_siblings(cpu) (1) +#endif + #endif /* CONFIG_GENERIC_CPU_TOPOLOGY */ =20 #endif /* XEN_CPU_TOPOLOGY_H */ --=20 2.43.0 From nobody Thu Sep 24 20:27:56 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=valinux.co.jp); dmarc=pass(p=none dis=none) header.from=valinux.co.jp ARC-Seal: i=2; a=rsa-sha256; t=1785027370; cv=pass; d=zohomail.com; s=zohoarc; b=OEYuzyE9oemA8bt6wY5IBIY6nzVdWwsw1Soh+Q5N0kTUYF+nOhVTtHxl53Z1kNCZoTSfBvML3zrHAMAiWIBhPsq9HaG0NONlmebu+Ch5o4VzfnE28Qw1j1PYbF/WW88uvqnSE159zXj8rCbeSK+2MPtaWVbhyMl+VLLi0PkQpfA= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1785027370; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=01BVibp9N+6FzbKMto0Oht3aSEyswKGmnDSZws9+QRs=; b=WdvB19rrb6H+1ckAnRDnpl/bBQ/Im3mQdtW+Pw9wCH1W3HbyD0eplPPv4HoMdTpyZzFttqBSONClQN8CGbAtgwXumExx5SkhTMcgto9+rqbi+q7n1xA1XVlpdpvcc1IvHMr+ad7TLusRXkSd/+L+KmF0jk9iJPCGDEUyzKGH+5k= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=valinux.co.jp); dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1785027370948527.2513893685057; Sat, 25 Jul 2026 17:56:10 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1370884.1618783 (Exim 4.92) (envelope-from ) id 1wnn9g-0007gM-QW; Sun, 26 Jul 2026 00:55:48 +0000 Received: by outflank-mailman (output) from mailman id 1370884.1618783; Sun, 26 Jul 2026 00:55:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wnn9g-0007gF-Mi; Sun, 26 Jul 2026 00:55:48 +0000 Received: by outflank-mailman (input) for mailman id 1370884; Sun, 26 Jul 2026 00:55:47 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wnn9e-0007ch-UO for xen-devel@lists.xenproject.org; Sun, 26 Jul 2026 00:55:47 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wnn9e-007Oo9-BN for xen-devel@lists.xenproject.org; Sun, 26 Jul 2026 02:55:46 +0200 Received: from [10.42.69.11] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a65598d-e002-0a2a0a5209dd-0a2a450bc172-30 for ; Sun, 26 Jul 2026 02:55:46 +0200 Received: from [52.101.125.142] (helo=TYVP286CU001.outbound.protection.outlook.com) by tlsNG-42698a.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a655b0f-b7e8-0a2a450b0019-34657d8e44af-3 for ; Sun, 26 Jul 2026 02:55:45 +0200 Received: from OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:458::18) by OS7P286MB5490.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:397::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.245.12; Sun, 26 Jul 2026 00:55:41 +0000 Received: from OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM ([fe80::c8c9:25cd:8d13:96d6]) by OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM ([fe80::c8c9:25cd:8d13:96d6%6]) with mapi id 15.21.0245.012; Sun, 26 Jul 2026 00:55:41 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=valinux.co.jp header.i="@valinux.co.jp" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ah42GzXthYp/knocBHPsbAHIjJe94fKskPW3Ye9+crgW6fXcxAfG4XZPEG/l8OsB0X1Zkw53zW40g6V0ofQpHukZ7GBBjEyro+vDI/boOF/7OKn7SLJMxW2BUXcH6TJyFpmKzrD0GajE3Ai7y9gyYAkkw9LTgOna2aLcH3UIAMB1BXENs4paflM3xz5Nvkov2GD/FBEJI1c5uA5W76RaYAAv/5LDSeNVPev8LlJkQaBq3pI4GKm1AONLQer5N3T1dcaZI13QqWcuOVw1a8r5AeyeH9/zONGBTTLM9mAIF7wsgXz3lRKrHx9P4gpU7j/BAA/kxFTMjoy7P+WSKnlwkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=01BVibp9N+6FzbKMto0Oht3aSEyswKGmnDSZws9+QRs=; b=YF3q9VqsZYYVUqkg5rtvSUihAIlKu7ch8kp+2IncvX3EW1RfKN82wpH3GOd9oYlnMqv3TJ9j9uvNHbbqRD0ExDgceq63ZAqiUiARuecqBFbja8cMgGzWIPdxg+j1MNxyiNlSZaJj2H4CF1nyHMG+89T4NikaZNbne275jjpRF1VtDEuwcGOCnKdYQcQ9UjGGcmohZCxlF3TFRZLRrueqk2tnwdnGXIEKOAzzah04KFPNPsAIlpTL9BD3btrUxfagX6orxa54IJhfKZZfFPQ3a0gWgQtAtn3/ds9LJOMt4kF7cPIBt4qWV4O8v/IoX2qKc44AABOnBT98AKmqHyGgTw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=valinux.co.jp; dmarc=pass action=none header.from=valinux.co.jp; dkim=pass header.d=valinux.co.jp; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=valinux.co.jp; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=01BVibp9N+6FzbKMto0Oht3aSEyswKGmnDSZws9+QRs=; b=fT7Ub2TOCFtzR0bdz2txEL+4x5aK7ozmmrY2u6IXRqP2pRCZl6yMunGEYA2f1dOzrRSVRMsrvPfpT/k4nSgrD+23Wy2UQTYTT1GXTI7gXtfChByK8NnoP6T/XtnqxI6fWj81xCIzYxHVKHEVm88AFE2aYH0GvJMHFcidNykQNTo= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=valinux.co.jp; From: Hirokazu Takahashi To: xen-devel@lists.xenproject.org Cc: Mykyta_Poturai@epam.com, Hirokazu Takahashi , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , Anthony PERARD , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie Subject: [PATCH v8 4/4] xen/acpi: Parse PPTT to initialize CPU topology Date: Sun, 26 Jul 2026 09:55:17 +0900 Message-ID: <20260726005517.379267-5-taka@valinux.co.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260726005517.379267-1-taka@valinux.co.jp> References: <20260726005517.379267-1-taka@valinux.co.jp> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: TYCP286CA0101.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:2b4::14) To OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:458::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OS9P286MB7222:EE_|OS7P286MB5490:EE_ X-MS-Office365-Filtering-Correlation-Id: ce6cb3b6-5a7c-46e4-fc6f-08deeab09dcb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|23010399003|366016|7416014|376014|10070799003|56012099006|10067099003|6133799003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: ri0YG0hUyWtNm+eSCrZl/moSFuvMrOzbUDsb7tm9zqIbOJiS/SPTV6llTuZ4flgBNheHJK50FvykPZ8Geow63W1hBJi+2F/PYKDWVXG1V2NnlFGLY8Azqwq5BmSJFekR7dwyFPBVzZSkHLUhkwXLMr3FDoTKdgktxMcZi+Ruear+Q4jNobDPSvAv/OiOB6UXeVIypdmH0/BAn5a9rmi/9hJBNT67A8ixa9PUaLOug5NxttbFxDP0768elCRF+fikQW7uMof/n3+ADXDGPSJWLmy6MaYIHNkal3ZdfGHFeCAbbMyyK+CUPnJUdpFXopkZtOzSfCxesxgkMGBG1uVvf8Zwnd4b6v+cjoIVUf3cq4erhW0UU7qGiXgFgC+Us+q3SJqmYowBiEHy1/VxRqmhlcVc2cDSlTrWJXU1WxZncrb1n21hFvSqj0f2PnsJpMs0ei+BBBVWKDCRd8B8ygdcmBvzmLHi8vFW0KhE0u+M4PRuxjKtCaOysh5oORHCHHo2gHzVgbOaGmytDao8WO/U4hr/yWoQ7Yf0WN3SVvV+j9dTuP7QLcKIbTmBcn4iKjN1j4JE68YqtcZvuJyv6UjfDv+EYhAOkNc0pO0jfNupJGM+aVsNowRkHVO4M/dWTO+6uHy0KKIUpgzZ2qHyrWfqI7+9AFV1u295kWuZ8BUK6H8= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(23010399003)(366016)(7416014)(376014)(10070799003)(56012099006)(10067099003)(6133799003)(18002099003)(22082099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?Ja+cLe5JSr4P2HtayO+FneS9bN9mfM+SHy1siH1XK9hVGi83lyCZTMS/4bja?= =?us-ascii?Q?OQkLP/4++OVzo1yE/Dy5Xw2Belq9QilFrMIAXWLU1qQ3yH2ErrgXnUzQKH6/?= =?us-ascii?Q?afjeQU3WSiMSKcecgMJzOF4GuZ6zl3GL0uas6L/Fp8WUrg9By+4ZldNNuOqX?= =?us-ascii?Q?WYiS5OfzDscsStxpi1oG80g5HI4bbuW3WrVVut/4Qt1xRXT05O2xyIRHHUDL?= =?us-ascii?Q?HIJXHM4RXAULvQJuSQXQtcNqeklx/s3ELbXAodnWS7XWOyhTTy57ljGXMofX?= =?us-ascii?Q?hY/32P5kaSiYxCNUySv5EM26mcQE+XNTZv6g7TI6zCAIZYRQgyDDPi8ufs6+?= =?us-ascii?Q?wNpjSMpzYPMrKvhi9OiC0IqygD+BNpir735F4D5kF6ivsTRqQIek97zRcxMK?= =?us-ascii?Q?F+EKpegwdzaOyt6zWgPNAop97zd1WjK0N0hEjrRcxhtMZh14KwEE6VkOsa1G?= =?us-ascii?Q?uVQA+Xg7tcR/MrReu5G1eg2hyI48whlHmjFNObMo27j/TD9x9RYaj3RZt/kL?= =?us-ascii?Q?NMY1uqdnpysK8jD45K29B0luU0ljBr0oZXgramb2NMuSCdiUrFNhVSOYDlpe?= =?us-ascii?Q?Bv1K9BtR4z6i0Hwj+/C4P2pRJESN2QhzGsYCmSbEC2qBQufLXukK4wIQU3nW?= =?us-ascii?Q?9eWNtaeorpAryZbpGfKOjGbNP7RiVms1S7ql6iRpbeAAJaTw9tVtJUNk7JT6?= =?us-ascii?Q?F0cBEvQZm8QYxCOyPZg28JnYBX5qgIvZQnNw7JeeL0sSIAce+oJb595zS5HG?= =?us-ascii?Q?vADEUaHkN+yhqRSS2RvxRLdoyLQRmavw9/d/DFX6U4AE3Gz5bjmgiEICdGHp?= =?us-ascii?Q?T2d+ZxCdW+Tr5wTtYV6C4Q9JIHq7gxprzSeWinWD06oMcMuqIPyg2uzCWDIx?= =?us-ascii?Q?gQlAgogAQmIbs5EbAh5NjW2KOd5gn1YioVwlNdLOPJUPXzWXdkeXwAgweomM?= =?us-ascii?Q?SeqPNc84tLx4AjBQr0u9SFzerktm9IgLg5mSJTdeQW+CCVowA50y5uByFcBV?= =?us-ascii?Q?kOwzepxSF8P2YDUJ8hytFViMflIAi7Sg1ATqEb49VFpjA59Q1kqcnZThAg5Z?= =?us-ascii?Q?DH2igaAPstGMVlTYUr8oqH/vZ0vI+vAoaME95OTohls2QycgFgdZ3ZXOkhV3?= =?us-ascii?Q?lPWGCzOxgg6ShTflH2YA8jE5kFsfSSpfqYgt+BvdLVcGD8h++UEfgRffMibf?= =?us-ascii?Q?pghMr5J+YsGHy+gxvejfIxuENOvWBjnCiCV6YGfOu/9X+7WHXFYrCMjUszmG?= =?us-ascii?Q?lrCGYWPhCNMgbIPKH+EiqXzUeh1BVQ7+SvgOfOagm88SgH5CpR4nkvOQ4Gb7?= =?us-ascii?Q?ufXnMGYGDrrkRSSKebmoXCLylMeNS6HA43UOiVt1CSKg9Y6RNnIv0Us7w6wC?= =?us-ascii?Q?/6bv3Tfqai9K8/bHTm0rHcY2woK7pn1Ucr3fnWCRxTcaqGg5xh9ipsDF5IKQ?= =?us-ascii?Q?iUQA/8UEhK/afcuRQ4dCkZqFc9CaRz8jc1KM131tJMWLj+GvgndccsWlSCLg?= =?us-ascii?Q?aClFVPvGHBGSb4nTvaUEzW74fDWCZXbL7KIPTk2BpN5Ih9mhYuequm8i3TBi?= =?us-ascii?Q?+ZOl+9dYx03dXPSHOUbxuJSsDTpLDmMHzR4PCM2TDH3/Axnp2ec1a8Lpy2OZ?= =?us-ascii?Q?kglFeOxABel4z/RmiVwME6Yls0L6cAfsqpVjFWURZYpF/ZcOuSikeeNnAU3q?= =?us-ascii?Q?lv1TmP++NNk79WoYndgQnGnIrextE5i1x5EtJv6WinyOv+ozG2QGXO/XboIJ?= =?us-ascii?Q?e8OUBsaDaTLneH29/3zGjCD00LhiaA5CDQzkm1j18O9woKPN6gGgTE8BbLJW?= X-MS-Exchange-AntiSpam-MessageData-1: A5G5evQY9PTdtw== X-OriginatorOrg: valinux.co.jp X-MS-Exchange-CrossTenant-Network-Message-Id: ce6cb3b6-5a7c-46e4-fc6f-08deeab09dcb X-MS-Exchange-CrossTenant-AuthSource: OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jul 2026 00:55:41.6370 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 7a57bee8-f73d-4c5f-a4f7-d72c91c8c111 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: AelQKnLJ2zwI5AqncoRoEviK41Z/zok31SOxT2NIc2qmYt5J5dxxK30q7BJUS5OYnTGrlY0peKCzPTqWJmDOHQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: OS7P286MB5490 X-purgate-ID: tlsNG-42698a/1785027346-1ACDF9EA-6CA06AF7/0/0 X-purgate-type: clean X-purgate-size: 14306 X-ZohoMail-DKIM: pass (identity @valinux.co.jp) X-ZM-MESSAGEID: 1785027373146154100 Content-Type: text/plain; charset="utf-8" Parse the ACPI PPTT (Processor Properties Topology Table) to initialize the CPU topology. For ACPI 6.3 and later, the ACPI_PPTT_ACPI_PROCESSOR_IS_THREAD flag is checked to determine the presence of threading. For ACPI 6.2 and earlier, CPUs are assumed not to support threading. Signed-off-by: Hirokazu Takahashi --- Changes in v8: * Relaxed processor node length check to allow proc->header.length >=3D table_size. * Treated root nodes (nodes with parent =3D=3D 0) as equivalent to ACPI_PPTT_PHYSICAL_PACKAGE nodes. * Moved INVALID_ACPIID definition to xen/acpi.h to make it available cross-architecture. * Removed ARM-specific references from comments in architecture-agnostic code. * Added explicit parentheses around bitwise operations in logical expressions. * Placed binary logical operators (||, &&) at the end of lines when splitting conditional statements. * Combined variable declarations and initializations where appropriate. * Removed trailing full stops ('.') from printk log messages. * Fixed printk format specifier mix-up. xen/arch/arm/acpi/boot.c | 2 + xen/arch/x86/include/asm/acpi.h | 2 - xen/drivers/acpi/topology.c | 308 ++++++++++++++++++++++++++++++-- xen/include/xen/acpi.h | 4 + 4 files changed, 301 insertions(+), 15 deletions(-) diff --git a/xen/arch/arm/acpi/boot.c b/xen/arch/arm/acpi/boot.c index 4ac0fd8f51..fc7ecb5749 100644 --- a/xen/arch/arm/acpi/boot.c +++ b/xen/arch/arm/acpi/boot.c @@ -85,6 +85,7 @@ acpi_map_gic_cpu_interface(struct acpi_madt_generic_inter= rupt *processor) return; } bootcpu_valid =3D true; + acpi_map_cpu_acpiid(0, processor->uid); return; } =20 @@ -119,6 +120,7 @@ acpi_map_gic_cpu_interface(struct acpi_madt_generic_int= errupt *processor) =20 /* map the logical cpu id to cpu MPIDR */ cpu_logical_map(enabled_cpus) =3D mpidr; + acpi_map_cpu_acpiid(enabled_cpus, processor->uid); =20 enabled_cpus++; } diff --git a/xen/arch/x86/include/asm/acpi.h b/xen/arch/x86/include/asm/acp= i.h index 217819dd61..7a89baa143 100644 --- a/xen/arch/x86/include/asm/acpi.h +++ b/xen/arch/x86/include/asm/acpi.h @@ -132,8 +132,6 @@ struct acpi_sleep_info { extern u32 x86_acpiid_to_apicid[]; #define MAX_LOCAL_APIC MAX(256, 4 * NR_CPUS) =20 -#define INVALID_ACPIID (-1U) - extern u32 pmtmr_ioport; extern unsigned int pmtmr_width; =20 diff --git a/xen/drivers/acpi/topology.c b/xen/drivers/acpi/topology.c index 56fcfa4945..8dd397cc4d 100644 --- a/xen/drivers/acpi/topology.c +++ b/xen/drivers/acpi/topology.c @@ -4,33 +4,315 @@ #include #include #include +#include + +#define ACPI_PPTT_MAX_LEVELS 16 + +static uint32_t __initdata map_cpu_acpiid[NR_CPUS] =3D { + [0 ... NR_CPUS - 1] =3D INVALID_ACPIID +}; =20 /* - * TODO: Populate the topology information by scanning the ACPI - * PPTT (Processor Properties Topology Table). + * The first argument 'cpu' is the logical CPU ID assigned by Xen, + * and the second argument 'acpi_id' the 32-bit ACPI processor ID. */ -int __init acpi_init_cpu_topology(void) +void __init acpi_map_cpu_acpiid(unsigned int cpu, uint32_t acpi_id) { - unsigned int cpu; + map_cpu_acpiid[cpu] =3D acpi_id; +} + +static unsigned int __init get_logical_id(unsigned int key, + unsigned int *map, + unsigned int *count) +{ + unsigned int id; + + for ( id =3D 0; id < *count; id++ ) + if ( map[id] =3D=3D key ) + return id; + + map[*count] =3D key; + + return (*count)++; +} + +static bool __init verify_subtable(const struct acpi_subtable_header *entr= y, + const struct acpi_table_pptt *pptt) +{ + unsigned long table_end =3D (unsigned long)pptt + pptt->header.length; + + if ( entry->length < sizeof(*entry) || (entry->length & 3) ) + { + printk(XENLOG_ERR "ACPI: PPTT subtable length is invalid\n"); + return false; + } + + if ( (unsigned long)entry + entry->length > table_end ) + { + printk(XENLOG_ERR "ACPI: PPTT subtable extends beyond table end\n"= ); + return false; + } + + return true; +} + +static bool __init verify_proc(const struct acpi_pptt_processor *proc) +{ + unsigned long table_size; + + if ( proc->header.length < sizeof(*proc) ) + { + printk(XENLOG_ERR "ACPI: PPTT processor node length is too small\n= "); + return false; + } =20 /* - * Generate temporary cpu topology information for now. - * It assumes that the cpu doesn't have SMT and all CPUs - * belong to the same socket. + * Each private resource is represented by a 32-bit resource ID. + * Ensure the structure length accurately accounts for the trailing ar= ray. */ + table_size =3D sizeof(*proc) + + (unsigned long)proc->number_of_priv_resources * sizeof(uint32_t); + + if ( proc->header.length < table_size ) + { + printk(XENLOG_ERR "ACPI: PPTT processor node length invalid\n"); + return false; + } + + return true; +} + +static const struct acpi_pptt_processor *__init find_pptt_node( + const struct acpi_table_pptt *pptt, uint32_t acpi_id) +{ + const struct acpi_subtable_header *entry; + unsigned long table_end =3D (unsigned long)pptt + pptt->header.length; + const void *ptr =3D pptt + 1; + + while ( (unsigned long)ptr + sizeof(*entry) <=3D table_end ) + { + entry =3D ptr; + + if ( !verify_subtable(entry, pptt) ) + break; + + if ( entry->type =3D=3D ACPI_PPTT_TYPE_PROCESSOR ) + { + const struct acpi_pptt_processor *proc; + + proc =3D container_of(entry, const struct acpi_pptt_processor, + header); + + if ( !verify_proc(proc) ) + break; + + /* + * Leaf node verification is only required for ACPI 6.3 + * (PPTT revision 2) or later. + */ + if ( (proc->flags & ACPI_PPTT_ACPI_PROCESSOR_ID_VALID) && + proc->acpi_processor_id =3D=3D acpi_id && + (pptt->header.revision < 2 || + (proc->flags & ACPI_PPTT_ACPI_LEAF_NODE)) ) + return proc; + } + + ptr +=3D entry->length; + } + + return NULL; +} + +/* + * Populate the topology information by scanning the ACPI PPTT + * (Processor Properties Topology Table). + */ +int __init acpi_init_cpu_topology(void) +{ + acpi_status status; + struct acpi_table_header *table_header; + const struct acpi_table_pptt *pptt; + unsigned int num_sockets =3D 0; + unsigned int num_clusters =3D 0; + unsigned int num_cores =3D 0; + unsigned int *socket_map =3D xvzalloc_array(unsigned int, nr_cpu_ids); + unsigned int *cluster_map =3D xvzalloc_array(unsigned int, nr_cpu_ids); + unsigned int *core_map =3D xvzalloc_array(unsigned int, nr_cpu_ids); + unsigned int cpu; + int ret =3D 0; + + status =3D acpi_get_table(ACPI_SIG_PPTT, 0, &table_header); + if ( ACPI_FAILURE(status) ) + { + /* A missing PPTT is benign; fall back to the default topology. */ + ret =3D -ENODEV; + goto out; + } + + if ( !socket_map || !cluster_map || !core_map ) + { + printk(XENLOG_ERR + "ACPI: Failed to allocate memory for topology parsing\n"); + ret =3D -ENOMEM; + goto out; + } + + pptt =3D container_of(table_header, const struct acpi_table_pptt, head= er); + + for_each_possible_cpu(cpu) + { + uint32_t acpi_id =3D map_cpu_acpiid[cpu]; + struct cpu_topology *topo =3D &cpu_topology[cpu]; + const struct acpi_pptt_processor *proc; + unsigned int level; + unsigned int core_group_key =3D 0; + unsigned int cluster_group_key =3D 0; + unsigned int socket_group_key =3D 0; + bool threading =3D false; + + proc =3D find_pptt_node(pptt, acpi_id); + if ( !proc ) + { + printk(XENLOG_WARNING + "ACPI: No PPTT leaf node for CPU %u (ACPI ID %#x)\n", + cpu, acpi_id); + ret =3D -ENOENT; + goto out; + } + + /* + * Limit the maximum loop depth to prevent an infinite loop in case + * the PPTT is corrupted or contains cyclic references. + */ + for ( level =3D 0; level < ACPI_PPTT_MAX_LEVELS; level++ ) + { + const unsigned int offset =3D (const void *)proc - (const void= *)pptt; + + /* + * If this proc has no parent node, it is the root node. Treat= it + * as equivalent to an ACPI_PPTT_PHYSICAL_PACKAGE node. + */ + if ( proc->flags & ACPI_PPTT_PHYSICAL_PACKAGE || !proc->parent= ) + { + socket_group_key =3D offset; + + /* + * If cluster/core info is absent upon reaching the physic= al + * package, assume one cluster per socket and one core per + * cluster. + */ + if ( cluster_group_key =3D=3D 0 ) + cluster_group_key =3D socket_group_key; + + if ( core_group_key =3D=3D 0 ) + core_group_key =3D cluster_group_key; + + break; + } + else if ( level =3D=3D 0 ) + { + /* + * ACPI_PPTT_PROCESSOR_IS_THREAD is supported in PPTT + * revision 2 and later. Assume no threading support when + * PPTT revision is 1. + */ + if ( proc->flags & ACPI_PPTT_ACPI_PROCESSOR_IS_THREAD ) + threading =3D true; + else + core_group_key =3D offset; + } + else if ( level =3D=3D 1 ) + { + if ( threading ) + core_group_key =3D offset; + else + cluster_group_key =3D offset; + } + else if ( level =3D=3D 2 && threading ) + cluster_group_key =3D offset; + + if ( (proc->parent & 3) || + proc->parent < sizeof(*pptt) || + proc->parent > pptt->header.length - sizeof(*proc) || + (proc->parent + sizeof(*proc) > offset && + proc->parent < offset + proc->header.length) ) + { + printk(XENLOG_WARNING + "ACPI: PPTT parent offset is invalid\n"); + break; + } + + proc =3D (const void *)pptt + proc->parent; + + if ( proc->header.type !=3D ACPI_PPTT_TYPE_PROCESSOR ) + { + printk(XENLOG_WARNING + "ACPI: PPTT parent node is not a processor structur= e\n"); + break; + } + + if ( !verify_subtable(&proc->header, pptt) || + !verify_proc(proc) ) + break; + } + + if ( socket_group_key =3D=3D 0 ) + { + printk(XENLOG_WARNING + "ACPI: Could not reach the physical package node for CP= U %u (ACPI ID %#x)\n", + cpu, acpi_id); + ret =3D -ENOENT; + goto out; + } + + topo->phys_socket_id =3D + get_logical_id(socket_group_key, socket_map, &num_sockets); + topo->phys_cluster_id =3D + get_logical_id(cluster_group_key, cluster_map, &num_clusters); + topo->phys_core_id =3D + get_logical_id(core_group_key, core_map, &num_cores); + } + for_each_possible_cpu(cpu) { struct cpu_topology *topo =3D &cpu_topology[cpu]; + unsigned int tcpu; =20 - topo->phys_core_id =3D cpu; - topo->num_siblings =3D 1; + for_each_possible_cpu(tcpu) + { + struct cpu_topology *ttopo =3D &cpu_topology[tcpu]; =20 - cpumask_set_cpu(cpu, topo->thread_sibling); - cpumask_copy(topo->core_sibling, &cpu_possible_map); - cpumask_copy(topo->cluster_sibling, &cpu_possible_map); + if ( cpu > tcpu ) + continue; + + if ( topo->phys_core_id =3D=3D ttopo->phys_core_id ) + { + cpumask_set_cpu(tcpu, topo->thread_sibling); + cpumask_set_cpu(cpu, ttopo->thread_sibling); + } + + if ( topo->phys_cluster_id =3D=3D ttopo->phys_cluster_id ) + { + cpumask_set_cpu(tcpu, topo->cluster_sibling); + cpumask_set_cpu(cpu, ttopo->cluster_sibling); + } + + if ( topo->phys_socket_id =3D=3D ttopo->phys_socket_id ) + { + cpumask_set_cpu(tcpu, topo->core_sibling); + cpumask_set_cpu(cpu, ttopo->core_sibling); + } + } + + topo->num_siblings =3D cpumask_weight(topo->thread_sibling); } =20 - return 0; + out: + xvfree(socket_map); + xvfree(cluster_map); + xvfree(core_map); + + return ret; } =20 /* diff --git a/xen/include/xen/acpi.h b/xen/include/xen/acpi.h index cbb02e0f35..9788586be4 100644 --- a/xen/include/xen/acpi.h +++ b/xen/include/xen/acpi.h @@ -52,6 +52,8 @@ (!(entry)) || (unsigned long)(entry) + sizeof(*(entry)) > = (end) || \ (entry)->header.length < sizeof(*(entry))) =20 +#define INVALID_ACPIID (-1U) + #ifdef CONFIG_ACPI =20 #include @@ -137,10 +139,12 @@ static inline int acpi_boot_table_init(void) =20 #ifdef CONFIG_ACPI_CPU_TOPOLOGY =20 +void acpi_map_cpu_acpiid(unsigned int cpu, uint32_t acpi_id); int acpi_init_cpu_topology(void); =20 #else /* CONFIG_ACPI_CPU_TOPOLOGY */ =20 +static inline void acpi_map_cpu_acpiid(unsigned int cpu, uint32_t acpi_id)= {} static inline int acpi_init_cpu_topology(void) { return -EOPNOTSUPP; --=20 2.43.0