From nobody Thu Sep 24 20:54:09 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=1785215249; cv=pass; d=zohomail.com; s=zohoarc; b=akfCxaCnhuctSkcntvHhsxiYeItYDATSTmROKO3F+5xgQeB/7q1n2izpRIFFemqA3L6+JFpfGUTfsmNVn8v+/SDQH2fEYPGewA1nU3vbPmZWIhK5hZU9vqZj5TGeGN8OQ9vzf4uRdyNCHDFKZiJwQplBlOtEnihlAjrKFVU8gXQ= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1785215249; 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=nVzP9NhYns4rOlfOqDWENUFJy13P4GQAm4eByiwt3dA=; b=h8kM2m4J/SeSlnlhVKtnu3/v6uL0CPJZcl3CyHQj1sqQkRK7DPnyn4L/r0ECXb0RERIWzLTCuVk3xsYWRUBEtuaVp/SHb9XB7em8kERCPfnETi52/KJFNP6DxgP+3o7aZtX9Mff8DF2e9vAYPRzrnEVrr7gzrzSZ/yTBMULozXQ= 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 1785215249469464.82832031462794; Mon, 27 Jul 2026 22:07:29 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1372049.1619446 (Exim 4.92) (envelope-from ) id 1woa1r-0000c4-Az; Tue, 28 Jul 2026 05:06:59 +0000 Received: by outflank-mailman (output) from mailman id 1372049.1619446; Tue, 28 Jul 2026 05:06:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1woa1r-0000bn-7Z; Tue, 28 Jul 2026 05:06:59 +0000 Received: by outflank-mailman (input) for mailman id 1372049; Tue, 28 Jul 2026 05:06:57 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1woa1p-0000Z0-8l for xen-devel@lists.xenproject.org; Tue, 28 Jul 2026 05:06:57 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1woa1o-00Fj7M-M2 for xen-devel@lists.xenproject.org; Tue, 28 Jul 2026 07:06:56 +0200 Received: from [10.42.69.4] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a6838ed-bab6-0a2a0a5309dd-0a2a4504d6a2-4 for ; Tue, 28 Jul 2026 07:06:55 +0200 Received: from [52.101.125.79] (helo=TYVP286CU001.outbound.protection.outlook.com) by tlsNG-ebf023.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a6838ea-b57f-0a2a45040019-34657d4f8021-4 for ; Tue, 28 Jul 2026 07:06:55 +0200 Received: from OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:458::18) by TY1P286MB3277.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:2e5::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.245.13; Tue, 28 Jul 2026 05:06:50 +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; Tue, 28 Jul 2026 05:06:50 +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=tcYnf959EAQ5anKA9Pnq8EIlevcB95riZDvrxLcibbb3f+vRBoZbJbnHyYHvUdhEIf4GRneqJ+KiF6r7FzMscQlwBwRmOpqRpPeUCcGwzbfqxWyIUmGjKJqrUeg0HQPo8Wqug6sQJXc7K62z1ijMqTBEfskAsVSnC0zziEtuM6uq3XlAIoR0BDi9CnnFjbDxe/cy5lY6DF/W6wjzCCnw007pH5r4QxOVJulXsl1UNYeK2kB2m+hl1yB1my7qxClaETH6yTtnDy8jc9M70VHOBS+431oggGmQIqxx228Gs5fa8fz/qEdgpVENJzFn2Fg5sZerEC7gDCY7GrXUWATupw== 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=nVzP9NhYns4rOlfOqDWENUFJy13P4GQAm4eByiwt3dA=; b=exX5rFFIDFGoW5siSDnZY1HqhtwS6LdLOE8+SUgbikK7DuPc4In4hpoP0kRBpzl1ytJPe8CJnMSVPdzTzm7JrKXVaePMR43R0hvazyimqwmpaWJ9DqVpKcLiplZkNjVob4JnLaC2lWrN2VFqReKlNXenyXVw9cN8/u6xF790pZbu+0tT9ugmhh/qZUKTgIiCpEj5aqpS+XRSYoHWkWB6qaavrVLfuaOJ3qz4YO2gRVeaO4MnsbKDwJvTMmQGzBTxzMREhtyaG0oUCVD0Nrwusr2Xw8y2jG1e2jRa8xEky3V0Ae+WyIlRNWmBMPoSsQ/xVmXy3F9g6re0Cw+0Q3Hypg== 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=nVzP9NhYns4rOlfOqDWENUFJy13P4GQAm4eByiwt3dA=; b=DJ2f/jqxnR2Lw3UoeosTzC1gdiAH67gxaagkRCqkj7dAQNyiXdbMo4Um1icFq0n1crOMW/sC0KxZgj6IPudwToeoNruwdlsvTRGAPLlO7J7fsxBrLQb2Up09CFwW6EeWTzIA1S8sNFey0XcaglhE0ZQFs8NeacJ9J5LYBMedMSE= 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 v9 1/4] xen/device-tree: Parse 'cpu-map' node for CPU topology exploration Date: Tue, 28 Jul 2026 14:06:39 +0900 Message-ID: <20260728050642.411240-2-taka@valinux.co.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260728050642.411240-1-taka@valinux.co.jp> References: <20260728050642.411240-1-taka@valinux.co.jp> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: TYCPR01CA0160.jpnprd01.prod.outlook.com (2603:1096:400:2b1::13) To OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:458::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OS9P286MB7222:EE_|TY1P286MB3277:EE_ X-MS-Office365-Filtering-Correlation-Id: 6fff4abc-a94e-4053-990e-08deec66087f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|366016|10070799003|23010399003|1800799024|6133799003|18002099003|22082099003|56012099006|10067099003; X-Microsoft-Antispam-Message-Info: vm63xZAqD1ol/SM2DJOO7jOfMRGKgAzd5DgMsf9YwJVQk5Nemdpe15jDsMBeMXIyTX2zy1SjUtOqCujNqmWvr+lLMDxAFXkSRY989qbbH/oOwPRSqrmLoY/SiPSUr+k+xZHnDkmwnj4v6/HtqR10uan022l6AesyeDWlmkGekYcoVbf3EI2agQTMNNzAxd9i8lYhf3/FiPrAprbhD0rcTuYkk8MXv2DWbVOUHzX0Z31fsgm2bEyKb11XebJcVcq/lke1sIc6oY3vUWWvb7FDRB31EfajOjgwgJICekoSL6aKtYBPvJWXUpC4jG2TeAQNroabppZqFJVxqXgn9PwdOfiRJnJIvMoiIds72UrFBvwQ8EzuYWvKUgpPgRogThuZInt/NWBNeZqI89EFS0DFc1Q0PKtgrQiFM2ne6YQjxqLSCdeQCNhUNJZ4QCz0E7s0SQVWFJkDH9SQ1kxrTHUXTadRCkz5UGYrmisygQs6AoNIUrzesNfXwcJR/aFKRe98synu83YjMnakRPE2w5ThxnCwB9a6OJ5bhhyfsAUzRWrgqKXR+Ax/tU5FcKK7Cb8JDETwV3l/R9bguaD9rqBib1flCrI3cJnbABKQMbUBpzcdn6Z7G/1RFEe7YIqIFOgByGkOTXo/7IV+ZtdLPww2NUDAMWOy7V8pI6UraYfMVls= 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)(376014)(7416014)(366016)(10070799003)(23010399003)(1800799024)(6133799003)(18002099003)(22082099003)(56012099006)(10067099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?gUSY1AoD0zEiPxNfTZk52QYsHwp0ucO+rvolr7dyh10mVmQZGLfJ1vJr0miU?= =?us-ascii?Q?L5rteoTAbeZsftfE2+pgMvkIloMUNpB0i+IhBrylc/Opdgam1bIDXpXc7/nH?= =?us-ascii?Q?zM3ZKl9eWmbDmWUShrNB051CkAuULAICZzUNvxeZ7pqoQTlLBdW14wsSQttu?= =?us-ascii?Q?AeZOeBldV2zG/0meWg0pQp0HCN31a7idjhVr0tzxYnnNuqt/OKMW/mJYv+mH?= =?us-ascii?Q?0TLcTZDIJcAb82V4oF2qZJuXH8EyblI2s9zmSxLsoOOgBUzjmtiQkMdFRKKy?= =?us-ascii?Q?1c4lVeXTK4Wh7bLCn/MGtMQxCyd2SMKgXKQ6PrG+oxC/38CFd3LILr3MdTtq?= =?us-ascii?Q?8Ib4E8bBwMUgwVlt8SGzGEVu/ClpsfevvPzzzi74nsEDuXel4GUPqmSss2J4?= =?us-ascii?Q?CmaWNHjnc8R7ex3UxuRXPVhg2UfUaFfuPp/teUc8+P3U9HBElKcwf/yiYegT?= =?us-ascii?Q?4hd3/xciALdilg0iZQLcyfJKrOKUpb7QV6inHm+w3ONiAS84BGSf8Y2dsLKO?= =?us-ascii?Q?YuW79fKQZ+tqe2AoS7GIQCyozT08HASnrPRUyCKlH62VhSZuXHUcZ4baUbfk?= =?us-ascii?Q?+YTB0w3cNx4ZaLr7SWKd21EDX/hTNzRSZ80I3PDahg+zCa//o79dDONzMp2p?= =?us-ascii?Q?wp96h5I4HC+x5TtotjBKrnHo1OW8g0eCDn4tnSz0kIFcmTYmG72Q9JzwGxC6?= =?us-ascii?Q?+vLAbFC5qXUmzwgJnfCCTt111E4QRj4wSofyWMHOcnXFXPe25JQupvZLIHfv?= =?us-ascii?Q?c0SwYrGipd4sMNWILHd31RzMGF3atEze4KBRjEpYJPf0Oc0FTuF1XADImzaG?= =?us-ascii?Q?v2VrwKU1NEwbD/uGNZX3NXbHit7Q8nFIUiaswBbmxF6bJzCcAnpgB+dcJJaE?= =?us-ascii?Q?9+VDPJcUs8cv1EYpm6r6iJS/ViPtIRKQXKzp5LYZ6cTaSxTTW81xhlMSrrex?= =?us-ascii?Q?XPHN73uSvWJu+q8p9chloBShlySlctB9uIQejKqiZmgZRjCzGfOpBbB3y0Mh?= =?us-ascii?Q?N9P7lZpvE20vE7qSFrl+Kjgz34WdrnPBDPgjx/cv0XB7knBoIfV17lPpgG9u?= =?us-ascii?Q?qMxHyrGR5LMuxwbnsdpPJb3R+NEKHnVp8cnXU+dSTCf8kiAj6mbiiyBMddUR?= =?us-ascii?Q?Ve/TFgPTldScW7etD/8m1m3bK5gNmUg3l8um13Xa8vbvtqTGuUlVKF2kwZ2B?= =?us-ascii?Q?hMJRZNjW+fRpno7TBu4/pc6M1XtM6huhXf9nWLKpc3BGPkTsiq211UpnRySU?= =?us-ascii?Q?oFQgMtOWqKLWNKmStux9zYtPCPmD4OwJYKZoI3DfmYoY0NSSNWefnojo3/8t?= =?us-ascii?Q?89Ocbkip8Ph2Jyl2mE1bl5DU1u5mzWIanMYkkV+El4nw+rMbHH9CH4wGolJb?= =?us-ascii?Q?3W7WIE3c5Qf0hQRi8JWUBklBSaHi5lz6QjJRrvfzTkB46NK4O8NA/KjoKtlQ?= =?us-ascii?Q?6Mn07G9SzpbiokgmRvYp3zI+bbgo6qA88xqaxVo5Hx+1QkImnLYJK8O7RY62?= =?us-ascii?Q?WyJvQizbKB7HXpaHk8w02TTxSmo5wzhlBYm8B1vqYZfNal1GzUiaqfagdbEy?= =?us-ascii?Q?f9ap2xAWzLHR7S4yEvi1yak2ZJzA3eSyM9ZfGxQnGM8YFxtX4YlLJAOj6pHA?= =?us-ascii?Q?d9iwkbMQnTfQk2f7tif50it1gOflGOaxRkpvdIRj4sGKp5iNa5zt73ys3bb4?= =?us-ascii?Q?z9d4/bXMbtTwZ1nvTSCRaQ+fWAe93KAUeZcddGASdN0cbZidoUYOfHEqZuVJ?= =?us-ascii?Q?fOq9W5ZiNgVwNtJmgpfGejbYl4nQW2gZX2pYT2Ko3zyNfXM+1iyOlx1jNAbD?= X-MS-Exchange-AntiSpam-MessageData-1: WDp+qifzthaKAQ== X-OriginatorOrg: valinux.co.jp X-MS-Exchange-CrossTenant-Network-Message-Id: 6fff4abc-a94e-4053-990e-08deec66087f X-MS-Exchange-CrossTenant-AuthSource: OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2026 05:06:50.7886 (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: mQlci9GKPDRjdcjSyZLAdVDckAgU9FBLMs1ZC1APdmkzjUGNMTHofXwWoO3DWpNyee1k98dt7oQa9JLqIjheKw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY1P286MB3277 X-purgate-ID: tlsNG-ebf023/1785215215-51CD7B50-6ECC4581/0/0 X-purgate-type: clean X-purgate-size: 21500 X-ZohoMail-DKIM: pass (identity @valinux.co.jp) X-ZM-MESSAGEID: 1785215250398158500 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 --- 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:54:09 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=1785215241; cv=pass; d=zohomail.com; s=zohoarc; b=PgyAANYbeBu/8GU0BRWXU5jf+3ugG+2yUUFdm010/yoVyEQRmSf9Z5qDLYi1zhC/Q4+wFDj0y1kKcGdsvbtp23DICfNNRb+ulS6geefvZL2KlGcgtqMKNPbrSt/fh8n5aXr4QeIwi0XZo8bT7Lc3Xyk86DtKSoq6u2pIxreNnb8= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1785215241; 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=Hf/gX/YYaeKQ4pEkqq7WGWP8yDdVjs83d6+pjOTzM6AI3yNla3yavfM2xNy3hjzpyDx89EIev//LQzMUn5h8wY54EksKJrqpFRYC4+jDnMyX0NuUogWXXO+/0bfn8uw97RRFnsSOYmjiA48WHlfS29/9SN2Oja+g5IATeAGMxqU= 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 1785215241289377.0369853327179; Mon, 27 Jul 2026 22:07:21 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1372050.1619454 (Exim 4.92) (envelope-from ) id 1woa1r-0000px-Tn; Tue, 28 Jul 2026 05:06:59 +0000 Received: by outflank-mailman (output) from mailman id 1372050.1619454; Tue, 28 Jul 2026 05:06:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1woa1r-0000nI-Px; Tue, 28 Jul 2026 05:06:59 +0000 Received: by outflank-mailman (input) for mailman id 1372050; Tue, 28 Jul 2026 05:06:58 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1woa1q-0000Z7-Gn for xen-devel@lists.xenproject.org; Tue, 28 Jul 2026 05:06:58 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1woa1p-00Fj7M-Tk for xen-devel@lists.xenproject.org; Tue, 28 Jul 2026 07:06:57 +0200 Received: from [10.42.69.4] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a6838ed-bab6-0a2a0a5309dd-0a2a4504d6a2-20 for ; Tue, 28 Jul 2026 07:06:57 +0200 Received: from [52.101.125.79] (helo=TYVP286CU001.outbound.protection.outlook.com) by tlsNG-ebf023.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a6838ea-b57f-0a2a45040019-34657d4f8021-5 for ; Tue, 28 Jul 2026 07:06:57 +0200 Received: from OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:458::18) by TY1P286MB3277.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:2e5::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.245.13; Tue, 28 Jul 2026 05:06:53 +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; Tue, 28 Jul 2026 05:06:53 +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=XtgKGevNDHKn9+cQqkmEp+3WjzEhP7Y2kTB6VeMBlyMvYjLO24gr8uZ6egyAdIaDUGyoHlmb1PAYOl3/tyZCOal57E5xpGnFs7VmPddiJlsQ8Oc90zWmpUG5qUTXnqrVWlNU5Izx3Ky176/R0bUiEIra6GzuWcEYNKLyY/CH4QQghcljsLfCV8m9gpgtrrId9vlHzMD1xkBy82HKbLBwOuYYX3Gt/HAUuJyx+1A8XDbZwLB3MJiVXiELTqksZZ+qZ5/qgFT0jmkjt3AfdgRlfkSEtM1lfvsf7uQGznJrkYqJK9I+ILwyB2bXxmUfrcq6JFBnKZYGoj85clXPhW479A== 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=hESe9Z6yh8FU/OqOyAujnHe/OGUxIZqCUPQSQfGMlVL/OeQB2YXW0AtDA3gkemF2wL12g6th3BDS2wZXwc3Rf5XVYCr5aFjqjEHAo2kIOR61iqWLpNFZKP4cceRrlhBiekkf6HMofVWhx+eFyaVtTAzWVtQoAmBTjKNPmyYlXNA2TT7YZQNZpEJCXbxX+zM3bnb7NJueXhPnDBIbpHBYNCKzJHVT5wPxd965SWSkPyLxVpEHmjMEgKai1XCCZoSEOcedUJ1CLuiIEaCi6xCDzpip/kz4v+v6pCxX8DSYeQ+iiJg9RVjpS8yNNMAnOMM5XLSz9gKiJ0ZBk5ElHhQlsw== 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=LNNDUCEnNY0o5YG2i5F+S+SwJ289F3zO5uhmp4N3jCoy3+WDHJucDjylBgX5oKBNQOXCkpJe3NinuKKLuSl3xLyE9/7nrxVTx5LSi9Wh5vIWyeHXD8wxKxTISZQG7ljtxbl+S9MvhQ0uUREaspc017XhpCyHELTcEeZD00aW7T0= 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 v9 2/4] xen/sched: Link CPU topology to scheduler Date: Tue, 28 Jul 2026 14:06:40 +0900 Message-ID: <20260728050642.411240-3-taka@valinux.co.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260728050642.411240-1-taka@valinux.co.jp> References: <20260728050642.411240-1-taka@valinux.co.jp> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: TYCPR01CA0158.jpnprd01.prod.outlook.com (2603:1096:400:2b1::9) To OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:458::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OS9P286MB7222:EE_|TY1P286MB3277:EE_ X-MS-Office365-Filtering-Correlation-Id: 16d3b7c3-32b4-4f66-c843-08deec6609fa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|366016|10070799003|23010399003|1800799024|6133799003|18002099003|22082099003|56012099006|10067099003; X-Microsoft-Antispam-Message-Info: YmjEUchs4Vw9I2AE2dzWOjUlEPlvm9JN/J8z1/NJZR5cFmQeujyNZvTiXrr/d99v+TMguA8heo4s8XHtO8bAkCZ9nKw3dSiOeHb85tKTcCnoDgQwvNt78GLPES02NHcdYuwmE+mMdv6UV5iRaD9PS60sc43sAVeTKjZ8kOR6R0Ut06ONTPW0dBktlfC1rHY7B189JsOWDRtffcWA5pz2r64paVreggJA0PnpUZ5/0D2TQ0x0RcW/knCq1x/2D07TsFczvni8CniKrG76hYZdAXkfWasl3W4zGGVoJhgcJbfknEWAl4eVAo95IA9Gv/67IiTHrC5TwW6pIL14D/DJJeozYvecJKTGyANx0/dhIMP3McOOojNudsNWLQpoIFZADcsQ1x/Dd6YY53kklnHq6itd+jYm7k9JSqjB7yzA2v2G+1vFrehweb2yJ7qXX5ea6BaI26OedIefLtcwSUecM2haXgDLJJJfyeR9wcFaq8XiCx5xVgjU2CXwEDIinu48I+I+OFdTQQyd6UUytWmniUXY2B7yYiIbaV4POY02ZmbTDFBozKRuVy4q0bgwn3CMAhvIfEnBoHmlZXoqXblFnFEJHu4r5tQlyQk+c67YlBd6s43acnZZjrIOkxw0ZczMrGvP/2Aklt4AiYxWp4yav++tCPvEjdpTY2k+LAWUwd8= 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)(376014)(7416014)(366016)(10070799003)(23010399003)(1800799024)(6133799003)(18002099003)(22082099003)(56012099006)(10067099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?fHdCs4wDsSWE5D7RtNVpFjmhzIGOMkYeslCB0L96HQ2/IMfNzNcC+FQkwced?= =?us-ascii?Q?yxBZD2X4rn3mMDIiECvWz0q5s8/1N0C9uk7uLAgdjU+3pbOWIC/TtliVjvIx?= =?us-ascii?Q?HXXKUqGfxdQ4jNwbvpjuStUSpvdvMKhYhro6iaFK4GYT0UTC5e+VRQXQ98Sb?= =?us-ascii?Q?TbDMgYSJzeb0yQCuwSJ25SkXYWe+VHyzLcqv+P8iqLElDcyqGSzMAQkFzVMp?= =?us-ascii?Q?2CgYU+K3jA8097wtAeLvj51wxj3e/qgysZ61gN2RCMpzGcd8DkE5P6HGdJT1?= =?us-ascii?Q?XuOlGhPHzho4o3emn0uII/dtDjPmW0pjuDRnrSBXEANDwRlQn+37crZdtRi3?= =?us-ascii?Q?XwsZlaylso0UYTvWSe5mWak+/jyHSXhumtCGe914B1KhZz+aFpC2X0P947Um?= =?us-ascii?Q?srIbuw6ZYwz9IKIHkamWVr4QfjYzDxysqaJA2LM6YpemzK5wrxGnQA5/UxZb?= =?us-ascii?Q?TCZksKTpJBqFAxsTuyYQgXAXYn4XhiTAtw6TAM0NJdJoUmH08dsfjlw0Hynk?= =?us-ascii?Q?kpMCipQThSl3W1b38T5rBQEiaBcaCogdboshORwnorAWg2o0rvaTMt3b0cKQ?= =?us-ascii?Q?na31XkOA4TsTIg+WI2q73qM9aUJkxv5WMZWndsoAMxKPx5iFkCCPHfCC6Qps?= =?us-ascii?Q?DohnubLcfcBm4FsyFyqtSyei9hOxTsPf/h64tzhBWN4n6q7L1WfL+u/hZCAi?= =?us-ascii?Q?CkO2p7K+faZRZhbOqdoG3DPxmuDUU7hFyIpEyVZ+7Yv9aseSYw9Vk9VK4bUd?= =?us-ascii?Q?bUAFlaJs+vCaWzB6sA8ecdHP8e6QFXNWNpw3T/GAaS1jRRfU50fRMK9OQ1sO?= =?us-ascii?Q?umvHsxl9rRApFe23tPzX+C0lMTfnZqN4G7nMTtobmoHn+cjuDd2AfIjvl7jQ?= =?us-ascii?Q?d0OU7Di6v53GBKXr15w5v8e9uA7r7jGOnBNn6YwteyhS/x3jhun1O2jViFpN?= =?us-ascii?Q?1J4d15XGHWHBZpJ0C7+OT/KwTxt2e7N8mwDgZabX0Tva5ufbVD49z+E28oGg?= =?us-ascii?Q?ag5em5fK1rej/dh6nCOwO0QWVTuD0GBw6EtIBz3T4AG1mwQBDr1SduwtYZcZ?= =?us-ascii?Q?jI0KfETIlyu12BE6NergcUR/jpL8naF9TPxVccvfgi3EN3WjD4GVm0YuqKOb?= =?us-ascii?Q?gR36TFx8oWgSm4lZomuAZPMK0KopC17Elbo9d15OrOdhWGVhpRsgRL3UTYe6?= =?us-ascii?Q?HRQCGWfJdV63PoWtCkulRL5I7iJFYnK0KkZIwl6uaBLrrKK8N62gRf6tz0lN?= =?us-ascii?Q?BOQfPzrj7mjibnQZ5mZEsk9buGt8Zlui0YR4JEAUcK2teT/KS90iMhgAKyUr?= =?us-ascii?Q?pf2bQdgGZXM7xNgWQQeIAVDZ872zxJlrouXLT/IaP/o8eOmcp4FgminwVAiJ?= =?us-ascii?Q?7YOl4B0UWRhZmiGpL62EZ4rPdmjgP8tURjofhB+seV3mDf2pprYgpO1HMseH?= =?us-ascii?Q?bTdLZmQS/PDUcoX/woqWRkwiLgFt5+o+syrdmt3ag5mFubbypyz5Yhuz4RVR?= =?us-ascii?Q?4ASiToCGg5MVIq+dlPk31PY1fzTCD03quiBgy4JMKj13ODdinHnyfrNmiaCx?= =?us-ascii?Q?WrCqKY78s2zvTDlH1oRLusnLP6OiRUYuRqLqTULMAjDYzjeJhxjhZhmmfJVK?= =?us-ascii?Q?oHBTAM81h8/iCkRRtEvj3B4AnymkmegP4G4eLRm30wOr/CnGUMX6yVr2dd2q?= =?us-ascii?Q?EOd3OWAU+cZDou47xtPImIbrSMy+h5qu5KTcxzkZjaJ8hxHxu7JXuQfLzWsL?= =?us-ascii?Q?ruSdDI57BeXBUhO4Nd1LlV9LhuFM9zBgq7VIH1ruhGqnYuMohXRfZU+7hkUL?= X-MS-Exchange-AntiSpam-MessageData-1: uqhd6jJI+8nxIA== X-OriginatorOrg: valinux.co.jp X-MS-Exchange-CrossTenant-Network-Message-Id: 16d3b7c3-32b4-4f66-c843-08deec6609fa X-MS-Exchange-CrossTenant-AuthSource: OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2026 05:06:53.2755 (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: lQ0d8v4fljutI4aLKD8aKtrDpFFJTjQChQzbDgN0vz4Zt39rvtAhpMxXCJX6C4CgM8EnGWvmt8RG71w+EWGjAA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY1P286MB3277 X-purgate-ID: tlsNG-ebf023/1785215217-53EC6B50-2CC5A6A2/0/0 X-purgate-type: clean X-purgate-size: 9046 X-ZohoMail-DKIM: pass (identity @valinux.co.jp) X-ZM-MESSAGEID: 1785215242495158500 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:54:09 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=1785215248; cv=pass; d=zohomail.com; s=zohoarc; b=Aci8O5tpGVfZN2+8GSxnCb6abaDwQ+aB0x+jS+UHESH3f0O2Gy39W4Y9v24O4YqDe1f8wczG7DiSJyRZtBV5aXeeYxQ9Wfiy0Vh4rvBcGedwmYKrpALHr7ury4ijuvm5781TStjrW6sWvw6xMh+lB2FT+sDD3qL8dW5xmx9pX90= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1785215248; 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=ckej9nXRwa2RQrV+Q/bA/1NLGj6f+UR6zJn5T2JY208ewHTKZ+k6Jzh07FVL371TH/KJlpHqnriEAJvSaAvkysfBBwuI4vJ6moaZz19obwGZuU3VMVsFXA0kgUaJ0o+yJsoZB3v0c8n9lZM5/Rmf0vICQ1SiwQemlcxh4Hlr5FU= 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 1785215248344764.4978015796746; Mon, 27 Jul 2026 22:07:28 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1372051.1619469 (Exim 4.92) (envelope-from ) id 1woa1t-0001Br-5n; Tue, 28 Jul 2026 05:07:01 +0000 Received: by outflank-mailman (output) from mailman id 1372051.1619469; Tue, 28 Jul 2026 05:07:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1woa1t-0001Bk-1p; Tue, 28 Jul 2026 05:07:01 +0000 Received: by outflank-mailman (input) for mailman id 1372051; Tue, 28 Jul 2026 05:06:59 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1woa1r-0000dK-HK for xen-devel@lists.xenproject.org; Tue, 28 Jul 2026 05:06:59 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1woa1q-00Fj7M-Tz for xen-devel@lists.xenproject.org; Tue, 28 Jul 2026 07:06:58 +0200 Received: from [10.42.69.4] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a6838ed-bab6-0a2a0a5309dd-0a2a4504d6a2-26 for ; Tue, 28 Jul 2026 07:06:58 +0200 Received: from [52.101.125.79] (helo=TYVP286CU001.outbound.protection.outlook.com) by tlsNG-ebf023.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a6838ea-b57f-0a2a45040019-34657d4f8021-6 for ; Tue, 28 Jul 2026 07:06:58 +0200 Received: from OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:458::18) by TY1P286MB3277.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:2e5::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.245.13; Tue, 28 Jul 2026 05:06:55 +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; Tue, 28 Jul 2026 05:06:55 +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=x78fsjhVdsZMdnHk3L9mANNjqkf5m0eA7enKDB1Cx+C3KVvSUuqbBdjNrn8DDKoOHuz6pke/1DWyZM+bGH8nXKhorGwFX2BF9OBkoES3v6pgZnpdRbu+E1jO99wcDpq3MNlHvPNeUCmdERS7WtS5oFxHXLCMoDPEwEBNYunnj9PCF+FlpuAwy/AJXnuPWHyGm8ze1CLKh1elFa72CFtu6m4VQl0G8AUq3Bfam2bRvRMI0Tq/QT5foXWG6bAzajfvdmxOzbuzKgqghvona69Fdgb1dQ4vbi5IhP7/Eoxnu6QPzPVw7l45ZGTvKQMar8HQjfcvok6Xarq3yen4XMkA7w== 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=IQuuhZdMD1610CZTOw7rRPkadOVzrwmoYZeeA55NsDhsA9YGJXzwEuj8C3Y6XjigD8V0KXgXfFDe0bjhOrfaa1X1NBetSOZtTaTg52TkrcIsTJYynb4J+dW6/Ig4E9lp1IEKMxskVyvJv9hPdxZo4UWHkxB1NjT4oRrOKrAE8qgrLF7+9dY3jjtBDw47sM4AlJXGh10UjvYubIc+NzNChFTBd+4M7aKYWrPTYTIQKxlZEXDOcULUB2tjziAiTN2oBHHKyFWc7Rho0+CjzBP7vFNSWQkRyMK840CqNg6C0+moGk/gSkG8cYOIBlH6R/v13bNpR+STe3oVA7bhaadE/w== 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=XDJlo7jePH0TGyg+xqt8lhBrEiJGC4Pdeuyt+DJ09b+IjchgcNuxABEgxntlgdhweMLa+24W9plNN9ZPv6XWx+RWWw8p/16VVZvP6lErhnf9YrNsTHjZdI7ISc0wykNQKm+q9K2I7LuLmvCBwcMd2OSeDbQwjxSBi4zsrSzawOU= 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 v9 3/4] xen/sched: Make cpu_nr_siblings() architecture-specific Date: Tue, 28 Jul 2026 14:06:41 +0900 Message-ID: <20260728050642.411240-4-taka@valinux.co.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260728050642.411240-1-taka@valinux.co.jp> References: <20260728050642.411240-1-taka@valinux.co.jp> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: TYCPR01CA0152.jpnprd01.prod.outlook.com (2603:1096:400:2b1::6) To OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:458::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OS9P286MB7222:EE_|TY1P286MB3277:EE_ X-MS-Office365-Filtering-Correlation-Id: 6c7c126e-1313-4afe-dc2d-08deec660b38 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|366016|10070799003|23010399003|1800799024|18002099003|22082099003|56012099006|10067099003; X-Microsoft-Antispam-Message-Info: TPRtjHYC1GTZsY4lQm9j4z/JDNXmW9PFPEEAxFl9wT1EUM1daE/npQsXQG1eD7Ig/CaOMUYF9dDlpOJQiaVNZshzhLYglY0PD7mOl4EmAjkmZYz4aYagmJ7sPIOQ7t8I/SCfJt+jX0ZBLPVFvjf1up78IG8/jIRfLKTIM4qSJ0nnFXjMrwxkX3g8gwfJ+Sio6htGvyEAbBaZelTSolo+mVGK96OPySNJ+RRQBapOeGX5/JhUEPb5M8c+nIH8TKlhyFYChKkZ1+ayMLGf2HJ7d6qvLH6zeeKZaiOX4IC1ZCl8gRr9Z3+jMbjKU4HGzLTJYQLGR/RN3476IuxnNXjEpSjLiZdejp/7yrIyXqLr6ox7UbwU4VvrSCUHPos2mtcLpb96HKajpsPa45n0d7fU3MwdYDPwOL070zA+oO9NaUrFpvJvnIQ5JZfLhqKKJa32x4t+g3p3e59iNnAM/nBpDXq2867SYEIp68wJGynHsLAXITco6J7B95jHy2i+2lLnkrEinN79fzzwzuLD3+kawjJn4RgWAK7J+esbDhmqHjWohSqObKJLvbRuucqoeUxmiCwBQGkom9b1NPDMhgbY+tjxjQUNjx94sws5Jg9BwHoufMEB9HA/tuPSyvYvnIedEok49Vd9QRnA3bR64b+3DurcIS+qMW0x74/fN53htFI= 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)(376014)(7416014)(366016)(10070799003)(23010399003)(1800799024)(18002099003)(22082099003)(56012099006)(10067099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?cYh1gK/pMn7o1cdw2unT64+1yCbLU+4E3i/ht4InSqs+c0O0xhnPcActiAwC?= =?us-ascii?Q?ZAr0g+mjQOlhIKFrJSUXfTU9bdqluL+Uw09cft+OCopglvz25j7/eLBqtkfK?= =?us-ascii?Q?Fnk+ARFCs+7wxoElsREep5D7OjR30nw2rKgtHOQPnZtE+kcf05VVaihj9VVV?= =?us-ascii?Q?5hvi0uvLSjaNO3Q++6i+/ei1yxZw2GQ/0O1UQmwqYMD3yUXkszfJyvkX08vN?= =?us-ascii?Q?qFJpvqKCqlKdMZ6pF6x3B2StmNbQdxUJFHKQ4obXr3M8XSQPnP96goYtvdbd?= =?us-ascii?Q?MwATle5ybDLNTQ8fZG+VF0CeXkvl93G01oJ29YDXOulJdzSmAWwGtpoK4NtR?= =?us-ascii?Q?zPcCrqk7aknCowdSTK2P80p+DwifZxyeuOn6cdITeY2SfhaTdSw2gjgdsAVl?= =?us-ascii?Q?4y97auH+6/DEsru7AXkpMb+6QGTZMujFtQk8gf65PHXS8q7ygbgriVWkurx/?= =?us-ascii?Q?WiUdLR68Dz8w4qkxttuHIeMgelwYiZtPsGUPtlmt/luiPZeCvTj9+bIubD22?= =?us-ascii?Q?Yt1X6CweNbjSAyhd4E8SYRU9uBCWlYNdMOvNPfYSPYw29UprFwTRXY0++wFq?= =?us-ascii?Q?h4ErxVwXjJq3J6f6AAomdPodWhnh/f0v/YduOmFIBroY0fwIvp82f+ayx0GE?= =?us-ascii?Q?YyKkFr+9nnx9k7nb5n4bN/bmvNnJwI732+hrw9nErW1cjLGFT8qeufosqsTI?= =?us-ascii?Q?ERxYNM21HWRz50k119o3bGtevTrnOQDibrVWWv6nOHboEGCoVefqEBgfbkV7?= =?us-ascii?Q?Zy+CMCH66fVVtAaideHMXKCUKqRukllnVi1vF+T4bYGYzBHQThFq+HLIignH?= =?us-ascii?Q?GD3YM/1s6FsjAdOoouSwD+AYBWJ43pzbSiVm6RxBK3zrdZY5ZSC+jupW7rTU?= =?us-ascii?Q?JiuSsH6CoLdqsC1WrPXQ9a1hcKZQUF2DKolfNbtwjDTnm9MWMP/NDbcBnZ8H?= =?us-ascii?Q?QUt42unCMYNJ4G4U8WR40wAz1Jc1OWRNA8z6Ct9VDfAOu4jZd7mfMFnG+2FI?= =?us-ascii?Q?1YMwoxYitA1dRN+FtgXAfnXZeOz0VV8zePPnhGZJpiaZyOqrSUZWRnygvn1Z?= =?us-ascii?Q?4AcvuRgWDXdvd5KOskq5PG/X85hyhkWfnJeSkHCRpwaZRZ5ricQg/e4dUhOl?= =?us-ascii?Q?rhoCYzAr4mtiumY4emllHpgtzxkyaVrBnfTjx6yFd5UZ9VNiaGOXFuxqCMb/?= =?us-ascii?Q?jG7dSYdreTyHhOP3dMhILrm5BhbHhVmxcVY6ukHcUFbcyv/JTrLv/Tk+S60M?= =?us-ascii?Q?PUPQ69KYm0kHWV/i3HTYHDHdBqM+tCuGtRSum1mJwYH3jUd8y2revZCj/MUH?= =?us-ascii?Q?doN2VttkvfZzMfq6QnWuzv8lWbAhmFQK1tZ2/JyGy4F+yMM/RRUEu9GvTHcD?= =?us-ascii?Q?/MWh8E733NYIwOvRUbBuPFS+dlIP5MMKSt/AK8q8F4Pop0pV3968UdhiXtD2?= =?us-ascii?Q?ZqtN4nK7fzkFxPFze5V6DEWKsP3tIbNB9av5MZ2J7BxtZd1zAwLreyUuRSS1?= =?us-ascii?Q?Z729Psxjozn6EGZejUTQXIm6FIOVT2MmepThzhu4jgBJOGK1voOoETF+A0Qa?= =?us-ascii?Q?bqT0IrXIaVDnPD923WPQUivKKX7vwFsNq1rZjPhnQ5J4njvldif4CHwjX1z0?= =?us-ascii?Q?hJTybDr9PiNMdtVmPPYCBVFT9obep+WNeAe+2PKeezlAR0DcbUpySYPf3SAS?= =?us-ascii?Q?5oyAN33591saC3yaFllcbJYIpVp4TBo9HIuN+NVpxkP6qMJ9qi7V2KsBr9kN?= =?us-ascii?Q?w/G0s/01ZO7R2SB6CULxrqdwbnEbavd53b/N9ejXHKiYOaVJ4+fMa4CQFzhJ?= X-MS-Exchange-AntiSpam-MessageData-1: gwVQwGOQP5tFoQ== X-OriginatorOrg: valinux.co.jp X-MS-Exchange-CrossTenant-Network-Message-Id: 6c7c126e-1313-4afe-dc2d-08deec660b38 X-MS-Exchange-CrossTenant-AuthSource: OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2026 05:06:55.4057 (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: C7keh0eK+w+7Apfn3mo3EcWzeW3NVtBZWUs5kNXbKOS3kmUjwNwTnBeBt5SFDdtvn2uvMMZC1p572Kqmc2FBWQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY1P286MB3277 X-purgate-ID: tlsNG-ebf023/1785215218-520D5B50-05A66480/0/0 X-purgate-type: clean X-purgate-size: 3435 X-ZohoMail-DKIM: pass (identity @valinux.co.jp) X-ZM-MESSAGEID: 1785215250328158500 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:54:09 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=1785215240; cv=pass; d=zohomail.com; s=zohoarc; b=Yr6v99LOK6gQlnojQ+XDyA3hpnEYtQV+6n3XzkP8DDVnM9vnk7A3t9CNUrWWmDFxHTI5ZDCFPMjd9MLH6vmNAHNqpdwDbE3z3tNPdk7hycUzPljhmzPVOd51RXnjFGj+kQsIl51te+cxm/9OFkSO44WmatILK4aohyDotNHY44o= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1785215240; 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=NRJALSvaO0+13oGmqfWWX2m0DlQpLj2Y93MTzehhhNM=; b=DqRK66cKUMN4EVXCKAYEDVjAlomqHf6MIzjHSMjEDzK5aT8T3GPL741SW4W6iK0ifmC91SJHSowGn583c0AJAj3egHypEFfP9td8/i+QmYKzMPVkaQ8zl3Diu2EwkR6POpo6jkV5vFiEzxvAcrFpI8WIY8fczICXG28vSblOQUQ= 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 1785215240294363.35996341471775; Mon, 27 Jul 2026 22:07:20 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1372052.1619475 (Exim 4.92) (envelope-from ) id 1woa1t-0001IK-Km; Tue, 28 Jul 2026 05:07:01 +0000 Received: by outflank-mailman (output) from mailman id 1372052.1619475; Tue, 28 Jul 2026 05:07:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1woa1t-0001Hs-Gp; Tue, 28 Jul 2026 05:07:01 +0000 Received: by outflank-mailman (input) for mailman id 1372052; Tue, 28 Jul 2026 05:07:00 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1woa1s-00011Q-HG for xen-devel@lists.xenproject.org; Tue, 28 Jul 2026 05:07:00 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1woa1r-00Fj7M-UB for xen-devel@lists.xenproject.org; Tue, 28 Jul 2026 07:06:59 +0200 Received: from [10.42.69.4] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a6838ed-bab6-0a2a0a5309dd-0a2a4504d6a2-30 for ; Tue, 28 Jul 2026 07:06:59 +0200 Received: from [52.101.125.79] (helo=TYVP286CU001.outbound.protection.outlook.com) by tlsNG-ebf023.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a6838ea-b57f-0a2a45040019-34657d4f8021-7 for ; Tue, 28 Jul 2026 07:06:59 +0200 Received: from OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:458::18) by TY1P286MB3277.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:2e5::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.245.13; Tue, 28 Jul 2026 05:06:57 +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; Tue, 28 Jul 2026 05:06:57 +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=kYlJlerv89DcY5PlB0gA2Jy5rfjxKteyAQA2B4xzTQFR7lfZhC2v7ugm76YUfHklkKEQqKGlNgdu0xpJPvKrD5V5abNSCuYbMIG8V7AmUsFEsUT9cof/JWJNXWliFlNAj1cq6yvGGZqAPuCV7u+cqY11d2SHbX3JujyWzTzqZlCZnyd8NQRYTGy5dpuKNsB+eAHVSj+rIEvi5vR5h3qhCE7JqIkx7kqvldCW18FahZREgUDlwv9dXDMM3WzdHg5n53+mlPDNrC0mS+rIgO/4DaOPEZiY3xKG1Z9Ir/QKJr2xLF1Xlxl1obv5SUZ9CCF7LPCguXT/LzY01woP2nIsnw== 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=NRJALSvaO0+13oGmqfWWX2m0DlQpLj2Y93MTzehhhNM=; b=uFlae9nVykJzHD9Cb3xgdOsXKWvUnxixh2XBzz9rt5Ox8JHthMoMWQIxxiG+U/oL5MXD3cvg06Bx08E/MBu9CfMmQgX4KnutRUncItX09Ozb3Yek5S6VCJ5qzIPZ9ZE52F4uattx1Nkapa2H87kPO9B11ckCfSWOet5D/TUNycBWba0ikg0cdZ568Z3XPkxfyE25gLyPtjQcLMsT2q7L6q3WMAtr6vSC9q1cjb3WJ9Zs0iV1QSFSVWkbKr01H9vnUt1g/Tta24aloARxOFdgJTNqpLXCljWz211blUpFokKMBxKAybVYRqErjKUsW0HIs9fwmJlPU+WkS1nzNn1NBQ== 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=NRJALSvaO0+13oGmqfWWX2m0DlQpLj2Y93MTzehhhNM=; b=uKbAEwiKS2R/N/MaiDMqJScXBov/lvNTEdvX+5VfvjsO6kxOb/b40tGnuAxCpmoX5IjHhnfxts1f8CjfdfPP5Wq3TdZBkMbA6TVspBXajx8y6VwPYqSNQSz5O8CYEtTanMGec9HuColGMgknD3PXAhCNQ42AgWyoNhNkVwk5xeE= 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 v9 4/4] xen/acpi: Parse PPTT to initialize CPU topology Date: Tue, 28 Jul 2026 14:06:42 +0900 Message-ID: <20260728050642.411240-5-taka@valinux.co.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260728050642.411240-1-taka@valinux.co.jp> References: <20260728050642.411240-1-taka@valinux.co.jp> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: TYCPR01CA0157.jpnprd01.prod.outlook.com (2603:1096:400:2b1::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_|TY1P286MB3277:EE_ X-MS-Office365-Filtering-Correlation-Id: b6a8b051-f3c6-45bf-c610-08deec660c6a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|366016|10070799003|23010399003|1800799024|6133799003|18002099003|22082099003|56012099006|10067099003; X-Microsoft-Antispam-Message-Info: U9BaHD7BqVrFWkrt0r4EdTQhLXVEVIldRjPPlhOoF8joANhWu+ngR8v6F/nfjQaLBJ3KvzfZcIC4KVerQ7wFtBK4EjIkwXXM7O+fXbRWrVHfDQKMuUH0UaFdRKqTkz64UmCYu/0dB+SGnUqRK35t30TcMPQmvpCIa3P010PIdwM7ZBqRsqlXUsBndRfF1NJ4tXvZJeSGT2E4Wt4o2nGSpQYSrGY6pPHIoMyKOlzzlXoCIII7Cp/pIUdM943Sm/fjgMwhp87dyspAFNsM9vqQ0Q/77QazKDI6YUQ3G9+p4gN8b+/iXwyaZVviZ3hbw84Pep1sYHB8Dhz4E4V78ooSOEidY83TwoP9RyHbY0AbCm9As+19AFlIxJ2+HlmJUtUb7T8eX3BfE08GSVw2ILBegKr85tBMR9ktfU99jj4y7tsrcKLHnOkorNwsae+jR4AAmYPAdmrCuWg9GDkd2A9sdV7QtR6tuhf72i4oYyc63sFuCguQp+d8sNXeZwdYO4QokyH9oMRZBEDKMRMPCQbT5Ibfj3OK/N2OeOV625Bh/U0ykEv/ztOB0FGUZKOZz+2pSHMHGfx67wABjxEBMulRqb88MDJlM/rECMthGNvo6fxIxdWrEOkXqzWWXfOB6drUyDBRv5RCOVHA1W7j84VdzQuAxaeFRErFTsSWbaUxBpY= 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)(376014)(7416014)(366016)(10070799003)(23010399003)(1800799024)(6133799003)(18002099003)(22082099003)(56012099006)(10067099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?AMjoq4XAp0RSTdOXLivQZMn3moZ0cryEh0FC8O3PFznFolElxcvxSfoIw5/7?= =?us-ascii?Q?i6pdGL8OBOD+058kiDXr+pjmurivzHZzL2SgReycgAjuMVkHy08dHbLop6la?= =?us-ascii?Q?xLxYvT5l2IfbxxI38Pr7QyFAV+6AnTHurIS2TVTZpvdQc7jVvegQP0pT90A+?= =?us-ascii?Q?yNo0l7Z/d9qX0LFNTG/+j17d2yhzgnGG08ygVuTf2qdtIVq2fbLmlT7M5zWo?= =?us-ascii?Q?HMD6/mDODqanxpQpqLnxJFefi07OYIB8ZjEdg2lnGYP8th6GSks91cGTpoW3?= =?us-ascii?Q?QFYmpgs6tfdCjJwV6/KmVBlwY86bEezCIFWBpUDPhD6SqcdvY4yD/V15F5O0?= =?us-ascii?Q?Ui5ys7N5UHEtJ+WFGIj0rqRAyyP6XK73oIIgbeThRRAwnvkbbSCV4AdIWwI7?= =?us-ascii?Q?5Pen6Yx3ZKHCEM0EfHpnQ6WSrLqLmanNDbDz65w8v2gsCaz/iy/Nzo4UkFi4?= =?us-ascii?Q?cIJkCrCLEDi9QToCWmznR5sPmQfNqTvcamB8Yeld4zmsIkAVVw8UajHwIFKa?= =?us-ascii?Q?HbIvB1DS9PVz6uEiZLp3s+fumwBU6S50IWHBMMMvCMVAkMDSuVZEWKxCta6c?= =?us-ascii?Q?5CTW/2BIdSsxU1xVlXOYugMjwySiZXzJd5pjRHV3nBEGYHVPhs1ZW5g2ddK+?= =?us-ascii?Q?YVRnJ2gPSr7Y7vIPjZ2CjOffBEjcpcyg33moyFOb4qZC8hEHkRTJ2MOb+eD6?= =?us-ascii?Q?l2NRBSRoOFYwZYfKsi/I2l/atXzIXKrrJti0r4gG8PIDHZhyd65n+mGaRvl5?= =?us-ascii?Q?S2U0CZ/3g5WwU69oBjb7a30/KcnPFaC5JFZwLIID3Vh2BI5jSDxiaRY53YxZ?= =?us-ascii?Q?qb9OE1BQUudtSKbH2fwRn74IOJqyEN1JJOUFxDoyWzIec2UzxeGQPq5LtHnJ?= =?us-ascii?Q?N9yHj2XLQ2JkKr5KckdG7Q7V7IzYnfayis5pVZ76H5DD0np7CIMWC0Q3ajQE?= =?us-ascii?Q?sdW6p4YcEUYPLW6yJ+2lhHM5FswKQZvgEzkh2jDKj2GGh+g9w9Kqcia3CxUc?= =?us-ascii?Q?Jzk758diJKQYlGAqEGGSYyEuCNDS5QRtXouWtZgemY4aLCzG/jrxN0dVfdne?= =?us-ascii?Q?6hoXLgEYO34l/Z2QQ553r64PoCY4FCpSlevLn6PB/pms29JHRorxO4fMTIDY?= =?us-ascii?Q?vzLPbS74mS3ld5VDOhZkKovvRWOpUZr1WURIca0wLszL3I7WjDoeAcXUmS78?= =?us-ascii?Q?9ecZuSw7IH/DOGt+SumrccpnbVy8DDTLvjIkNVXEXqUaCDE2sHcYGGHO4B9J?= =?us-ascii?Q?c78taqqO66bL/2PE/0Sn3oIvX8PT+LXIkMRQVBcLZZCVjxDO9BgEHqUflGyW?= =?us-ascii?Q?s0k64cqPp7ysUUlyodsQvNxuuXXU92DuzlkgjnF6vRMAWy/Ig/zjHmXfyVWE?= =?us-ascii?Q?mljj1TRvEvstKNZq/EStd4R5shy7E6wDQ4Nce28mjtpWD0U4lyPIPANoN5Fw?= =?us-ascii?Q?62DrnULjN4TLxWx0t3EgJkuABTi90qzsDs+D08QwOv/LeOFlO/irpSNxgyC1?= =?us-ascii?Q?HwR7Hw8UTvaMyMilmx5YtWuR5Q3r8sJ9kI0vdIO3gYG5ktpA2lJuWdoBSApU?= =?us-ascii?Q?RsoHVys9HbgQsnwNMi3UJO0zyRGtcFz1W/t8JNRsbz02o1nm7iMlGsd+78A3?= =?us-ascii?Q?QI5MLuXykEPhOr6ElYaGfQi31BtPkMo5f1QtVwRSIbDbmPemHJTWQZGXGc/F?= =?us-ascii?Q?wwkIq6VGyZIbtWx4L+H+B88+Qqn3ceUFNfp7SOzYJxzGvfYcT+DT3VLD3ehm?= =?us-ascii?Q?6LIv1rRLKjMlrjtcMPVV4+e2kFo8PHMKzNQk8WfE9VSbWdvotACZOLNGRKU3?= X-MS-Exchange-AntiSpam-MessageData-1: hzfyaBwDCKnJOA== X-OriginatorOrg: valinux.co.jp X-MS-Exchange-CrossTenant-Network-Message-Id: b6a8b051-f3c6-45bf-c610-08deec660c6a X-MS-Exchange-CrossTenant-AuthSource: OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2026 05:06:57.4042 (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: 2ddBm6qrEYYsLuMZ/uvPlDFpA/YkKcJx5O3Huf7dJomzXaVwwvU1iPFkcC/6mNdq6Q8lYNHROFB15EFV/rGvMQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY1P286MB3277 X-purgate-ID: tlsNG-ebf023/1785215219-C08D9B50-33643606/0/0 X-purgate-type: clean X-purgate-size: 14692 X-ZohoMail-DKIM: pass (identity @valinux.co.jp) X-ZM-MESSAGEID: 1785215242555158500 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 Acked-by: Jan Beulich --- Changes in v9: - Add bounds checking for the number of private resources in the PPTT processor table. - Verify the validity of entries when indexing into the map_cpu_acpiid tab= le. - Coding style adjustments (following Xen standards): * Place logical operators ('||', '&&') at the end of lines when splitting multi-line conditions. * Place arithmetic operators ('+', '-') at the end of lines when wrapping long assignment statements. * Enclose bitwise operations in parentheses within conditional expressio= ns that combine logical operators. * Combine variable declaration and initialization where applicable. xen/arch/arm/acpi/boot.c | 2 + xen/arch/x86/include/asm/acpi.h | 2 - xen/drivers/acpi/topology.c | 323 ++++++++++++++++++++++++++++++-- xen/include/xen/acpi.h | 4 + 4 files changed, 316 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..c543ed85c9 100644 --- a/xen/drivers/acpi/topology.c +++ b/xen/drivers/acpi/topology.c @@ -4,33 +4,330 @@ #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. + * Reject if the number of private resources exceeds what can fit in + * the 8-bit limit of proc->header.length. */ + if ( proc->number_of_priv_resources > + (UINT8_MAX - sizeof(*proc)) / sizeof(uint32_t) ) + { + printk(XENLOG_ERR "ACPI: PPTT too many private resources\n"); + return false; + } + + /* + * Ensure the structure length accurately accounts for the trailing ar= ray. + */ + table_size =3D sizeof(*proc) + + 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 =3D + container_of(entry, const struct acpi_pptt_processor, head= er); + + 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) +{ + 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; + acpi_status 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; + + if ( acpi_id =3D=3D INVALID_ACPIID ) + { + printk(XENLOG_WARNING "ACPI: Invalid ACPI ID for CPU %u\n", cp= u); + ret =3D -EINVAL; + goto out; + } + + 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->pare= nt ) + { + 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