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_ */ From patchwork Tue Nov 14 04:01:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yicong Yang X-Patchwork-Id: 164716 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp1635251vqg; Mon, 13 Nov 2023 20:04:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IH48hVUeh7urIgAXKQmT03PRpGKwe/VVgShvxJ+L7jXvLg/SJzWfExQXaHtc0g2x4J4AjuO X-Received: by 2002:a17:902:ce86:b0:1b5:561a:5ca9 with SMTP id f6-20020a170902ce8600b001b5561a5ca9mr1373486plg.50.1699934694713; Mon, 13 Nov 2023 20:04:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699934694; cv=none; d=google.com; s=arc-20160816; b=L00wYUBxLZaYZeDcaQeOqsKU5XQjgSJprZkGPQp9vk1wGIGBSp/qWJsmC3xQXagkmq zbjXkC7RhumqYxRaWDkbIjfSjMn4q1enIVUr0AJY4WPFgz+nAfX+Kh5nv++xF/H4+zFr YDF39JMImu3PHi5+dQ9tMZRakjj2Lrksnx4l0iekk7eErbG7gfxCo4lxl0RA2aspBEcS vY9+UqdTQroJ1fsTsMReMCZVRHEEt/DTenC5jbqjPVPJ2VH09+NPE2ZbfTyvnQmzXxeW JTUX4VrDBGV5QR8jxAKvJXzLMpOKpXo1mAjaYB2R8GZ2PSjvvkmZE930jacQvhrHEyeT QIfA== 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=WjBoSnpqWtcUTQYzGtIORvr3hpAK9wwFtnX7rP/srwg=; fh=3iB9MPM7gOV8iaw6nlpksJFY47xoJvfTkJIkOXUlBK4=; b=0MrJNkAWvCpEmKJXTRoP2J2CFaI1epXEqRqxFz0rhtI7BCexsY8mFNhdIDBqvySARt xyquxEooy9eiyxoRH7bwtJ/T5iMhMUvu42P9oIYURr4QIBRQOwEuX6/7ofe+wDOlVpb9 U5ui5oBU+ioY23fvtmv3TTRzvGNRX6IjewTvOIZOMnw3w22lhqLBbC29DJd8ng6UMAZJ NAfxJLBlZpoaz+1fePWIma7jNjhje3G1JB3bG3YcWMr68Nn+YyL5anuRlmSwY6YlZIni 0Z1gg9XHxhGwaZD4+xPyASvjLC5+8mUVphIeftkpIft32brfZCWicgfSlNV+qONrXHZ3 lpTA== 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:5 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. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id d17-20020a170902ced100b001c8944c933dsi7378750plg.380.2023.11.13.20.04.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Nov 2023 20:04:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 DBD3F80530D7; Mon, 13 Nov 2023 20:04:43 -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 S231888AbjKNEEc (ORCPT + 30 others); Mon, 13 Nov 2023 23:04:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229645AbjKNEEa (ORCPT ); Mon, 13 Nov 2023 23:04:30 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BECCD43 for ; Mon, 13 Nov 2023 20:04:26 -0800 (PST) Received: from canpemm500009.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4STszQ0Bd9z1P8JP; Tue, 14 Nov 2023 12:01:06 +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 2/4] arch_topology: Support SMT control for OF based system Date: Tue, 14 Nov 2023 12:01:08 +0800 Message-ID: <20231114040110.54590-3-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:04:44 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782510722572566644 X-GMAIL-MSGID: 1782510722572566644 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 7fb91f41d66d..02dc0266cbac 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -529,6 +529,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_num_threads) + topology_smt_set_num_threads(i); + cpu = get_cpu_for_node(core); if (cpu >= 0) { if (!leaf) { From patchwork Tue Nov 14 04:01:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yicong Yang X-Patchwork-Id: 164717 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp1635295vqg; Mon, 13 Nov 2023 20:05:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IFaZAaHmUQrisUN9uc9crawvcYugt3m3GauFUNFSOSd8QgrQkzsB0rNi5//Kj6+cYAm2CJp X-Received: by 2002:a05:6870:fb87:b0:1e9:bd5c:ae40 with SMTP id kv7-20020a056870fb8700b001e9bd5cae40mr11896218oab.38.1699934700484; Mon, 13 Nov 2023 20:05:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699934700; cv=none; d=google.com; s=arc-20160816; b=yYLvX2qKqLv28jIjIKAhHRXextn8iwdgvJ2QD32G8SSDAYSmzYUWyQfW1iRQISQCEJ WFnEhJVV99O+DjDQq7HxU4P39VFkLZIMThYFKn0jkfWzhLZZUC/sRII3541UBELH9kkB CQOJsi6m1HZ2UyEpv/is0sGlL5KQbKr4s4wpaJiyA4Wl+axQu3KPV8GqxX3UPnQm4DM0 WENqa8vq0Ho8R5xU4O8a1UnvtFF+PD+sRt1rsnAOU9Wes+OJ1GdxoJXoodHbKj163AXB 4uNJ7IT36hEAIp6YW/soWqq+F60Q2bxpnkDMm2F5QWGa6nvyVkLbcw725peO7Nnd+yRl BokQ== 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=sj73GfBXe/BwMfpQHDa6N0NmBrbO1mzMKorLkWovCHTOL6LgPYWeeVAg/Fi5c4uus2 azkYmtg212IycsQ9X6Bsf6TDRyPzgdLqf+gWauf8QYR68JhUy8WP7APJ6pZUyO/53d/N EFRBakqmACQf1duNZIjD29IDr1wSnKw9H4xDDeUhGxBwFmPsJsaA8p/OSR3pu9MjCqgx gw6bMs99zhRdUPyxyjTPO17mPME4T09wYlAq3tWr3RoaHn/cXe6kv8nlWq34DFmZRlSw W3J+Pu5/Tbj0LBaIG2xylbYY117RKa0p6velG/jrUBPIc6KKLv1ExO7YI7BQyfXa66MG qRSg== 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 c1-20020aa78e01000000b006bf2e5f0841si6786409pfr.393.2023.11.13.20.05.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Nov 2023 20:05:00 -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 91DE780236DB; Mon, 13 Nov 2023 20:04:59 -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 S232047AbjKNEEo (ORCPT + 30 others); Mon, 13 Nov 2023 23:04:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229708AbjKNEEb (ORCPT ); Mon, 13 Nov 2023 23:04:31 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C590D45 for ; Mon, 13 Nov 2023 20:04:26 -0800 (PST) Received: from canpemm500009.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4STt2x0HVNzvQh4; Tue, 14 Nov 2023 12:04:09 +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:24 +0800 From: Yicong Yang To: , , , CC: , , , , , , , Subject: [PATCH v3 3/4] arm64: topology: Support SMT control on ACPI based system Date: Tue, 14 Nov 2023 12:01:09 +0800 Message-ID: <20231114040110.54590-4-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=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,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]); Mon, 13 Nov 2023 20:04:59 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782510728047522932 X-GMAIL-MSGID: 1782510728047522932 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 14 04:01:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yicong Yang X-Patchwork-Id: 164718 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp1635328vqg; Mon, 13 Nov 2023 20:05:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IF155YlDgsnAd+AwsSGh4a3DHRPb2NPDsr5yaz3L54n6fdcweLCEtEdSS5XBZ7462A5Xteh X-Received: by 2002:a17:90b:4a0f:b0:283:551b:bd95 with SMTP id kk15-20020a17090b4a0f00b00283551bbd95mr2906449pjb.13.1699934706454; Mon, 13 Nov 2023 20:05:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699934706; cv=none; d=google.com; s=arc-20160816; b=bHLo8T8KXGJPyFg5EX4OQ1t/GJxwzEu42X72FNeiBly1I2YQmHWjBHaN16SNopa8fr 75jAaMwp1lX4OR9F8iCVGS4+XEVFPaOL0TMgyg38ZZ2O3pCsmiQHiIsICoIXXnDM+vLn WQ3X6Pr4TEl8XDxMWK2VkC7M+XRgXeKqt4zbqWgb3JmTe023T6hKAWLdfG12YuIEoPM5 tUQqe9SP9aPfNMwf0BiXOoQ3kQ3wOShNjJBsDZ6vWa+ejU7jnJzPqy8r2bu/JJ8UcvU1 eTW0KGNLsFwlQRE+HH5OBlVi/RdH1gH1VOAwgCHKfJCZVdrbWqxw8aatRrVeqtIhTDJ0 XQaw== 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=OJ6IU2rp/j9zsTENmN84SYKsNmexyuQX+AHJQ+tsIjU=; fh=3iB9MPM7gOV8iaw6nlpksJFY47xoJvfTkJIkOXUlBK4=; b=VUXL9gX39ToRRaYRq2whdvZsy/BIkIMaF0HaeBuxHr26a7ARdKhMxEJlxpiAj8xA3K U23LqA6Hezu+RUA40d+LgTzAST4V40obtq79Kkxutlja6i91VvD7VeTI4xJHemlIaA/w jj9YQpUrHvSadBicehH4MtzNj6rtKJ5vHp1tjVwuhdZiQuMlQLwaq6c2lReTqOBCzQY0 W0MS/sEGXaY4XCKyezXQboe2np6n+wQOVVfzy6eqk9fsqdskEdceA2VPEZZ1vKyBWSV/ VJUPCKdaL8mk38Csfo0kZ17HsMc8vZIkdcGOyI8394sZmTmQr6LLNe7QEuMScpays0cD cPig== 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 z11-20020a17090acb0b00b0028054d20dadsi11780240pjt.95.2023.11.13.20.05.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Nov 2023 20:05:06 -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 5C30D809E8E6; Mon, 13 Nov 2023 20:05:04 -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 S232008AbjKNEEl (ORCPT + 30 others); Mon, 13 Nov 2023 23:04:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229742AbjKNEEb (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 6C11DD44 for ; Mon, 13 Nov 2023 20:04:26 -0800 (PST) Received: from canpemm500009.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4STsxx6GSyzMmPP; 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:24 +0800 From: Yicong Yang To: , , , CC: , , , , , , , Subject: [PATCH v3 4/4] arm64: Kconfig: Enable HOTPLUG_SMT Date: Tue, 14 Nov 2023 12:01:10 +0800 Message-ID: <20231114040110.54590-5-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 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]); Mon, 13 Nov 2023 20:05:04 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782510734485603816 X-GMAIL-MSGID: 1782510734485603816 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..002bcde32575 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 select IRQ_DOMAIN select IRQ_FORCED_THREADING select KASAN_VMALLOC if KASAN