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_ */ From patchwork Tue Nov 21 09:26:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yicong Yang X-Patchwork-Id: 167587 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp499949vqb; Tue, 21 Nov 2023 01:29:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IGJ9JfaqqmDzKAqN2/K9NEGEwb4lpTjm3rDGVa/PXFQw1JehNHkF6lZ8yladxaSKOykpR9H X-Received: by 2002:a05:6359:630e:b0:16d:f46f:16a9 with SMTP id sf14-20020a056359630e00b0016df46f16a9mr37625rwb.17.1700558991863; Tue, 21 Nov 2023 01:29:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700558991; cv=none; d=google.com; s=arc-20160816; b=CcFdb1yVjcQRWD/IjyeSSbzqEwcuZ4R8EaajSuMH7u/6hVpiInvv55SK+g0sXVkAN6 A1U0hNBqMa8gZXwGGsZSLb+Tw9i37fMkUhNovjHF5yjtZM+1zBEh+srOdt4thc3QlnKz mPjuF5kRv+mmm7RQ8OvqsNIR5lDC+duFy+tVDH3lD1IhdIjzkPXNhyt+xdKQGrbn+c26 vbtDPJ2Ol5aVqXE8g1id8otQFGPt5dprZ/gb6oI/IPLNYd9EAER3qYmotpyNT10Jd/U8 EK45H4RRH19G4shG9KkUMe4z8r5dt/kLQghGcNF/u7q9/pU2/GX4w+qOPOdLW1+pHrY6 flKA== 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=eyUMLXsoIuhkBPshhbJZuVrOlIB+AoZQP17LzzWJ2aM=; fh=3iB9MPM7gOV8iaw6nlpksJFY47xoJvfTkJIkOXUlBK4=; b=TZxtygPltaJHefG3g1Aelee3uTAwx4hDe6lMfktgAESvOMlvIxlSovVP7Sx0LTTz9f GoD98mwFTMttiJLNXVVCiSvFn/DoHn/e850PEeh+S9IXmmrhDDU8LcW8PmymxnlVQAds Y2qpkSxkn32iV4VR4ZEk0N9W3r/PrmkomJxjEY4Ckb6mEx6d6GEzGl3F1cmuYq7qk+is Hm+oFV7OP997a6x0zT4zFNWpdDYUEFiVzM2CRs8FCB7AzAJmKu/KEdsZ8QBqxN0mDN85 WdVzFuOw1PyC9Yfd95Fm/w614b3Wial2nxcPOZ+XIVu9QTXejoCcozUWt3hLVNF9p+vV GJKg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id n186-20020a6327c3000000b005b8f24e6526si9969668pgn.234.2023.11.21.01.29.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 01:29:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 63A0C80E73C4; Tue, 21 Nov 2023 01:29:50 -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 S233622AbjKUJ3k (ORCPT + 99 others); Tue, 21 Nov 2023 04:29:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232257AbjKUJ3c (ORCPT ); Tue, 21 Nov 2023 04:29:32 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4929123 for ; Tue, 21 Nov 2023 01:29:24 -0800 (PST) Received: from canpemm500009.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4SZJrw6gJ3z1P8k5; 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:20 +0800 From: Yicong Yang To: , , , CC: , , , , , , , Subject: [PATCH v4 2/4] arch_topology: Support SMT control for OF based system Date: Tue, 21 Nov 2023 17:26:00 +0800 Message-ID: <20231121092602.47792-3-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:50 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783165345089470630 X-GMAIL-MSGID: 1783165345089470630 From: Yicong Yang On building the topology from the devicetree, we've already gotten the SMT thread number of each core. Update the largest SMT thread number to enable the SMT control. Signed-off-by: Yicong Yang --- drivers/base/arch_topology.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index 3ed6bdf9460e..252a436e0c1b 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -526,6 +526,13 @@ static int __init parse_core(struct device_node *core, int package_id, i++; } while (t); + /* + * We've already gotten threads number in this core, update the SMT + * threads number when necessary. + */ + if (i > topology_smt_get_num_threads()) + topology_smt_set_num_threads(i); + cpu = get_cpu_for_node(core); if (cpu >= 0) { if (!leaf) { From patchwork Tue Nov 21 09:26:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yicong Yang X-Patchwork-Id: 167586 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp499921vqb; Tue, 21 Nov 2023 01:29:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IGw3+BNCTiAZjGWtSqQgpGbZt+AZ3yP01eKRj/jsfSc+otlkTt5gAZCK32xcn3WAyB8RqI8 X-Received: by 2002:a9d:7851:0:b0:6c6:4843:2abc with SMTP id c17-20020a9d7851000000b006c648432abcmr11474766otm.18.1700558988076; Tue, 21 Nov 2023 01:29:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700558988; cv=none; d=google.com; s=arc-20160816; b=kxOykASNf8AY8htOwkKJhQZR9Fv1Evi5IJxKEeHIseYypTDWgSL5WDjCmEor6j6RyV tQ+Wpdm9O4eac4+c+I7c7C6fc46CgEzZObNxnF4OZE+4Z332d8+MM4MeG0PvOIBRYJgQ 51cL/+0wuYSslVILYPJQXuUuIEf5PmUg62V0xxqrF6doTRQLZxur3wiHecibsyXiGkTu +P6rZxydAGjfHrZRoehSqmoxw+jYleA5FG995a4613bSdeb03k5QPABhshazc6TxwkzJ Gj1TZBECv2wiIclx036h9WgtuPsImKx3ks46JxiJ1LN4a2f0TOXuyl8KYyNAc7CAmWeR EQYg== 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=qdn/c2ldV6pRMP6ABZUKaVNPGYAjT0cccb5LyUh6pmw=; fh=3iB9MPM7gOV8iaw6nlpksJFY47xoJvfTkJIkOXUlBK4=; b=ooVkvWoLAqTviRB16ENYz4ycR/46KIHCPK1n9B3RJJ6BJz9yPziEOmfKUowAmXK1Sp w6DQgIUrpDe9Q+Q2WGl0VkuviNekmmBinA3tmDr4l0mnLdwHpDNVJXq76BEqOHIZZgt6 5mPTRnDMUoE9xRYmGi4WQTXwA9szjGOQkNjHUTeRVNH/X1mdCNJ5UTd4WdOfeTNgkn0T //asuy/QwSmNr2AtW/HtcbMCdE3ZOfawqXUqzY9i7IGQO5Jmmln23WYKr279cStAb9tt 78xL2wQGIA7KyyHtCP+ZYbHVe9egYpw4xbxq+8Ou+Fs+iVwkyXYgzlZOIKTI+pT3g35D TrMA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id g16-20020a635650000000b005b861478b70si9741616pgm.341.2023.11.21.01.29.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 01:29:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id DCCD480CCDA7; Tue, 21 Nov 2023 01:29:38 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232600AbjKUJ3f (ORCPT + 99 others); Tue, 21 Nov 2023 04:29:35 -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 S232033AbjKUJ3c (ORCPT ); Tue, 21 Nov 2023 04:29:32 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3DFF122 for ; Tue, 21 Nov 2023 01:29:24 -0800 (PST) Received: from canpemm500009.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SZJwT4GGSzvQwK; Tue, 21 Nov 2023 17:28:57 +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:20 +0800 From: Yicong Yang To: , , , CC: , , , , , , , Subject: [PATCH v4 3/4] arm64: topology: Support SMT control on ACPI based system Date: Tue, 21 Nov 2023 17:26:01 +0800 Message-ID: <20231121092602.47792-4-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=-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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Tue, 21 Nov 2023 01:29:39 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783165341242862071 X-GMAIL-MSGID: 1783165341242862071 From: Yicong Yang For ACPI we'll build the topology from PPTT and we cannot directly get the SMT number of each core. Instead using a temporary xarray to record the SMT number of each core when building the topology and we can know the largest SMT number in the system. Then we can notify the arch_topology for supporting SMT control. Signed-off-by: Yicong Yang --- arch/arm64/kernel/topology.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c index 817d788cd866..0dc360c32ec8 100644 --- a/arch/arm64/kernel/topology.c +++ b/arch/arm64/kernel/topology.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -43,11 +44,16 @@ static bool __init acpi_cpu_is_threaded(int cpu) */ int __init parse_acpi_topology(void) { + int thread_num, max_smt_thread_num = 1; + struct xarray core_threads; int cpu, topology_id; + void *entry; if (acpi_disabled) return 0; + xa_init(&core_threads); + for_each_possible_cpu(cpu) { topology_id = find_acpi_cpu_topology(cpu, 0); if (topology_id < 0) @@ -57,6 +63,20 @@ int __init parse_acpi_topology(void) cpu_topology[cpu].thread_id = topology_id; topology_id = find_acpi_cpu_topology(cpu, 1); cpu_topology[cpu].core_id = topology_id; + + entry = xa_load(&core_threads, topology_id); + if (!entry) { + xa_store(&core_threads, topology_id, + xa_mk_value(1), GFP_KERNEL); + } else { + thread_num = xa_to_value(entry); + thread_num++; + xa_store(&core_threads, topology_id, + xa_mk_value(thread_num), GFP_KERNEL); + + if (thread_num > max_smt_thread_num) + max_smt_thread_num = thread_num; + } } else { cpu_topology[cpu].thread_id = -1; cpu_topology[cpu].core_id = topology_id; @@ -67,6 +87,9 @@ int __init parse_acpi_topology(void) cpu_topology[cpu].package_id = topology_id; } + topology_smt_set_num_threads(max_smt_thread_num); + + xa_destroy(&core_threads); return 0; } #endif From patchwork Tue Nov 21 09:26:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yicong Yang X-Patchwork-Id: 167585 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp499854vqb; Tue, 21 Nov 2023 01:29:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IHwHTESBUEzQH7Qy5xwPWEL5aIiZCn4BlOvGhiUvZ13sT60/ivm2n9sEdp6tM8fHC2IBV0c X-Received: by 2002:a05:6808:302a:b0:3a7:8f94:743a with SMTP id ay42-20020a056808302a00b003a78f94743amr13010882oib.10.1700558977420; Tue, 21 Nov 2023 01:29:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700558977; cv=none; d=google.com; s=arc-20160816; b=sP7na/EDfOahDHY86auoy/dy1rmLv96XfPjOGW89Kd7ZsiZm/T4JAnrkTq/Q4oD845 Njk+b0GWt/6BEH2dGeNLUbzKTP8/WghtKaYF3IeitMwVNaoxcbMW5hQxg6yk75aqb+ZV tMtnttdKZpwX0z1X2RI/jg+H5fVUZS09l7Ednm2RuWRfhn0NPBVceTu5UmejvTPC7MKK ZqHwCB7fYa75rEsDQP6kO4zuv1mgmfcBK4Jkc8hlTHor2MDp2fm62WxQzOmrwXQCkuBE WR3ECYIoamxNNYaTnOhM/7qBeWZB+Lb6D9pgBzoKBeEHs8H0SrfI11i0CCknkNMOQhRu EDrw== 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=xi5q7GySyYvE5kX2pNz1QQ2a129qDFSB/K0qNl1GHcc=; fh=3iB9MPM7gOV8iaw6nlpksJFY47xoJvfTkJIkOXUlBK4=; b=QXnS++PlxWqNEdtnHVGZUhbw2Arppb4STyWRR3z6zTy63quAhW87xrQLuZ5OCUA51s p0X6zUPjX3Sp9p6YZui1i1KDpvXsZN0TVyFL4zz04RBJCGBeiVinfb5k5kxmKEErZNpA LzX7v/fkVhs7W8KQtri1PJl6vERixphfea01q1o6VN6U/uXaI4jwNIAfPyQGkt3Ro8FC lD6hMArOUgu7DmbaRlb3MX60kpXx7sKJ2CXHHeFIUfhNvDPXFfFqdYwsFXF/19DobSJA ldplbizLP4zG49N9Hd/IBkVOGnWzl1SGcBGFfgICeCloqpIKAoXPK37B9qncTXEPo8l4 6k6w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id 31-20020a63105f000000b005b882238681si10052572pgq.620.2023.11.21.01.29.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 01:29:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id 443158098AE5; Tue, 21 Nov 2023 01:29:32 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231961AbjKUJ3d (ORCPT + 99 others); Tue, 21 Nov 2023 04:29:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232222AbjKUJ3c (ORCPT ); Tue, 21 Nov 2023 04:29:32 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A590E124 for ; Tue, 21 Nov 2023 01:29:24 -0800 (PST) Received: from canpemm500009.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SZJwJ66JjzWhfF; Tue, 21 Nov 2023 17:28:48 +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:20 +0800 From: Yicong Yang To: , , , CC: , , , , , , , Subject: [PATCH v4 4/4] arm64: Kconfig: Enable HOTPLUG_SMT Date: Tue, 21 Nov 2023 17:26:02 +0800 Message-ID: <20231121092602.47792-5-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=-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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Tue, 21 Nov 2023 01:29:32 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783165330245424975 X-GMAIL-MSGID: 1783165330245424975 From: Yicong Yang Enable HOTPLUG_SMT for SMT control. Signed-off-by: Yicong Yang --- arch/arm64/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 7b071a00425d..9f3f4efc0375 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -233,6 +233,7 @@ config ARM64 select HAVE_KRETPROBES select HAVE_GENERIC_VDSO select HOTPLUG_CORE_SYNC_DEAD if HOTPLUG_CPU + select HOTPLUG_SMT if (SMP && HOTPLUG_CPU) select IRQ_DOMAIN select IRQ_FORCED_THREADING select KASAN_VMALLOC if KASAN