Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1616017ybl; Fri, 10 Jan 2020 22:58:53 -0800 (PST) X-Google-Smtp-Source: APXvYqzoIJNcicNJTS8FN8mhkyiEe5A45CaFODiNiaerP/D9R2IGRCdhjVC3GP+t0HNWKKCnmSFB X-Received: by 2002:aca:8d5:: with SMTP id 204mr5162614oii.141.1578725933355; Fri, 10 Jan 2020 22:58:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578725933; cv=none; d=google.com; s=arc-20160816; b=pmLXdZXTCtULk1TGbGPo+4gEsr2R2SN1hTyMjCoN/j7bSsG2amtVf629Okvruvh/1V cjV8qNlhdwMrqXRhtxZ2lTWjO1QBet7QZ6QJ8fYAYtuydbeeowelCWP14s3f0lKTROtw PLfucKKLlo1stkvOlf6ZyO+Xw7t5yR4cwVvSS04CSk3LOl9sThuQqycN3PojTZXyONGQ vBHPLt1snl+cQUv2iHxCZduUIqEn2oj1GHqalex/SpGCcwOnz723Opa43GcSXzWpHmm1 NUDB0uLWs6j2LI5ha6A0H5e+uqjDC+0eZNCYuyJ36mmebOTnpYARK49k7oiJLd1M1ZtE 1Eqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=qxA0z/4+zFJ9aQZfAjQ79mcncwouLlD44LuqiXNg1cg=; b=BTtA8VgT2lt/Z8Oil20kVy9YqoCmx7cIRZd/UD+tVsGyAdnfBb7kgBo7/eX7k8huuW PrCivx1G/MRCaqR4iEJDtErAxbfzXRq7a2R1PKb2yeFciqwHFtDw4iLCjo40fXKjx5Yu pzM/fs5SFt1+7N3I9SQEIwUtjLJ0TzsZZMjL+VsrS5VtiluPKIH1xsbe/hki+Nbcvz24 1t/6nnWx2qYGYs938vZ6BBVA9qV3/i+UBmsFFYX3fdq0en6UZvh/Y6DFSjp35ujxemQA W4FA8jscRCef/AoCI45ASilFrGT6Ly9QmG/Of7c0zhK9KcsaH74Aj+Ms0U2Dh9hDKcW1 G0Vw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f9si3182010otp.111.2020.01.10.22.58.41; Fri, 10 Jan 2020 22:58:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728426AbgAKG5n (ORCPT + 99 others); Sat, 11 Jan 2020 01:57:43 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:8693 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728413AbgAKG5n (ORCPT ); Sat, 11 Jan 2020 01:57:43 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 202AF6B31E8B1024BCDB; Sat, 11 Jan 2020 14:57:39 +0800 (CST) Received: from localhost.localdomain (10.67.165.24) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Sat, 11 Jan 2020 14:57:29 +0800 From: Zeng Tao To: CC: , Zeng Tao , "Greg Kroah-Hartman" , "Rafael J. Wysocki" , Subject: [PATCH v2] cpu-topology: Skip the exist but not possible cpu nodes Date: Sat, 11 Jan 2020 14:53:40 +0800 Message-ID: <1578725620-39677-1-git-send-email-prime.zeng@hisilicon.com> X-Mailer: git-send-email 2.8.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.165.24] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When CONFIG_NR_CPUS is smaller than the cpu nodes defined in the device tree, all the cpu nodes parsing will fail. And this is not reasonable for a legal device tree configs. In this patch, skip such cpu nodes rather than return an error. With CONFIG_NR_CPUS = 128 and cpus nodes num in device tree is 130, The following warning messages will be print during boot: CPU node for /cpus/cpu@128 exist but the possible cpu range is :0-127 CPU node for /cpus/cpu@129 exist but the possible cpu range is :0-127 CPU node for /cpus/cpu@130 exist but the possible cpu range is :0-127 Signed-off-by: Zeng Tao --- Changelog: v1->v2: -Remove redundant -ENODEV assignment in get_cpu_for_node -Add comment to describe the get_cpu_for_node return values -Add skip process for cpu threads -Update the commit log with more detail --- drivers/base/arch_topology.c | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index 5fe44b3..01f0e21 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -248,22 +248,44 @@ core_initcall(free_raw_capacity); #endif #if defined(CONFIG_ARM64) || defined(CONFIG_RISCV) +/* + * This function returns the logic cpu number of the node. + * There are totally three kinds of return values: + * (1) logic cpu number which is > 0. + * (2) -ENDEV when the node is valid one which can be found in the device tree + * but there is no possible cpu nodes to match, when the CONFIG_NR_CPUS is + * smaller than cpus node numbers in device tree, this will happen. It's + * suggested to just ignore this case. + * (3) -EINVAL when other errors occur. + */ static int __init get_cpu_for_node(struct device_node *node) { - struct device_node *cpu_node; + struct device_node *cpu_node, *t; int cpu; + bool found = false; cpu_node = of_parse_phandle(node, "cpu", 0); if (!cpu_node) - return -1; + return -EINVAL; + + for_each_of_cpu_node(t) + if (t == cpu_node) { + found = true; + break; + } + + if (!found) { + pr_crit("Unable to find CPU node for %pOF\n", cpu_node); + return -EINVAL; + } cpu = of_cpu_node_to_id(cpu_node); if (cpu >= 0) topology_parse_cpu_capacity(cpu_node, cpu); else - pr_crit("Unable to find CPU node for %pOF\n", cpu_node); + pr_warn("CPU node for %pOF exist but the possible cpu range is :%*pbl\n", + cpu_node, cpumask_pr_args(cpu_possible_mask)); - of_node_put(cpu_node); return cpu; } @@ -286,9 +308,8 @@ static int __init parse_core(struct device_node *core, int package_id, cpu_topology[cpu].package_id = package_id; cpu_topology[cpu].core_id = core_id; cpu_topology[cpu].thread_id = i; - } else { - pr_err("%pOF: Can't get CPU for thread\n", - t); + } else if (cpu != -ENODEV) { + pr_err("%pOF: Can't get CPU for thread\n", t); of_node_put(t); return -EINVAL; } @@ -307,7 +328,7 @@ static int __init parse_core(struct device_node *core, int package_id, cpu_topology[cpu].package_id = package_id; cpu_topology[cpu].core_id = core_id; - } else if (leaf) { + } else if (leaf && cpu != -ENODEV) { pr_err("%pOF: Can't get CPU for leaf core\n", core); return -EINVAL; } -- 2.8.1