From patchwork Thu Apr 24 14:48:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Pieralisi X-Patchwork-Id: 28977 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qg0-f69.google.com (mail-qg0-f69.google.com [209.85.192.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 9FAD02036A for ; Thu, 24 Apr 2014 14:48:45 +0000 (UTC) Received: by mail-qg0-f69.google.com with SMTP id a108sf5833888qge.4 for ; Thu, 24 Apr 2014 07:48:45 -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=QdtqCCa6m0hbWcVY638adoCyGxL3JDWP9/dH5RlffDg=; b=gwo+I4CbIglZm4OJCHXJD8KiT+VTrwnADYduODlGgF7JDeYo8pV4w8EM8IFulimbZ6 J/frGDu51+Dzz/oHgbevNNh2d6pTGZSzzC+7/rHjZnEpotyFzpyev8FedwRWXkpTA82v N+qsVCN6gc87UxjmlPb0dKDMqZZ4zEzCPIxdrbdyh0wWt8PbpyEDfBeZSfxisMZOkguI pRJlgFoAsYfCXAK9CiQt7xPJnSBmVFRPdmfFQtRuhNXcc+wq2UMAxkwZnUy/2XRqFhoE BFVjjXOjX6M8SJIw72pyOCSkKO97rWfdsKvGPTEnWxTy1k3w19HTSFR4sY1qV4v1qkzs 00aA== X-Gm-Message-State: ALoCoQljZiTcN0FkxUiWaahriLtZp40rfG6AYaMfR91I9eP4KPpNmHyN9QoimJ0gjuGDFRqUuqTH X-Received: by 10.236.121.238 with SMTP id r74mr129271yhh.23.1398350925323; Thu, 24 Apr 2014 07:48:45 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.20.138 with SMTP id 10ls1071492qgj.92.gmail; Thu, 24 Apr 2014 07:48:45 -0700 (PDT) X-Received: by 10.58.132.228 with SMTP id ox4mr656504veb.54.1398350925164; Thu, 24 Apr 2014 07:48:45 -0700 (PDT) Received: from mail-ve0-f171.google.com (mail-ve0-f171.google.com [209.85.128.171]) by mx.google.com with ESMTPS id d9si972987vca.134.2014.04.24.07.48.45 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 24 Apr 2014 07:48:45 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.128.171; Received: by mail-ve0-f171.google.com with SMTP id jy13so2988509veb.2 for ; Thu, 24 Apr 2014 07:48:45 -0700 (PDT) X-Received: by 10.52.73.40 with SMTP id i8mr414141vdv.53.1398350925068; Thu, 24 Apr 2014 07:48:45 -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.221.72 with SMTP id ib8csp22139vcb; Thu, 24 Apr 2014 07:48:44 -0700 (PDT) X-Received: by 10.224.129.66 with SMTP id n2mr3250631qas.55.1398350923802; Thu, 24 Apr 2014 07:48:43 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id s6si2267927qaj.200.2014.04.24.07.48.43 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Apr 2014 07:48:43 -0700 (PDT) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WdKvo-00011b-Rt; Thu, 24 Apr 2014 14:47:20 +0000 Received: from service87.mimecast.com ([91.220.42.44]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WdKvl-0000rt-N9 for linux-arm-kernel@lists.infradead.org; Thu, 24 Apr 2014 14:47:19 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.21]) by service87.mimecast.com; Thu, 24 Apr 2014 15:46:52 +0100 Received: from red-moon ([10.1.255.212]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 24 Apr 2014 15:47:06 +0100 Date: Thu, 24 Apr 2014 15:48:46 +0100 From: Lorenzo Pieralisi To: Mark Brown Subject: Re: [PATCH 2/4] arm64: topology: Add support for topology DT bindings Message-ID: <20140424144846.GB8191@red-moon> References: <1398198078-7473-1-git-send-email-broonie@kernel.org> <1398198078-7473-2-git-send-email-broonie@kernel.org> MIME-Version: 1.0 In-Reply-To: <1398198078-7473-2-git-send-email-broonie@kernel.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-OriginalArrivalTime: 24 Apr 2014 14:47:06.0311 (UTC) FILETIME=[0FFB0570:01CF5FCC] X-MC-Unique: 114042415465202401 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140424_074718_196005_442BC1A3 X-CRM114-Status: GOOD ( 27.64 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.3.2 on bombadil.infradead.org summary: Content analysis details: (-0.7 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 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: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) 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 On Tue, Apr 22, 2014 at 09:21:16PM +0100, 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 > --- > arch/arm64/kernel/topology.c | 203 +++++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 195 insertions(+), 8 deletions(-) > > diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c > index ff662b23af5f..a326f5b37546 100644 > --- a/arch/arm64/kernel/topology.c > +++ b/arch/arm64/kernel/topology.c > @@ -17,10 +17,191 @@ > #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) { > + 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; > +} > + > +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); > + of_node_put(t); > + 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) { > + leaf = false; > + ret = parse_cluster(c, depth + 1); > + of_node_put(c); > + if (ret != 0) > + return ret; > + } > + 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); > + of_node_put(c); > + return -EINVAL; > + } > + > + if (leaf) { > + ret = parse_core(c, cluster_id, core_id++); > + } else { > + pr_err("%s: Non-leaf cluster with core %s\n", > + cluster->full_name, name); > + ret = -EINVAL; > + } > + > + of_node_put(c); > + if (ret != 0) > + return ret; > + } > + 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_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_map: > + of_node_put(map); > +out: > + of_node_put(cn); > + return ret; > +} > + > /* > * cpu topology table > */ > @@ -39,8 +220,7 @@ static void update_siblings_masks(unsigned int cpuid) > > if (cpuid_topo->cluster_id == -1) { > /* > - * DT does not contain topology information for this cpu > - * reset it to default behaviour > + * DT does not contain topology information for this cpu. > */ > pr_debug("CPU%u: No topology information configured\n", cpuid); > return; > @@ -71,15 +251,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 +268,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(); > +} I tested it and tried to clobber it a bit with some DT changes, it seems fine. Apart from an ultra-minor decoration change (attached): Reviewed-by: Lorenzo Pieralisi >From 7adf9fb420bd005cfab75d663fcd7aa1d8fe1b2a Mon Sep 17 00:00:00 2001 From: Lorenzo Pieralisi Date: Thu, 24 Apr 2014 12:46:14 +0100 Subject: [PATCH] arm64: kernel: topology: minor cosmetic changes This patch applies some minor changes to the topology code in preparation for merging it. Signed-off-by: Lorenzo Pieralisi --- arch/arm64/kernel/topology.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c index a326f5b..43514f9 100644 --- a/arch/arm64/kernel/topology.c +++ b/arch/arm64/kernel/topology.c @@ -31,11 +31,12 @@ static int __init get_cpu_for_node(struct device_node *node) if (!cpu_node) return -1; - for_each_possible_cpu(cpu) + 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); -- 1.7.5.4