From nobody Sun Jun 14 12:10:59 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 D3AB1C433F5 for ; Wed, 18 May 2022 09:34:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234307AbiERJeJ (ORCPT ); Wed, 18 May 2022 05:34:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234347AbiERJd7 (ORCPT ); Wed, 18 May 2022 05:33:59 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1A6B5AFB36 for ; Wed, 18 May 2022 02:33:55 -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 C8A471063; Wed, 18 May 2022 02:33:54 -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 5378B3F66F; Wed, 18 May 2022 02:33:53 -0700 (PDT) From: Sudeep Holla To: Atish Patra , linux-kernel@vger.kernel.org Cc: Sudeep Holla , Atish Patra , Vincent Guittot , Morten Rasmussen , Dietmar Eggemann , Qing Wang , linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, Rob Herring Subject: [PATCH v2 1/8] arch_topology: Don't set cluster identifier as physical package identifier Date: Wed, 18 May 2022 10:33:18 +0100 Message-Id: <20220518093325.2070336-2-sudeep.holla@arm.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220518093325.2070336-1-sudeep.holla@arm.com> References: <20220518093325.2070336-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 Sun Jun 14 12:10:59 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 463D1C433EF for ; Wed, 18 May 2022 09:34:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234366AbiERJeF (ORCPT ); Wed, 18 May 2022 05:34:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234348AbiERJeA (ORCPT ); Wed, 18 May 2022 05:34:00 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B17DBAFB2F for ; Wed, 18 May 2022 02:33:56 -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 80B09106F; Wed, 18 May 2022 02:33:56 -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 09EB73F66F; Wed, 18 May 2022 02:33:54 -0700 (PDT) From: Sudeep Holla To: Atish Patra , linux-kernel@vger.kernel.org Cc: Sudeep Holla , Atish Patra , Vincent Guittot , Morten Rasmussen , Dietmar Eggemann , Qing Wang , linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, Rob Herring Subject: [PATCH v2 2/8] arch_topology: Set thread sibling cpumask only within the cluster Date: Wed, 18 May 2022 10:33:19 +0100 Message-Id: <20220518093325.2070336-3-sudeep.holla@arm.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220518093325.2070336-1-sudeep.holla@arm.com> References: <20220518093325.2070336-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 imay result in getting the thread siblings wrongs as the core identifiers can be same for 2 different CPUs belonging to 2 different cluster. So, in order to get the thread sibling cpumasks correct, we need to update them only if the cores they belong are in the same cluster within the socket. Let us skip updation of the thread sibling cpumaks if 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 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index 44f733b365cc..7f5aa655c1f4 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -697,15 +697,17 @@ void update_siblings_masks(unsigned int cpuid) if (cpuid_topo->package_id !=3D cpu_topo->package_id) continue; =20 - if (cpuid_topo->cluster_id =3D=3D cpu_topo->cluster_id && - cpuid_topo->cluster_id !=3D -1) { + cpumask_set_cpu(cpuid, &cpu_topo->core_sibling); + cpumask_set_cpu(cpu, &cpuid_topo->core_sibling); + + if (cpuid_topo->cluster_id !=3D cpu_topo->cluster_id) + continue; + + if (cpuid_topo->cluster_id !=3D -1) { cpumask_set_cpu(cpu, &cpuid_topo->cluster_sibling); cpumask_set_cpu(cpuid, &cpu_topo->cluster_sibling); } =20 - cpumask_set_cpu(cpuid, &cpu_topo->core_sibling); - cpumask_set_cpu(cpu, &cpuid_topo->core_sibling); - if (cpuid_topo->core_id !=3D cpu_topo->core_id) continue; =20 --=20 2.36.1 From nobody Sun Jun 14 12:10:59 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 53F55C433EF for ; Wed, 18 May 2022 09:34:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234284AbiERJeP (ORCPT ); Wed, 18 May 2022 05:34:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234342AbiERJeB (ORCPT ); Wed, 18 May 2022 05:34:01 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7C364AF317 for ; Wed, 18 May 2022 02:33:58 -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 43B6B150C; Wed, 18 May 2022 02:33:58 -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 B684D3F66F; Wed, 18 May 2022 02:33:56 -0700 (PDT) From: Sudeep Holla To: Atish Patra , linux-kernel@vger.kernel.org Cc: Sudeep Holla , Atish Patra , Vincent Guittot , Morten Rasmussen , Dietmar Eggemann , Qing Wang , linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, Rob Herring Subject: [PATCH v2 3/8] arch_topology: Set cluster identifier in each core/thread from /cpu-map Date: Wed, 18 May 2022 10:33:20 +0100 Message-Id: <20220518093325.2070336-4-sudeep.holla@arm.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220518093325.2070336-1-sudeep.holla@arm.com> References: <20220518093325.2070336-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 7f5aa655c1f4..bdb6f2a17df0 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 Sun Jun 14 12:10:59 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 D1F9DC433EF for ; Wed, 18 May 2022 09:34:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234313AbiERJeR (ORCPT ); Wed, 18 May 2022 05:34:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234339AbiERJeC (ORCPT ); Wed, 18 May 2022 05:34:02 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2441EAFAF4 for ; Wed, 18 May 2022 02:34:00 -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 08C5615A1; Wed, 18 May 2022 02:34:00 -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 77A9F3F66F; Wed, 18 May 2022 02:33:58 -0700 (PDT) From: Sudeep Holla To: Atish Patra , linux-kernel@vger.kernel.org Cc: Sudeep Holla , Atish Patra , Vincent Guittot , Morten Rasmussen , Dietmar Eggemann , Qing Wang , linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, Rob Herring Subject: [PATCH v2 4/8] arch_topology: Add support for parsing sockets in /cpu-map Date: Wed, 18 May 2022 10:33:21 +0100 Message-Id: <20220518093325.2070336-5-sudeep.holla@arm.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220518093325.2070336-1-sudeep.holla@arm.com> References: <20220518093325.2070336-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 bdb6f2a17df0..77aab5fea46b 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 From nobody Sun Jun 14 12:10:59 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 BA19DC433F5 for ; Wed, 18 May 2022 09:34:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234425AbiERJeb (ORCPT ); Wed, 18 May 2022 05:34:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234364AbiERJeF (ORCPT ); Wed, 18 May 2022 05:34:05 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D76F8B0400 for ; Wed, 18 May 2022 02:34:02 -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 990A51063; Wed, 18 May 2022 02:34:02 -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 59D823F66F; Wed, 18 May 2022 02:34:00 -0700 (PDT) From: Sudeep Holla To: Atish Patra , linux-kernel@vger.kernel.org Cc: Sudeep Holla , Atish Patra , Vincent Guittot , Morten Rasmussen , Dietmar Eggemann , Qing Wang , linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, Rob Herring , Andy Shevchenko Subject: [PATCH v2 5/8] arch_topology: Check for non-negative value rather than -1 for IDs validity Date: Wed, 18 May 2022 10:33:22 +0100 Message-Id: <20220518093325.2070336-6-sudeep.holla@arm.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220518093325.2070336-1-sudeep.holla@arm.com> References: <20220518093325.2070336-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" Instead of just comparing the cpu topology IDs with -1 to check their validity, improve that by checking for a valid non-negative value. Suggested-by: Andy Shevchenko Signed-off-by: Sudeep Holla --- drivers/base/arch_topology.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index 77aab5fea46b..be99a78f5b31 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -662,7 +662,7 @@ static int __init parse_dt_topology(void) * only mark cores described in the DT as possible. */ for_each_possible_cpu(cpu) - if (cpu_topology[cpu].package_id =3D=3D -1) + if (cpu_topology[cpu].package_id < 0) ret =3D -EINVAL; =20 out_map: @@ -688,7 +688,7 @@ const struct cpumask *cpu_coregroup_mask(int cpu) /* not numa in package, lets use the package siblings */ core_mask =3D &cpu_topology[cpu].core_sibling; } - if (cpu_topology[cpu].llc_id !=3D -1) { + if (cpu_topology[cpu].llc_id >=3D 0) { if (cpumask_subset(&cpu_topology[cpu].llc_sibling, core_mask)) core_mask =3D &cpu_topology[cpu].llc_sibling; } @@ -719,7 +719,8 @@ void update_siblings_masks(unsigned int cpuid) for_each_online_cpu(cpu) { cpu_topo =3D &cpu_topology[cpu]; =20 - if (cpu_topo->llc_id !=3D -1 && cpuid_topo->llc_id =3D=3D cpu_topo->llc_= id) { + if (cpu_topo->llc_id >=3D 0 && + cpuid_topo->llc_id =3D=3D cpu_topo->llc_id) { cpumask_set_cpu(cpu, &cpuid_topo->llc_sibling); cpumask_set_cpu(cpuid, &cpu_topo->llc_sibling); } @@ -733,7 +734,7 @@ void update_siblings_masks(unsigned int cpuid) if (cpuid_topo->cluster_id !=3D cpu_topo->cluster_id) continue; =20 - if (cpuid_topo->cluster_id !=3D -1) { + if (cpuid_topo->cluster_id >=3D 0) { cpumask_set_cpu(cpu, &cpuid_topo->cluster_sibling); cpumask_set_cpu(cpuid, &cpu_topo->cluster_sibling); } --=20 2.36.1 From nobody Sun Jun 14 12:10:59 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 0EAE1C433EF for ; Wed, 18 May 2022 09:34:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234345AbiERJeW (ORCPT ); Wed, 18 May 2022 05:34:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234371AbiERJeI (ORCPT ); Wed, 18 May 2022 05:34:08 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EF51FB040F for ; Wed, 18 May 2022 02:34:04 -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 9E7EB1042; Wed, 18 May 2022 02:34:04 -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 DC5F33F66F; Wed, 18 May 2022 02:34:02 -0700 (PDT) From: Sudeep Holla To: Atish Patra , linux-kernel@vger.kernel.org Cc: Sudeep Holla , Atish Patra , Vincent Guittot , Morten Rasmussen , Dietmar Eggemann , Qing Wang , linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, Rob Herring Subject: [PATCH v2 6/8] arch_topology: Avoid parsing through all the CPUs once a outlier CPU is found Date: Wed, 18 May 2022 10:33:23 +0100 Message-Id: <20220518093325.2070336-7-sudeep.holla@arm.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220518093325.2070336-1-sudeep.holla@arm.com> References: <20220518093325.2070336-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" There is no point in looping through all the CPU's physical package identifier to check if it is valid or not once a CPU which is outside the topology(i.e. outlier CPU) is found. Let us just break out of the loop early in such case. Signed-off-by: Sudeep Holla --- drivers/base/arch_topology.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index be99a78f5b31..6d3346efe74b 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -662,8 +662,10 @@ static int __init parse_dt_topology(void) * only mark cores described in the DT as possible. */ for_each_possible_cpu(cpu) - if (cpu_topology[cpu].package_id < 0) + if (cpu_topology[cpu].package_id < 0) { ret =3D -EINVAL; + break; + } =20 out_map: of_node_put(map); --=20 2.36.1 From nobody Sun Jun 14 12:10:59 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 DAB95C433F5 for ; Wed, 18 May 2022 09:34:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234423AbiERJej (ORCPT ); Wed, 18 May 2022 05:34:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234357AbiERJeL (ORCPT ); Wed, 18 May 2022 05:34:11 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0AF5CB042C for ; Wed, 18 May 2022 02:34:06 -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 90D0C1063; Wed, 18 May 2022 02:34:06 -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 DDDBB3F66F; Wed, 18 May 2022 02:34:04 -0700 (PDT) From: Sudeep Holla To: Atish Patra , linux-kernel@vger.kernel.org Cc: Sudeep Holla , Atish Patra , Vincent Guittot , Morten Rasmussen , Dietmar Eggemann , Qing Wang , linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, Rob Herring Subject: [PATCH v2 7/8] of: base: add support to get the device node for the CPU's last level cache Date: Wed, 18 May 2022 10:33:24 +0100 Message-Id: <20220518093325.2070336-8-sudeep.holla@arm.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220518093325.2070336-1-sudeep.holla@arm.com> References: <20220518093325.2070336-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" It is useful to have helper function just to get the pointer to the device node of the last level cache for a given logical cpu. It can be used as unique firmware identifier for the last level cache. This is useful to obtain the cpumask/cpumap of all the CPUs sharing the last level cache using the device node pointer as unique identifier for the last level cache. Cc: Rob Herring Signed-off-by: Sudeep Holla --- drivers/of/base.c | 33 +++++++++++++++++++++++++-------- include/linux/of.h | 1 + 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index d4f98c8469ed..0b6a8c3f9a85 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -2072,17 +2072,17 @@ struct device_node *of_find_next_cache_node(const s= truct device_node *np) } =20 /** - * of_find_last_cache_level - Find the level at which the last cache is - * present for the given logical cpu + * of_find_last_level_cache_node - Find the device node at which the last + * cache is present for the given logical cpu * - * @cpu: cpu number(logical index) for which the last cache level is needed + * @cpu: cpu number(logical index) for which the last cache level's device + * node is needed * - * Return: The the level at which the last cache is present. It is exactly - * same as the total number of cache levels for the given logical cpu. + * Return: The device node corresponding to the last cache for the given + * logical cpu */ -int of_find_last_cache_level(unsigned int cpu) +struct device_node *of_find_last_level_cache_node(unsigned int cpu) { - u32 cache_level =3D 0; struct device_node *prev =3D NULL, *np =3D of_cpu_device_node_get(cpu); =20 while (np) { @@ -2091,7 +2091,24 @@ int of_find_last_cache_level(unsigned int cpu) np =3D of_find_next_cache_node(np); } =20 - of_property_read_u32(prev, "cache-level", &cache_level); + return prev; +} + +/** + * of_find_last_cache_level - Find the level at which the last cache is + * present for the given logical cpu + * + * @cpu: cpu number(logical index) for which the last cache level is needed + * + * Return: The level at which the last cache is present. It is exactly + * same as the total number of cache levels for the given logical cpu. + */ +int of_find_last_cache_level(unsigned int cpu) +{ + u32 cache_level =3D 0; + struct device_node *np =3D of_find_last_level_cache_node(cpu); + + of_property_read_u32(np, "cache-level", &cache_level); =20 return cache_level; } diff --git a/include/linux/of.h b/include/linux/of.h index 04971e85fbc9..ca0384cf08a3 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -297,6 +297,7 @@ extern struct device_node *of_get_child_by_name(const s= truct device_node *node, =20 /* cache lookup */ extern struct device_node *of_find_next_cache_node(const struct device_nod= e *); +extern struct device_node *of_find_last_level_cache_node(unsigned int cpu); extern int of_find_last_cache_level(unsigned int cpu); extern struct device_node *of_find_node_with_property( struct device_node *from, const char *prop_name); --=20 2.36.1 From nobody Sun Jun 14 12:10:59 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 2F4A9C433EF for ; Wed, 18 May 2022 09:34:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234473AbiERJen (ORCPT ); Wed, 18 May 2022 05:34:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234368AbiERJeQ (ORCPT ); Wed, 18 May 2022 05:34:16 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1D793AFB32 for ; Wed, 18 May 2022 02:34:08 -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 5F6731042; Wed, 18 May 2022 02:34:08 -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 C4DC83F66F; Wed, 18 May 2022 02:34:06 -0700 (PDT) From: Sudeep Holla To: Atish Patra , linux-kernel@vger.kernel.org Cc: Sudeep Holla , Atish Patra , Vincent Guittot , Morten Rasmussen , Dietmar Eggemann , Qing Wang , linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, Rob Herring Subject: [PATCH v2 8/8] arch_topology: Add support to build llc_sibling on DT platforms Date: Wed, 18 May 2022 10:33:25 +0100 Message-Id: <20220518093325.2070336-9-sudeep.holla@arm.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220518093325.2070336-1-sudeep.holla@arm.com> References: <20220518093325.2070336-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" ACPI PPTT provides cache identifiers and especially the last level cache identifier is used in obtaining last level cache siblings amongst CPUs. While we have the cpu map representing all the CPUs sharing last level cache in the cacheinfo driver, it is populated quite late in the boot while the information is needed to build scheduler domains quite early. On DT platforms we can use the pointer to the last level cache as the firmware identifier for the last level cache and build the cpumap sharing the last level cache based on the same. Cc: Rob Herring Signed-off-by: Sudeep Holla --- drivers/base/arch_topology.c | 18 ++++++++++++++---- include/linux/arch_topology.h | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index 6d3346efe74b..bc57f0f1862e 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -661,11 +661,14 @@ static int __init parse_dt_topology(void) * Check that all cores are in the topology; the SMP code will * only mark cores described in the DT as possible. */ - for_each_possible_cpu(cpu) + for_each_possible_cpu(cpu) { if (cpu_topology[cpu].package_id < 0) { ret =3D -EINVAL; break; } + cpu_topology[cpu].llc_fw_node =3D + of_find_last_level_cache_node(cpu); + } =20 out_map: of_node_put(map); @@ -681,6 +684,12 @@ static int __init parse_dt_topology(void) struct cpu_topology cpu_topology[NR_CPUS]; EXPORT_SYMBOL_GPL(cpu_topology); =20 +#define IS_VALID_LLC_ID(x) \ + ((x)->llc_id >=3D 0 || (x)->llc_fw_node) +#define IS_MATCH_LLC_ID(x, y) \ + (((x)->llc_id >=3D 0 && (x)->llc_id =3D=3D (y)->llc_id) || \ + ((x)->llc_fw_node && (x)->llc_fw_node =3D=3D (y)->llc_fw_node)) + const struct cpumask *cpu_coregroup_mask(int cpu) { const cpumask_t *core_mask =3D cpumask_of_node(cpu_to_node(cpu)); @@ -690,7 +699,8 @@ const struct cpumask *cpu_coregroup_mask(int cpu) /* not numa in package, lets use the package siblings */ core_mask =3D &cpu_topology[cpu].core_sibling; } - if (cpu_topology[cpu].llc_id >=3D 0) { + + if (IS_VALID_LLC_ID(&cpu_topology[cpu])) { if (cpumask_subset(&cpu_topology[cpu].llc_sibling, core_mask)) core_mask =3D &cpu_topology[cpu].llc_sibling; } @@ -721,8 +731,7 @@ void update_siblings_masks(unsigned int cpuid) for_each_online_cpu(cpu) { cpu_topo =3D &cpu_topology[cpu]; =20 - if (cpu_topo->llc_id >=3D 0 && - cpuid_topo->llc_id =3D=3D cpu_topo->llc_id) { + if (IS_MATCH_LLC_ID(cpu_topo, cpuid_topo)) { cpumask_set_cpu(cpu, &cpuid_topo->llc_sibling); cpumask_set_cpu(cpuid, &cpu_topo->llc_sibling); } @@ -777,6 +786,7 @@ void __init reset_cpu_topology(void) cpu_topo->cluster_id =3D -1; cpu_topo->package_id =3D -1; cpu_topo->llc_id =3D -1; + cpu_topo->llc_fw_node =3D NULL; =20 clear_cpu_topology(cpu); } diff --git a/include/linux/arch_topology.h b/include/linux/arch_topology.h index 58cbe18d825c..d8a36b0e27c9 100644 --- a/include/linux/arch_topology.h +++ b/include/linux/arch_topology.h @@ -69,6 +69,7 @@ struct cpu_topology { int cluster_id; int package_id; int llc_id; + void *llc_fw_node; cpumask_t thread_sibling; cpumask_t core_sibling; cpumask_t cluster_sibling; --=20 2.36.1