From patchwork Tue Nov 14 04:01:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yicong Yang X-Patchwork-Id: 164719 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp1635406vqg; Mon, 13 Nov 2023 20:05:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IGqB6DJK+ctLlPx7eESTlRIqAeerrzLDmVj499ULlSw0Gz8/oRUm2vbVht3OxAPeO4VYSXa X-Received: by 2002:a17:902:c382:b0:1cc:32df:40e7 with SMTP id g2-20020a170902c38200b001cc32df40e7mr1259547plg.66.1699934719005; Mon, 13 Nov 2023 20:05:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699934718; cv=none; d=google.com; s=arc-20160816; b=bmvDO/7PpxFI+VYBvX217LcDxhHWBfUgnkAKnn5q9qd66LKKUx/rnttQe8pZzBMk4P 0Lg3G505bCs0TrrqIuK4Aty2GJ/LE96hfHytn+7TovrFbJGoLSskF82xVwHe1DMLoL1A PduPJZZC6J4kmEIFbc78ZwHfbORdIy/kia0OFJaS5X89e69aSBO0jxvc2kyIjlWYT8Ni 4GPajuYxlEG2zh2OVO30cSlf3EgvfcsCcXyLaUbfLqbGGUUwjZnhB+AwxEa0QP1k5B9I YFQ9Vc6T/29Ulzpu94O8GKRhwK7oBrYh0CgJ67L6beHxVLP1gYI/plTHq8Zq4xvandRI 2YEA== 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=2/uqxDbOpDTsZoGrmDDCAMfB1YMp6HcCqb9OvtQA5MA=; fh=3iB9MPM7gOV8iaw6nlpksJFY47xoJvfTkJIkOXUlBK4=; b=WBv40+LaQbXDMFcLQLz+NgMe/7WaUYzr69f1gtB2IQdGc46Tl+FokmQIMZZqa1By16 JNhvmSdX4dekds454GXPpkoo5L9d3QyAG3dvWvX2rTCkQ/W/5VBvqOukACSNZS5tG7Rp S8IMvUgB7ql7pUATtKE5DAc8W20Oj4id30kWMLFg7m1BZCuPM6fgEcGSvCp7U7GMOIxN TWIEJOUnEuyiq1bfexoDQMsiT0Ic5t0tUAcC8rbVhWIkATe2qSN2Duruvv1LgW0cHUQq O58Pt2grdPcpGZS3PGAuBHcyY1P8SrVqIY+eqbLTNksQ8zhEksEJTiqBDSuh1cVcc/Gi rMyA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id jk6-20020a170903330600b001b811261289si6505407plb.482.2023.11.13.20.05.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Nov 2023 20:05:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 8B7928053FAE; Mon, 13 Nov 2023 20:05:12 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231976AbjKNEEh (ORCPT + 30 others); Mon, 13 Nov 2023 23:04:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231514AbjKNEEb (ORCPT ); Mon, 13 Nov 2023 23:04:31 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5896B1A7 for ; Mon, 13 Nov 2023 20:04:25 -0800 (PST) Received: from canpemm500009.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4STsxx1hqkzMml7; Tue, 14 Nov 2023 11:59:49 +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.31; Tue, 14 Nov 2023 12:04:23 +0800 From: Yicong Yang To: , , , CC: , , , , , , , Subject: [PATCH v3 1/4] arch_topology: Support basic SMT control for the driver Date: Tue, 14 Nov 2023 12:01:07 +0800 Message-ID: <20231114040110.54590-2-yangyicong@huawei.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20231114040110.54590-1-yangyicong@huawei.com> References: <20231114040110.54590-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=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email 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 (groat.vger.email [0.0.0.0]); Mon, 13 Nov 2023 20:05:12 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782510748357447302 X-GMAIL-MSGID: 1782510748357447302 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 - record the allowed setting of SMT thread number by topology_smt_set_num_threads() - update the SMT thread number for the framework after the topology enumerated on arm64 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 | 32 ++++++++++++++++++++++++++++++++ include/linux/arch_topology.h | 9 +++++++++ 2 files changed, 41 insertions(+) diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index b741b5ba82bd..7fb91f41d66d 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -28,6 +28,9 @@ static struct cpumask scale_freq_counters_mask; static bool scale_freq_invariant; static DEFINE_PER_CPU(u32, freq_factor) = 1; +/* Maximum threads number per-Core */ +static int topology_smt_num_threads = 1; + static bool supports_scale_freq_counters(const struct cpumask *cpus) { return cpumask_subset(cpus, &scale_freq_counters_mask); @@ -729,6 +732,28 @@ const struct cpumask *cpu_clustergroup_mask(int cpu) return &cpu_topology[cpu].cluster_sibling; } +#ifdef CONFIG_HOTPLUG_SMT + +void __init topology_smt_set_num_threads(unsigned int num_threads) +{ + topology_smt_num_threads = 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 +866,13 @@ 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_num_threads, topology_smt_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..574942a12ae1 100644 --- a/include/linux/arch_topology.h +++ b/include/linux/arch_topology.h @@ -92,6 +92,15 @@ 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); +#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) { } +#endif + #endif #endif /* _LINUX_ARCH_TOPOLOGY_H_ */