From nobody Thu Sep 24 19:51: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=1789120010; cv=pass; d=zohomail.com; s=zohoarc; b=AIlyswhn+8uRkY4hJG4L9e2DvBFHi5kgWnyH+hxfCTDrLXHWe17gWsbC0QnwAoSjyQSnBb0Lxj4VhN2xBDPzQ6IM1TK4PL2zwrF91ffsVXfDCQEcJJAFeOUGv94Q5w6ozyzKbEg1eb3f03Jz7DUbmU0VHT02yKbH85qiEsBBCdI= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789120010; 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=98Ejx9hGWuJ2tgdfHUsmj4uLOcuV/PMVq9M0S9wHihk=; b=Vj9yzzSKvtGrfHdHCvwBv7ImOEZsU7Z/s2MDQjuC91jRMBZcY7WcADEVtGdSWqpk4OkijKcdjdNj9cuhRTkT9D05C4tHunlyznB5OBAfykiDJEAj8+SjQEsKHj6EPfgsIz98Y4zb9/HznAQOZQedpYjdbpvpJFomLoJxxLIaH/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 178912001050976.7031767285622; Fri, 11 Sep 2026 02:46:50 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1416164.1645323 (Exim 4.92) (envelope-from ) id 1x4xqA-0008KX-1E; Fri, 11 Sep 2026 09:46:38 +0000 Received: by outflank-mailman (output) from mailman id 1416164.1645323; Fri, 11 Sep 2026 09:46:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1x4xq9-0008KQ-Uf; Fri, 11 Sep 2026 09:46:37 +0000 Received: by outflank-mailman (input) for mailman id 1416164; Fri, 11 Sep 2026 09:46:37 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1x4xq8-0008K4-Re for xen-devel@lists.xenproject.org; Fri, 11 Sep 2026 09:46:37 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1x4xq7-00DZoV-PD for xen-devel@lists.xenproject.org; Fri, 11 Sep 2026 11:46:35 +0200 Received: from [10.42.69.4] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6aa3cdf2-e002-0a2a0a5209dd-0a2a4504d672-16 for ; Fri, 11 Sep 2026 11:46:35 +0200 Received: from [52.101.125.101] (helo=TYVP286CU001.outbound.protection.outlook.com) by tlsNG-ebf023.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6aa3cdf8-b57f-0a2a45040019-34657d6558a2-3 for ; Fri, 11 Sep 2026 11:46:35 +0200 Received: from OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:458::18) by TYYP286MB5003.JPNP286.PROD.OUTLOOK.COM (2603:1096:405:14b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.9; Fri, 11 Sep 2026 09:46:30 +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.0406.007; Fri, 11 Sep 2026 09:46:30 +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=ElL7oN1QigY2qGvUKJr4ue7+dyuoZ+F+86sNC2KI23gRzaptSfwH4ZYDXuqPcVc4FVucRO6CIuwvMF2tefhh6H51zxiXJkL9KmPOG+OOmS1ywUBZ1ZQ/bWNynmsi2rvLJtdWGxyg/dXSVpXhbtTdMzUG8V08jbzogNMb3zmqAsrzUJjFOmdyMKnzRKzlfuVuuY2583leJI5aYgTDe0udpBbWnlmvYULjEgbXWpYDEoQZX5Ksbb4KWHjF5J/+R6Q7szcgyJsWFNUUDC9LbUdGped9DcAof3p028vHFgQpGKkNGBSXiAxxKR/TcblMR8PWKs7cPje6U2Uh4muSiQTOGQ== 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=98Ejx9hGWuJ2tgdfHUsmj4uLOcuV/PMVq9M0S9wHihk=; b=lWIi2A4EKDWA5JYO+hfORouThDqTKcm1+fBSQkUhUL4fGNTLzgJZfrLZrdYLB6qSXNA4MWKgY1Lz4c4Rm+WermGF8P+GCmQ1u0xZGpWIm/QzEkPd7npBqkaXBBg8HuqQSmOV6m65x9DW6hDbgxLF+PEeZO7ZGqkIKLgR3r1CrW4Nu7klJ6WKjb4MDdHDMyjysSrP9zdJARBeWTV7ckr/nPIhUqgzQGi7Dr00jvdaiNaoVfhaJrVxRChDbSx7b0Y53BGskfaroIMsyXnQhm3wnHfv/0h95T+WUCURayewY9jCaezxQal641fpfjPdvo0p1Nal3HfnDNbNE8TkmMeW9Q== 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=98Ejx9hGWuJ2tgdfHUsmj4uLOcuV/PMVq9M0S9wHihk=; b=pUZrFqUbq4mjUtszoFdBD+4Ig7DLKoWVgqH6t+Gqh+cnBbpxkNCWhSRAf4nEJBaDdlcHKTVFBnqZ+SBD0ic5G5rxNE0JUrmcIBAWRx23kVQXpMZqvmFZK5QaQtQta5AmaLivjZLQwLbbC6AkAD3zQJnRvgv/DYhPnMswE/rGWEo= 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: michal.orzel@amd.com, Mykyta_Poturai@epam.com, Hirokazu Takahashi , Jan Beulich , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Andrew Cooper , Anthony PERARD , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v10 1/4] xen/device-tree: Parse 'cpu-map' node for CPU topology exploration Date: Fri, 11 Sep 2026 18:42:10 +0900 Message-ID: <20260911094213.79936-2-taka@valinux.co.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260911094213.79936-1-taka@valinux.co.jp> References: <20260911094213.79936-1-taka@valinux.co.jp> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: TYWPR01CA0049.jpnprd01.prod.outlook.com (2603:1096:400:17f::20) To OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:458::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OS9P286MB7222:EE_|TYYP286MB5003:EE_ X-MS-Office365-Filtering-Correlation-Id: a9278e18-1c65-4b78-af55-08df0fe98eb1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|1800799024|23010399003|7416014|376014|366016|56012099006|22082099003|18002099003|10067099003|6133799003; X-Microsoft-Antispam-Message-Info: 57Y7wa/bICunFTF7nnEaEFUsQjtFagRcw9ljjRl+h/k25UzRAsuD4bc64BDeODvOFYZAhly5q10IsGg6OYmHEw7UNCJZq6rdoGl4Y0LtGagkZmnqRV2qyZy7gdB9m7/jUAwV3XWGfU90Z1fO/Pamxz0Vk6ZMD96T6tU012QNcMki80qIO1NBPRpyMd8VlCotIUvR5AD9NBf1VMFg5pJm6WndcZyo2KvXORd7qF0l49IKF4HEIgvqTow4l68kVCc5Y61pdETW526lRrOXC5xoYyJKN6tovpGkvTQ4zsiuUmAPpBbhvYGHfB/WV799KxYr6hYTrs2ik20nz23uyuFXtmMF0Oq8A+L3+Ij4Eq6UuJTV9jnxT8zq6HO1VxxhFBFfKVz6X2YApEf1hC03D8zenO4NtMzBfT/lNcnzaP4VF61q461576xBH+K2RXnowCoNLO8tGCppdygOmfWMwEo4gyo11VQUSbfBFGgGH7i6wAMBcBagWww4RUFid2hIHVOXhE7STVpvBaAdv0GtnVc7mGuBv3P30gXtCZ1tJ0zQXxHAeem0yCT05SwZjWm2mSD2xj2As5CloU73bKQYGB0rgg4jw0c5zSxcC1I2FmipzRWOdOuwjaP0dtudmwxOiFdLlepyy2IS5UCICctmN3Xzfwz/M+ovi82G96SO5mNkvYY= 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)(10070799003)(1800799024)(23010399003)(7416014)(376014)(366016)(56012099006)(22082099003)(18002099003)(10067099003)(6133799003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?jlCsbeB1dzopRR/eh7vO8dNbHqPeiGSzJ5mpToduUSDQsb0rZsv2VUGl2bUe?= =?us-ascii?Q?DJi1XX2zjdyGiBYDatXN1voU8rTE8khrYFT1WQCvPjTNRpnXW1XzhAUWn9/n?= =?us-ascii?Q?koZkueFlOUJitTAljTHM1ArvTHPnOuKTz1EzgduftDWco2vogbyP0b+WtmUP?= =?us-ascii?Q?zjRYsUIkJyCkS1sE5Tct1K+0fpoF034R63l7vjl320PXwBpHoaSFU8Qh+D7E?= =?us-ascii?Q?DuAuaaqi28bITxpYjllXJ6TI4RP/nTBNkz6G14ZbSDS3M35ljo2qR5vBLC2q?= =?us-ascii?Q?sEPMZFtUe9LROn1SyC/O3/RQM8EAvwNwGfnOBFIM6le22w13IIRC7y3dEGoL?= =?us-ascii?Q?C/tWkHiAmfn8J/V9wT1uLpgCauW+j7Nz1B1LumXGLr91OYzaEke+C2oddY7e?= =?us-ascii?Q?YCbqELGI6GIetGq+Fm5CYf/RtvfguAwv3E0AXgmL7rdh+Ct+m5GDz+O0Bk6/?= =?us-ascii?Q?tpD/iolJACdbK6+iCBK6GwaH1ZPMUryf7IgUoMqc6I0WVPoDrUb+q2pk3Wt9?= =?us-ascii?Q?xOdeTBDrSErrbFIrgDjHryy6cSsuLTSoNaxUGpborWKliUW+ngOp3idob5Rc?= =?us-ascii?Q?fMjvOobeZZg/Ppbh2BTw77VR4v/sI5+mbxbdUJvnGH9ZWpZNA5lPOz55p/bv?= =?us-ascii?Q?4jDMS5jDwuJF48sicmYthcumQdawINCSok8dO/uYMJI9pjseAWo+DKZCk1JI?= =?us-ascii?Q?UTbDp9VVTovY0JW1hxoWUjDko1cZmmvNsWyd0FK1BEALuoH4I5nPWXX10fZA?= =?us-ascii?Q?p5G+7YaexRdig4u2Qh/gZw4IzcFRrbGqjviKDVRnPSAPggWntRe20E7KdnoC?= =?us-ascii?Q?w+xrENWbksQaWnIm1bwpLSzACjFrwSos1xi45eGiMHQvScZe9lf+l+fJuCav?= =?us-ascii?Q?NLIQKdA9EyXYSxLslnFMytbjh6ujOtsGtWB+kgP7kMh3qquiZma+ObXTLPRq?= =?us-ascii?Q?y8VC8AdEB0y9H2e4x+rkz4Sl0Y3OYuiFnPdPJLe9tFQIvAt9eImU48rk7Rox?= =?us-ascii?Q?jDBkG7Lz6LH8Wh97MTdNP09ihFKaqitZ6VPhu0kvodQLEDUV7lc2K3hNsLP2?= =?us-ascii?Q?YmLNanGwcJsgc7xV8bvuwntVKrehQgBkbHTBc50D9ULQTAu+dEwkSHIKRuIz?= =?us-ascii?Q?mqzx6dItfe0S1sA017rhc8lL6NRFQjM1A6IPaRBzif4RwB14YHigYAP9akU6?= =?us-ascii?Q?UqqYdadgrVQ/kKQfQefdvFPQKbciGbameEGzZJykWYYTLtREnoKIYMJ/HoL/?= =?us-ascii?Q?EU8az24C9wna6ELuZZSUELkwKthZ958udiwIKxNiRa6fw5v9xc4eaVI+Exfd?= =?us-ascii?Q?HhUck+YJFUaCxY7fAkDqWK2wKPV006aOHwULyRDxCnsL3iW2reJxUzG5p1lF?= =?us-ascii?Q?83OFwUM1keWhmxnNOI1+4VHsOrwgDs7MR0uY5Hjzay1DrQ2CJXqqO3SV99I1?= =?us-ascii?Q?47l1jZr1yGZyFp0VzI9wERDeCyTZbGoFk9XQBBWYAFpEitDfOssa+Jf6EqNX?= =?us-ascii?Q?mYwUU/8GFG2fnljS/EsTTxjsiQgyR+lOFmTaCGcnRukKquago05M7sH2yPfx?= =?us-ascii?Q?vJRL+HJjjK5K4JET1uhh6eGSpIn3gYXQV0QHWfeteCafTE7pTZLuW1LpF3N3?= =?us-ascii?Q?ohVZFFiLzYP4icwsklrcd5hCz1ESg2ZfescnsC6rp5PQBy7u1C6Hbk4dZJY9?= =?us-ascii?Q?NSXbWegcczmUraukddzFzJQmnrRjg5AHCno6Zq09CtPFV2mIEqnl1w0c1vbb?= =?us-ascii?Q?zJys3QLZoZYuouTwDn4DkB3hvrLSGApM29C1HCMRsVoJFn34ceJgQSmwtrmp?= X-MS-Exchange-AntiSpam-MessageData-1: bqyDaIL2eqUv/Q== X-OriginatorOrg: valinux.co.jp X-MS-Exchange-CrossTenant-Network-Message-Id: a9278e18-1c65-4b78-af55-08df0fe98eb1 X-MS-Exchange-CrossTenant-AuthSource: OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2026 09:46:30.7039 (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: iQv9AkxHzqsDHq7boSbM99xtBMtQQlIzHJUEGCDUJnV/BMFJ7rbcQHXROHl7zxwj3yXceDgAkiXNW3u/LRDmiA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYYP286MB5003 X-purgate-ID: tlsNG-ebf023/1789119995-C22D4B50-2AE1035F/0/0 X-purgate-type: clean X-purgate-size: 22213 X-ZohoMail-DKIM: pass (identity @valinux.co.jp) X-ZM-MESSAGEID: 1789120013147158500 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, simply ignore it. Signed-off-by: Hirokazu Takahashi Reviewed-by: Jan Beulich # common, acpi --- Changes in v10: - Postpone the invocation of init_cpu_topology() until after nr_cpu_ids is finalized. - Improve the Device Tree cpu-map node parsing logic: * Rename functions and variables to accurately reflect the DT nodes being processed. * Simplify the parsing algorithm by eliminating recursive calls and avoiding passing INVALID_TOPO_ID as an argument. - Unify all license headers to GPL-2.0-only. - Return an error instead of triggering an ASSERT() when duplicate CPU definitions are detected. - Replace BUG_ON() with ASSERT() for condition checks in dt_init_cpu_topology(). - Update commit messages to remove details that no longer match the current implementation. xen/arch/arm/Kconfig | 1 + xen/arch/arm/setup.c | 3 + xen/arch/arm/smpboot.c | 5 + 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 | 347 ++++++++++++++++++++++++++ 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 +++ 14 files changed, 571 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/setup.c b/xen/arch/arm/setup.c index 86532d0a35..108f1c703e 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -10,6 +10,7 @@ =20 #include #include +#include #include #include #include @@ -387,6 +388,8 @@ void asmlinkage __init noreturn start_xen(unsigned long= fdt_paddr) nr_cpu_ids =3D smp_get_max_cpus(); printk(XENLOG_INFO "SMP: Allowing %u CPUs\n", nr_cpu_ids); =20 + init_cpu_topology(); + /* * Some errata relies on SMCCC version which is detected by psci_init() * (called from smp_init_cpus()). diff --git a/xen/arch/arm/smpboot.c b/xen/arch/arm/smpboot.c index 1806c47a08..904130efdf 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 ) 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..f784afbd3d --- /dev/null +++ b/xen/common/cpu-topology.c @@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#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..ce9da0bb36 --- /dev/null +++ b/xen/common/device-tree/cpu-topology.c @@ -0,0 +1,347 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * 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 socket_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, + .socket_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->socket_id !=3D map->socket_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; + + 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 bool __init is_cpu_map_empty( unsigned int cpu ) +{ + return (cpu_map[cpu].socket_id =3D=3D INVALID_TOPO_ID) && + (cpu_map[cpu].cluster_id =3D=3D INVALID_TOPO_ID) && + (cpu_map[cpu].core_id =3D=3D INVALID_TOPO_ID) && + (cpu_map[cpu].thread_id =3D=3D INVALID_TOPO_ID); +} + +static int __init parse_core(const struct dt_device_node *core, + unsigned int socket_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; + } + + if ( !is_cpu_map_empty(cpu) ) + { + printk(XENLOG_ERR + "ERROR: Duplicate CPU definition for CPU%u\n", cpu); + return -EINVAL; + } + + cpu_map[cpu].socket_id =3D socket_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; + } + + if ( !is_cpu_map_empty(cpu) ) + { + printk(XENLOG_ERR + "ERROR: Duplicate CPU definition for CPU%u\n", cpu); + return -EINVAL; + } + + cpu_map[cpu].socket_id =3D socket_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 socket_id, + unsigned int cluster_id) +{ + bool has_cores =3D false; + int ret =3D 0; + + if ( dt_find_child_node_by_name(cluster, "cluster0") ) + { + printk(XENLOG_WARNING + "WARNING: Topology for clusters of clusters not yet support= ed\n"); + return -EINVAL; + } + + for ( unsigned int core_id =3D 0; ; core_id++ ) + { + const struct dt_device_node *core; + char name[20]; + + 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; + + ret =3D parse_core(core, socket_id, cluster_id, core_id); + if ( ret !=3D 0 ) + return ret; + } + + if ( !has_cores ) + printk(XENLOG_WARNING "WARNING: %s: empty cluster\n", + dt_node_name(cluster)); + + return ret; +} + +static int __init parse_socket(const struct dt_device_node *socket, + unsigned int socket_id) +{ + bool has_cluster =3D false; + int ret =3D 0; + + for ( unsigned int cluster_id =3D 0; ; cluster_id++ ) + { + const struct dt_device_node *cluster; + char name[20]; + + snprintf(name, sizeof(name), "cluster%u", cluster_id); + cluster =3D dt_find_child_node_by_name(socket, name); + + if ( !cluster ) + break; + + has_cluster =3D true; + ret =3D parse_cluster(cluster, socket_id, cluster_id); + if ( ret !=3D 0 ) + return ret; + } + + /* + * If no cluster node is defined, assume the socket has + * a single cluster. + */ + if ( !has_cluster ) + ret =3D parse_cluster(socket, socket_id, 0); + + return ret; +} + +static int __init parse_package(const struct dt_device_node *package) +{ + bool has_socket =3D false; + int ret =3D 0; + + for ( unsigned int socket_id =3D 0; ; socket_id++ ) + { + const struct dt_device_node *socket; + char name[20]; + + snprintf(name, sizeof(name), "socket%u", socket_id); + socket =3D dt_find_child_node_by_name(package, name); + + if ( !socket ) + break; + + has_socket =3D true; + ret =3D parse_socket(socket, socket_id); + if ( ret !=3D 0 ) + return ret; + } + + /* + * If no socket node is defined, assume all clusters reside under + * a single socket. + */ + if ( !has_socket ) + ret =3D parse_socket(package, 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_package(map); +} + +int __init dt_init_cpu_topology(void) +{ + unsigned int cpu; + int ret; + + ASSERT(acpi_disabled); + ASSERT(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..090c793f33 --- /dev/null +++ b/xen/drivers/acpi/topology.c @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#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 19:51: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=1789120024; cv=pass; d=zohomail.com; s=zohoarc; b=WNVq61mOKfV3ioLY4izEOxJSOvQM6M357byc3GTree+jF4bDagdDxut4oLBxvEVfjO9w3dAiw+jw5jAqA3v/HnUgUykx4Oc3vGCmrOZgzw7uQcZY8gGTdGX7179ta51mQpfm1Ig6W3f/ttWWrGmwJt840cDCFZELaPFlXtU0V4I= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789120024; 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=2QN3BFSCAU2olLZdlHOeG7dSiGX9Gpgc5FnOC6U5PE4=; b=UC9NfrKcAaHIVXKMX2OaJBcfpI2lwQLPjrWUQsz1a0/XkojKPb08RjH9y8NIxpt2kwynjq4fS6L6pVPZD/jzCYfWfDJ6hLdTITuhRAj4BkB2rOWWDw9IaL9THMveEYuvmcb7fg4yo/fGhTlBo3ytGTOeIeAFOhQ7uefPTGhorc0= 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 1789120024224596.0266778424957; Fri, 11 Sep 2026 02:47:04 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1416167.1645333 (Exim 4.92) (envelope-from ) id 1x4xqP-0000Ct-CC; Fri, 11 Sep 2026 09:46:53 +0000 Received: by outflank-mailman (output) from mailman id 1416167.1645333; Fri, 11 Sep 2026 09:46:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1x4xqP-0000Cm-9R; Fri, 11 Sep 2026 09:46:53 +0000 Received: by outflank-mailman (input) for mailman id 1416167; Fri, 11 Sep 2026 09:46:52 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1x4xqO-0000CM-Cp for xen-devel@lists.xenproject.org; Fri, 11 Sep 2026 09:46:52 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1x4xqN-008kpW-Pt for xen-devel@lists.xenproject.org; Fri, 11 Sep 2026 11:46:51 +0200 Received: from [10.42.69.3] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6aa3ce04-e002-0a2a0a5209dd-0a2a45038ef0-16 for ; Fri, 11 Sep 2026 11:46:51 +0200 Received: from [52.101.125.103] (helo=TYVP286CU001.outbound.protection.outlook.com) by tlsNG-33051d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6aa3ce07-fae8-0a2a45030019-34657d6718d2-3 for ; Fri, 11 Sep 2026 11:46:51 +0200 Received: from OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:458::18) by TYYP286MB5003.JPNP286.PROD.OUTLOOK.COM (2603:1096:405:14b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.9; Fri, 11 Sep 2026 09:46:46 +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.0406.007; Fri, 11 Sep 2026 09:46:46 +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=W43TliTQ83uKMN08ts8bDVN/bTPBh77H2G7tHV5yRK1ioZJQuMz56j96I630bY/CiQD96LAr7F2MS6Fmlhv0gV6z4OBY+oWgUwJsvlAU81AQeuVwMxOqfrveHJo9KcGqdrrG8DjrCPcvD8x19NUQNR7rgAxeql11VFB+JdI/MdZAsJWQo2FcD4FGIvne+Dg4kUXBkYZDBQUHqLkWj0x0K9r2p4haAh283gwSaIkVpONjsdAMm1UG4CkQswJ9uFCScXcfEHd9WFB/hFOnLgMzZIQYA7RtEml3Zx/2Nl3f6mhm0Snc5DthnX+Gm0/YPcE0ZvqqKg1u2x6fl8DOClYCFA== 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=2QN3BFSCAU2olLZdlHOeG7dSiGX9Gpgc5FnOC6U5PE4=; b=y//mHE5pqcnGSKlMp2Ku1roDo8ghasJ+WdM11D8FbNtZeudIxHY+HnuqMuu+g9zgn8neekwPurunS/UV8yk29qVlcQrg3Gac6Fy3r0IduR90k1Trgf1nkGQInoLd5sg3rC01hq+Xm6I0UCt4oVDG56d5VVXvrIGTSnhrvK78f1KdaVgSCWKthN+lmeONgvhdDe4yRx6oLAQrvv767D5P4/U252eJQizCR4+MbSAirC19shHcwrV3Gz949ZitU62Trv6IaoYFAMyIelPbAyLEXRQNxH+ilCtdXPDbGXo300qhqZj2sMhuxqlN5PbusBKNruw+3AYrrpX2oEqxGRjEDg== 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=2QN3BFSCAU2olLZdlHOeG7dSiGX9Gpgc5FnOC6U5PE4=; b=pR9LDkBYyxWeRwzj34MLGZUp6sZpueUtbtEWXZ8XieFXJm5fU5r2zNYqjS9jB+y0Fcnz0Cuk5+5KLLc2fHT2QrfOtpdmQs4pu32TvD7Qf43KVdQxQGvGZA87ukdXOo/at4GV1YprDngWrjNZWYMJu8faKRbQcVZGiIk25Xz5wak= 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: michal.orzel@amd.com, Mykyta_Poturai@epam.com, Hirokazu Takahashi , Jan Beulich , Juergen Gross , Stefano Stabellini , Julien Grall , Bertrand Marquis , 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 v10 2/4] xen/sched: Link CPU topology to scheduler Date: Fri, 11 Sep 2026 18:42:11 +0900 Message-ID: <20260911094213.79936-3-taka@valinux.co.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260911094213.79936-1-taka@valinux.co.jp> References: <20260911094213.79936-1-taka@valinux.co.jp> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: TYCP286CA0054.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:2b5::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_|TYYP286MB5003:EE_ X-MS-Office365-Filtering-Correlation-Id: 5a9fc6f7-9583-495d-1e65-08df0fe997f8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|1800799024|23010399003|7416014|376014|366016|56012099006|22082099003|18002099003|10067099003|6133799003; X-Microsoft-Antispam-Message-Info: ikOYjXdQsqM9cEr2YU5AkRucjrM0KU/bi99Qkm+Fvi4lvtQPc5EVioUt85lk9YzXl+ceROKlN6Ngs7PDRKhDEqF6s9oXJnPzG8spwplrLlOYpPbOO2zHWuLkBf+MB4NdCjV0E60NQ+Q6UmH67mdfRPjyEwhO42V6z1++ART9vGHCZ962ovaZCFHJt80KrmLm3/XZRMcpz8WpcWk1wpSXW1PywAN8bYth4lSssGfQ7Upw1nwG+QvbqLR+N1hMYsTbAEEOxb0xXewcjO5rNNE50fEE4P+RlKQ/pi6t4d3t9Hfnc6EmsmwPsDIIjDwdEUzRInebqhINpidFyqpu8NV/pkYh6Y+a/tigoDiVSp06u21dItURzb7FO4mTxWOaLWU5AW7sHYDtJJjLg9tNqWwBaAClCvAt4nol4sJqfgxenDbtiIuUr6UyhFDH6AKRnHLlXnN4B/ULNzQGRyN/BfSELPgPRT0BsrcF58j6c3uPMX/E8mNsPUA3Q2x5o7KZ/VjYLEz8Tkaim30cMUXoSp4JdbNkKLadcK28+D19rwgq3wpGQneGlp75GnuZ0UY9HUHARn1pp/68eSiacsk9exYfQbqAPCKptsusimsK8dI37zM+SfihynHLJrgAjgjDyqXegPqULY6aTr0Ih/ux7iVdmrO29d7jzGlX98NJVGVDM90= 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)(10070799003)(1800799024)(23010399003)(7416014)(376014)(366016)(56012099006)(22082099003)(18002099003)(10067099003)(6133799003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?U50WlrxmWVAD5M20nORZbW7P0IcFoFitABq23i0CKNwvr9dTAp2GkXtjBXOi?= =?us-ascii?Q?MpaHYlunrYCvXB7va0pZ+DrSgM//r1AgGh5cMSKZgn8KEDd1xsu7JKUUn3y0?= =?us-ascii?Q?eqbyfYJF8HcxX7D+uDPR7XavjTeSpZaE0EA4miQMVjAeKjG2mNwG1fDlT1O3?= =?us-ascii?Q?E8Dv+ruTlrkCLsWHHp5bpJjY4xT5zt1YeV9LNtOqXacdJ/aKiH7NBJ37lhOe?= =?us-ascii?Q?rA474+MF3PKjcI6lD8reVfI93gW7qeBoEAyUCz1NRDWK/UJCCAmC5uii4uy+?= =?us-ascii?Q?E/6Zpe7hrWfnzbmp4ytU1dt0i5ECOSqzreaNp/ZruDPa8Xeqlo5KXOGlOQor?= =?us-ascii?Q?XnR/4ACW5nPxv5DOdfuMqJrc35GwIQVfpyhmytAsZf+92j7Li6jWjftpUyPs?= =?us-ascii?Q?QaemvfBMjcekqVNfvvOTSVmdvN2awNGH9U58G7rDcxnvDG0/YdS5LbxuV8wA?= =?us-ascii?Q?uV4neJiY5JuKQTexgjo2GIaMyX1H6lpTvXrZ69m7EoGlWj130ul2WsEU9pSE?= =?us-ascii?Q?PHEXIHemW4XVkMYARChW/iRiJekqJE7NsLmq+Apm8BGE4gmw2gYBeu0B9PqZ?= =?us-ascii?Q?DQhGsFhmRrpxj2LnPbK5yytcyx9v7c3Va4ZTlwkGhS4wNjkE3eqJlgkrebL6?= =?us-ascii?Q?suIJL0/035tZV77RNiwjYPsnTAnQ20wyQW8ACobeIpuNH0KVG66DHRVorrvR?= =?us-ascii?Q?OUG6FnMX2s7o36jra+09r7DUn7TPKGjCUApBnsfUUDO0iK2Co/RCqBaX4qlR?= =?us-ascii?Q?Hqr2/BBJaaR9C66cGi7v+dQwhts4qhZnluka025BEvZto8agni+qfh/GbiOf?= =?us-ascii?Q?3BHGAE2Ry2GJJ8HHOrT7xejwL3l1mPEJZFqOlgU5R7gCoHsmmj5OhM7YZaBG?= =?us-ascii?Q?T6Yf1KzSe6pKEn8CMRmFx8xpfKc+DANN49v/fe3UdLibkylmLRbhKdKSfKd7?= =?us-ascii?Q?s/nzVfrouawx/JLxbcKqTn2JlnzRvaLKy7AS8sbVl7ubviaHv/++WpWUMfS8?= =?us-ascii?Q?+DHtBCL8huOfqoZdOwfoxfGt9YDr3UNOSSfly0FjXa4Ym/7dNzwD7b6HHzpA?= =?us-ascii?Q?M3jYpAh2mg27teAPpRHcy/2BKia38QXFaZMp9g1iIMZsNPps65neQEAhMl4E?= =?us-ascii?Q?X5Rq46s3xwzEYX4ZIalbZSHwLXYwo1ZXOYrR1YnFDL+OB3QmddYfV/HIMR2m?= =?us-ascii?Q?hz2FG7QD7nMQNeFWe/ZoL/tsyEIdPp+dvb3LeBz4umIWJ4suuCPKU7oCACFr?= =?us-ascii?Q?dcxwUF2VqKsyFhgEkcYKpkbcFHbR+r0/+cTmd7dm+49eWBOl7MgKeJw8rBGv?= =?us-ascii?Q?xyybtT5Hm96VZDl3y6sfsvJt+JudnIXM+zXoiqfjjG1tnyjgpCIYGee9yQDI?= =?us-ascii?Q?Z4qqB3Fqp6TwIkpKmNqH2QgmgqLTHp/9iDeyxNU0PUMFpcYOY8TVY4VCx6uO?= =?us-ascii?Q?Uuzv9jjTZnnUtAxXbJjE4goB9ZfZQHZhx95MpvFLXFlr7BpPeCiiAu9S0snl?= =?us-ascii?Q?UZdnLhYdQNqZTlpdhhNqFKGxcVyTY+CJjHdH7Awi+J2mGiCtHgtvU3iT6OdK?= =?us-ascii?Q?s+edKrxuOHPh2/XZhNUV9DBPcb+gR69SiCA2Oic2PiAJMWH7O/gIdN+SoFEa?= =?us-ascii?Q?Sef2hQ2eWn6Wc6yTO2Mb+ovf8Amws0EIZd+Tu3itgJcrdL5IExZFIwzfczke?= =?us-ascii?Q?6qbheO60dulgR+rvJHDldr1BhEKnwR+6AIr+T4PdHEsf3O3q5RiOJWDPdfrf?= =?us-ascii?Q?KxE0svh0AYoI3aP8q+5v0yVfhCI60NYVwPi1SLK9ultknZjs0nzb+IoK+RJN?= X-MS-Exchange-AntiSpam-MessageData-1: Ew8np2R8P3OD9w== X-OriginatorOrg: valinux.co.jp X-MS-Exchange-CrossTenant-Network-Message-Id: 5a9fc6f7-9583-495d-1e65-08df0fe997f8 X-MS-Exchange-CrossTenant-AuthSource: OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2026 09:46:46.2421 (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: AtzAk5ctjnq0Lb4vxr9UtdhYDDChInON0aEKTYn1s5/Nv709OwGKL2qVe6LawJ+3cwyUFWfw7i7SdOsEPmw7fg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYYP286MB5003 X-purgate-ID: tlsNG-33051d/1789120011-6DAD44E9-FEE310CD/0/0 X-purgate-type: clean X-purgate-size: 9049 X-ZohoMail-DKIM: pass (identity @valinux.co.jp) X-ZM-MESSAGEID: 1789120024904158500 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 8ee8f88fb4..fe4125cd75 100644 --- a/xen/arch/arm/include/asm/processor.h +++ b/xen/arch/arm/include/asm/processor.h @@ -614,10 +614,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 904130efdf..da57137a1b 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 b1745c1071..c5340a924f 100644 --- a/xen/arch/riscv/include/asm/processor.h +++ b/xen/arch/riscv/include/asm/processor.h @@ -52,10 +52,6 @@ struct cpu_user_regs unsigned long hstatus; }; =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 ce9da0bb36..b070774cbb 100644 --- a/xen/common/device-tree/cpu-topology.c +++ b/xen/common/device-tree/cpu-topology.c @@ -320,6 +320,67 @@ static int __init parse_dt_topology(void) return parse_package(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; @@ -330,9 +391,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 4949606881..eef94528ad 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 8fb5ff0af3..6f1839b359 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 090c793f33..d6fe4ffa67 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 19:51: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=1789120051; cv=pass; d=zohomail.com; s=zohoarc; b=Vy3mDR/fxN0aqv18v3iupEs0tamtEo9Z1RfHVdIe6/ehFQ0JOSitCqnVnOU0wMs4AyY0RvBhrBWtTwObq5Uw7v6BcmM7GcIidIFt2QuQa1OqVMNHaQy5MiR9J+z5tuQeuoc0J3GXD3AxLNWqxQWEQGB/guYraYxaG+HoUkKEIHo= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789120051; 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=DQHSSUv6ukV+BKiUAKLe+m7272BwWIUtvYVDaW9Gcrw=; b=Oqwb2goQoWGfpLeW9Oe44luyF/09T5Vhv8H7srHUS43QiO8GLzykkpvFOEgPQVplEL0/yJJdozorPAoMDCQrJxY84D1xuiUfifdij2aGZKqZm191Xah7ayuH6l0aBtckKm3jF9Bfu9t6EuyZB8e4cgtgruWETBlMcVsyOWjBlIc= 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 1789120051179511.05651396176654; Fri, 11 Sep 2026 02:47:31 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1416176.1645342 (Exim 4.92) (envelope-from ) id 1x4xqj-0000m7-LG; Fri, 11 Sep 2026 09:47:13 +0000 Received: by outflank-mailman (output) from mailman id 1416176.1645342; Fri, 11 Sep 2026 09:47:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1x4xqj-0000m0-HS; Fri, 11 Sep 2026 09:47:13 +0000 Received: by outflank-mailman (input) for mailman id 1416176; Fri, 11 Sep 2026 09:47:11 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1x4xqh-0000j6-Li for xen-devel@lists.xenproject.org; Fri, 11 Sep 2026 09:47:11 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1x4xqh-000pr3-28 for xen-devel@lists.xenproject.org; Fri, 11 Sep 2026 11:47:11 +0200 Received: from [10.42.69.11] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6aa3ce0c-8faa-0a2a0a5109dd-0a2a450be1a4-38 for ; Fri, 11 Sep 2026 11:47:11 +0200 Received: from [52.101.229.130] (helo=TY3P286CU002.outbound.protection.outlook.com) by tlsNG-42698a.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6aa3ce1c-b7e8-0a2a450b0019-3465e582a678-3 for ; Fri, 11 Sep 2026 11:47:10 +0200 Received: from OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:458::18) by TYYP286MB5003.JPNP286.PROD.OUTLOOK.COM (2603:1096:405:14b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.9; Fri, 11 Sep 2026 09:47:07 +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.0406.007; Fri, 11 Sep 2026 09:47:07 +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=fBVd49n9cpD0ldQR84Tsx3NtlocS+jvyessQzvVx1tztiI88/Szn8aJCJARQRhGvYzGstNLie3hxpvXCa1kAim5QmYkjdAKObEU2jABEFtCg2dNW8jpkS3Zsb8+652gHh+9aGbNMhKHQOvoniBmWrYVkZCpV4PuDT1ea8MbbF6/oTfCkk9gwDvWKlcSg8W41W0n7r5hcyfBeR6VoVn4BTAqvAFbKDtAmm/imC8q5OvgjLTHAaRW/bR9e41y3g1sKJcgxEHmEtDCT9wWWupeP+HQ8WKmVg2U87UH2x8F8cqgT/tB4Q+ozWNKXNSFBj9mCRaudag4FAcgYF/LQTEJMdQ== 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=DQHSSUv6ukV+BKiUAKLe+m7272BwWIUtvYVDaW9Gcrw=; b=PkHjL7ujaBrljlpOR4O2oapevDHRyK8tKlDrUPo12Bhpyanr7ux+jmHsoq2Cohi+owxHl7LXWOBXcEcbs64A558lBXAOYcOkHydw+u6HUbNnCWU8ti+/bIMV0QWEH+mnjSeXmnzUqWfLj3oM6VZWDAZl1p4ycboU018K7LyYBG5W11Cv4EL9m31+BEwPCiQBKEL2t0CkQu5P7xc0k5q5RCXEmT5tTq8nH+Iztputj8sWBcIrXBXoXGrJmTDTSgoE1hQknDnH7GYN4alDlKL6LKhvnXIglwkxPSLsjFOkgmwSq0uuWO1FPaZB07pc4HdDFAST4ZESNnEWIEXJ1A97Cg== 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=DQHSSUv6ukV+BKiUAKLe+m7272BwWIUtvYVDaW9Gcrw=; b=l6wawT76zb+mLyCeOQFZgW/m4SakueT7A3qghGZshg1jmsY5R4a7NmU3HNLbEIn8kTXTa963joXLfakyzaFmqBvtR4vrTMCZKU/Wgb6Ycjp8co6zKYH1FWcB8Kmv8RPaqKdOBGaGJTtGS1r+1t/Fq7Rx5VJpIdjnnLKOG9NyBQE= 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: michal.orzel@amd.com, Mykyta_Poturai@epam.com, Hirokazu Takahashi , Jan Beulich , Juergen Gross , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Julien Grall , Stefano Stabellini , Dario Faggioli , George Dunlap Subject: [PATCH v10 3/4] xen/sched: Make cpu_nr_siblings() architecture-specific Date: Fri, 11 Sep 2026 18:42:12 +0900 Message-ID: <20260911094213.79936-4-taka@valinux.co.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260911094213.79936-1-taka@valinux.co.jp> References: <20260911094213.79936-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_|TYYP286MB5003:EE_ X-MS-Office365-Filtering-Correlation-Id: e7638002-16eb-4914-ec58-08df0fe9a48f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|1800799024|23010399003|7416014|376014|366016|56012099006|22082099003|18002099003|10067099003; X-Microsoft-Antispam-Message-Info: kbIfBiustNUcmmZB0KTVxRdryOTsZQUVCkGDv+hr1dvviGEWptRU82lv3exuooK2HuRXPZrBKBpU3WMeK/cgWd4FHlh62ci+e9WV4L0dJWi294aok2Jk3ygN4dZDTTHzQrNmDsz4PxjafJDh5Uj79lKzm8q6zK8iaUGRltlmH7j/aLFED851DQkHUqyqMkH2JYKQbnyR5Juw5/lUMFg5WU1i8u23ioyjU2uhn85N/p8OKql/puWk8uAZYgJ5AYSCm865prlNAN4DOmiAgU03JrsKGWVK7cs3hbohHxQtyLXFwE/+D3ia5knSwQ3FdHe/mRvY8gSXGlndEDBjjHDw5ZtNUXinRncwxX5NxWOg7fWSm5+4vmoEGsm8n+zUQCtXK6sKOSqYGyuhIJ3nVynCJYmQ4P6fpEQq6HWREx9wzXz39Jd8nL84anRWVInz+mLS8Ks8mhURyLpA4+43IY5pZK/IKqVqSyzfCGIld0fnUjcTxvR6fgDHnrreAamzAl5HsA7QLhG8DNjBGDSs9MVtzWxsWxyzwcdZYGsQmB47ZwLuvP+N5JE5K3yBgq2lGHjqj3JQ5s9JAXMkR0KDJ/nWIiayNvyE8xdm6f24DPP9oRk71tzkltvp8rjimB8iLqt481VKrotKRcEeDgLD4+sCtInfepcQ4LVFVWYJauCMj0k= 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)(10070799003)(1800799024)(23010399003)(7416014)(376014)(366016)(56012099006)(22082099003)(18002099003)(10067099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?n6ob0vr8vgizII/X4nhvWFi3sHEAmeHjKVErqiOnTRgSzGDIEolR8tkphwHE?= =?us-ascii?Q?qI2P8E+hZdMCsLnBzwTEndLYj80+/wXFVc2eAh5igJZSBhaeFh3fj/IpxEvD?= =?us-ascii?Q?JjHlCsIm9kGsVDPjs0ayRIyXF3IxnVS/7hbFQW1IeT0wcxK4Y9FJ/jEKeyOn?= =?us-ascii?Q?SjtiELa0Bbdy7hPQmlJfnz2lo69+WG89RNDFhAG3SRNTCYviNXwhsFE9r+pF?= =?us-ascii?Q?LFK2GKMVuY9VyCiFRzb7/IGygc/RjA6gJuo46Y6vgoEO/E483GEr3LjFHWs5?= =?us-ascii?Q?ycrzH1upvanbGvEJxoTFnxOebBhqCAQCVS3d92xkewM0IHgMpHU+dGJG/ds7?= =?us-ascii?Q?69edOiiigIrOfVCF82PVBhxF0tBavL9OzCFes9PkCALYs34dJJ4S55j6UXnA?= =?us-ascii?Q?lQPDGmdJqA3iJ8fS95TmVSh1KroEY0gWwtoKCt5lwCMBtqw7IPwqC7DUFm2N?= =?us-ascii?Q?mWD4oYbOqtEfBBODhSsL8xQtC9BZP2amUXnur9OFgmxKHHXWrAp6zZ/ZDJHq?= =?us-ascii?Q?MaThrbHtcxojbyydnyd8Am0sea93UEBHqqsExqxUcMMLkX+z4zATtmo9Iftn?= =?us-ascii?Q?/AycC+6kbJH6C1N6NSkPGmmKoQVqfL+sA+A4lnNjakOShCYBoBYVfkZhw/0K?= =?us-ascii?Q?v03ILVzayZkJvCyUKdeCKfLgKwauc2VgW6/5xKOER/+ncbM63ORXIpYXu8IB?= =?us-ascii?Q?fbHFKlz2WTHiPIf5QDEJtRTG4TvmD2VTjlR//2Q8syJK3Es5eAycP4xJudAz?= =?us-ascii?Q?oAK9W0xOoqGjMLvswl9FCABYt+0mSsfzMauW2pLj917zqLHdEGzDj3jdPvZS?= =?us-ascii?Q?nfRW8iP8AkmK7v7N5axxyl6tdiO+tSZXxIoaWppvobA2mHzf2dwZ9Kntv6px?= =?us-ascii?Q?LZEECVUjcxMh49EmZNHKJZD/4mZZhP9yVScgP5Nt4pNvPVu96eNKG7UIb6mF?= =?us-ascii?Q?EOCgk1b7GYE3K25Lal8/x6mj+S+rXMFoGxgahUU56jDYYYDJnsy+Ra3iaG+h?= =?us-ascii?Q?FJhEPpAldWM4+Ll5S5kIHvH28vuCwaGdwgJkyE1IwF5IzuzfKiXyoCo6JYcZ?= =?us-ascii?Q?3fpHRs7A/s6xDJQ8+EzrnoEM9mGj2lRfVRz4Q5vfNxbTXZmloSyKM+fZDsDf?= =?us-ascii?Q?iDzJcu0oD2Cz+1Y3/miQhVRSdXjb3D20egspP0BHPwJi6Vn1zijrXVbeQrHD?= =?us-ascii?Q?+8iqM1SHbdVlbNgtGsls26EDBg/Za3kn5S7m1l3sLoBZTw9KTbeX4WcnoIBM?= =?us-ascii?Q?0e71qd6gmjjVlxd0KrWvCn1+GPNLt8vlYjdFNuJwFuYAm0cmCbAWW/oHvPvl?= =?us-ascii?Q?zTdzC2fC26QqbiVROOgcI3NPfyC8A+hKv1RlyucKc4SUfcd/QkWFgaif99RW?= =?us-ascii?Q?O18uyp9VW9/YopEVPjzqgkuOt/57rUFFCT+cLA3719PfzE/7/TeBw7uG0KwK?= =?us-ascii?Q?DtQ79y96ivDAcROhd1amjCIWUdSqxpSWxCAR0f9/+Q9dpTrnlt9OTkPjWJ3Y?= =?us-ascii?Q?zVLmQSEdW0f6X6TOudTkN1aeh8PXu75m3nQwMKyP7vJR32c+k+ebCPZhKXSz?= =?us-ascii?Q?hV2sfvdjg/HTs8diFTnW/80eNIMmCfzOa1lkOTV2g/xuR9G9Lq4It+AcX7Vr?= =?us-ascii?Q?d3si9wxdBHEBo2QBctKVCWxa+Hi6Y85/W449Jby43AcVznzNXonq9frChAM1?= =?us-ascii?Q?VBSl2JJiJEZvW1+8Ejh8BqhHrSfcYkKoGT6UYpSUUCSZOGnd37t4Qu4CBA43?= =?us-ascii?Q?hduxsXSYaCNM0MEkNB8d3wIflMhwjimgCJ9mrj13JxjmC3nWc/o0z1WNEgES?= X-MS-Exchange-AntiSpam-MessageData-1: xUIc6jH/9ggGFQ== X-OriginatorOrg: valinux.co.jp X-MS-Exchange-CrossTenant-Network-Message-Id: e7638002-16eb-4914-ec58-08df0fe9a48f X-MS-Exchange-CrossTenant-AuthSource: OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2026 09:47:07.3262 (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: hXskXj8o2elGTSXAj7c9NHeJw5tZlES4dco7FhWRwD3sOMT8j4kL6NexUKDJAhU23gE/qxFlUhTYIDFH3xCdlg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYYP286MB5003 X-purgate-ID: tlsNG-42698a/1789120031-186CA9EA-866B678D/0/0 X-purgate-type: clean X-purgate-size: 3435 X-ZohoMail-DKIM: pass (identity @valinux.co.jp) X-ZM-MESSAGEID: 1789120052991158500 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 4b17e13a97..049b917c49 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 eef94528ad..6ede629fd2 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 19:51: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=1789120064; cv=pass; d=zohomail.com; s=zohoarc; b=LZAkC5xq0TWOjLlxASbnp7/QJ20h/LPCyfDEQLF1M7mc86JIxzUzJHYlPceEPxeuggpZpjn7DoVSol8qr/Lu2sDowzExzVWJupi0RMNhq2kne2/Y9HdPV4cag8Uc0V+OdD0WRYzHNT+fX/15XEkXRtEu2Oq/66DGebWvuJ/DvL4= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789120064; 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=gSMNjH+uFDnifcc7j4z3D1fg79w6dp+9PaRbS2TleWA=; b=La3Mj0PpfNdni/GXSzl+2CJSfOdx4r5zOJGrYLDfgr6R6m3L3tYLp8NcOV9pazEl9ga/ak9/t1oec2EfGYKw5jT/I2MZum589rFP/iPR2Kni7XH7FCz/YsbsigIvoJJQ3u0aEfdab67iJp5WJdr3DOh2vdb1Gr0ZYYUhrEzjvPA= 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 1789120064044376.6418001514304; Fri, 11 Sep 2026 02:47:44 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1416181.1645351 (Exim 4.92) (envelope-from ) id 1x4xr0-0001CS-W0; Fri, 11 Sep 2026 09:47:30 +0000 Received: by outflank-mailman (output) from mailman id 1416181.1645351; Fri, 11 Sep 2026 09:47:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1x4xr0-0001CL-T6; Fri, 11 Sep 2026 09:47:30 +0000 Received: by outflank-mailman (input) for mailman id 1416181; Fri, 11 Sep 2026 09:47:29 +0000 Received: from mx.expurgate.net ([195.190.135.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1x4xqy-0001AL-UJ for xen-devel@lists.xenproject.org; Fri, 11 Sep 2026 09:47:29 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1x4xqy-00DOxT-At for xen-devel@lists.xenproject.org; Fri, 11 Sep 2026 11:47:28 +0200 Received: from [10.42.69.11] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6aa3ce2a-8faa-0a2a0a5109dd-0a2a450b9902-10 for ; Fri, 11 Sep 2026 11:47:28 +0200 Received: from [52.101.125.124] (helo=TYVP286CU001.outbound.protection.outlook.com) by tlsNG-42698a.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6aa3ce2d-b7e8-0a2a450b0019-34657d7c3aca-3 for ; Fri, 11 Sep 2026 11:47:27 +0200 Received: from OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:458::18) by TYYP286MB5003.JPNP286.PROD.OUTLOOK.COM (2603:1096:405:14b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.9; Fri, 11 Sep 2026 09:47:23 +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.0406.007; Fri, 11 Sep 2026 09:47:23 +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=mV0o2nDR1s6YSzc26X4oTYKase8EE2OGXv7vI+Fix0xNT3mh+J6Ner2+GYFSW4qIxuXYR00NkyWVfMdW1hDWSyPVrjG3HIY/B28gTmwo6FNicazh1HySi+igG1d4Qxaq5/PYnJUuUg9e8E2sK18RoiZKn5cl3kHTvZNOlxsZOgzgS7QcMGYacZb4LwT2wwsq1vuRZiE4a3xLcmFdWTq1fBXWRtHDfYRJggykbfdExJ7wrqmklz0cIJOueUfaMPaRzJQNX0rma7++aqW1MESTmaA5iZVgNtDXMtoDFrmx9axB4RLNytZhZzByO2+dmFGrDg+hE6zhi6KWuCerqhtyKQ== 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=gSMNjH+uFDnifcc7j4z3D1fg79w6dp+9PaRbS2TleWA=; b=Iq3WzHnTqdf97sKSHW4ul4fH/9LG8IStHpj9MwBcxJfSe0sTFz1g4sZozrKlOn1D8QC12w6BJVWnTwXRWSAz2hOz6CFWl+sGPGiP4V0xQJ26XI6sJy068nb5QpE+/Hi4XxLIZILzpHvnrDacg4WhyPr3FyJ4m5LGgqMhVvW6VECBmcikoaB6SIlDxpxV6RDOfcHUASL1Z7u2CK6M5mA/UDcxOZmj0KPNCg3mQgDnMrAg7RHk/w1GB37v5tBfgvIxC6d+2GEu9EDI/tJsosBn66+XA9NVis+Rwy4Pomusjpt6ZryV4SipgOTw8ovcUMgU/AKrzBiGSt8FrfMIdrfFxQ== 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=gSMNjH+uFDnifcc7j4z3D1fg79w6dp+9PaRbS2TleWA=; b=tSb7nH/OSN/lWYJCkNY4/nnwGA1hO1MlIKi8N5XUmxF3vbRdraNYSEcm9IAZyy9Oht9QiSOgDMO3AN7nxIHuIbeGgHJCtvWH0NleEqdcIpQiKZE5u2ylfHpPXqu+eVB/VRiV8UC6N1S2hQXeU2Etl1oT0FiXjuv/PRMKjhx/1rA= 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: michal.orzel@amd.com, Mykyta_Poturai@epam.com, Hirokazu Takahashi , Jan Beulich , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Andrew Cooper , Anthony PERARD , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie Subject: [PATCH v10 4/4] xen/acpi: Parse PPTT to initialize CPU topology Date: Fri, 11 Sep 2026 18:42:13 +0900 Message-ID: <20260911094213.79936-5-taka@valinux.co.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260911094213.79936-1-taka@valinux.co.jp> References: <20260911094213.79936-1-taka@valinux.co.jp> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: TYCP286CA0152.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:383::14) To OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:458::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OS9P286MB7222:EE_|TYYP286MB5003:EE_ X-MS-Office365-Filtering-Correlation-Id: ee6257e6-ef7e-4de3-38c2-08df0fe9ae6c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|1800799024|23010399003|7416014|376014|366016|56012099006|22082099003|18002099003|10067099003; X-Microsoft-Antispam-Message-Info: dbDz2/ueeLPYe1FHZSp5HF02C6BdXH9A/9ywYSvzw25T6Ali1+jZXtO5JwrnUSEAJiJ5yFUglF+J8uI6bu46cZBw5jrilVUyZKUoCOm6p2yKb8mKBxqqhLtMAdexmPiAzuiK8LP+YUKQ9mpIpUWDxOdmv0ZTZQPUgDYPrqFu11CtYuYdNjUyNboC17DghdhU/IM4qqteIHH+rgY5+pqwVti+8u7vaxA0frSeScRhuKWovu7nA74N8ryHB8gmAnAML4oRJ0Ok1yioKeH1ltI/txtwYcbyrIiQs8xR6CiO259vblo9U2+RD7W5943k4EjEnASUE2+POu/rapzHiOI7MXDRzxbpLGrJfahwyqQCpGGbDlTvYAI/h9liIY41JZG8XBAAW7CFjMjA5q9sb5IpoQKKUlx6hy7khtGkPg+qJBZMkUZbyipj8iLShpO9PScgl3F37dt4CRKgjPar8u9+GRzZYi+LGxYB4pSU4t3V84lXkgmz/hkYtcjZUQWFhdfgM44Pqp/ClAwpZWK39SYfk2u0354EIg7pKtS7e8R0NF0Y+29qvPmfvClCABsJLLocYT5tkvyWQPtcFNZUKUEqdjCw342vEdU2jD+REo9q6SFueGL5piSxQglZlhSU/+SSF1K300ITsZ2L2G2B/9dvA1w76cdvG/24jK9XwY0d5n0= 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)(10070799003)(1800799024)(23010399003)(7416014)(376014)(366016)(56012099006)(22082099003)(18002099003)(10067099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?geIxV0Xq1/nIvsGglbZ+ELnKvh2q4pvCZwGyKdolvDqFlc+MmCRh/HtA3Hcq?= =?us-ascii?Q?yZboz//IRaZNPOdO8k24N6R+93wRkJdZm6Vohw50j/H4hHKd5BqLvl7pw6ii?= =?us-ascii?Q?Q0mJxjbV3dQhiP33m+7ampoAkPh/bfB9ck21Bf17IJCIyUMiLQEbaf8VROcN?= =?us-ascii?Q?HG5wQsvh/B7taomJMi7N9/rlAQ6aT+3zw4rfA0+PTh9z7Nb6p0mkkVcXC/Uj?= =?us-ascii?Q?9HayatuAysFXPsh/FI40+SxNSxVnIpXiKoni2NqcldgMrD5Fl1T8xDBp7I+w?= =?us-ascii?Q?AXjP/dg3+vZQAIDx1/2u+b8poSzWRTzgRR7XioKG4chsw6lJ0JooOqDW3IR+?= =?us-ascii?Q?jqhH6kKtRcwLcdOuc1Xmnxmiy5peDzHXpOOAL/CKfeo2Z6jx49l1mcJJzTVM?= =?us-ascii?Q?3UfehZ+NZeQptexVzX0mndmFaezUzFwUlf6jtPcnt8lTW8VUarURRH3Ga8D2?= =?us-ascii?Q?JX0BReZh5Tcmh62J3T91w5zGxR3nho7gwnANGT4wazxKDjk791pKwBVrGolW?= =?us-ascii?Q?Gsz8BcPlCLrvveKuVRcR9cdiOd6IzgjmL9XGl3t4XCtws7fvCQXRB/y4+Si4?= =?us-ascii?Q?GPNiadqdbg+sZFrSnmjCv6J+0Mzc1fJJEEke5f2/JczBCXADCk20OrQQRlXR?= =?us-ascii?Q?gMsjoK6RGcJJFqHdKoJBp0k9/L1FmNfRyGbcLNolq1UPwVyfBbTmRhPLfTMR?= =?us-ascii?Q?pNWZu7bRwyj33hRL0FvF4u77C/gd8zL9WfFx/utdMLri6ujP+EHyptuEhVXk?= =?us-ascii?Q?cKyDUsIoNby8A+3dW0Z6C2VfMP6SC4dIYurL7ZB2Zjl/AcJvFOnnVp2UXNPJ?= =?us-ascii?Q?WNTJe1STk35uoriE2le1VulNtGunBggrhhQ0ycvRV282s8JWWsfzqgRCtDaU?= =?us-ascii?Q?3UNqB+S/hq9rEcCgshRXtSzY9rjLTK78REL+IPkqLrR5vzs0JamsOHaRHpWt?= =?us-ascii?Q?DpSmjvwcSLw6wR1qbBoOlUw9VF6gNuYwy3XzU7JrOElP8KQEm9YREUTbC6oE?= =?us-ascii?Q?Xrj/H5q/ANSEUc2wzYENR+H/PHc+eJO773+nuAtll0Os5kkf/wylmLJltX1S?= =?us-ascii?Q?qyBD2r1RX4TsOtpj/U8658g4IMLusVQofGp+7Q8IyZn3g06Np2aWyHuK5tuZ?= =?us-ascii?Q?YOBTkEHBjHe5joatN99q0d0wWhLOFs6YyGqIYCFIVvKVYHpSy+WHKuwVjnrd?= =?us-ascii?Q?wCIt9VSl67Plzydrh5pLfpiSS9Ql+bFg1XD0UpTHSzFROzNSVe8E6VDyQlzN?= =?us-ascii?Q?TfldQTZwC7yC9XV73j/XXrJKP2lxhocdtPpuUV3plWQTq1AsXtgDBmyNzV/I?= =?us-ascii?Q?Fc60ffRyvEINFQLdQJJiAXXbZfY1f2nyUmhgNNFv15qRwJA+tiuK4DDoAl65?= =?us-ascii?Q?/kTKVFXddWA7oKqjVnxBFdI+FbWpqn6Upzqm1Ie66gHkbBuXN3HdKsq+FQiP?= =?us-ascii?Q?tRtsZ+/2wbxJUvsGbdJqq28pghYhuFOEhNRe7mFl9M/qJdexgI1UUd5P9umA?= =?us-ascii?Q?ZQSdrmwOgddtCxlqDSYzKSVZcPUUeVyQzx90UpBtcKoBSbOop1Bq4xTbZHFf?= =?us-ascii?Q?27R+KcOLbfj8nybSoIA6sLKSAQ+NJUuHMWt6ri0x4AZoXVctN8vpmm1Lfa3p?= =?us-ascii?Q?Dvc6gpGX+8Uxo3zgcNsoCOyoew3lA5ySmQu2Eb9xm2l9qoVuZNmdXIs+FGf+?= =?us-ascii?Q?R8HGY30nrLMZXbZDqriwlxGaxQaRP1kWnNfvWdNsCg+Tr5EF/Tm1yQbNi4+i?= =?us-ascii?Q?L7raJ+2BYvTEOy+Mb39gWJjkS4mIpiu78vDD0wNCf8Yob61QFSAQnOnbT9Kj?= X-MS-Exchange-AntiSpam-MessageData-1: 1mfckpDcXo7RIQ== X-OriginatorOrg: valinux.co.jp X-MS-Exchange-CrossTenant-Network-Message-Id: ee6257e6-ef7e-4de3-38c2-08df0fe9ae6c X-MS-Exchange-CrossTenant-AuthSource: OS9P286MB7222.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2026 09:47:23.8730 (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: co6cPM2ItFQQkaHYJvWQ3K7j8uW/PaLLCBmzhjad5JzKc9lkWmsWuNI93+i1SaO/sPtNw11/UjiIpobOLnzNrw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYYP286MB5003 X-purgate-ID: tlsNG-42698a/1789120048-AB2DC9EA-737AC99A/0/0 X-purgate-type: clean X-purgate-size: 14080 X-ZohoMail-DKIM: pass (identity @valinux.co.jp) X-ZM-MESSAGEID: 1789120065310158500 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 --- 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 d6fe4ffa67..c9b545115c 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