From nobody Fri May 8 01:40:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47F49C433EF for ; Fri, 13 May 2022 09:56:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379259AbiEMJ4X (ORCPT ); Fri, 13 May 2022 05:56:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378821AbiEMJ4O (ORCPT ); Fri, 13 May 2022 05:56:14 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 49D9D17ABA for ; Fri, 13 May 2022 02:56:12 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C11A11477; Fri, 13 May 2022 02:56:12 -0700 (PDT) Received: from usa.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7FBAB3F5A1; Fri, 13 May 2022 02:56:11 -0700 (PDT) From: Sudeep Holla To: Atish Patra , Atish Patra , linux-kernel@vger.kernel.org Cc: Sudeep Holla , Atish Patra , Vincent Guittot , Morten Rasmussen , Dietmar Eggemann , Qing Wang Subject: [PATCH 1/4] arch_topology: Don't set cluster identifier as physical package identifier Date: Fri, 13 May 2022 10:55:56 +0100 Message-Id: <20220513095559.1034633-2-sudeep.holla@arm.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220513095559.1034633-1-sudeep.holla@arm.com> References: <20220513095559.1034633-1-sudeep.holla@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Currently as we parse the CPU topology from /cpu-map node from the device tree, we assign generated cluster count as the physical package identifier for each CPU which is wrong. The device tree bindings for CPU topology supports sockets to infer the socket or physical package identifier for a given CPU. Since it is fairly new and not support on most of the old and existing systems, we can assume all such systems have single socket/physical package. Fix the physical package identifier to 0 by removing the assignment of cluster identifier to the same. Signed-off-by: Sudeep Holla --- drivers/base/arch_topology.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index f73b836047cf..44f733b365cc 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -543,7 +543,6 @@ static int __init parse_cluster(struct device_node *clu= ster, int depth) bool leaf =3D true; bool has_cores =3D false; struct device_node *c; - static int package_id __initdata; int core_id =3D 0; int i, ret; =20 @@ -582,7 +581,7 @@ static int __init parse_cluster(struct device_node *clu= ster, int depth) } =20 if (leaf) { - ret =3D parse_core(c, package_id, core_id++); + ret =3D parse_core(c, 0, core_id++); } else { pr_err("%pOF: Non-leaf cluster with core %s\n", cluster, name); @@ -599,9 +598,6 @@ static int __init parse_cluster(struct device_node *clu= ster, int depth) if (leaf && !has_cores) pr_warn("%pOF: empty cluster\n", cluster); =20 - if (leaf) - package_id++; - return 0; } =20 --=20 2.36.1 From nobody Fri May 8 01:40:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9FE27C433EF for ; Fri, 13 May 2022 09:56:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379271AbiEMJ42 (ORCPT ); Fri, 13 May 2022 05:56:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379223AbiEMJ4P (ORCPT ); Fri, 13 May 2022 05:56:15 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 608AE19029 for ; Fri, 13 May 2022 02:56:14 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 369B31515; Fri, 13 May 2022 02:56:14 -0700 (PDT) Received: from usa.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id EB67F3F5A1; Fri, 13 May 2022 02:56:12 -0700 (PDT) From: Sudeep Holla To: Atish Patra , Atish Patra , linux-kernel@vger.kernel.org Cc: Sudeep Holla , Atish Patra , Vincent Guittot , Morten Rasmussen , Dietmar Eggemann , Qing Wang Subject: [PATCH 2/4] arch_topology: Set thread and core siblings only within the cluster Date: Fri, 13 May 2022 10:55:57 +0100 Message-Id: <20220513095559.1034633-3-sudeep.holla@arm.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220513095559.1034633-1-sudeep.holla@arm.com> References: <20220513095559.1034633-1-sudeep.holla@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Currently the cluster identifier is not set on the DT based platforms. The reset or default value is -1 for all the CPUs. Once we assign the cluster identifier values correctly that may result in getting the core siblings wrongs as the core identifiers can be same for 2 different CPUs belonging to 2 different cluster. So, in order to get the core and thread sibling masks correct, we need to update them only if they belong to same cluster within the socket. Let us skip updation of the thread and core sibling cpumaks if the socket and the cluster identifier doesn't match. This change won't affect even if the cluster identifiers are not set currently but will avoid any breakage once we set the same correctly. Signed-off-by: Sudeep Holla --- drivers/base/arch_topology.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index 44f733b365cc..5812428253d8 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -694,11 +694,11 @@ void update_siblings_masks(unsigned int cpuid) cpumask_set_cpu(cpuid, &cpu_topo->llc_sibling); } =20 - if (cpuid_topo->package_id !=3D cpu_topo->package_id) + if (cpuid_topo->package_id !=3D cpu_topo->package_id || + cpuid_topo->cluster_id !=3D cpu_topo->cluster_id) continue; =20 - if (cpuid_topo->cluster_id =3D=3D cpu_topo->cluster_id && - cpuid_topo->cluster_id !=3D -1) { + if (cpuid_topo->cluster_id !=3D -1) { cpumask_set_cpu(cpu, &cpuid_topo->cluster_sibling); cpumask_set_cpu(cpuid, &cpu_topo->cluster_sibling); } --=20 2.36.1 From nobody Fri May 8 01:40:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DBE1BC433F5 for ; Fri, 13 May 2022 09:56:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379270AbiEMJ4f (ORCPT ); Fri, 13 May 2022 05:56:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379229AbiEMJ4Q (ORCPT ); Fri, 13 May 2022 05:56:16 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AF0C7193F5 for ; Fri, 13 May 2022 02:56:15 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A12B5143D; Fri, 13 May 2022 02:56:15 -0700 (PDT) Received: from usa.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 615403F5A1; Fri, 13 May 2022 02:56:14 -0700 (PDT) From: Sudeep Holla To: Atish Patra , Atish Patra , linux-kernel@vger.kernel.org Cc: Sudeep Holla , Atish Patra , Vincent Guittot , Morten Rasmussen , Dietmar Eggemann , Qing Wang Subject: [PATCH 3/4] arch_topology: Set cluster identifier in each core/thread from /cpu-map Date: Fri, 13 May 2022 10:55:58 +0100 Message-Id: <20220513095559.1034633-4-sudeep.holla@arm.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220513095559.1034633-1-sudeep.holla@arm.com> References: <20220513095559.1034633-1-sudeep.holla@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Let us set the cluster identifier as parsed from the device tree cluster nodes within /cpu-map. We don't support nesting of clusters yet as there are no real hardware to support clusters of clusters. Signed-off-by: Sudeep Holla --- drivers/base/arch_topology.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index 5812428253d8..46420db5a836 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -491,7 +491,7 @@ static int __init get_cpu_for_node(struct device_node *= node) } =20 static int __init parse_core(struct device_node *core, int package_id, - int core_id) + int cluster_id, int core_id) { char name[20]; bool leaf =3D true; @@ -507,6 +507,7 @@ static int __init parse_core(struct device_node *core, = int package_id, cpu =3D get_cpu_for_node(t); if (cpu >=3D 0) { cpu_topology[cpu].package_id =3D package_id; + cpu_topology[cpu].cluster_id =3D cluster_id; cpu_topology[cpu].core_id =3D core_id; cpu_topology[cpu].thread_id =3D i; } else if (cpu !=3D -ENODEV) { @@ -528,6 +529,7 @@ static int __init parse_core(struct device_node *core, = int package_id, } =20 cpu_topology[cpu].package_id =3D package_id; + cpu_topology[cpu].cluster_id =3D cluster_id; cpu_topology[cpu].core_id =3D core_id; } else if (leaf && cpu !=3D -ENODEV) { pr_err("%pOF: Can't get CPU for leaf core\n", core); @@ -537,7 +539,8 @@ static int __init parse_core(struct device_node *core, = int package_id, return 0; } =20 -static int __init parse_cluster(struct device_node *cluster, int depth) +static int __init +parse_cluster(struct device_node *cluster, int cluster_id, int depth) { char name[20]; bool leaf =3D true; @@ -557,7 +560,7 @@ static int __init parse_cluster(struct device_node *clu= ster, int depth) c =3D of_get_child_by_name(cluster, name); if (c) { leaf =3D false; - ret =3D parse_cluster(c, depth + 1); + ret =3D parse_cluster(c, i, depth + 1); of_node_put(c); if (ret !=3D 0) return ret; @@ -581,7 +584,7 @@ static int __init parse_cluster(struct device_node *clu= ster, int depth) } =20 if (leaf) { - ret =3D parse_core(c, 0, core_id++); + ret =3D parse_core(c, 0, cluster_id, core_id++); } else { pr_err("%pOF: Non-leaf cluster with core %s\n", cluster, name); @@ -621,7 +624,7 @@ static int __init parse_dt_topology(void) if (!map) goto out; =20 - ret =3D parse_cluster(map, 0); + ret =3D parse_cluster(map, -1, 0); if (ret !=3D 0) goto out_map; =20 --=20 2.36.1 From nobody Fri May 8 01:40:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33E37C433F5 for ; Fri, 13 May 2022 09:56:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379231AbiEMJ4l (ORCPT ); Fri, 13 May 2022 05:56:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379247AbiEMJ4S (ORCPT ); Fri, 13 May 2022 05:56:18 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 541DA1BE94 for ; Fri, 13 May 2022 02:56:17 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2DD231477; Fri, 13 May 2022 02:56:17 -0700 (PDT) Received: from usa.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id CF6F63F5A1; Fri, 13 May 2022 02:56:15 -0700 (PDT) From: Sudeep Holla To: Atish Patra , Atish Patra , linux-kernel@vger.kernel.org Cc: Sudeep Holla , Atish Patra , Vincent Guittot , Morten Rasmussen , Dietmar Eggemann , Qing Wang Subject: [PATCH 4/4] arch_topology: Add support for parsing sockets in /cpu-map Date: Fri, 13 May 2022 10:55:59 +0100 Message-Id: <20220513095559.1034633-5-sudeep.holla@arm.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220513095559.1034633-1-sudeep.holla@arm.com> References: <20220513095559.1034633-1-sudeep.holla@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Finally let us add support for socket nodes in /cpu-map in the device tree. Since this may not be present in all the old platforms and even most of the existing platforms, we need to assume absence of the socket node indicates that it is a single socket system and handle appropriately. Also it is likely that most single socket systems skip to as the node since it is optional. Signed-off-by: Sudeep Holla --- drivers/base/arch_topology.c | 37 +++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index 46420db5a836..ae61af84c161 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -539,8 +539,8 @@ static int __init parse_core(struct device_node *core, = int package_id, return 0; } =20 -static int __init -parse_cluster(struct device_node *cluster, int cluster_id, int depth) +static int __init parse_cluster(struct device_node *cluster, int package_i= d, + int cluster_id, int depth) { char name[20]; bool leaf =3D true; @@ -560,7 +560,7 @@ parse_cluster(struct device_node *cluster, int cluster_= id, int depth) c =3D of_get_child_by_name(cluster, name); if (c) { leaf =3D false; - ret =3D parse_cluster(c, i, depth + 1); + ret =3D parse_cluster(c, package_id, i, depth + 1); of_node_put(c); if (ret !=3D 0) return ret; @@ -584,7 +584,8 @@ parse_cluster(struct device_node *cluster, int cluster_= id, int depth) } =20 if (leaf) { - ret =3D parse_core(c, 0, cluster_id, core_id++); + ret =3D parse_core(c, package_id, cluster_id, + core_id++); } else { pr_err("%pOF: Non-leaf cluster with core %s\n", cluster, name); @@ -604,6 +605,32 @@ parse_cluster(struct device_node *cluster, int cluster= _id, int depth) return 0; } =20 +static int __init parse_socket(struct device_node *socket) +{ + char name[20]; + struct device_node *c; + bool has_socket =3D false; + int package_id =3D 0, ret; + + do { + snprintf(name, sizeof(name), "socket%d", package_id); + c =3D of_get_child_by_name(socket, name); + if (c) { + has_socket =3D true; + ret =3D parse_cluster(c, package_id, -1, 0); + of_node_put(c); + if (ret !=3D 0) + return ret; + } + package_id++; + } while (c); + + if (!has_socket) + ret =3D parse_cluster(socket, 0, -1, 0); + + return ret; +} + static int __init parse_dt_topology(void) { struct device_node *cn, *map; @@ -624,7 +651,7 @@ static int __init parse_dt_topology(void) if (!map) goto out; =20 - ret =3D parse_cluster(map, -1, 0); + ret =3D parse_socket(map); if (ret !=3D 0) goto out_map; =20 --=20 2.36.1