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: 12853430 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 DC7A7C433F5 for ; Wed, 18 May 2022 09:34:19 +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=jmLLV2yHlRDqYEUJlFP6rPvIQX2KToV2JKUzUzLah4Q=; b=CwCQROslIrR5Fl mdcVVQ+vg6vjCyklTB0BR9jgPAH2dTsSrv7lbWPP5vLMHn76g+L/yZH6LA4Bhj6l9HzwGLONTvvY2 17nDd35WJIlr53KXXRx8ODb7jVZgk2sM5u4VRCGOo/4gDT+6P5sQnNVVDra03w9m/OHLShy1fLaYz kuYK6v2Tdip4m+Kpov7B1+x2nyoX9n5UK0wCWri++csvTa1NTD+31CE2wk8hdhFdJtPu4aw2Z41qB FzaS3TnNG4yhCleV+Pry2/2iCmoQscg0HiyClSSQAqSN/OBhJqV7u0jKw8e7jAOqRxVXEyyniEKwo U7Bj4A658RXq+/7ZjdeA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrG4I-0012eo-Dg; Wed, 18 May 2022 09:34: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 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-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=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: 12853432 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 80D88C433F5 for ; Wed, 18 May 2022 09:34:45 +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=ah9w1uda4xan8WjY72gKSFPstMJoBDYc2IusHA/h3xA=; b=oRveRbK3Eu4+/Z aPa7S/wrZlizjQtmALuTt2Ozk5SKEtBcQaObjI0wE0vab3JY52mY9xn3AkMfs8oNf4gc3L89g8Hrk H7RK3FkSlpfX0gkMdpbtd+goC83gbFYnG+Diptpz/KY+d7tynzPn2kyWgxkl0ZeiyZYOrlI6NIQy5 G7fQh/6DjNaI5oqdDrWIcU1dcn7+7jCfO1xKMKCpDReBM34b3iKlEavTZBB1WHXUTf/MhDYnvq0dU eHbNa4tQFndkQv9+RPuRKdTzW2hgUAuiZFeSJbmtHM2cGl4smtMTiBMm5fP/dNy4e9o1KIudHxyFY riFwtiKlvViNk8eLQyRA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrG4i-0012zd-J9; Wed, 18 May 2022 09:34:36 +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-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=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: 12853433 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 1FB07C433F5 for ; Wed, 18 May 2022 09:35:20 +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=Y6ykKf4sw8WkNlCJIk4vrr9kT6KGPzpTKjIj49LPmO8=; b=f1q6Mi7CtG65NN ak3bHXAnUyRZI0T7oOoRulrwqc9rclSnAwtVev2h5Ckr8SCH4reYaD4KetQQDnc9GWWhPHh4LLQFo 6Bpo9LfmGjoZ367G34wdMTFJWYXva8uF8p+5gIsE2TCdGWK0L+mGbDea62QkRei6dPiutdYOmcuVQ DCixL3fEF/FN90Gemq5Zq21bJDMGWWelmOARTyl21SzKczYHNbv0pZPZAPtx/OHJuDOCRXaLidFbZ DdJDWxhbAyuoiHwatVP/4QlAW99/y5eGagCCcSyjGOdjdemle4HY1tpF6lnnrZq/YQ3JTXjhnSbjV 8HCwgnAKPiyS6l3JNUUQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrG5H-0013Rv-MO; Wed, 18 May 2022 09:35:11 +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-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=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: 12853434 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 6BBC2C433F5 for ; Wed, 18 May 2022 09:35:35 +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=RdyXrVgT1/A9IQvv2wIQdFw8uQ0PGoAPNN/+/ijHfXs=; b=i6+iqnvq+f6bbl GCrMHaQ5FhmRfzb5zI1izPyncntukmrtbeFe/i42GpcVYN+LLy+AkR4SrpTxKkmcbBQv5FLVaYlYd Mrt8hrvUHd00tPZM4QjkSfWwPE8mwst+/tKJMqQkHHfRQUE/VV4CeLqJxe0gEJrDkBAJPwcpp9FF6 +FDhG9iq6HRcDqzOWDu0f2aCSuO0IK1nWjfgyFm5VpRPdYo7qwvUvrGHOQemaaAfti417Wo93KadY SYwrJILp174L65IjOL8Vi8P9A/LAZTDgWlTzxBFaSo/0CJbx6QTgwP9vB4fC2wk+MO0KT/4Jk25oL bbJvXFa1QipyumOZZXmA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrG5X-0013jp-UC; Wed, 18 May 2022 09:35:27 +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-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=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: 12853435 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 5F2CBC433EF for ; Wed, 18 May 2022 09:35:59 +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=JUhqRTGhQ7NsbG1D9Z5A2XPchrH4umYnKcb7mtfiMRk=; b=NZEO3KwO8qRXVq oG/q6+9t6jVDFk42uH64e+mNTdChW6henfb5A2GcQDsWuU6eRALdQa2EG93NQzmcKybnqvoPO0vDn rtC4aNUGeJLaxc5IDqkhT/KoMrgvdY0l6TzcdZzARlGDz5nY0LhNofr5n94sFELHiI327Bls9Bun5 K9cynxvyJDRw15n81CKVvZdntaMktkU9wxx3uWSrNjKFKloiC89Od89nSD2kaX2whnLbLFI4JdhRD yXkNw7Cgxz6e89Eofqj4oirpyZA4vOHSwKkZH9hP0WwiBxBDIkporAxqEl+qsGQ+fgpSCb6HDYkZJ wpl7kLAevBGRz+15ZaeQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrG5u-001404-W9; Wed, 18 May 2022 09:35:51 +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-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=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: 12853436 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 3D139C433F5 for ; Wed, 18 May 2022 09:36:16 +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=UbU84MJ+N9rH92iov65PAqegpYKy5m4SmZxye5Jgg3g=; b=w7tLRmMnLebAZI qhAASVNwnfkT3kbi7wWA3oaOwFg1Q1xWkc9drBWUoRh4u0+FleEoTIoOf25Em4J8EIdPsy6TH5iB4 6zwV/+H6YGbz/yn5Is2H5Men+yFkU4yRCn3PSWI0ua0DeNGroL5HJJhECE5US2HixF9jbzlS2opll E4h9CpCIxNn+TRMQTUulEXhnZ6WGcPsqQNgxFyJtZKp8gAHMSsfR/PiYFpsUaltpfhqRVew+CzHiK EYkRMd70WyQqKUPjXOYyrG5CwA3vIMxytiQv5pk9eTRFIOfGIR+ccj9fXcLvEgNaRpSNtxbJ5liCL ex0FCWbIx1/AbjoXM02Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrG6C-0014Bb-Fz; Wed, 18 May 2022 09:36:08 +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-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=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: 12853437 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 64DEEC433F5 for ; Wed, 18 May 2022 09:37:00 +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=iTaviAAm/pWTsUIXWhPVDAyUFg93HlUOVFbBp2jSasM=; b=i3zpDqvPgIkLar KApZ7RIvJGeHsl2r2+Os6BLEom4ZSTWI2tcUlbIgVpbOXs4mGAk79ur4GbnrJUBoiVyIZ2+SSS7GR YzsD71mQZqqNZAsmviz8kxqCIA80QvzGLh7/E4kWFtA9OtYhceds5y17NhatC0n1ErF7lmvPBOy+A EwMK0nGYN73/i9RaGpI/1ilWuyvr2Uc11Tz3XyRFVOLh1kQOKh6ZrJCXSG0zqJoqZ3t9WA+4gsQmB gxfY2KMZ3lhVbYnARjliWksCrjxtG1FVmvYLpsdGbszUE3+j7hirpako0OabndKKqV1vI4bi/uCEk 8LjF0lSTopq/4kY+TksQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrG6t-0014cm-3S; Wed, 18 May 2022 09:36:51 +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-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=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: 12853448 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 98B22C433F5 for ; Wed, 18 May 2022 09:37:56 +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=ryn+XmoPZA4BfLz7h3FoLRpvlAAvR/wTz0P+O/IpvZA=; b=Nw/zlmbTpnyrzE X3xpMBJlTpFxHdFs3vn1YjxvZT7Vc9RzK0BoZxBSQVIwzB+wtKMc/bgjzpTwhixVazfwxnXkdf67u zcuMMno6WmiZT6jVt4OFbOLoEMyi1S14jHzTjpRCAQblxjFxWlLknL/nnctkzW6QV7X/J5XGG0arV GA/UiEwLo2ScAIalm+ep5Bcgtv82aQLF/GQqcPpaKDbCshjfLZRTnAHHhJ1S6jNnA9Uhvj5e+/QPM CxJmzi8NZbx3VHzoTnX2d6boWZHlR77Ji+tO1I2T7cU1ELN+0ueOYnrwYmKL8FesWUbDzEZV20Zgm 5Ap4BMSDxosABnnyoXBA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrG7o-0015CW-9f; Wed, 18 May 2022 09:37:48 +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-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=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;