From nobody Sat Jul 4 21:13:36 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=1783070186; cv=pass; d=zohomail.com; s=zohoarc; b=fzLO2OPKqy10/1CrN/3aB0Ciwr6LMaLqE1hcyJcPntPSChyJ6csOJqmDjwJFMOs8oML3gGcrWwAZ+y4gUPt6otUY0Z0OSoctr4TCFjKzziwTd4fs+i33zIyEIFTLblYiLKiOCvymx+BBrLTKC1RJoe9iZAGJQleBnx87sTCz5MY= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783070186; 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=NThAHoBNg8DkdpKZCAuwHukZHxyXIkvelDPgBuO8Jxc=; b=b2uC18odqAGHkYh1m3oGqSomz4wPA2KJuoT3+5VRk254lRZGVOtWVbD7Dbxz8BYcA6Ld+d15+F8PAKq+YN3GsiSiaOJVdrDUw3l0DeiTKkS03xp4U7jGWegtipeaR55pFYZ5bVC/+mi5D1Iraqr6f+7J1uVAT8Pc+WyilWqCAiY= 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 1783070186236473.7681542535902; Fri, 3 Jul 2026 02:16:26 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1353028.1609215 (Exim 4.92) (envelope-from ) id 1wfa05-0004Ez-U9; Fri, 03 Jul 2026 09:15:57 +0000 Received: by outflank-mailman (output) from mailman id 1353028.1609215; Fri, 03 Jul 2026 09:15:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wfa05-0004EK-PX; Fri, 03 Jul 2026 09:15:57 +0000 Received: by outflank-mailman (input) for mailman id 1353028; Fri, 03 Jul 2026 09:15:56 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wfa04-0004CB-EH for xen-devel@lists.xenproject.org; Fri, 03 Jul 2026 09:15:56 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wfa03-00GN2P-GX for xen-devel@lists.xenproject.org; Fri, 03 Jul 2026 11:15:55 +0200 Received: from [10.42.69.10] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a477dc6-2eae-0a2a0a5409dd-0a2a450ace40-8 for ; Fri, 03 Jul 2026 11:15:55 +0200 Received: from [52.101.125.115] (helo=TYVP286CU001.outbound.protection.outlook.com) by tlsNG-4011c0.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a477dc6-e40e-0a2a450a0019-34657d733221-4 for ; Fri, 03 Jul 2026 11:15:55 +0200 Received: from OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:458::18) by TY3P286MB3731.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:3d3::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.181.10; Fri, 3 Jul 2026 09:15:49 +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.0181.009; Fri, 3 Jul 2026 09:15:49 +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=nHYMtEk5qw5V/ZvYP2pL4lQE2SCWEx8+w7C1BO7kR8feLzMu1KpLVZBfNywUCTrRU7K23pccdInHQA/q09+ikOGdlf6z0EW6jnCMzs0OvoGPzImUoQR6DjVcv9aBzcpixLemGPrtkUd8OOmSusHayE2EI2uTzCQxMFspWfCln7UVj3LCLVFcEMWGQijqjUKHwWKXeMu+29TqScj5U/okS080A3EQkgUY2HUCm0RkAhCzLJu85A4Q6EIyMSim25DQhTljQLW5odK/AsiKNN3MXKmNOm4F7vGO+Wy+5tzvv0tBFOASVLRTsrROivnMrPliBwt7qYyCJ/3fG0UJFc/c3w== 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=NThAHoBNg8DkdpKZCAuwHukZHxyXIkvelDPgBuO8Jxc=; b=WFGTDRfzqPB4V6Fufp325EvdULp4YuuHuV6DoKNuqB41f4JOb2IExNDXI08YK0ElAX/EuD/HaQ6NlOVNOoL9ARePPI6To4Imsw5h4C+8QTqLHVNI3clGIDd96hv4rfE6nvDlQ77QaieDYYqblfThOjNUizvKK0nHrZuXDwrGWhmnm54/K5x4+ASWoCtPurI3syzdahTUniVbYaXGQ3rEKbxWUFQqaR+42/ap98xC0695n2Eecx5alyDA0yu+5UE9IS0f55oOqmc7/dD75s2R4m2NqOieKX47qxdWUQYZqkC6I2Q3bry5x2QJV1pWfL3ub6BSKc74FFqKQb+WAwT0hw== 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=NThAHoBNg8DkdpKZCAuwHukZHxyXIkvelDPgBuO8Jxc=; b=iNylflYEbu3pAMMmLruqtBRGJGU5UDRPWATkgN/7/MsTP2QuuPsTkCzbJrSEpO5aWAaTDjTT/e8121bSTqInKkvUWbwXho8PZAW97KzQwyuJZA2YwaxFj/dRpi858PYbArl2/McUOIC6LqhnJt3Z7mFHQ5uEIC+s6OWj5Itg/pI= 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: 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?= Subject: [PATCH v4 1/3] xen/device-tree: Parse 'cpu-map' node for CPU topology exploration Date: Fri, 3 Jul 2026 18:15:42 +0900 Message-ID: <20260703091544.183548-2-taka@valinux.co.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260703091544.183548-1-taka@valinux.co.jp> References: <20260703091544.183548-1-taka@valinux.co.jp> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: TY4P301CA0068.JPNP301.PROD.OUTLOOK.COM (2603:1096:405:36a::7) To OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:458::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OS9P286MB7222:EE_|TY3P286MB3731:EE_ X-MS-Office365-Filtering-Correlation-Id: dc408169-b0e3-4f62-e9a3-08ded8e3ac48 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|366016|1800799024|7416014|376014|10070799003|3023799007|29003799003|25016099003|6133799003|56012099006|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: 7sDJ0od3F7aChrt6sTpQC536rY0xOISWjcEeS7jjTRkxXBmnqN2Ay277rHnabzXvEIYVdbsyYEZGqs+Iaht7o5cKReRgPXA8MNzck+kwG/Ef4vO63cJs+gpHubD7pyy8yfp0QuJf1PdGjnd3wO3kGV/WtyZE8id5Y+q7aG8L1L14B8TPUqQT44rUBBmUd21Fkhk6CLftu2m47u2yhYzAcdP6PEM3ExJyAE8syTMxZfm98X4QSc48bMRlwa+LXPRT7dAEDTPydpHCuc0aiTaaIZ5F67wEjlJOaw+cYDZWdpwM0tfid/Ynh2nKkD8i4S68gfpclDMa3gmfJ6DMA8O2rFacISrZZreiU5DCJQotYIPsnIdNz2oqxCA/d7yyKpW7Gk1LgmJvVo7nuV92YkhbzYnZp7RjmUk9MjDEU/qiKtpu15C9ffqmrrZ7JTSAk4tjTHTiC7M4cc1mhwWIPmSn8qVwcF1lsFzHSDbty0PIgukOvXka3WLE1++ZCsaLiDhKBJxNX/EzhYnh/N7IUbd/mUwmMTZBlACl1z0d9vOaOrSuuq+i6Q0gfT+hzKeAUQDxOxxDy2egd6fvqIw5xL8DdJlhUJWQBZ4bYC53oQdxwakzCZebH8MJkmOzKhUCWj0CCcOG8oUjaKmpeIIh/moVXNZ1LQOFiaPX66CjfqjqF2w= 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)(23010399003)(366016)(1800799024)(7416014)(376014)(10070799003)(3023799007)(29003799003)(25016099003)(6133799003)(56012099006)(22082099003)(18002099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?uh6JORA60YRI0i+YuLX5dgLNcFkEgAXZP7p1Yn03h+vHi05RgaZtILKgpREx?= =?us-ascii?Q?AWw+6t8J2jKnKCSfMI2dDx4MjKViiufute/tT2ECtSfF5va1NTkscLd9bg2n?= =?us-ascii?Q?T41dJmKRGV2D42s/0mvUGqd+uw2HSxniyxL/s4ll1zat4Q73uisHhUN1ZdMv?= =?us-ascii?Q?32Cx/pMYKo/xX2nUNMmCZEpFwsoKbqHafjFh5dmcgDrMHcrSfkI3iIyTUFPD?= =?us-ascii?Q?hO7tMBhxc5cagdfrkg8K3vx3piVrq8PHTYpRReg8TssOMkgNHBeO7J5aDyVY?= =?us-ascii?Q?GGnHSQSedjkrWQKB7NhAz2yAoFTzAXUgfhQmb7GLFmfmUu1EGRbfsX+Sh0wm?= =?us-ascii?Q?JZijqC6NsZcaScSSeWMUjQE/g4hioJqaR/jBrOhkwGt08X1ydJktC1kV+YJH?= =?us-ascii?Q?ZX0gcDI8TExpbE29uUPCUYuwRrrFxHHNJLCd5eGm0yuqaJjP2xPy0vm50HZu?= =?us-ascii?Q?LHBI891XHB38X+FxWkLGswgxbZRdwJZg2GIXfw7iGEza6SlDTCbmPFUewZWx?= =?us-ascii?Q?Nf+pnCik2rc5+VbIS47MJkyiYxLpheJXa7KFo8mX31gqqCt025SC2lT37Qpy?= =?us-ascii?Q?vbnI+feihlxrjL60OZKLafeWK0Fly1SH5sOK/hDZDx1CHONSQ0szzmEuiqN6?= =?us-ascii?Q?+1p2Egf23dmhuqdyOOUCMBmBFkjCxrrDwLaKO2Ri6NtnVtBuSQF/nt5xYd0+?= =?us-ascii?Q?vVyFwnE3Or7TpHdtWh/mpcEYG0+1klBAfVV2LYDBUrcakqtgZX7d9PCFD/40?= =?us-ascii?Q?5HsKY/w8m7rircmyQ3YdO3W458gd6lIC3vDOojnPLzQEuJbl+gYc+E5HR3GP?= =?us-ascii?Q?rO9At3K6oc0Q9n9dOLYXobID1XfnIlOysrqt09fQwrYo2DVeJ5qvZeWgk/vb?= =?us-ascii?Q?9ZYtkQAI02nHzroZyCPo3ScBawVDO2fa2jiddbFMWAOy8oBlqUL59SKCA29c?= =?us-ascii?Q?H0UDUSRxjt2b8NfzuRx0kb8auNs8RzP3S1veYEPpy96e/IKyJqnTknIcIBvE?= =?us-ascii?Q?G5ffqtneWSAMNAVqFSSBTHFOvh1CWT2FdnuMphcDJdclEIgTl3u8E+5D+XEE?= =?us-ascii?Q?P1U9n75hKY9igd+Vz9r0u+Wg4xzNVv9ctJ3Hvw4RN2A/WtHv5YDkS0F+zGrm?= =?us-ascii?Q?QiaL8DBAR3F9ZMtK3GrKNNPB6/Fx+aEB5M1/yQopuuKsrKOBTCp6uQynnNbj?= =?us-ascii?Q?RSHc2g6DY7i/1KaQtl68fLJ9KNiWtEQOo073FKV4KT3HbRmD9q6zAM7th54w?= =?us-ascii?Q?TMcmRjiQqqELaK10LWI6LFlahpdU5AhDHUb6p1P94UUl7dvoH2c7iocFYHce?= =?us-ascii?Q?xOy4R2EtMIj4BkCK4PlHvFXlJfmR39pf0BtaySmySVIvsq9VBt8Ws6UO5ZEb?= =?us-ascii?Q?z26ss7hqPmZQc70j2NvqeNE3wzsftOOfQilNl4zhVrYqs9lCODx1pP3520SE?= =?us-ascii?Q?MU+PWmY2wZiU6MH+jwivCGV80XKdKPh27458lmTfyvtw8O5KMwvP9GcvCfJz?= =?us-ascii?Q?0RATmXWdkx+YVHy1qNh9kwPNq9kAqF0brJbWy7G8155kyR7HgHe2QGIOtKPg?= =?us-ascii?Q?P/uCXVB9vGPk+peHBfidiNo3QOV7rTdvTweUIBI/WTsHm+d3Z1ot73GaIJvn?= =?us-ascii?Q?jFIlMWeSpqCQpnvViC5K9JgsH5XzeOGCNyiN4EOpuM3aeSYxxYV8pQD+hDjP?= =?us-ascii?Q?TV7jDQtcIptd33Wgrqz59V9trFZTGDTqN0GanCw/QekOrBQyn03USlYs2112?= =?us-ascii?Q?B8TFW5N3CM/RshzDqF3ugIURbC1D3uOTmrK5MtsjpAFizLHW+QEccu/c4Cu8?= X-MS-Exchange-AntiSpam-MessageData-1: nbcw1yE3qkfuUg== X-OriginatorOrg: valinux.co.jp X-MS-Exchange-CrossTenant-Network-Message-Id: dc408169-b0e3-4f62-e9a3-08ded8e3ac48 X-MS-Exchange-CrossTenant-AuthSource: OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jul 2026 09:15:49.4886 (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: z5cChvhGNC5LgbV4nTCd46wtawED68Pfxr9ot0W4s/MpAM7Eh1j/qONZiypyvvQR+wNyNQl6a6QF+VjSg0pLuA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY3P286MB3731 X-purgate-ID: tlsNG-4011c0/1783070155-D653FDDE-276232E8/0/0 X-purgate-type: clean X-purgate-size: 22852 X-ZohoMail-DKIM: pass (identity @valinux.co.jp) X-ZM-MESSAGEID: 1783070188212158500 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 --- Changes in v4: - Only display the CPU topology configuration prompt in common/Kconfig if the architecture defines HAS_GENERIC_CPU_TOPOLOGY. - Move the definition of the global 'cpu_topology' pointer to common/cpu-topology.c. - Update the Makefile to explicitly build objects as .init.o when all functions and data within a file are annotated with __init/__initdata, ensuring their memory is reclaimed after system initialization. - Add an error log in the CPU-to-node mapping function for out-of-bounds cases. - Use ARRAY_SIZE() instead of raw macros when guarding array accesses. - Rename variables and functions to avoid ambiguous or misleading terms: - Avoid 'cpuid' to prevent confusion with x86 CPUID features/instruction= s. - Avoid 'node' where it could be confused with a NUMA node, explicitly renaming them to clarify they refer to a Device Tree node. - Move local variable declarations into the narrowest possible scope. - Replace the unsupported "%pOF" printk format specifier with "%s" and explicit node name retrieval. - Remove #include from cpu-topology.h, and ensure the header directly includes only what its definitions require. - Remove #include from dt-cpu-topology.h, replacing it with a forward declaration of 'struct dt_device_node'. - Use 'const' qualifiers for pointer declarations where the pointed-to structure is not modified. Changes in v3: - Use (nr_cpu_ids - 1) as the maximum CPU ID here. The fix for the sparse map mismatch issue on ARM Xen has been split out into a separate patch. - Switch topology sibling masks to cpumask_var_t for dynamic allocation. - Allow the system to keep running with a degraded fallback even if the topology table allocation fails. - Clean up the code to follow the Xen coding style. Please let me know if I missed any style nits! - Verify successful builds across x86, RISC-V, and PPC environments. Changes in v2: - Generate topology information even when ACPI is enabled. Note that this is a temporary implementation and doesn't yet parse the PPTT (Processor Properties Topology Table). - Added support for cpu-map node in Device Tree that doesn't contain explicit cluster node definitions. xen/arch/arm/Kconfig | 1 + xen/arch/arm/smpboot.c | 7 + xen/common/Kconfig | 18 ++ xen/common/Makefile | 1 + xen/common/cpu-topology.c | 62 +++++ xen/common/device-tree/Makefile | 1 + xen/common/device-tree/cpu-topology.c | 355 ++++++++++++++++++++++++++ xen/drivers/acpi/Kconfig | 3 + xen/drivers/acpi/Makefile | 1 + xen/drivers/acpi/topology.c | 38 +++ xen/include/xen/acpi.h | 2 + xen/include/xen/cpu-topology.h | 35 +++ xen/include/xen/dt-cpu-topology.h | 29 +++ 13 files changed, 553 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 5fa89fcb24..a390844432 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -22,6 +22,7 @@ config ARM select HAS_GRANT_CACHE_FLUSH if GRANT_TABLE select HAS_STACK_PROTECTOR select HAS_UBSAN + select HAS_GENERIC_CPU_TOPOLOGY =20 config ARCH_DEFCONFIG string diff --git a/xen/arch/arm/smpboot.c b/xen/arch/arm/smpboot.c index 7f3cfa812e..5ce2bcf6ec 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 @@ -242,6 +244,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 ) @@ -279,6 +284,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 5ff71480ee..6ee689cbdd 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -188,6 +188,24 @@ config VM_EVENT config NEEDS_LIBELF bool =20 +config HAS_GENERIC_CPU_TOPOLOGY + bool + +config DT_CPU_TOPOLOGY + bool + +config GENERIC_CPU_TOPOLOGY + bool "CPU topology support (UNSUPPORTED)" if UNSUPPORTED + depends on HAS_GENERIC_CPU_TOPOLOGY + select DT_CPU_TOPOLOGY if DEVICE_TREE_PARSE + select ACPI_CPU_TOPOLOGY if ACPI + help + Retrieve CPU topology information from the device tree to optimize + virtual CPU scheduling. + + Note: Implementation for parsing CPU topology from the ACPI PPTT + is currently missing. + config NUMA bool =20 diff --git a/xen/common/Makefile b/xen/common/Makefile index 6018e25614..34b333cdb3 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.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..94cb9ba312 --- /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 + +struct cpu_topology *__ro_after_init cpu_topology; + +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); + } + + XFREE(cpu_topology); +} + +void __init init_cpu_topology(void) +{ + unsigned int cpu; + + cpu_topology =3D xzalloc_array(struct cpu_topology, nr_cpu_ids); + if ( !cpu_topology ) + { + printk(XENLOG_ERR "Failed to allocate memory for cpu_topology tabl= e\n"); + 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(); + printk(XENLOG_ERR "Failed to allocate memory for cpu_topology = table\n"); + return; + } + } + + if ( acpi_disabled ) + dt_init_cpu_topology(); + else + acpi_init_cpu_topology(); +} + +/* + * 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/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..b653227ef4 --- /dev/null +++ b/xen/common/device-tree/cpu-topology.c @@ -0,0 +1,355 @@ +/* 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 +#include + +struct cpu_map { + unsigned int thread_id; + unsigned int core_id; + unsigned int cluster_id; + unsigned int package_id; +}; + +static const unsigned int __initdata invalid_topo_id =3D ~0U; +static struct cpu_map __initdata cpu_map[NR_CPUS] =3D { + [0 ... NR_CPUS - 1] =3D {invalid_topo_id, invalid_topo_id, invalid_top= o_id, 0} +}; +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 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_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 struct dt_device_node *__init + dt_find_child_node_by_name(const struct dt_device_node *dt, + const char *name) +{ + struct dt_device_node *np; + + dt_for_each_child_node(dt, np) + if ( np->name && (dt_node_cmp(np->name, name) =3D=3D 0) ) + break; + + return np; +} + +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 id %u exceeds the max cores %lu\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 logical 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, "c= pu", 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 i =3D 0; + unsigned int cpu; + + do { + const struct dt_device_node *t; + char name[20]; + + snprintf(name, sizeof(name), "thread%u", i); + t =3D dt_find_child_node_by_name(core, name); + + if ( !t ) + break; + + leaf =3D false; + cpu =3D get_cpu_for_node(t); + if ( cpu !=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 i; + } + else + { + printk(XENLOG_ERR + "ERROR: %s: Can't get CPU for thread\n", dt_node_name(t= )); + return -EINVAL; + } + i++; + } while ( true ); + + 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; + } + + 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 =3D 0; + unsigned int i =3D 0; + + /* + * 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. + */ + do { + const struct dt_device_node *c; + char name[20]; + int ret; + + snprintf(name, sizeof(name), "cluster%u", i); + c =3D dt_find_child_node_by_name(cluster, name); + + if ( !c ) + break; + + leaf =3D false; + ret =3D parse_cluster(c, package_id, i, 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; + i++; + } while ( true ); + + /* Now check for cores */ + i =3D 0; + do { + const struct dt_device_node *c; + char name[20]; + int ret; + + snprintf(name, sizeof(name), "core%u", i); + c =3D dt_find_child_node_by_name(cluster, name); + + if ( !c ) + 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(c)); + return -EINVAL; + } + + if ( leaf ) + { + ret =3D parse_core(c, 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; + } + + i++; + } while ( true ); + + 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 =3D 0; + int ret; + + do { + const struct dt_device_node *c; + char name[20]; + + snprintf(name, sizeof(name), "socket%u", package_id); + c =3D dt_find_child_node_by_name(socket, name); + + if ( !c ) + break; + + has_socket =3D true; + ret =3D parse_cluster(c, package_id, invalid_topo_id, 0); + if ( ret !=3D 0 ) + return ret; + + package_id++; + } while ( true ); + + if ( !has_socket ) + ret =3D parse_cluster(socket, 0, invalid_topo_id, 0); + + return ret; +} + +/* + * Generate cpu topology information when cpu-map node doesn't exist. + * It assumes that the cpu doesn't have SMT and all CPUs on a NUMA + * node belong to the same socket. + */ +static void __init fixup_topology(void) +{ + unsigned int cpu; + unsigned int clid =3D 0; + unsigned int pkgid =3D 0; + + for_each_possible_cpu(cpu) + { + struct cpu_map *map =3D &cpu_map[cpu]; + + map->package_id =3D cpu_to_node(cpu); + if ( map->package_id !=3D pkgid ) + { + pkgid =3D map->package_id; + clid =3D 0; + } + map->cluster_id =3D clid++; + map->core_id =3D 0; + map->thread_id =3D 0; + } +} + +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 ) + { + printk(XENLOG_ERR "ERROR: No CPU information found in DT\n"); + return -EINVAL; + } + + map =3D dt_find_child_node_by_name(cpus, "cpu-map"); + if ( !map ) + return -ENOENT; + + return parse_socket(map); +} + +void __init dt_init_cpu_topology(void) +{ + unsigned int cpu; + + BUG_ON(!acpi_disabled); + BUG_ON(!cpu_topology); + + if ( parse_dt_topology() ) + fixup_topology(); + + for_each_possible_cpu(cpu) + setup_siblings_masks(cpu); +} + +/* + * 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/Kconfig b/xen/drivers/acpi/Kconfig index e3f3d8f4b1..5277b7bf83 100644 --- a/xen/drivers/acpi/Kconfig +++ b/xen/drivers/acpi/Kconfig @@ -8,3 +8,6 @@ config ACPI_LEGACY_TABLES_LOOKUP config ACPI_NUMA bool select NUMA + +config ACPI_CPU_TOPOLOGY + bool diff --git a/xen/drivers/acpi/Makefile b/xen/drivers/acpi/Makefile index 477408afbe..bcdb1b5e1b 100644 --- a/xen/drivers/acpi/Makefile +++ b/xen/drivers/acpi/Makefile @@ -10,3 +10,4 @@ obj-$(CONFIG_PM_OP) +=3D pm-op.o =20 obj-$(CONFIG_X86) +=3D hwregs.o obj-$(CONFIG_X86) +=3D reboot.o +obj-$(CONFIG_ACPI_CPU_TOPOLOGY) +=3D topology.init.o diff --git a/xen/drivers/acpi/topology.c b/xen/drivers/acpi/topology.c new file mode 100644 index 0000000000..6bd2d96ebb --- /dev/null +++ b/xen/drivers/acpi/topology.c @@ -0,0 +1,38 @@ +/* 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). + */ +void __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); + } +} + +/* + * 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..d531c76370 100644 --- a/xen/include/xen/acpi.h +++ b/xen/include/xen/acpi.h @@ -101,6 +101,8 @@ void acpi_table_print (struct acpi_table_header *header= , unsigned long phys_addr void acpi_table_print_madt_entry (struct acpi_subtable_header *madt); void acpi_table_print_srat_entry (struct acpi_subtable_header *srat); =20 +void acpi_init_cpu_topology(void); + /* the following four functions are architecture-dependent */ void acpi_numa_slit_init (struct acpi_table_slit *slit); void acpi_numa_processor_affinity_init(const struct acpi_srat_cpu_affinity= *); diff --git a/xen/include/xen/cpu-topology.h b/xen/include/xen/cpu-topology.h new file mode 100644 index 0000000000..f64820febf --- /dev/null +++ b/xen/include/xen/cpu-topology.h @@ -0,0 +1,35 @@ +/* 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 */ + +#define cpu_topology ((struct cpu_topology *)NULL) +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..cb8a266479 --- /dev/null +++ b/xen/include/xen/dt-cpu-topology.h @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef XEN_DT_CPU_TOPOLOGY_H +#define XEN_DT_CPU_TOPOLOGY_H + +struct dt_device_node; + +#ifdef CONFIG_DT_CPU_TOPOLOGY + +void map_cpu_to_dt_node(unsigned int cpu, struct dt_device_node *cpu_node); +void 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) {} + +#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 Sat Jul 4 21:13:36 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=1783070192; cv=pass; d=zohomail.com; s=zohoarc; b=S0l9xIMe3XcT2Eq2EZOQyZnJJipQ/9wMOzzTCqfvrNXeGkaNnUHmFuYuwXu0dxpWPso5Na6LmOZ4rpGJzZ6ZIbaDzP0cIX2yb/tJHi7fP9ZSdq/oU53VZnWDS1gUljVNIBFCTcBwxZ4cyl7rG+e4hkRZnY0xwWAj4USRsELNQv8= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783070192; 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=+YHhlMJ0BRCDYFFnZBlOKPtPhGxi/edvzDAP34FGr24=; b=eZ2U4F/K4+4jD3xqXcuuCvzRoi/N43dmId32/AMcb7zU2QHlLVfa/NcE19kr3XXltpamg7YJts4Xq+4i0cTCEUt6aGUmbES7hdLsS6ZUxQDPfZGmM/B4p5Ra49n8PilQKOhJbSekymimsxU7L0b++HDfEBsPWD39PQsHPYM6tGU= 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 1783070192733334.89890312994373; Fri, 3 Jul 2026 02:16:32 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1353029.1609228 (Exim 4.92) (envelope-from ) id 1wfa07-0004cI-8y; Fri, 03 Jul 2026 09:15:59 +0000 Received: by outflank-mailman (output) from mailman id 1353029.1609228; Fri, 03 Jul 2026 09:15: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 1wfa07-0004cA-4o; Fri, 03 Jul 2026 09:15:59 +0000 Received: by outflank-mailman (input) for mailman id 1353029; Fri, 03 Jul 2026 09:15:57 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wfa05-0004CO-EJ for xen-devel@lists.xenproject.org; Fri, 03 Jul 2026 09:15:57 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wfa04-00GN2P-RH for xen-devel@lists.xenproject.org; Fri, 03 Jul 2026 11:15:56 +0200 Received: from [10.42.69.10] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a477dc6-2eae-0a2a0a5409dd-0a2a450ace40-18 for ; Fri, 03 Jul 2026 11:15:56 +0200 Received: from [52.101.125.115] (helo=TYVP286CU001.outbound.protection.outlook.com) by tlsNG-4011c0.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a477dc6-e40e-0a2a450a0019-34657d733221-5 for ; Fri, 03 Jul 2026 11:15:56 +0200 Received: from OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:458::18) by TY3P286MB3731.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:3d3::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.181.10; Fri, 3 Jul 2026 09:15:51 +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.0181.009; Fri, 3 Jul 2026 09:15:51 +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=aLQf9NjWFAp0sgYXR18wZlVg/+WBL1XhhzCuFFSa2YTAVJVYMICZeO4I6K35UUMjbt4mrsy2qDe77Rp7m3Bf51boIW8Fqd32UyQKDZT9VVTwGakSK/03W0/S1CtkgGubAoEkvF4iguTzp86j8flI23e2jRRSTlbqufDERIW0RjQrHjTdSgyt9Jj6I9OdnKectMb1ryXKLwPd91LaELnLiwLsBQNwHc1wnLf4APmc6pLCllN5dZmLLEHvJ4ffHWTXaJQdiuRjrud9uBbUOZChgXf/aOYsIW9ZdEtaIosZab0Z+cjXzpKhBoP7y0ZHoKi5yJRGZZ+SZ1M/dnMvvACc6w== 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=+YHhlMJ0BRCDYFFnZBlOKPtPhGxi/edvzDAP34FGr24=; b=NsYvwOpSjf9vS+JCTcngE8sLnQkwc7UojEJkKIjDO34iNzeF0T/M9FoTWJao+S4Ryt2hp9JOn6nC+fqeKu1Xc0P/TVBZ6YNm1eJPAN19MzJnPBypqydbUXRf4yHAmDQomnJJvTZBbFAoG2xwH0QVKKijGLKao8y4RIhiVMkNA0uu4LoncwPzIJo5/B2lggyvv2RIZ0SCA3gTNMOK0TtF9hyMgtHYmco4HeNpvVJd/widtHrwrcQZMmt4LgEhIw+eI3laLeHjFOMYxWmGKoyCbuh4trG6BJNmpp3q6DXrr/DsHgMZmvarpx0ySJG8CVWeYw4RrZ4KOltp0Y2YStyy2Q== 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=+YHhlMJ0BRCDYFFnZBlOKPtPhGxi/edvzDAP34FGr24=; b=S73jlVwO/nBJ5kW3IUiFk+6QGyNfHhcIZ/W++QIYEJSl5S93Db6GcKl8kfTPW9b7/gcFaLXgGf2tuehwKxjAfFscOrHBeoI5dpMRQk+yjFQ/j9YBTkwknpfcur8Czt2V6aBzGWHv2u+CGxLaqlrW7A6SP0E9wnPfEGbBfxJG+bY= 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: 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?= , Timothy Pearson , Alistair Francis , Connor Davis , Oleksii Kurochko , Dario Faggioli , Juergen Gross , George Dunlap Subject: [PATCH v4 2/3] xen/sched: Link CPU topology to scheduler Date: Fri, 3 Jul 2026 18:15:43 +0900 Message-ID: <20260703091544.183548-3-taka@valinux.co.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260703091544.183548-1-taka@valinux.co.jp> References: <20260703091544.183548-1-taka@valinux.co.jp> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: TY4P301CA0066.JPNP301.PROD.OUTLOOK.COM (2603:1096:405:36a::19) To OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:458::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OS9P286MB7222:EE_|TY3P286MB3731:EE_ X-MS-Office365-Filtering-Correlation-Id: 3bb621b4-27f9-4158-1e13-08ded8e3ad3b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|366016|1800799024|7416014|376014|10070799003|6133799003|56012099006|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: nA6/Gz9DLhADgr6Uqb4vb8g/ivN7hfVWeBPFRkSrrFRqZXVc5mqcceZusHmkG4cOolrqdGuiFfa7GNDp9hiz8pNhdcJYw+Wnh9+21xBghhYswIM9/uIx0heSIM2QGSsryD/CJOz68YPojqRt5QQ7AeNF3KBQs2pob/tMLT4rBJ0ZFv4+FISDstVYbJHHU/8yGkDQzl1zK88EAhcETXYxS/bUHOJ4zUKp91wu6bWm5rS42JTETGQZ423dof71D9dBNMeIwz0B8j0pNNSya0lThgK0xgl88C2Q1WrbjCoQ8D5VjgaWaNVj9ACBf/RVqYeXatumWHFQaXywYir+dW3YY3yepjROTm5qyhhkh0QE26nHP1ApjN/OFtnE+SAgvMlVTc5IUNZu8QB2ObghrFu7SG14MELa6lNB1uDy5tMIMXMbRvSqZPhUL0/W+D/JcuzcHMEyyx4ot58qbSRF9Z87BTs/Ne1LO3z7Uwe/BvIAyV+ox3iSzHv/ILkN0oB73y05/k5hGm7bPWjCCT1eTBHjoziiTzqfUFCecNMlHE4VVhMnFV1RAItoavZ89Fxz5+Ex7Uxg79GW7qqfO6VrPEtElHLKYLf/2YW7sPsOtx46C2tpN0b2W+AHKMpd9ZHFpWWSjJvcDob0gLAqixKjWYeA7FQ18tEB0g/Lce4nMfKHevk= 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)(23010399003)(366016)(1800799024)(7416014)(376014)(10070799003)(6133799003)(56012099006)(22082099003)(18002099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?0D1BFx68aW6aVfbvesUXY8qnLYpTgYMqvDI/zjEIZblavbahj17IdISxMZR7?= =?us-ascii?Q?zJrAs2gOk4PmK9DR4nUSqu+IMi4DlqpVuMuHBpM0HXOkT9d2lcU2vHEGZRUQ?= =?us-ascii?Q?d4SN0SnmA3kM5rusKqnWzyLsAvX02v7NqRHTgMbXX0R68LYmokg/uOCQbR4R?= =?us-ascii?Q?fQs9HpuPaiwixb2V5otqNTlU6U12G3cMisPtHQwQJm1PUb4zog1lvLXmj5JD?= =?us-ascii?Q?X7j5rsLRhEdYwY8Vno+s5T0/IWpohADqqSQnYS3WsD7oF/EZt7tUvJplYn3W?= =?us-ascii?Q?JMpBX4NlX4BAwlSjZT4hparUwKzV4SFxTdHuUp/j0t/+0knpQsaTavaN8JS3?= =?us-ascii?Q?gF//RuRiZtoUdLBXr25aH1xpECThf/9TcG07i6T7tiWznhkCHVPSSU4yHCq+?= =?us-ascii?Q?1kdZsc+Dicz41dOKlLaTDcVsMwuLTM7aYlkk/E2PEa2RVBIVh7m4NhdG5HQb?= =?us-ascii?Q?iaFuNx3Gf2MDKo4M3p2zWUQ471gvEwYMSvkfUGjI7TBXoj2VIMOAvRxm0oBD?= =?us-ascii?Q?1HbPPjsdi+g1t/ak7GAHBc9HMPZHTzhoWt0PDIf5+gjcFc766qXWTMhBT+1l?= =?us-ascii?Q?js8GCwarqWmkVBHGGqbwd2eQ7+iHjhfiuQC+Xfk6h7u5a72Kv71fz93BG4T9?= =?us-ascii?Q?sqSZfz0fOCIYJhrULkjc5AbAODl2gqYCJo1Pyj1Enk9/YOVGA4ief1m8Gl8U?= =?us-ascii?Q?dablmPisjYCRWEaVtScoq+NeNwf0TErHANS9ZtuRNodGz0Mjcc8jmkTyHS7V?= =?us-ascii?Q?by1y56iAddykWGmKDYC3hoc+Wl4n7ehYuazWWCQQMphr4cx974wJXemHUbIY?= =?us-ascii?Q?bfzCuNTJEs9TIOGO5jqXdSz3v3pG5RENCouhI6muQ4E5hfOTcxNqmSFIvD9M?= =?us-ascii?Q?BzuAncAHkwBe4u8LL+cKpuvPEeBh2mL3slGXC1CoorfXJyP6A50qmFuMGKA7?= =?us-ascii?Q?7PFM6ZnueCjq6jdwqu8dpPFi2eW5crNUFneE/jXKMWTOEsBsnygSgidopipa?= =?us-ascii?Q?XWvFTsHueAzPHL0gp6ohfxl9HZGpcudtXNVfMU3HbPyHrDqUjhk11oK3ubAX?= =?us-ascii?Q?yq9Brn4yWZZFyEwoPtIgGde4OGDrOhls5dA4ryQlZV4xW7FbeFhYeAz80xki?= =?us-ascii?Q?8rIGA4uTrW39NQa4t4DmFq4Jmna2d/GYHieUmgsSqZx8UXSdoLAikCSY4Ztc?= =?us-ascii?Q?YwdM+HCCkU1TB7I8xT1FqYPrx/DcVSpAAzLkLiqpIHuP+BNBpJglG3hDnCrf?= =?us-ascii?Q?hAMJx1MEDHUmvo9AV/lmuYFgDIbWdDh6vL3wW/y376nkpAzUkTVdlrn8tEqz?= =?us-ascii?Q?6KDZkxMVi6u6wav7AuQKaueJHqBIZoNPaqUsjr7nezX6tjR8BB3E93nzB6hJ?= =?us-ascii?Q?SE7gGOmRM7rgn9mep++85z6tPBO0M43LZ+NsFgGPNyyAJxxDY6cK13CAhWbL?= =?us-ascii?Q?ndVgsZ+zMtirgXUCfAP3+GiO5wtwVtXug7sb1XN6jV8s8M78ySCLmO8XwcZq?= =?us-ascii?Q?A+vbBrSI+pRF1ed2arYnOua9VN+Dba7a68fixxed74upp3hYRYpiFXZ93vvo?= =?us-ascii?Q?QGa+8q/5vMFSuMZ1mRQk+RkFTyaWz2pX/hPt9SgNnlkZc3JnWDVcwJkxauZK?= =?us-ascii?Q?K4dfY3ixGKtGHG7VOKRHHaWNUowLPZ/5BedddCDiZ/wXhYcSQD1fbifDMPVz?= =?us-ascii?Q?nVQESFmozWbjobUJTG+fVy4SGYk72M71L1sH+FElPQNKITf5rfu2scGE75Gh?= =?us-ascii?Q?0JH6RDH2UUAhfHvIxIh8T046+0QVTQWjcOHaZH6+VlM/O2zzcZIOVLNuegeE?= X-MS-Exchange-AntiSpam-MessageData-1: x9kPTIBldMY/0w== X-OriginatorOrg: valinux.co.jp X-MS-Exchange-CrossTenant-Network-Message-Id: 3bb621b4-27f9-4158-1e13-08ded8e3ad3b X-MS-Exchange-CrossTenant-AuthSource: OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jul 2026 09:15:51.0417 (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: y4EaEG/NesYEwkb1Vgnv91kV8OexUC+y+UesgDFni0vdAPuYU6GhQjS/Gbe2ZmYjfX5m/3WzO/In61hqPvEQ2g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY3P286MB3731 X-purgate-ID: tlsNG-4011c0/1783070156-D5D23DDE-8CB46B54/0/0 X-purgate-type: clean X-purgate-size: 9565 X-ZohoMail-DKIM: pass (identity @valinux.co.jp) X-ZM-MESSAGEID: 1783070194054158500 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 --- Changes in v4 - Explicitly #include in cpu-topology.h to guarantee that arch-specific definitions of cpu_to_core() and cpu_to_socket() take precedence over the generic fallbacks. - Introduce inline initialization functions for cpu_sibling_mask and cpu_core_mask in cpu-topology.h, providing separate variants for both when CONFIG_GENERIC_CPU_TOPOLOGY is enabled and disabled. Changes in v3 - Remove the temporary definitions of cpu_to_core() and cpu_to_socket() from RISC-V and PPC processor.h. - Minimize the use of #ifdef blocks, leveraging compiler Dead Code Elimination (DCE) where possible. 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 | 51 ++++++++++++++++++++++++++ xen/common/sched/credit2.c | 3 ++ xen/common/sysctl.c | 1 + xen/drivers/acpi/topology.c | 3 ++ xen/include/xen/cpu-topology.h | 45 ++++++++++++++++++++++- 9 files changed, 103 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 5ce2bcf6ec..3c9f2a5c53 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 b653227ef4..43322a153f 100644 --- a/xen/common/device-tree/cpu-topology.c +++ b/xen/common/device-tree/cpu-topology.c @@ -330,6 +330,55 @@ 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); + 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; + + /* Reuse the calculated core id if clustering is not supported */ + if ( cpumask_empty(topo->cluster_sibling) ) + topo->phys_cluster_id =3D topo->phys_core_id; + else + { + first_cpu =3D cpumask_first(topo->cluster_sibling); + 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); + 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); + } +} + void __init dt_init_cpu_topology(void) { unsigned int cpu; @@ -342,6 +391,8 @@ void __init dt_init_cpu_topology(void) =20 for_each_possible_cpu(cpu) setup_siblings_masks(cpu); + + setup_cpu_topology_ids(); } =20 /* diff --git a/xen/common/sched/credit2.c b/xen/common/sched/credit2.c index 95946634d1..ada430f262 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 @@ -37,6 +38,8 @@ static unsigned int cpu_nr_siblings(unsigned int cpu) { #ifdef CONFIG_X86 return cpu_data[cpu].x86_num_siblings; +#elif defined(CONFIG_CPU_TOPOLOGY) + return cpu_topology ? cpu_topology[cpu].num_siblings : 1; #else return 1; #endif 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 6bd2d96ebb..9155edc0be 100644 --- a/xen/drivers/acpi/topology.c +++ b/xen/drivers/acpi/topology.c @@ -22,6 +22,9 @@ void __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); } diff --git a/xen/include/xen/cpu-topology.h b/xen/include/xen/cpu-topology.h index f64820febf..ee34425680 100644 --- a/xen/include/xen/cpu-topology.h +++ b/xen/include/xen/cpu-topology.h @@ -4,6 +4,9 @@ #define XEN_CPU_TOPOLOGY_H =20 #include +#include +#include +#include =20 #ifdef CONFIG_GENERIC_CPU_TOPOLOGY =20 @@ -11,16 +14,56 @@ 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; void init_cpu_topology(void); =20 +static inline void init_cpu_sibling_map(unsigned int cpu) +{ + if ( 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 + { + cpumask_set_cpu(cpu, per_cpu(cpu_sibling_mask, cpu)); + cpumask_copy(per_cpu(cpu_core_mask, cpu), &cpu_possible_map); + } +} + +#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 -#define cpu_topology ((struct cpu_topology *)NULL) static inline void init_cpu_topology(void) {} =20 +static inline void init_cpu_sibling_map(unsigned int cpu) +{ + /* + * If CONFIG_GENERIC_CPU_TOPOLOGY is disabled, it is assumed that + * all CPUs reside in the same socket and that SMT is not used. + */ + cpumask_set_cpu(cpu, per_cpu(cpu_sibling_mask, cpu)); + cpumask_copy(per_cpu(cpu_core_mask, cpu), &cpu_possible_map); +} + +#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 Sat Jul 4 21:13:36 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=1783070186; cv=pass; d=zohomail.com; s=zohoarc; b=i8QXCnzxvGe9q+rObUfrpbzQGSz6i3xvm/m1YM9VU82zjWngCIn90m6ogCjfeQ2GuEp7/5uuQ/7uwqEIkdZu9dE1HB2Q7T89gGGahm33q9otyN1QIEHbd8nqQpcPuC4uxHPDYEGvXpSzyTXomCN+XQ/B5uNmsU7hLS42O65rNMQ= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783070186; 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=cnhJk1GWwfTBQlXCmlfrD1hdxu7L/SP10nBbA09ZTac=; b=mYDAJSaFOX9p5FeYIJzswkge9FbkHCDy0Ehz6GOMb7rjJG9BTHAYHB0n0QWy2FQuu3hWWIHRej62y41M2foXG3+5igDGdtqBwunfzvEp0Csp/LGT2TXNWTfunihFAoripH/iTl8knIB8D+I6vSipMoMa2DaubbTXagjPfNNu7+s= 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 1783070185999656.007593198854; Fri, 3 Jul 2026 02:16:25 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1353030.1609237 (Exim 4.92) (envelope-from ) id 1wfa08-0004pL-G4; Fri, 03 Jul 2026 09:16:00 +0000 Received: by outflank-mailman (output) from mailman id 1353030.1609237; Fri, 03 Jul 2026 09:16:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wfa08-0004pD-CV; Fri, 03 Jul 2026 09:16:00 +0000 Received: by outflank-mailman (input) for mailman id 1353030; Fri, 03 Jul 2026 09:15:58 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wfa06-0004QW-Gu for xen-devel@lists.xenproject.org; Fri, 03 Jul 2026 09:15:58 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wfa05-00GN2P-T4 for xen-devel@lists.xenproject.org; Fri, 03 Jul 2026 11:15:57 +0200 Received: from [10.42.69.10] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a477dc6-2eae-0a2a0a5409dd-0a2a450ace40-22 for ; Fri, 03 Jul 2026 11:15:57 +0200 Received: from [52.101.125.115] (helo=TYVP286CU001.outbound.protection.outlook.com) by tlsNG-4011c0.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a477dc6-e40e-0a2a450a0019-34657d733221-6 for ; Fri, 03 Jul 2026 11:15:57 +0200 Received: from OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:458::18) by TY3P286MB3731.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:3d3::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.181.10; Fri, 3 Jul 2026 09:15:52 +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.0181.009; Fri, 3 Jul 2026 09:15:52 +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=uULWK3Wp7UmAqolW0O87DbjhR/76XnHEmq8iiCnKPIqg+IQuQErTi+WLR4KqESCF+bzfbISpFDzpGQKxQcECrkbJaK2GDOgbXcxN4WHGyLgja/GaRNgmgOE/1uOrxEtgsQzC7Vy9GiuUGI7xJdKi+WLGyDm/2tsTRdiIDJaIdqIQVKK73M+ELsUfGhal06CjnOQSkOpja/RLMTLSmpgPWeZPlhY0aHENH2nrSoMgE75lu85B6PHjUpdESbpjxIJ4HsQg475Wu88x3c+A0gkOvahrX22et4ti1Baa2T8tiYs6CHa5Wevr0rbfKku4P5Z/VZ7YvoUexajQ+2QWn9y+kg== 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=cnhJk1GWwfTBQlXCmlfrD1hdxu7L/SP10nBbA09ZTac=; b=HyPVswMvWB7UuGHOlDzV7IzZLg4yHRpSjAGIOax7l8ipQDz+xgEg/5F4XM3U7BT04H8C05X5pkFa+i2T9/nhJnOUroKR0H+ZAkVhOTcK1MtnBEpnZP56mn7AOyOKlVvwU8nnuOelLDxiIX8GLmcb+fOPmzL8am59rucxG4jkgc1pL3mCRQO2NMOPwDt0d52AbifNr1GYJ0LmjoECwBr7O87TUxUa5iSVRCCy8v7Z4c0pILuBoa52ppF9S4jQ7lmL+sJbgoDY5b+tVO9CJQCXWEQO7rPolqRtJWCqD5ORKeFu7dsYZiFHdIOGk7SmYPP7qKJQ6WansCCOeaxjsN++ZA== 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=cnhJk1GWwfTBQlXCmlfrD1hdxu7L/SP10nBbA09ZTac=; b=Rtv2s3MO7xV10pJDpPuN6KUucd9DvuK2szy6i0Nhvf5B6dG1/eqi4APBIrbbRuJ6LQ0So01msRnZU9R0ov+XI6n7YQQ1kOCw+BA2qhkZV2ZkPyn22ml1HlXdhWoYWzCIBm5Dpu6WSIYNvAF7aDuPIbw7C97Sc3tKWfICK0BZi/Q= 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: Hirokazu Takahashi , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Michal Orzel , Julien Grall , Stefano Stabellini , Dario Faggioli , Juergen Gross , George Dunlap Subject: [PATCH v4 3/3] xen/sched: Make cpu_nr_siblings() architecture-specific Date: Fri, 3 Jul 2026 18:15:44 +0900 Message-ID: <20260703091544.183548-4-taka@valinux.co.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260703091544.183548-1-taka@valinux.co.jp> References: <20260703091544.183548-1-taka@valinux.co.jp> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: TY4P301CA0070.JPNP301.PROD.OUTLOOK.COM (2603:1096:405:36a::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_|TY3P286MB3731:EE_ X-MS-Office365-Filtering-Correlation-Id: 48dcbeaa-84cd-4c33-485b-08ded8e3ae2c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|366016|1800799024|7416014|376014|10070799003|56012099006|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: oo16E+eLbXDUCFPcNBT4Dz+rz9LjNOoPYtNKSgAMBOMwG6HGOVTNXWMNYgm4QYXWWpKimioYbo9CBtYbNVXw4K4aRW6pdx/BNYTfuyfnD5x9I8WhxwmmRoV3h0F9uxmZI/v4A7YKCZC/cs4UGECp/cugJbwM2r5/oMH4V6AYsFum3fLjSkWsh5z3360Qyq8cXJCeVtO71zMFzSSZZd0Rs5nVUuySmWmWFNE6w1XNsSS01Bjq1/b3bxGpyIWCWlIsoBEVvdj1+SVUhom0G6ESipmXGH3xeW1N4xwl7pdnXc5fxM65/UKJxols15pyTipDAfhSuWVJXH+4OKTpvAJzUcm0kmePpe8M+53vyHOnUNdQVClCNDIlnStaJafpRDlBzyzhIloBUj4ySPrbUS3AAn7qFBSFdjAUBQUOQWBJ3oM11AdTjgRg8Q8Zy3pdH4l0CHoV6w/5mmsyK1QmM8Rb3RPnLnCKU8Twc1Xxtq+Dj6ioZIln+nLsZh1h8mTGoBlmK+q8EVEKJ2pLu2OnUBS5JClyJ/WJYhJu/zZ5X9daDW49fUe+gdDXPmkksE2wGMgho+SQG8Y75U3Jo5yxhkDfphfHfsSlD71g1SfxB4v4yWSCg/z/WafnMGiq4Zwptz1+qfDI2oFJlgjQyWs1j/p8jKCFLkr9oPFaBEZ2B4aPh3w= 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)(23010399003)(366016)(1800799024)(7416014)(376014)(10070799003)(56012099006)(22082099003)(18002099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?kmcPo6fmRptx6CRdZrK7XnS12tnW+Ob00UId9DjIEV1N2xs62uS9SlfgGNT5?= =?us-ascii?Q?I7oFiec8X1WEBIHDcwFYrVPnzakYEBn1+hqNY3y/Np+k9UfTM6dlQcDGcwOc?= =?us-ascii?Q?KSsmtZiOSib5f9RBgWKYWhPU8avcKxt+v1V0PaKsyZ4luexRibTU6BMu3kkb?= =?us-ascii?Q?sh2hmngLYWqZBbVxBur6zzMHpg5ojxM4uT6eGFE7n7JttVNroLdsVpOCZNpi?= =?us-ascii?Q?wR1WIUYNOo3c1RDggHXVCTOsu3nBYeiEto7Tq6/i5+wmuFuE7JVmrdV4Wxd8?= =?us-ascii?Q?D33+MqXMJiSOA9sr2/DUKv0FJE5QI2UeijtaBNo6R/AwOaDgY/Pxn+es65rT?= =?us-ascii?Q?WxXlGOrO3uWxwcnh0Qp24TN44rCCYwU8yXNvlxXgE8OTMr1wayaiErG+Hq24?= =?us-ascii?Q?X5A4o+HuDFsiZSWASCUJT1IOkvGHssvzMArZIai7xNGsC9R/JWgqAK1veGFU?= =?us-ascii?Q?9cSwVrTZYTbMWMeKkg797YMqIoIwCwu2qlIDreNOyeHdiQgTkM8nBI7u7IJK?= =?us-ascii?Q?p7bsHI3Vjk9W9SgOUnAT+SfZg282Ti/88WWlam5mDP2e7WK3i+dSrB6F6Gw0?= =?us-ascii?Q?GfNjDlU1odXMXA3w23x8s9cBukOy37CU/kwoqAn8qziCE+hRxJvUFdqLwbUT?= =?us-ascii?Q?QcrmuqsF96tOwCvffNbelqIjSTvLFv/yyzmyVAZ9Llmxejjss1VuGz0sf1xq?= =?us-ascii?Q?VDRMWPW2cLCMyI6driJKXIuoLOk5fjn8GYAMsS3bT1ks66E2JaMZoqldYTVR?= =?us-ascii?Q?CRE0gRfUPweDfoRhX1sMQC/jPuoBVPWKIYnx+B8BDqMqHFIa7Q2NWIh++ATu?= =?us-ascii?Q?uEz5pVG/IaOzXSJLAy40x2aCWUf+6QdOq5WL/BkEiM8csQLPh+xiP7SdRJSJ?= =?us-ascii?Q?hkKTkqW369bilv5688Ehh2xHbVcaQne0D5xn6p2D9QPW+2iemmr/GaMN/aof?= =?us-ascii?Q?cSF5JsTFgkJCJhOl79zifRH9V8DvcG+WcUXGw2yDP5D/nXzTBqFm55p37L/A?= =?us-ascii?Q?H77dj3hwjEeCQXqRCRVtVQACc5raRj5QtJAshCyrA+hPZmh2ac148MMq33SN?= =?us-ascii?Q?LB77Ff90lf//5ldWHAnNXYFBIyfTcmCMViLhpAZtxV5luwUj0mlxEX52wWaI?= =?us-ascii?Q?F8h+gKxM8bM8Oxxc/jjbNqYOx0COMY88Ie0EvfK+pwNJG+hIYX1KiL59OJpU?= =?us-ascii?Q?EmahtrpOvqD3DKIoWm5gl7Sa9GrEDm0I46eqOR/APbrcL/li3cE21YQb0L8C?= =?us-ascii?Q?OanVuhtrKG1Vid4ezwGZONnV+WFyw5nw0YOvDxjsPgcIbKkdYJswSmVJragm?= =?us-ascii?Q?z1AAzr1ffezE74IYSc9Ipfe4bPXGsGtDl+QZcB+Vs7nrtdwur+dE6D46aGGC?= =?us-ascii?Q?Klvdfth8FLujQbgWQhGQnlZSmVqVzZyxvqYq/VKmNFxhrJxCnOBl2j0qMG2O?= =?us-ascii?Q?fq0fBs+4uBAZzWjf2nmhohiIlwerFlHmRxV1/CBerMpZHpxyyVwfwcPAoRa6?= =?us-ascii?Q?T9QAtyq9eV58HW2G1MGzM87kXRNpj44qQaVn/bPcOo3B06XkPK77km917hwS?= =?us-ascii?Q?+oXUVZccU9P4Q8DFGpy0qJlqHe5cd/1uGrHjMy1p+yt2TM5CZnizKr7Jq2KU?= =?us-ascii?Q?L3OJ+CJ8i3LmH2RNCAJU1hPWISDDwKvtk8pufEB8ZMUlOLe9C2VlLzkQd9u4?= =?us-ascii?Q?boHrg+DkH+xzNUfXL3BO4C5gjdWtTAMPCIdUriZ3CjCNDqxbArZipulOCvly?= =?us-ascii?Q?428BzznIgc6P4uOl2XRqpLv6u4wFqcXZGNHimO3dDrod1A1b2fqNmm91TybR?= X-MS-Exchange-AntiSpam-MessageData-1: HF2eafndh9FfyQ== X-OriginatorOrg: valinux.co.jp X-MS-Exchange-CrossTenant-Network-Message-Id: 48dcbeaa-84cd-4c33-485b-08ded8e3ae2c X-MS-Exchange-CrossTenant-AuthSource: OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jul 2026 09:15:52.6061 (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: /KYaUN8VH2Le7wWtViC/OOGIMQYPFVDfpI6KJdndlSqIv3cnEqd3dQwKcaomwQlYAI0oKYiYxgDdbDiZYPcPiA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY3P286MB3731 X-purgate-ID: tlsNG-4011c0/1783070157-3C67BDDE-406116AF/0/0 X-purgate-type: clean X-purgate-size: 3386 X-ZohoMail-DKIM: pass (identity @valinux.co.jp) X-ZM-MESSAGEID: 1783070188113158500 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 --- xen/arch/x86/include/asm/processor.h | 1 + xen/common/sched/credit2.c | 22 +++------------------- xen/include/xen/cpu-topology.h | 5 +++++ 3 files changed, 9 insertions(+), 19 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 ada430f262..6c645f0e21 100644 --- a/xen/common/sched/credit2.c +++ b/xen/common/sched/credit2.c @@ -29,22 +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_X86 - return cpu_data[cpu].x86_num_siblings; -#elif defined(CONFIG_CPU_TOPOLOGY) - return cpu_topology ? cpu_topology[cpu].num_siblings : 1; -#else - return 1; -#endif -} - /* * Credit2 tracing events ("only" 512 available!). Check * include/public/trace.h for more details. @@ -882,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 ee34425680..646cd0ff04 100644 --- a/xen/include/xen/cpu-topology.h +++ b/xen/include/xen/cpu-topology.h @@ -41,6 +41,7 @@ static inline void init_cpu_sibling_map(unsigned int cpu) =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 @@ -64,6 +65,10 @@ static inline void init_cpu_sibling_map(unsigned int cpu) #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