From patchwork Tue Nov 21 09:25:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yicong Yang X-Patchwork-Id: 167588 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp499963vqb; Tue, 21 Nov 2023 01:29:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IGjmSUGmwm69KmRqWsMeG7WUJV6t9f8J5XV9YNwrRDThN7FO+wWDSQdRG6T4Xfzpg4xEKWS X-Received: by 2002:a17:90a:d784:b0:285:3348:9fe3 with SMTP id z4-20020a17090ad78400b0028533489fe3mr3192606pju.7.1700558994118; Tue, 21 Nov 2023 01:29:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700558994; cv=none; d=google.com; s=arc-20160816; b=eTp2UcMlCLl/2vmzZEs1wtRDcaVFD3tN3iQ3SGrGQwGI3qe9WHA0LdW56pL7nWxYgZ WiMev3n+yTbDLaACFwP1H8gepLjC3brgS6YI9D+o8xSjftnsa7/tlLNlcP8J3uRlmqbP pEbcLn0DAXkSrlmEmxe+H5QQZB8hk9/RhnYC7Nd2nGcQ/DRdDicYST4dhOBlHkjZ90bS FeOCxsu7KhEuY52AKRg1g894DZ4low+YSEJECrEh6qOR0H2z/kQ6ZcE1z5tbWiWlNmda ICdRSFsqbLhEqvGK4Ip5Q2i2bdy6xitKhvC8QbxtlADy1S9qdusObalQR6PeTgjS8mHH jRnw== 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; bh=AvL8RO7AdImP5StM1+zIJjgLJOiwpdrw+v23ocyiNkc=; fh=3iB9MPM7gOV8iaw6nlpksJFY47xoJvfTkJIkOXUlBK4=; b=FREm5Tc65Uv3f197hWLZz0MBGtWw6UkTyg/enj/9G1VbljKx9DSrr3RAnwhfS1pDtV qI/ds43oNVDyEPw5Xs+PaQimDAq3AhwA+D1lVsGpeettW2P+ekgAvMWXn+2NMTkMF4Kv WkNAH926Six+/tvckUqfwqVDpw1pFd5z8zjK7RVsqjhl3vtpAGsf4EZDq0a0vtQ1NSNp nRmDHQgi9aKzE+rauJLbLbYeDoPpsGedk/xMH8mozhqmIzki6gIh8olYD/OZSX38kPl4 e9hZHx0d52mZRKHgN+zno/dWM5wciRPCJTEuZm0JLkbQa/TtOipxlPBqdWdpLYTHxhnj NXzg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id mq16-20020a17090b381000b0028098007c8csi13312566pjb.84.2023.11.21.01.29.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 01:29:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 158C780DFF56; Tue, 21 Nov 2023 01:29:53 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233695AbjKUJ3n (ORCPT + 99 others); Tue, 21 Nov 2023 04:29:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230371AbjKUJ3d (ORCPT ); Tue, 21 Nov 2023 04:29:33 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A197C121 for ; Tue, 21 Nov 2023 01:29:24 -0800 (PST) Received: from canpemm500009.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SZJrw0K7BzsRPH; Tue, 21 Nov 2023 17:25:52 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by canpemm500009.china.huawei.com (7.192.105.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 21 Nov 2023 17:29:19 +0800 From: Yicong Yang To: , , , CC: , , , , , , , Subject: [PATCH v4 1/4] arch_topology: Support basic SMT control for the driver Date: Tue, 21 Nov 2023 17:25:59 +0800 Message-ID: <20231121092602.47792-2-yangyicong@huawei.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20231121092602.47792-1-yangyicong@huawei.com> References: <20231121092602.47792-1-yangyicong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.165.33] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To canpemm500009.china.huawei.com (7.192.105.203) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 21 Nov 2023 01:29:53 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783165347822578161 X-GMAIL-MSGID: 1783165347822578161 From: Yicong Yang The core CPU control framework supports runtime SMT control which is not yet supported by arch_topology driver and thus arch_topology based architectures. This patch implements it in the following aspects: - implement topology_is_primary_thread() to indicate the primary thread, required by the framework - architecture code can get/set the SMT thread number by topology_smt_{get, set}_num_threads() - update the SMT thread number for the framework after the topology enumerated on arm64, which is also required by the framework For disabling SMT we'll offline all the secondary threads and only leave the primary thread. Since we don't have restriction for primary thread selection, the first thread is chosen as the primary thread in this implementation. This patch only implements the basic support for SMT control, which needs to collabrate with ACPI/OF based topology building to fully enable the feature. The SMT control will be enabled unless the correct SMT thread number is set and HOTPLUG_SMT kconfig is selected. Signed-off-by: Yicong Yang --- drivers/base/arch_topology.c | 38 +++++++++++++++++++++++++++++++++++ include/linux/arch_topology.h | 14 +++++++++++++ 2 files changed, 52 insertions(+) diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index b741b5ba82bd..3ed6bdf9460e 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -729,6 +729,36 @@ const struct cpumask *cpu_clustergroup_mask(int cpu) return &cpu_topology[cpu].cluster_sibling; } +#ifdef CONFIG_HOTPLUG_SMT + +/* Maximum threads number per-Core */ +static unsigned int topology_smt_num_threads = 1; + +void __init topology_smt_set_num_threads(unsigned int num_threads) +{ + topology_smt_num_threads = num_threads; +} + +unsigned int __init topology_smt_get_num_threads(void) +{ + return topology_smt_num_threads; +} + +/* + * On SMT Hotplug the primary thread of the SMT won't be disabled. For x86 they + * seem to have a primary thread for special purpose. For other arthitectures + * like arm64 there's no such restriction for a primary thread, so make the + * first thread in the SMT as the primary thread. + */ +bool topology_is_primary_thread(unsigned int cpu) +{ + if (cpu == cpumask_first(topology_sibling_cpumask(cpu))) + return true; + + return false; +} +#endif + void update_siblings_masks(unsigned int cpuid) { struct cpu_topology *cpu_topo, *cpuid_topo = &cpu_topology[cpuid]; @@ -841,6 +871,14 @@ void __init init_cpu_topology(void) reset_cpu_topology(); } + /* + * By this stage we get to know whether we support SMT or not, update + * the information for the core. We don't support + * CONFIG_SMT_NUM_THREADS_DYNAMIC so make the max_threads == num_threads. + */ + cpu_smt_set_num_threads(topology_smt_get_num_threads(), + topology_smt_get_num_threads()); + for_each_possible_cpu(cpu) { ret = fetch_cache_info(cpu); if (!ret) diff --git a/include/linux/arch_topology.h b/include/linux/arch_topology.h index a07b510e7dc5..0367f3a61838 100644 --- a/include/linux/arch_topology.h +++ b/include/linux/arch_topology.h @@ -92,6 +92,20 @@ void update_siblings_masks(unsigned int cpu); void remove_cpu_topology(unsigned int cpuid); void reset_cpu_topology(void); int parse_acpi_topology(void); + +#ifdef CONFIG_HOTPLUG_SMT +bool topology_is_primary_thread(unsigned int cpu); +void topology_smt_set_num_threads(unsigned int num_threads); +unsigned int topology_smt_get_num_threads(void); +#else +static inline bool topology_is_primary_thread(unsigned int cpu) { return false; } +static inline void topology_smt_set_num_threads(unsigned int num_threads) { } +static inline unsigned int topology_smt_get_num_threads(void) +{ + return 1; +} +#endif + #endif #endif /* _LINUX_ARCH_TOPOLOGY_H_ */