From patchwork Mon Mar 24 15:36:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Pieralisi X-Patchwork-Id: 26933 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f71.google.com (mail-yh0-f71.google.com [209.85.213.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id EF7E720062 for ; Mon, 24 Mar 2014 15:36:18 +0000 (UTC) Received: by mail-yh0-f71.google.com with SMTP id a41sf15372437yho.2 for ; Mon, 24 Mar 2014 08:36:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:date:from:to:subject:message-id :references:mime-version:in-reply-to:user-agent:cc:precedence :list-id:list-unsubscribe:list-archive:list-post:list-help :list-subscribe:sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list:content-type :content-disposition; bh=p34ZMAT4RkRzwy86gNNh8Gy/V8/lWBcp013xjCbEo1E=; b=iIfkAw3Vzxhpi1YV651UUs+0Sepx3IprVl+Hr12wwWAFeLgPlgPP5USPxhY+wzfhVM XnL9Y4HsL2+211ONdw+1+Wjky2rxBY6auQceJUikklXfuC+pcYIlwL22/e6k4n08xQ8+ KhE2o30vK1vRlUnfhu5dOQ2dfNVLrJibZhPmYqzL/wvC2BVrOdiNQ6S5R8R2QhpwEDh2 a2N8ola4vU/dz7Ao+MNOXapnX1KRQsq9wgb0An9A/+lmQNLx3sw9B+GFDlbzR1INMdb2 aqOTLSH3Nj57jJZAdreEIsJVZHhQdggT2pkt0kSmJzoyhsD7AmG3NR5/o/pleIKGkzc/ d0ew== X-Gm-Message-State: ALoCoQkBjbHfb2TYZrOoIOSRTPe67Y1atryXyOedVn83si3RCQRFRy22TeaYFfTQnfsT+ly6Catx X-Received: by 10.58.136.35 with SMTP id px3mr17248022veb.31.1395675378701; Mon, 24 Mar 2014 08:36:18 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.96.200 with SMTP id k66ls1696610qge.85.gmail; Mon, 24 Mar 2014 08:36:18 -0700 (PDT) X-Received: by 10.220.106.84 with SMTP id w20mr51154649vco.18.1395675378557; Mon, 24 Mar 2014 08:36:18 -0700 (PDT) Received: from mail-ve0-f176.google.com (mail-ve0-f176.google.com [209.85.128.176]) by mx.google.com with ESMTPS id y10si3106829vei.150.2014.03.24.08.36.18 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 24 Mar 2014 08:36:18 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.176 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.176; Received: by mail-ve0-f176.google.com with SMTP id cz12so5721978veb.7 for ; Mon, 24 Mar 2014 08:36:18 -0700 (PDT) X-Received: by 10.221.40.10 with SMTP id to10mr2118362vcb.22.1395675378454; Mon, 24 Mar 2014 08:36:18 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.78.9 with SMTP id i9csp231823vck; Mon, 24 Mar 2014 08:36:17 -0700 (PDT) X-Received: by 10.180.12.14 with SMTP id u14mr17067326wib.0.1395675375750; Mon, 24 Mar 2014 08:36:15 -0700 (PDT) Received: from casper.infradead.org (casper.infradead.org. [2001:770:15f::2]) by mx.google.com with ESMTPS id k5si9314519wiw.1.2014.03.24.08.36.15 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Mar 2014 08:36:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:770:15f::2 as permitted sender) client-ip=2001:770:15f::2; Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WS6uS-000680-AX; Mon, 24 Mar 2014 15:35:32 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WS6uD-0003Gp-6f; Mon, 24 Mar 2014 15:35:17 +0000 Received: from service87.mimecast.com ([91.220.42.44]) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WS6u4-0003DA-6H for linux-arm-kernel@lists.infradead.org; Mon, 24 Mar 2014 15:35:10 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.21]) by service87.mimecast.com; Mon, 24 Mar 2014 15:34:42 +0000 Received: from red-moon ([10.1.255.212]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 24 Mar 2014 15:34:55 +0000 Date: Mon, 24 Mar 2014 15:36:11 +0000 From: Lorenzo Pieralisi To: Mark Brown Subject: Re: [PATCH 2/4] arm64: topology: Add support for topology DT bindings Message-ID: <20140324153611.GA16245@red-moon> References: <1395422881-10029-1-git-send-email-broonie@kernel.org> <1395422881-10029-2-git-send-email-broonie@kernel.org> MIME-Version: 1.0 In-Reply-To: <1395422881-10029-2-git-send-email-broonie@kernel.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-OriginalArrivalTime: 24 Mar 2014 15:34:55.0281 (UTC) FILETIME=[9B36DA10:01CF4776] X-MC-Unique: 114032415344200201 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140324_113508_613004_EEC13B96 X-CRM114-Status: GOOD ( 31.93 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [91.220.42.44 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Mark Rutland , "linaro-kernel@lists.linaro.org" , Mark Brown , Catalin Marinas , Will Deacon , "linux-arm-kernel@lists.infradead.org" X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lorenzo.pieralisi@arm.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.176 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Content-Disposition: inline Hi Mark, On Fri, Mar 21, 2014 at 05:27:59PM +0000, Mark Brown wrote: > From: Mark Brown > > Add support for parsing the explicit topology bindings to discover the > topology of the system. > > Since it is not currently clear how to map multi-level clusters for the > scheduler all leaf clusters are presented to the scheduler at the same > level. This should be enough to provide good support for current systems. > > Signed-off-by: Mark Brown Please apply the patches attached, that fix some stale comments and add of_node_put in paths that could otherwise be broken by return statements. Patch "arm64: kernel: topology: removed stale comment" applies to patch 1 of this series. Patch "arm64: kernel: topology updates" applies to patch 2 of this series. Both should be squashed into your original patches. Please have a final look and test them, they work for me. Having said that, on the updated patch 1 and 2 of this series: Reviewed-by: Lorenzo Pieralisi > --- > > - Discard the DT data if any CPUs are omitted from the topology. > - Call of_node_put() where required. > > arch/arm64/kernel/topology.c | 192 +++++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 186 insertions(+), 6 deletions(-) > > diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c > index ff662b23af5f..d0cb687fb7f5 100644 > --- a/arch/arm64/kernel/topology.c > +++ b/arch/arm64/kernel/topology.c > @@ -17,10 +17,183 @@ > #include > #include > #include > +#include > #include > > #include > > +static int __init get_cpu_for_node(struct device_node *node) > +{ > + struct device_node *cpu_node; > + int cpu; > + > + cpu_node = of_parse_phandle(node, "cpu", 0); > + if (!cpu_node) > + return -1; > + > + for_each_possible_cpu(cpu) { > + if (of_get_cpu_node(cpu, NULL) == cpu_node) > + return cpu; > + } > + > + pr_crit("Unable to find CPU node for %s\n", cpu_node->full_name); > + return -1; > +} > + > +static int __init parse_core(struct device_node *core, int cluster_id, > + int core_id) > +{ > + char name[10]; > + bool leaf = true; > + int i = 0; > + int cpu; > + struct device_node *t; > + > + do { > + snprintf(name, sizeof(name), "thread%d", i); > + t = of_get_child_by_name(core, name); > + if (t) { > + leaf = false; > + cpu = get_cpu_for_node(t); > + if (cpu >= 0) { > + cpu_topology[cpu].cluster_id = cluster_id; > + cpu_topology[cpu].core_id = core_id; > + cpu_topology[cpu].thread_id = i; > + } else { > + pr_err("%s: Can't get CPU for thread\n", > + t->full_name); > + return -EINVAL; > + } > + of_node_put(t); > + } > + i++; > + } while (t); > + > + cpu = get_cpu_for_node(core); > + if (cpu >= 0) { > + if (!leaf) { > + pr_err("%s: Core has both threads and CPU\n", > + core->full_name); > + return -EINVAL; > + } > + > + cpu_topology[cpu].cluster_id = cluster_id; > + cpu_topology[cpu].core_id = core_id; > + } else if (leaf) { > + pr_err("%s: Can't get CPU for leaf core\n", core->full_name); > + return -EINVAL; > + } > + > + return 0; > +} > + > +static int __init parse_cluster(struct device_node *cluster, int depth) > +{ > + char name[10]; > + bool leaf = true; > + bool has_cores = false; > + struct device_node *c; > + static int cluster_id __initdata; > + int core_id = 0; > + int i, ret; > + > + /* > + * First check for child clusters; we currently ignore any > + * information about the nesting of clusters and present the > + * scheduler with a flat list of them. > + */ > + i = 0; > + do { > + snprintf(name, sizeof(name), "cluster%d", i); > + c = of_get_child_by_name(cluster, name); > + if (c) { > + ret = parse_cluster(c, depth + 1); > + if (ret != 0) > + return ret; > + leaf = false; > + of_node_put(c); > + } > + i++; > + } while (c); > + > + /* Now check for cores */ > + i = 0; > + do { > + snprintf(name, sizeof(name), "core%d", i); > + c = of_get_child_by_name(cluster, name); > + if (c) { > + has_cores = true; > + > + if (depth == 0) > + pr_err("%s: cpu-map children should be clusters\n", > + c->full_name); > + > + if (leaf) { > + ret = parse_core(c, cluster_id, core_id++); > + if (ret != 0) > + return ret; > + } else { > + pr_err("%s: Non-leaf cluster with core %s\n", > + cluster->full_name, name); > + return -EINVAL; > + } > + of_node_put(c); > + } > + i++; > + } while (c); > + > + if (leaf && !has_cores) > + pr_warn("%s: empty cluster\n", cluster->full_name); > + > + if (leaf) > + cluster_id++; > + > + return 0; > +} > + > +static int __init parse_dt_topology(void) > +{ > + struct device_node *cn, *map; > + int ret = 0; > + int cpu; > + > + cn = of_find_node_by_path("/cpus"); > + if (!cn) { > + pr_err("No CPU information found in DT\n"); > + return 0; > + } > + > + /* > + * When topology is provided cpu-map is essentially a root > + * cluster with restricted subnodes. > + */ > + map = of_get_child_by_name(cn, "cpu-map"); > + if (!map) > + goto out; > + > + ret = parse_cluster(map, 0); > + if (ret != 0) > + goto out; > + > + of_node_put(map); > + > + /* > + * 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) { > + if (cpu_topology[cpu].cluster_id == -1) { > + pr_err("CPU%d: No topology information specified\n", > + cpu); > + ret = -EINVAL; > + } > + } > + > +out: > + of_node_put(cn); > + return ret; > +} > + > /* > * cpu topology table > */ > @@ -71,15 +244,10 @@ void store_cpu_topology(unsigned int cpuid) > update_siblings_masks(cpuid); > } > > -/* > - * init_cpu_topology is called at boot when only one cpu is running > - * which prevent simultaneous write access to cpu_topology array > - */ > -void __init init_cpu_topology(void) > +static void __init reset_cpu_topology(void) > { > unsigned int cpu; > > - /* init core mask and power*/ > for_each_possible_cpu(cpu) { > struct cpu_topology *cpu_topo = &cpu_topology[cpu]; > > @@ -93,3 +261,15 @@ void __init init_cpu_topology(void) > cpumask_set_cpu(cpu, &cpu_topo->thread_sibling); > } > } > + > +void __init init_cpu_topology(void) > +{ > + reset_cpu_topology(); > + > + /* > + * Discard anything that was parsed if we hit an error so we > + * don't use partial information. > + */ > + if (parse_dt_topology()) > + reset_cpu_topology(); > +} > -- > 1.9.1 > > >From 134718e495a8d989c84dafe27d1b56b3c2e029c3 Mon Sep 17 00:00:00 2001 From: Lorenzo Pieralisi Date: Mon, 24 Mar 2014 14:52:24 +0000 Subject: [PATCH 2/2] arm64: kernel: topology updates Signed-off-by: Lorenzo Pieralisi --- arch/arm64/kernel/topology.c | 33 ++++++++++++++++++++------------- 1 files changed, 20 insertions(+), 13 deletions(-) diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c index 0e2cfeb..60f5f47 100644 --- a/arch/arm64/kernel/topology.c +++ b/arch/arm64/kernel/topology.c @@ -31,12 +31,15 @@ static int __init get_cpu_for_node(struct device_node *node) if (!cpu_node) return -1; - for_each_possible_cpu(cpu) { - if (of_get_cpu_node(cpu, NULL) == cpu_node) + for_each_possible_cpu(cpu) + if (of_get_cpu_node(cpu, NULL) == cpu_node) { + of_node_put(cpu_node); return cpu; - } + } pr_crit("Unable to find CPU node for %s\n", cpu_node->full_name); + + of_node_put(cpu_node); return -1; } @@ -55,6 +58,7 @@ static int __init parse_core(struct device_node *core, int cluster_id, if (t) { leaf = false; cpu = get_cpu_for_node(t); + of_node_put(t); if (cpu >= 0) { cpu_topology[cpu].cluster_id = cluster_id; cpu_topology[cpu].core_id = core_id; @@ -64,7 +68,6 @@ static int __init parse_core(struct device_node *core, int cluster_id, t->full_name); return -EINVAL; } - of_node_put(t); } i++; } while (t); @@ -107,11 +110,11 @@ static int __init parse_cluster(struct device_node *cluster, int depth) snprintf(name, sizeof(name), "cluster%d", i); c = of_get_child_by_name(cluster, name); if (c) { + leaf = false; ret = parse_cluster(c, depth + 1); + of_node_put(c); if (ret != 0) return ret; - leaf = false; - of_node_put(c); } i++; } while (c); @@ -124,20 +127,24 @@ static int __init parse_cluster(struct device_node *cluster, int depth) if (c) { has_cores = true; - if (depth == 0) + if (depth == 0) { pr_err("%s: cpu-map children should be clusters\n", c->full_name); + of_node_put(c); + return -EINVAL; + } if (leaf) { ret = parse_core(c, cluster_id, core_id++); - if (ret != 0) - return ret; } else { pr_err("%s: Non-leaf cluster with core %s\n", cluster->full_name, name); - return -EINVAL; + ret = -EINVAL; } + of_node_put(c); + if (ret != 0) + return ret; } i++; } while (c); @@ -173,9 +180,7 @@ static int __init parse_dt_topology(void) ret = parse_cluster(map, 0); if (ret != 0) - goto out; - - of_node_put(map); + goto out_map; /* * Check that all cores are in the topology; the SMP code will @@ -189,6 +194,8 @@ static int __init parse_dt_topology(void) } } +out_map: + of_node_put(map); out: of_node_put(cn); return ret; -- 1.7.5.4