Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2977724imw; Wed, 6 Jul 2022 15:14:06 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u4aV0UyyuAgis0gd7ChSt1HYJKiR3/VaHbIBApYGr4Zdawt0+EAsn0Ldd4V8OrFpwTEwTM X-Received: by 2002:a05:6402:5214:b0:437:5b1d:9966 with SMTP id s20-20020a056402521400b004375b1d9966mr57805217edd.16.1657145646437; Wed, 06 Jul 2022 15:14:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657145646; cv=none; d=google.com; s=arc-20160816; b=YViwxwj5vzz3ARMS8YHttq+H154ONxJJvb3NXUHNZ+jjBKJsVDJS7j4zM3qnGsVJhx cIS5gqzbamDyNgevcsXnN03LIhW+CxKc/+e5e3AHVczNiQDCfpwpQak8ALZ0ZP9yF3Er 0kX2Q64rgqj+YC8ybbHrIg690i+dY9Rnzg2/RDFG9U9ghbYC59Ax58vrvyCcCnw5nj3I ZaCeVLKIcRZ/zmDSOOw4Sbutt8S0oFoFEzq22sIj/xGv0mFLlyFex+hbLY1/MsRyAcNE QraldtczQSG0+zx6o1ORLJgpn1R4GpduMNgGLhvEMjJHhF28P6P10rVlWmJ1O/y7V6cm YI3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=YMOUx8tRXrNtuUeXMdx6sLrOQrLpo6dcTRjSCKuQc0Y=; b=Y8eeOXum33jw/S+H6S57MujTrvBIOJVIjI/A3BDuLpQjYZhkHU0ve+ksBYvvHhimrm 9qLhWS3UJ9U9EzBp7DM4y/pAAKK/ydmokVS6gvupdHxCPcK7WuChy00+hnufKPHiCYg/ MmUI9vhMfbcoF8KlFUshrSshXMpnKa/RExfUszDDlm2aN7rJEFI/Gr0IQRyQKIYG64fm 9h2AoiCLuIuQwPqrtoPif9IiPM2xpBObgUqBwsMeuREBPUUMQ7Ao3zUV7IqUw6jzWQRW dtg7W6z5N0YPMO+t+PMAlRRQOhzgFzHHJdplLrsoULhKszsixXriWQVRKoC9vD7fkyC5 QHvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=UYKAelmy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dm8-20020a170907948800b0072632426373si15318196ejc.865.2022.07.06.15.13.41; Wed, 06 Jul 2022 15:14:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=UYKAelmy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234351AbiGFViP (ORCPT + 99 others); Wed, 6 Jul 2022 17:38:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234001AbiGFViO (ORCPT ); Wed, 6 Jul 2022 17:38:14 -0400 Received: from mail-yw1-x1133.google.com (mail-yw1-x1133.google.com [IPv6:2607:f8b0:4864:20::1133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79CFCE8C for ; Wed, 6 Jul 2022 14:38:13 -0700 (PDT) Received: by mail-yw1-x1133.google.com with SMTP id 00721157ae682-31c89111f23so102709487b3.0 for ; Wed, 06 Jul 2022 14:38:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=atishpatra.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=YMOUx8tRXrNtuUeXMdx6sLrOQrLpo6dcTRjSCKuQc0Y=; b=UYKAelmyu8hR8xtMcdAR5kd1mv8eoTvSrr43mXrkLTDNp7Up1QaEHT06vXLI2hfzGi UgyOvRNXV+lnTdsGajUy0ju4uTNazHUOkRkqbgyEg9cM3N8iAYjp4BSKrQMLIxcIPNF8 jCzJvOSiH9aVkes4u0/X29QTr5+jvw3j86MAY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=YMOUx8tRXrNtuUeXMdx6sLrOQrLpo6dcTRjSCKuQc0Y=; b=h7ZtqobUvU2B2VDWA8at3E9hZm+xyeFXRWixm0rmct1rsEF24Di30mzx2Jg6haGtLH WaqxP1DhvFOypkUeQzArhD5Jh48ry25cwcVU/75Wa79V1ZsH0o4/VAj6HpHMLM6lDAS1 e+48FxXgjvuPRsp5PUNUUzW2Hz/BojyI7DK77IUs87Ow6BMbzAjwnGO2QtwsfIbrzEmj KZUO6ddI2gSDtAUfv6wuFh0WBwTgQfjNe9OiI4Qa8qy+uoJv/DpQJFEp9zE3sxDgd2zG efieu85k7axrHNKTp/OICNXKGfW/SZWGAdAzmyKe9NDjHRf6kYWZ0IPDXwhI3DDUQSAm C/ZQ== X-Gm-Message-State: AJIora/qCKAOhBSrFIFP2XZbjE+Ch0FelQqdXAfBmqS6qFFjLqxuTWZ2 4hyPLLaaiqqcQ57dSHp+EZGhX37eUkq4L8HS1k3Z X-Received: by 2002:a81:5d55:0:b0:31c:dce7:96c9 with SMTP id r82-20020a815d55000000b0031cdce796c9mr9652700ywb.519.1657143492665; Wed, 06 Jul 2022 14:38:12 -0700 (PDT) MIME-Version: 1.0 References: <20220706184558.2557301-1-mail@conchuod.ie> In-Reply-To: <20220706184558.2557301-1-mail@conchuod.ie> From: Atish Patra Date: Wed, 6 Jul 2022 14:38:01 -0700 Message-ID: Subject: Re: [PATCH] riscv: arch-topology: fix default topology reporting To: Conor Dooley Cc: Paul Walmsley , Palmer Dabbelt , Palmer Dabbelt , Albert Ou , Sudeep Holla , Daire McNamara , Conor Dooley , Niklas Cassel , Damien Le Moal , Geert Uytterhoeven , Zong Li , Emil Renner Berthing , Jonas Hahnfeld , Guo Ren , Anup Patel , Changbin Du , Heiko Stuebner , Philipp Tomsich , linux-riscv , "linux-kernel@vger.kernel.org List" , Brice Goglin Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 6, 2022 at 11:46 AM Conor Dooley wrote: > > From: Conor Dooley > > RISC-V has no sane defaults to fall back on where there is no cpu-map > in the devicetree. > Without sane defaults, the package, core and thread IDs are all set to > -1. This causes user-visible inaccuracies for tools like hwloc/lstopo > which rely on the sysfs cpu topology files to detect a system's > topology. > > Add sane defaults in ~the exact same way as ARM64. > > CC: stable@vger.kernel.org > Fixes: 03f11f03dbfe ("RISC-V: Parse cpu topology during boot.") > Reported-by: Brice Goglin > Link: https://github.com/open-mpi/hwloc/issues/536 > Signed-off-by: Conor Dooley > --- > > Sudeep suggested that this be backported rather than the changes to > the devicetrees adding cpu-map since that property is optional. > That patchset is still valid in it's own right. > > arch/riscv/include/asm/topology.h | 13 +++++++++++++ > arch/riscv/kernel/Makefile | 1 + > arch/riscv/kernel/smpboot.c | 4 ++++ > arch/riscv/kernel/topology.c | 32 +++++++++++++++++++++++++++++++ > 4 files changed, 50 insertions(+) > create mode 100644 arch/riscv/include/asm/topology.h > create mode 100644 arch/riscv/kernel/topology.c > > diff --git a/arch/riscv/include/asm/topology.h b/arch/riscv/include/asm/topology.h > new file mode 100644 > index 000000000000..36bc6ecda898 > --- /dev/null > +++ b/arch/riscv/include/asm/topology.h > @@ -0,0 +1,13 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > +/* > + * Copyright (c) 2022 Microchip Technology Inc. and its subsidiaries > + */ > + > +#ifndef _ASM_RISCV_TOPOLOGY_H > +#define _ASM_RISCV_TOPOLOGY_H > + > +#include > + > +void store_cpu_topology(unsigned int cpuid); > + > +#endif /* _ASM_RISCV_TOPOLOGY_H */ > diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile > index c71d6591d539..9518882ba6f9 100644 > --- a/arch/riscv/kernel/Makefile > +++ b/arch/riscv/kernel/Makefile > @@ -50,6 +50,7 @@ obj-y += riscv_ksyms.o > obj-y += stacktrace.o > obj-y += cacheinfo.o > obj-y += patch.o > +obj-y += topology.o > obj-y += probes/ > obj-$(CONFIG_MMU) += vdso.o vdso/ > > diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c > index f1e4948a4b52..d551c7f452d4 100644 > --- a/arch/riscv/kernel/smpboot.c > +++ b/arch/riscv/kernel/smpboot.c > @@ -32,6 +32,7 @@ > #include > #include > #include > +#include > > #include "head.h" > > @@ -40,6 +41,8 @@ static DECLARE_COMPLETION(cpu_running); > void __init smp_prepare_boot_cpu(void) > { > init_cpu_topology(); > + > + store_cpu_topology(smp_processor_id()); > } > > void __init smp_prepare_cpus(unsigned int max_cpus) > @@ -161,6 +164,7 @@ asmlinkage __visible void smp_callin(void) > mmgrab(mm); > current->active_mm = mm; > > + store_cpu_topology(curr_cpuid); > notify_cpu_starting(curr_cpuid); > numa_add_cpu(curr_cpuid); > update_siblings_masks(curr_cpuid); > diff --git a/arch/riscv/kernel/topology.c b/arch/riscv/kernel/topology.c > new file mode 100644 > index 000000000000..db72862bd5b5 > --- /dev/null > +++ b/arch/riscv/kernel/topology.c > @@ -0,0 +1,32 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * Copyright (c) 2022 Microchip Technology Inc. and its subsidiaries > + * > + * Based on the arm64 version, which was in turn based on arm32, which was > + * ultimately based on sh's. > + * The arm64 version was listed as: > + * Copyright (C) 2011,2013,2014 Linaro Limited. > + */ > + > +#include > +#include > +#include > + > +void store_cpu_topology(unsigned int cpuid) > +{ > + struct cpu_topology *cpuid_topo = &cpu_topology[cpuid]; > + > + if (cpuid_topo->package_id != -1) > + goto topology_populated; > + > + cpuid_topo->thread_id = -1; > + cpuid_topo->core_id = cpuid; > + cpuid_topo->package_id = cpu_to_node(cpuid); > + > + pr_debug("CPU%u: package %d core %d thread %d\n", > + cpuid, cpuid_topo->package_id, cpuid_topo->core_id, > + cpuid_topo->thread_id); > + > +topology_populated: > + update_siblings_masks(cpuid); > +} > This function is pretty much the same as the arm64 one except the UP/mpidr check. Can we move this to the common code as well ? > base-commit: b6f1f2fa2bddd69ff46a190b8120bd440fd50563 > -- > 2.37.0 > -- Regards, Atish