From patchwork Wed May 18 09:33:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 12853423 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BE0BCC433F5 for ; Wed, 18 May 2022 09:35:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=04RnM0vgRlrA4ZyfgSeVvlAJbmvXiZ/UR26vZYzKUbY=; b=4kKIWsV2LFOVIr WUdvUpe0LenSPOAqSSqRdrf+MR6InBBTQRTPfEvGZH6VgBS/ymHAptkB8od7QpNSIZ55ktjqN1jdY lNqbt6mNZyvWm5+Q/iB5Inyfb7/co1CgaFxegSUnYI8UiSE/+zg/EU5i+0AcNVGOyPnO94LEuUFw/ e6Ma7QtmzsHOqZ0GM7nAvJ3Zmzg6kKCmkyRaYwXyB1iG3GGY4ILAjnx54FQNgQTpjn1dHg8lclaxw mm38F+qB1BsCDg3X33iH7buE3id1gBx4vP6QTGFLG7eOwHLjeJYpVacYaoVYLMjZF6B4fx/IXnico logtDUaTXP3xWSM94cmA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrG49-0012aN-TA; Wed, 18 May 2022 09:34:01 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrG46-0012Xe-Kz; Wed, 18 May 2022 09:34:00 +0000 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220518_023358_768630_E0E04CA2 X-CRM114-Status: GOOD ( 12.06 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 *cluster, int depth) bool leaf = true; bool has_cores = false; struct device_node *c; - static int package_id __initdata; int core_id = 0; int i, ret; @@ -582,7 +581,7 @@ static int __init parse_cluster(struct device_node *cluster, int depth) } if (leaf) { - ret = parse_core(c, package_id, core_id++); + ret = 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 *cluster, int depth) if (leaf && !has_cores) pr_warn("%pOF: empty cluster\n", cluster); - if (leaf) - package_id++; - return 0; } From patchwork Wed May 18 09:33:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 12853425 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EC913C433F5 for ; Wed, 18 May 2022 09:35:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=HX3/7iFyIa7lnef1BBwnIkKUr0+Jo1tBxL6P6qyJwTw=; b=4AcMuST46VQmOC X01UtYNlx4FTv+KtqJ1hFR/ipi7CrRNt2PT6HgiT4GHSYpy261OfSVcWm0fTBEERB+yrBTKRLtw4X uXhiCpeqQT3rgYYRMgSdwdGh+JmFrZKmrxg2mAyDzmcTvXE3k2PyC+iLpF6Q5z7tvx8Qww1B1buJ2 zb1OGbsViHALyUA7osq2QWIZ9OVanOwhYsSYjtfslPiSwwEpTqKUhuVsfWLkdJtzA2O1Cj6iT27Kw f01lL2/53SiwaYpelCAe6estxpFgeMX6/AL8ZzNPGlbbqGotexiaGc2ZsPAXvNVBXcgJGToL5Y2Ca jAU+2iOajkkh1jXrX0Bg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrG4W-0012lc-Pm; Wed, 18 May 2022 09:34:24 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrG47-0012Y7-BN; Wed, 18 May 2022 09:34:01 +0000 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220518_023359_471193_CF2C171B X-CRM114-Status: GOOD ( 12.19 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 != cpu_topo->package_id) continue; - if (cpuid_topo->cluster_id == cpu_topo->cluster_id && - cpuid_topo->cluster_id != -1) { + cpumask_set_cpu(cpuid, &cpu_topo->core_sibling); + cpumask_set_cpu(cpu, &cpuid_topo->core_sibling); + + if (cpuid_topo->cluster_id != cpu_topo->cluster_id) + continue; + + if (cpuid_topo->cluster_id != -1) { cpumask_set_cpu(cpu, &cpuid_topo->cluster_sibling); cpumask_set_cpu(cpuid, &cpu_topo->cluster_sibling); } - cpumask_set_cpu(cpuid, &cpu_topo->core_sibling); - cpumask_set_cpu(cpu, &cpuid_topo->core_sibling); - if (cpuid_topo->core_id != cpu_topo->core_id) continue; From patchwork Wed May 18 09:33:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 12853426 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AF9E7C433EF for ; Wed, 18 May 2022 09:35:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=xTVm7F8J4pvefDipKEZlulNRvCttVDPdeziTIA1Dxj8=; b=T1BxPZdNDP1vbX alnjfAPwTr+FNNSxRUogysGG0d4fbfqVIgnRTMNbd1pK1mIO8E7yBfPggYaLhFO4PUaEZREv8HfGV SFLdvcc9tNvLAkeCyRiB/s0oV+R/KQMp7xAvAiQgEW1XKfmJ1lE7HAg7TAzWeIR14TKj9B+l3Lsrx Z4z0eZVqbxjAEsd5iK2BPmHnRbuKdNJOPe5Lwb9gZuu5sHDU7GG1joOTXEEOY2s8jvJ+xJ7axjdv2 qNfIT0jg0rNglNOKAIqc+p72RUESc+jkRu2IUCYHGhz1D8qqc9ZLheEsFIIobc1GdRgSXhq45b4II UcCmGV6qvV/Lu2kN5xlA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrG4p-00132Y-B8; Wed, 18 May 2022 09:34:44 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrG48-0012ZX-5H; Wed, 18 May 2022 09:34:01 +0000 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220518_023400_328324_F578EE2C X-CRM114-Status: GOOD ( 12.39 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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) } 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 = true; @@ -507,6 +507,7 @@ static int __init parse_core(struct device_node *core, int package_id, cpu = get_cpu_for_node(t); if (cpu >= 0) { cpu_topology[cpu].package_id = package_id; + cpu_topology[cpu].cluster_id = cluster_id; cpu_topology[cpu].core_id = core_id; cpu_topology[cpu].thread_id = i; } else if (cpu != -ENODEV) { @@ -528,6 +529,7 @@ static int __init parse_core(struct device_node *core, int package_id, } cpu_topology[cpu].package_id = package_id; + cpu_topology[cpu].cluster_id = cluster_id; cpu_topology[cpu].core_id = core_id; } else if (leaf && cpu != -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; } -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 = true; @@ -557,7 +560,7 @@ static int __init parse_cluster(struct device_node *cluster, int depth) c = of_get_child_by_name(cluster, name); if (c) { leaf = false; - ret = parse_cluster(c, depth + 1); + ret = parse_cluster(c, i, depth + 1); of_node_put(c); if (ret != 0) return ret; @@ -581,7 +584,7 @@ static int __init parse_cluster(struct device_node *cluster, int depth) } if (leaf) { - ret = parse_core(c, 0, core_id++); + ret = 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; - ret = parse_cluster(map, 0); + ret = parse_cluster(map, -1, 0); if (ret != 0) goto out_map; From patchwork Wed May 18 09:33:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 12853427 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 76B03C433EF for ; Wed, 18 May 2022 09:36:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Ks6+92TBAzt/x0jT8foxWtqClHyj5swBR1SS9YurPV4=; b=4pzAzsf5bURYdg H6S+47eKslmUQ+iKZUt3XB3T/weTQvnZeBcWWWktzxOkXhtq5qk69ZiX0GagGI+2lBfRVydwLHpuD 4zmfDpbrF5IKBehUKjNHsxHTVRazdyIJ5B/i8eJszs0Ok56yeIeBRbPGOe2LKp3uuG1eqfiKR5zdn nrDot+W0daBTfaNeEI6rvC/vV8laiiZHupfayxHbkJ2vqAWLltAAK6KJZdKT4gk30dTfJbtJRYl4V ZwAKOAx6vzWJg3dYRpz0tFWf+wazujK0hcFQuhUgkhXEkL5IvO0kBItWFIG5AefdN58C6G6ETI2zE NhC9mpzj8zeM1VzEYp5g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrG5K-0013UK-Ri; Wed, 18 May 2022 09:35:14 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrG48-0012a5-R1; Wed, 18 May 2022 09:34:02 +0000 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220518_023400_955436_ECEEF20C X-CRM114-Status: GOOD ( 16.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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; } -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_id, + int cluster_id, int depth) { char name[20]; bool leaf = true; @@ -560,7 +560,7 @@ parse_cluster(struct device_node *cluster, int cluster_id, int depth) c = of_get_child_by_name(cluster, name); if (c) { leaf = false; - ret = parse_cluster(c, i, depth + 1); + ret = parse_cluster(c, package_id, i, depth + 1); of_node_put(c); if (ret != 0) return ret; @@ -584,7 +584,8 @@ parse_cluster(struct device_node *cluster, int cluster_id, int depth) } if (leaf) { - ret = parse_core(c, 0, cluster_id, core_id++); + ret = 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; } +static int __init parse_socket(struct device_node *socket) +{ + char name[20]; + struct device_node *c; + bool has_socket = false; + int package_id = 0, ret; + + do { + snprintf(name, sizeof(name), "socket%d", package_id); + c = of_get_child_by_name(socket, name); + if (c) { + has_socket = true; + ret = parse_cluster(c, package_id, -1, 0); + of_node_put(c); + if (ret != 0) + return ret; + } + package_id++; + } while (c); + + if (!has_socket) + ret = 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; - ret = parse_cluster(map, -1, 0); + ret = parse_socket(map); if (ret != 0) goto out_map; From patchwork Wed May 18 09:33:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 12853428 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 855D2C433EF for ; Wed, 18 May 2022 09:36:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=T/qT/DAgAsjL2ulu/Zo9j4e3sI/NBzVem988lO/+4MI=; b=djowCBouFuAkAW aeUDGv7vnsq4T5pnLyRqYr3qA4HEiPCTUV7H0xr7bRIAtWdyjJ9Z5XBECQFLqTBmVtcK42J6ZM0cl dR8+5d+WWiJPz2ZloNhwXmwg4WQxlDBLIaJFb7cWWusOq5I2fJAqNAwxdnzH8JZQND8IJ00MSZZRI ojrqVPWpsLrQhpJOO8ZlG5U7lBzjbl55qB1jzz9k1boXoma82gzm0HG0tIHiUCwTZ53SdVEvObKf6 CKfGKEnX+I1ueWapyIAeBxSh4LP+m9FWi8OF2jLmuK6Wgj+6ADUV65F2y7igan62FZMOHqBQnRrop hJjHBRUNaeO5fR0Q683A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrG5b-0013mm-8r; Wed, 18 May 2022 09:35:31 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrG4B-0012aw-AM; Wed, 18 May 2022 09:34:04 +0000 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220518_023403_468756_550B468F X-CRM114-Status: GOOD ( 11.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 == -1) + if (cpu_topology[cpu].package_id < 0) ret = -EINVAL; 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 = &cpu_topology[cpu].core_sibling; } - if (cpu_topology[cpu].llc_id != -1) { + if (cpu_topology[cpu].llc_id >= 0) { if (cpumask_subset(&cpu_topology[cpu].llc_sibling, core_mask)) core_mask = &cpu_topology[cpu].llc_sibling; } @@ -719,7 +719,8 @@ void update_siblings_masks(unsigned int cpuid) for_each_online_cpu(cpu) { cpu_topo = &cpu_topology[cpu]; - if (cpu_topo->llc_id != -1 && cpuid_topo->llc_id == cpu_topo->llc_id) { + if (cpu_topo->llc_id >= 0 && + cpuid_topo->llc_id == 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 != cpu_topo->cluster_id) continue; - if (cpuid_topo->cluster_id != -1) { + if (cpuid_topo->cluster_id >= 0) { cpumask_set_cpu(cpu, &cpuid_topo->cluster_sibling); cpumask_set_cpu(cpuid, &cpu_topo->cluster_sibling); } From patchwork Wed May 18 09:33:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 12853429 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AF0F4C433F5 for ; Wed, 18 May 2022 09:37:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=QaKu0DsegPZlMnXe5NloyxRcYR8luHPZrWslCc/gkjw=; b=HYVNOkRF3ZsXSD aGTtxKv8JvB+FW5XCGnyDjsSqgn2S5+QF3pGnnFUbjXHEfC99Bjl4I7MHibT1ZPCpplR8UWYnswI0 6PuXRYn5cMx4nG0pxlU9ZbPeEKZXmbZr4h8V9rOnyjk0MCLnohd5xinDzPcRPW+/ZgWVfgxL0tTdl NXMkOaNkJSrZWmpVeXb33/+SGFOvGCmkxP8DB1KgZwoPFai7pPbrjjEcd2+46bwBil6ly8txI2IMV l+agT9TkX5+ST3pOFuzD4ssaP1MmtssWO2yb1EWSQ49YZvAWqH/h914LZqKpL3W2ajhyLhhWT8EdK tbkm6qSHO9JfOfe1sT/Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrG5y-00141o-9t; Wed, 18 May 2022 09:35:54 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrG4D-0012bv-7I; Wed, 18 May 2022 09:34:06 +0000 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220518_023405_350765_57D8992B X-CRM114-Status: GOOD ( 11.49 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 = -EINVAL; + break; + } out_map: of_node_put(map); From patchwork Wed May 18 09:33:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 12853440 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A121EC433F5 for ; Wed, 18 May 2022 09:37:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=tELVMhwZaJwa/KeG8fd7uykVtRX0opn41Yuh9DW2h+0=; b=ogW10Gzn+Il1AH zdcgBgRzUWzdJ3C2RpMCvm9eD+XoAYHX13Le2Cr1wAfP160+WG3fXYvlZL7jgXyjCG65nezNu9Pnl PzrjYjNTQWF94j8QG7CzMpInqCSoBxRqZHVXHqBYEZaCspgWGK1fPVNOkhjn0xeHkopW044R5ZnwR VxwlXJMWTvnGg9DMZeM1A2DkS3LNpgIOiiA0YD2m9n8lG9qP94C6tmjmnSzwYNCQYuuHcHTAAGFA6 CivuiosmfZbvtN9nPcCNdirpqIVy4SdZMPNG3YTJMXzyOeBhOoD+84O4EGaZT26R913P6gOTd++PY ev4FkjdYZmGHNBdzq9Nw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrG6E-0014Ci-N2; Wed, 18 May 2022 09:36:10 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrG4F-0012dG-CN; Wed, 18 May 2022 09:34:09 +0000 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220518_023407_555956_D588C6E9 X-CRM114-Status: GOOD ( 16.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 struct device_node *np) } /** - * 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 = 0; struct device_node *prev = NULL, *np = of_cpu_device_node_get(cpu); while (np) { @@ -2091,7 +2091,24 @@ int of_find_last_cache_level(unsigned int cpu) np = of_find_next_cache_node(np); } - 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 = 0; + struct device_node *np = of_find_last_level_cache_node(cpu); + + of_property_read_u32(np, "cache-level", &cache_level); 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 struct device_node *node, /* cache lookup */ extern struct device_node *of_find_next_cache_node(const struct device_node *); +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); From patchwork Wed May 18 09:33:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 12853441 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E091FC433EF for ; Wed, 18 May 2022 09:38:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=W680QIYxfJiZ5r7qOSjhERIHeULEnPVGG1lH0mDlDq4=; b=m9ZvxewmR1P9Qy fo44l5x6O0OobZvirTqubtiCDiNbzHee+E/tRE8aNItvZ9Q5g9W4h24p1uq6XRjPTWO335ELiVGnC QNMGuJp1AanDDxVfYE0VnoUu5zbiZJf9aMR8iKgdOSDgLMSZb3GWW0lm1LhECrsBX2Zc+YVygon38 TGWhqvCcS77FlDFPXyjvbiwybelNGZJlve/zV9MHPiuMaMEJlia8g5bQb0pvKUZzas2hoRd8js89v 3new3HWywI2iMMjdV1RSOXW4DWfN3nFrChuMDNFnweMw2B9ff03tPcciqrXj2CvMgLZau1JPWQhFY WdAQiB7uhGLJP6lCfYSw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrG75-0014hN-Gi; Wed, 18 May 2022 09:37:03 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrG4H-0012eD-54; Wed, 18 May 2022 09:34:10 +0000 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220518_023409_316153_E16F45E2 X-CRM114-Status: GOOD ( 19.74 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 = -EINVAL; break; } + cpu_topology[cpu].llc_fw_node = + of_find_last_level_cache_node(cpu); + } 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); +#define IS_VALID_LLC_ID(x) \ + ((x)->llc_id >= 0 || (x)->llc_fw_node) +#define IS_MATCH_LLC_ID(x, y) \ + (((x)->llc_id >= 0 && (x)->llc_id == (y)->llc_id) || \ + ((x)->llc_fw_node && (x)->llc_fw_node == (y)->llc_fw_node)) + const struct cpumask *cpu_coregroup_mask(int cpu) { const cpumask_t *core_mask = 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 = &cpu_topology[cpu].core_sibling; } - if (cpu_topology[cpu].llc_id >= 0) { + + if (IS_VALID_LLC_ID(&cpu_topology[cpu])) { if (cpumask_subset(&cpu_topology[cpu].llc_sibling, core_mask)) core_mask = &cpu_topology[cpu].llc_sibling; } @@ -721,8 +731,7 @@ void update_siblings_masks(unsigned int cpuid) for_each_online_cpu(cpu) { cpu_topo = &cpu_topology[cpu]; - if (cpu_topo->llc_id >= 0 && - cpuid_topo->llc_id == 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 = -1; cpu_topo->package_id = -1; cpu_topo->llc_id = -1; + cpu_topo->llc_fw_node = NULL; 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;