Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4232629imw; Thu, 7 Jul 2022 15:12:59 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vHr/KiVCaOWt++PExWDZowf+9gu+Y4XNGw5RoANeGt9w7hcZnXmxgWvaIucOlZ0fIvGJAp X-Received: by 2002:a17:907:a429:b0:726:2d63:25f7 with SMTP id sg41-20020a170907a42900b007262d6325f7mr325888ejc.112.1657231979047; Thu, 07 Jul 2022 15:12:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657231979; cv=none; d=google.com; s=arc-20160816; b=VWwFnbUKtd2wAjBh1p4Dfg2hjtFNNFeM1AT7X3+7JwIviDfQeggWsOi+G+CbP2qQY8 cTwfez0SC7WkE/BmbNrfDUUqvaL8KycS4PG/Tk1nSKKnY4eHp10pK4zi3eNbSR23v0FC 9J3J0o+ygLpHPOZaN3Se8sJgGG16ghJjMe4wGWaZPolibFGyLLIB36AKLUQcsTJTgNNL jdbcG+tAWYLgQ3Sh7UyEm6aYlC2R3vtmtgA8ccU+3HSEyBx4Maaw/7o7TFTWROM8vLKg pPe8F0MhN3ynwZoNSn0fId9Llst9OQ9/I0hyuiXy0zk5cgGsdWi2l16Lhuy/epNduS4K tglg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7E7EjtLMLS23T2bsvt4SNELdhBh6QzAyNMiy3mGJiIQ=; b=oMOgAdA/fVDgXPA8MtdK+IHDkgqx/0gpA9eHe9Gr4curbtlHoBHg5bvOBxvbSpP6Rv Cdps1oGeULtUs8jioX4Njdm+0vgTUgypQHkCXepoey0ktcDos3p6iYRn6VTowTDmdkUF 8L+yTNdEzm1XeUALTGDHZ2wXt3tQMzTneIJ9us+WCHSJmP5CbqhLArL75QCffCIzrL66 xG8JugxKqiPSvIu1DzAs74BwsR5dI0BWdgXeFpTLceFk2MvsQ64fw4NT/GBCD+O6pvWX 7un47Af4LONbzf0UFXWPz8JZe7ut5S3feftaNpNckURH9/K2ltXnmFcXHIavaUDKkjGV zApQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@conchuod.ie header.s=google header.b=IpDj5afJ; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=conchuod.ie Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o5-20020a056402444500b0043a64cca77asi15182377edb.424.2022.07.07.15.12.33; Thu, 07 Jul 2022 15:12:59 -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=@conchuod.ie header.s=google header.b=IpDj5afJ; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=conchuod.ie Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236560AbiGGWFC (ORCPT + 99 others); Thu, 7 Jul 2022 18:05:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236624AbiGGWFA (ORCPT ); Thu, 7 Jul 2022 18:05:00 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A06F2CC8A for ; Thu, 7 Jul 2022 15:04:59 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id o4so28141686wrh.3 for ; Thu, 07 Jul 2022 15:04:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=conchuod.ie; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7E7EjtLMLS23T2bsvt4SNELdhBh6QzAyNMiy3mGJiIQ=; b=IpDj5afJY9kCBQK/vOv90bAyHCUlUto7onzuO/nC3gDHXS58GwaZXLBMRi1NpV8ze2 7b17aX7eg5pNGdN+ljCBcQEc7Flzi0KrNPzi/DSS83gxm/xyJ6d8Y10aQ11y5TH8tSm7 qxtNVNxZoHIHsKaon5dlXSvMpW9bZI5FVCtqvHtnlP/HB2Wrg8hCLpJp20X1soauPaZK P6wZGFi3ZwZviCg8NdSlenWNPuXDtvx6V91JHpVX/vU12PqONkh1XKjIVuPe/Qsc7Scw 3xn/BvmyMLVj2asQTVoDw2k2nLgR7SK989r2ZPBZIJK8ddDzmN3y0lb0xRMqXv3YSmq0 gvJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7E7EjtLMLS23T2bsvt4SNELdhBh6QzAyNMiy3mGJiIQ=; b=uhvBfQj37fo/4vWi1MiZCanRyofHijNNF/tIGoNVUcr8HxXg37QFYq5n5FnnXCKLLE g1YynnqbSlhXb5iWaBtQXhzHO0Uer2TBxMjZ5R9EE1YgoAkGYDDP7v6NVH9cQX+6zIcN 9Kx3DQDJuF1tLHzZOF16u9U1EOav2ZYlGflL9iB5dUhoX+i+SdlghelmWmJvIKxnuR94 U9JqFSBc/pqB/zBFTMfnTr8G0i1NK+iPUGvQlI2qxXsjDZ4mCIwgZjCUjKZ9ZOSsZi2n FVSaFVGG8Whgn8OerbiFKPQAwiUmAHbQ91LJ9dgzJVGSqSslCxg+8o2EA79RUcJGB0AZ sOdQ== X-Gm-Message-State: AJIora+mMnogC0huarh5es2Nk4Vr2sON2feFGJwbEszy9KwkfyFKB3fE DCgkKdSD1ikWcbOh7X+E8YchsA== X-Received: by 2002:a5d:5c05:0:b0:21d:83b4:d339 with SMTP id cc5-20020a5d5c05000000b0021d83b4d339mr40615wrb.611.1657231497860; Thu, 07 Jul 2022 15:04:57 -0700 (PDT) Received: from henark71.. ([51.37.234.167]) by smtp.gmail.com with ESMTPSA id bn24-20020a056000061800b0020fe35aec4bsm38625743wrb.70.2022.07.07.15.04.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 15:04:57 -0700 (PDT) From: Conor Dooley To: Paul Walmsley , Palmer Dabbelt , Palmer Dabbelt , Albert Ou , Sudeep Holla , Catalin Marinas , Will Deacon , Greg Kroah-Hartman , "Rafael J . Wysocki" Cc: Daire McNamara , Conor Dooley , Niklas Cassel , Damien Le Moal , Geert Uytterhoeven , Zong Li , Emil Renner Berthing , Jonas Hahnfeld , Guo Ren , Anup Patel , Atish Patra , Changbin Du , Heiko Stuebner , Philipp Tomsich , Rob Herring , Marc Zyngier , Viresh Kumar , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Brice Goglin Subject: [RFC 1/4] riscv: arch-topology: fix default topology reporting Date: Thu, 7 Jul 2022 23:04:34 +0100 Message-Id: <20220707220436.4105443-2-mail@conchuod.ie> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220707220436.4105443-1-mail@conchuod.ie> References: <20220707220436.4105443-1-mail@conchuod.ie> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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. Changes since v1: - removed the GENERIC_ARCH_TOPOLOGY dependancy on SMP - removed a duplicate call to update_siblings_masks() --- arch/riscv/Kconfig | 2 +- arch/riscv/include/asm/topology.h | 13 +++++++++++++ arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/smpboot.c | 5 ++++- arch/riscv/kernel/topology.c | 32 +++++++++++++++++++++++++++++++ 5 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 arch/riscv/include/asm/topology.h create mode 100644 arch/riscv/kernel/topology.c diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 2af0701b7518..4b6c2fdbb57c 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -52,7 +52,7 @@ config RISCV select COMMON_CLK select CPU_PM if CPU_IDLE select EDAC_SUPPORT - select GENERIC_ARCH_TOPOLOGY if SMP + select GENERIC_ARCH_TOPOLOGY select GENERIC_ATOMIC64 if !64BIT select GENERIC_CLOCKEVENTS_BROADCAST if SMP select GENERIC_EARLY_IOREMAP 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..a8239b4b61f3 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,9 +164,9 @@ 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); set_cpu_online(curr_cpuid, 1); /* 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); +} -- 2.37.0