Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2134866pxb; Fri, 29 Jan 2021 14:19:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJwy1b3q6E04X6m2tlQfQEp3ITOYzlthTwn9gJo4EVVBAfYxSqo11rXaqu0P709T6tk0nvW5 X-Received: by 2002:a17:906:4bc1:: with SMTP id x1mr6683880ejv.509.1611958759958; Fri, 29 Jan 2021 14:19:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611958759; cv=none; d=google.com; s=arc-20160816; b=b8OnCe1qHahRbzkguk3tRdac4v/wIKFF1OpBPGwAvSbnhw5Ciq6KZaEEolMIT68ZKg yHijdi8tzEM5Mm26ichynWbV5ClSPc03RD8NdqZdOHaEXkXCICb5xGdYM4jNsQxegBHy T8I1O00z07O6inmF2sHR4UBBLxf4+/7zGiglej4oLlJPYKQ5mtUp+o8S+E1xLLhjBX91 MwA/3awatLKyxMKGy+1ZTiAqaxr5RzX63Ex0BgGDYSI58MRVAfWDfa+r2+ffMhfPHTih 4AdBj9P3xtcW2CzCVA3fLVczBu83db5ybNU3smZDiLI+dGIMXX6RZEHEVEtR+Iw7rl17 hZ3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=KRdVj8aDHVVWjYR6nci89gkQtpmD5ypYkI2gm5mcuf4=; b=vBR/7pBXvKsKhm3U8zcHWywXv8HpSea+pnr4XYQ5+LBrp1OGKybl9+NQ4X+0rU9Hx2 9qSkC9+EglJwdYgeWE6K3QHGsWJL16L2m6paD5I0zj8ZjueNFc0ys01WMPgvLBXtoQ9H 0f/FRi5hJOOCMlZwo+pcemCYxFfGm7rR5+5RUpdpAKC27bFUHZfA3caH/Wz+leb5bgJN ME1Ydc11Ak8vXwZclN8L3WhafLOJ2Y8O724o2vXMVNeTwIzvd4Q57YVinKndA2itjOyr gv//ymXOs9VxTBFZcy0486rOt2smsWw4dfANCkpSgsc1SFtnam6EwAEHvbYYQCk1ozEh kDRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Pw7iqrIC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id oz26si5533337ejb.181.2021.01.29.14.18.54; Fri, 29 Jan 2021 14:19:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Pw7iqrIC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233500AbhA2WR2 (ORCPT + 99 others); Fri, 29 Jan 2021 17:17:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233401AbhA2WR1 (ORCPT ); Fri, 29 Jan 2021 17:17:27 -0500 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D58AC061573 for ; Fri, 29 Jan 2021 14:16:47 -0800 (PST) Received: by mail-pl1-x62f.google.com with SMTP id h15so6093336pli.8 for ; Fri, 29 Jan 2021 14:16:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=KRdVj8aDHVVWjYR6nci89gkQtpmD5ypYkI2gm5mcuf4=; b=Pw7iqrICxBPTIMPeUWRHhbCw5REf5ZKOgix+DO/BQJK7JhhzhxFa5JfSMWTjcQfpGd QwW8D2wrNIir8wvWk80dTmyR6T/JtvzhL7EmZvg8+4WR4hUwk1HQEkigD1GyzUKvJvvJ KW6gZFbYAIx0JbKeR8yk7E+NcUOGmo0d3+U5sR9oZG3yoygvvN6sogM6vfSN5VJZ6HxD o5+dd/GVAlobFtKFqf5n5YDpqDwCdyHXteN1WmksawHnXjctR8YcLX4ws2jhS0M87TrV uZNQr9oCuNv6uToQElt5rmm339VizL0H7h/OD9vqTzKd/yuQwaqgMT8UALxmEeVRSv+8 VAPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=KRdVj8aDHVVWjYR6nci89gkQtpmD5ypYkI2gm5mcuf4=; b=E8ZlRk3RcUTskzRWEGKM305/1jy3IDO86R0f8d2QdZzFauU1evTSFeLkJsXMU8DKB6 BzcK+RpOHKM9oY4jxeW8w9AidOZHkbK0iSPHkWO7GPJJrmwqePzvX3OrOOwUD48rBind udck8sGR0dzt3jCiKthFi3O3kELHArkGPIxBsgSWVevRoyRMrg4lI5rNxDgPTAowf5cX hyPL5j4NyEsZMrS0KhNVsc/BV3p7YmgM7pNm2bLtQQPWy0TdozFjGhTATpbdcZHIKJQ0 Cl3PcxFyDyAUOxAg3hTkhhEfGPFBzNRGAVMBJRDaZNlh/eY/K+/huVJC9XwfaJBu80bZ X35Q== X-Gm-Message-State: AOAM532v4/+jAAMN0x6LK0XssnO5ettOFKBzrCN0kXWiC/TgcQsAOBj1 /39kxPGCsmE+OSG9GWjmFGs= X-Received: by 2002:a17:903:228a:b029:da:d645:ab58 with SMTP id b10-20020a170903228ab02900dad645ab58mr6516799plh.25.1611958606857; Fri, 29 Jan 2021 14:16:46 -0800 (PST) Received: from localhost (g54.222-224-210.ppp.wakwak.ne.jp. [222.224.210.54]) by smtp.gmail.com with ESMTPSA id 101sm8596927pjo.38.2021.01.29.14.16.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jan 2021 14:16:46 -0800 (PST) Date: Sat, 30 Jan 2021 07:16:43 +0900 From: Stafford Horne To: Jan Henrik Weinstock Cc: jonas@southpole.se, stefan.kristiansson@saunalahti.fi, openrisc@lists.librecores.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] openrisc: use device tree to determine present cpus Message-ID: <20210129221643.GZ2002709@lianli.shorne-pla.net> References: <0b26eda7-229d-3dc9-f2ae-19b9212fb0ea@rwth-aachen.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0b26eda7-229d-3dc9-f2ae-19b9212fb0ea@rwth-aachen.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 29, 2021 at 07:29:31PM +0100, Jan Henrik Weinstock wrote: > This patch proposes to use the device tree to determine the present cpus > instead of assuming all CONFIG_NRCPUS are actually present in the system. > > Signed-off-by: Jan Henrik Weinstock > --- > arch/openrisc/kernel/smp.c | 18 +++++++++++++++--- > 1 file changed, 15 insertions(+), 3 deletions(-) > > diff --git a/arch/openrisc/kernel/smp.c b/arch/openrisc/kernel/smp.c > index 29c82ef2e..75be7e34f 100644 > --- a/arch/openrisc/kernel/smp.c > +++ b/arch/openrisc/kernel/smp.c > @@ -16,6 +16,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -68,14 +69,25 @@ void __init smp_init_cpus(void) > > void __init smp_prepare_cpus(unsigned int max_cpus) > { > - int i; > + u32 cpu_id; > + struct device_node *cpu, *cpus; > > /* > * Initialise the present map, which describes the set of CPUs > * actually populated at the present time. > */ > - for (i = 0; i < max_cpus; i++) > - set_cpu_present(i, true); > + cpus = of_find_node_by_path("/cpus"); > + for_each_child_of_node(cpus, cpu) { > + if (of_property_read_u32(cpu, "reg", &cpu_id)) { > + pr_warn("%s missing reg property", cpu->full_name); > + continue; > + } > + > + if (cpu_id >= max_cpus) > + continue; > + > + set_cpu_present(cpu_id, true); > + } Hello, I looked into what other architectures do. Risc-V does something similar but it does the setup in 2 parts: - it uses the device tree to set possible CPU's in setup_smp. Using for_each_of_cpu_node and set_cpu_possible. - Then in smp_prepare_cpus, it loops over possible cpus with for_each_possible_cpu. Note, it seems risc-v does't actually check max_cpus when setting set_cpu_present which may be a bug. I think the two part approach is what we want to do: - we should do set_cpu_possible in smp_init_cpus based on device tree. Basically the same as your loop above but using for_each_of_cpu_node and NR_CPUS. - we can then do set_cpu_present using for_each_possible_cpu in smp_prepare_cpus. What do you think? -Stafford > } > > void __init smp_cpus_done(unsigned int max_cpus) > -- > 2.17.1 >