From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9894DCAC59A for ; Thu, 18 Sep 2025 09:24:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:MIME-Version:Date:Message-ID:From:References:To: Subject:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=9jnbqyXSA4Ctu9o0Xm560pR7SsN2PmvLG6tord0rwA4=; b=tI/gckIQuXoTSLApO+nRwTz9t8 QgxrRrAkyVe4vqsvRvs6/gdqQgsN0/qGEBlDdXH9RrvRh6kmbdP1l6xxUEMxp7vDccjtjMBeLjAZX Sq7vNSYdhrbnMM87QeeIo5YvfMswfOFtdOVnSIhlfhuGHZX/vwS7BOdZlq1lPjoBac4a0FfDe5I4G NgRS6ffUx5qvHEeO2PMPg8jRjAbmVLQFhfa4Jxn3VM0lHIeDS0jhmKliZI0PVHqYzGGZ61l7tg2i+ zjV7YLsbN8+6LZHE3WYq8PSME90dIbUuYdO4OmGvNXW+o0q0/rt0gDPiHOU2ra6ata1cEQa5Gyhlb bOa1Ix3A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1uzAro-0000000GrCV-0F20; Thu, 18 Sep 2025 09:23:52 +0000 Received: from szxga03-in.huawei.com ([45.249.212.189]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1uzArk-0000000Gr9m-1bDN for linux-arm-kernel@lists.infradead.org; Thu, 18 Sep 2025 09:23:50 +0000 Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4cS9764xnDzPtWM; Thu, 18 Sep 2025 17:18:58 +0800 (CST) Received: from dggemv712-chm.china.huawei.com (unknown [10.1.198.32]) by mail.maildlp.com (Postfix) with ESMTPS id ABAAB1800B4; Thu, 18 Sep 2025 17:23:34 +0800 (CST) Received: from kwepemq200018.china.huawei.com (7.202.195.108) by dggemv712-chm.china.huawei.com (10.1.198.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 18 Sep 2025 17:23:34 +0800 Received: from [10.67.121.177] (10.67.121.177) by kwepemq200018.china.huawei.com (7.202.195.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 18 Sep 2025 17:23:33 +0800 Subject: Re: [PATCH v2] arch_topology: move parse_acpi_topology() to common code To: Yunhui Cui , , , , , , , , , , , , References: <20250918014828.78383-1-cuiyunhui@bytedance.com> From: Yicong Yang Message-ID: <0020389a-676c-74ab-b68f-cd0a44538980@huawei.com> Date: Thu, 18 Sep 2025 17:23:33 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.5.1 MIME-Version: 1.0 In-Reply-To: <20250918014828.78383-1-cuiyunhui@bytedance.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.121.177] X-ClientProxiedBy: kwepems100001.china.huawei.com (7.221.188.238) To kwepemq200018.china.huawei.com (7.202.195.108) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250918_022348_738714_FD43E016 X-CRM114-Status: GOOD ( 25.05 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2025/9/18 9:48, Yunhui Cui wrote: > Currently, RISC-V lacks arch-specific registers for CPU topology > properties and must get them from ACPI. Thus, parse_acpi_topology() > is moved from arm64/ to drivers/ for RISC-V reuse. > > Signed-off-by: Yunhui Cui > --- > arch/arm64/kernel/topology.c | 87 +--------------------------------- > drivers/base/arch_topology.c | 89 ++++++++++++++++++++++++++++++++++- > include/linux/arch_topology.h | 1 + > 3 files changed, 90 insertions(+), 87 deletions(-) > > diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c > index 5d07ee85bdae4..55650db53b526 100644 > --- a/arch/arm64/kernel/topology.c > +++ b/arch/arm64/kernel/topology.c > @@ -26,7 +26,7 @@ > #include > > #ifdef CONFIG_ACPI > -static bool __init acpi_cpu_is_threaded(int cpu) > +bool __init acpi_cpu_is_threaded(int cpu) > { > int is_threaded = acpi_pptt_cpu_is_thread(cpu); > > @@ -39,91 +39,6 @@ static bool __init acpi_cpu_is_threaded(int cpu) > > return !!is_threaded; > } > - > -struct cpu_smt_info { > - unsigned int thread_num; > - int core_id; > -}; > - > -/* > - * Propagate the topology information of the processor_topology_node tree to the > - * cpu_topology array. > - */ > -int __init parse_acpi_topology(void) > -{ > - unsigned int max_smt_thread_num = 1; > - struct cpu_smt_info *entry; > - struct xarray hetero_cpu; > - unsigned long hetero_id; > - int cpu, topology_id; > - > - if (acpi_disabled) > - return 0; > - > - xa_init(&hetero_cpu); > - > - for_each_possible_cpu(cpu) { > - topology_id = find_acpi_cpu_topology(cpu, 0); > - if (topology_id < 0) > - return topology_id; > - > - if (acpi_cpu_is_threaded(cpu)) { > - cpu_topology[cpu].thread_id = topology_id; > - topology_id = find_acpi_cpu_topology(cpu, 1); > - cpu_topology[cpu].core_id = topology_id; > - > - /* > - * In the PPTT, CPUs below a node with the 'identical > - * implementation' flag have the same number of threads. > - * Count the number of threads for only one CPU (i.e. > - * one core_id) among those with the same hetero_id. > - * See the comment of find_acpi_cpu_topology_hetero_id() > - * for more details. > - * > - * One entry is created for each node having: > - * - the 'identical implementation' flag > - * - its parent not having the flag > - */ > - hetero_id = find_acpi_cpu_topology_hetero_id(cpu); > - entry = xa_load(&hetero_cpu, hetero_id); > - if (!entry) { > - entry = kzalloc(sizeof(*entry), GFP_KERNEL); > - WARN_ON_ONCE(!entry); > - > - if (entry) { > - entry->core_id = topology_id; > - entry->thread_num = 1; > - xa_store(&hetero_cpu, hetero_id, > - entry, GFP_KERNEL); > - } > - } else if (entry->core_id == topology_id) { > - entry->thread_num++; > - } > - } else { > - cpu_topology[cpu].thread_id = -1; > - cpu_topology[cpu].core_id = topology_id; > - } > - topology_id = find_acpi_cpu_topology_cluster(cpu); > - cpu_topology[cpu].cluster_id = topology_id; > - topology_id = find_acpi_cpu_topology_package(cpu); > - cpu_topology[cpu].package_id = topology_id; > - } > - > - /* > - * This is a short loop since the number of XArray elements is the > - * number of heterogeneous CPU clusters. On a homogeneous system > - * there's only one entry in the XArray. > - */ > - xa_for_each(&hetero_cpu, hetero_id, entry) { > - max_smt_thread_num = max(max_smt_thread_num, entry->thread_num); > - xa_erase(&hetero_cpu, hetero_id); > - kfree(entry); > - } > - > - cpu_smt_set_num_threads(max_smt_thread_num, max_smt_thread_num); > - xa_destroy(&hetero_cpu); > - return 0; > -} > #endif > > #ifdef CONFIG_ARM64_AMU_EXTN > diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c > index 1037169abb459..c22746b45d57a 100644 > --- a/drivers/base/arch_topology.c > +++ b/drivers/base/arch_topology.c > @@ -823,12 +823,99 @@ void remove_cpu_topology(unsigned int cpu) > clear_cpu_topology(cpu); > } > > +__weak bool __init acpi_cpu_is_threaded(int cpu) > +{ > + int is_threaded = acpi_pptt_cpu_is_thread(cpu); > + > + return !!is_threaded; > +} > + you seem to miss the comment here in v1. acpi_pptt_cpu_is_thread() may return -ENOENT, in which case the CPU shouldn't be threaded? thanks.