From patchwork Fri Jul 28 07:57:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 127476 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp315354vqg; Fri, 28 Jul 2023 02:48:04 -0700 (PDT) X-Google-Smtp-Source: APBJJlEOTivnqWAXTT4Ea1Ny6nsD5I/aOgy4BUjVXFRhRIL42ExNOB9B2fvrXMbDis9EGDA/fAxv X-Received: by 2002:a17:907:b09:b0:998:de72:4c89 with SMTP id h9-20020a1709070b0900b00998de724c89mr1699230ejl.50.1690537683818; Fri, 28 Jul 2023 02:48:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690537683; cv=none; d=google.com; s=arc-20160816; b=PJkQIXSyBQ6uS1NkKKcHNZnR+5jD4LRu/lPm1xfYPLjwqAlLozgjKOhJHI2k/3hrQD RF0cP8SI7BRanI3/kSeBQGsgdrNSRUXopZhzUExOr9QRjxk97GOSHrvAmazSuO7A8LDU yGo4StvKw2FFv0kvZRQ7TuMW323+SQtOV86lgv6CkJIVANyezZi7ggtRb/p37Rq9KKMD NeWZcq6I24Tu8dNT+zKw4B6WEDoNoaZfn5UclJ4VUptJaxtrNVaA/7QvCRSDub1isJF/ pykHOWfQ7wJZ+666DD9+HZFXdWRiHnxIVxAqILbNCp4SstLmkxo6H1m1MRAZ+gQ3e/0e /UlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=cSt15Rr+JQTNzb15gpi7pyOrqtr97YDY270BQfFkjWw=; fh=egciPyZMdA+j5ET/Kc4afIgStzzWWEvipSFeIUceJDc=; b=DcqIDk6R4VpOKaDQNpoOJhNJfpnw0MacxbUnlC1Srf4NriJU67tWCmGTxuerwHrDte YsSrXYA/80PBTvWtAKI+21s+5bbtvnblX5aMdNHylR/mw2v1Hk0uKHJxx37HTzYJc/A1 iouIYHUh2pQg6AYgrmC+HsbIB6OZKgrtRjkZdRf1dCf40p7dcOYUZazrtm+hvcNOpael mp3DZAzS9BJc3TAgjr/s612EE5plGTDyg+k+1jUxUsQdsNTb/8ih6BKQYg4eqDdiHJ07 XgZ6cEra64UJQyWs+kEElGF/s5+rgU5s8/G+5oa+e/uyk1eKsF4Ug9MqSVLCCy+f/X7J IFiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Kmyr3KI+; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="FV/f0ixm"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y20-20020a17090629d400b0099349f9c248si2458408eje.592.2023.07.28.02.47.39; Fri, 28 Jul 2023 02:48:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Kmyr3KI+; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="FV/f0ixm"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234593AbjG1H6U (ORCPT + 99 others); Fri, 28 Jul 2023 03:58:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234547AbjG1H55 (ORCPT ); Fri, 28 Jul 2023 03:57:57 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE8031BD6; Fri, 28 Jul 2023 00:57:55 -0700 (PDT) Date: Fri, 28 Jul 2023 07:57:53 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690531074; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cSt15Rr+JQTNzb15gpi7pyOrqtr97YDY270BQfFkjWw=; b=Kmyr3KI+i0LioI8zz4U/BVS5wjkNVtrgJTbyZeXEamHQ0QOzIBM/nnXvsYykbGnJWmaxD0 FGR3EPNRfgTT7wXfsLv7pKt9WzhAeXhzXH0k0+zHutORRMQUuQgu2Iq6t7/s7YREG7cHPy Tt1+E3eoaDwFWbKw5t45l9qXFm2F62R6K4O6oO8QRjJoTJqZaPyYq+ezM7Bg6tLMdbWW5v wcDSal8FC50CUmZOmg8DC2LJ56Y6e7wIXIn+r5wy+xTbOFgeiLUVIHfZlkDu+phC5g4vmR yM1dVDGdYddjNEH/oyZQ+e90wvRGTKt8PzKbY1c/0hnONHzf6CnLXzWIuZCDSA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690531074; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cSt15Rr+JQTNzb15gpi7pyOrqtr97YDY270BQfFkjWw=; b=FV/f0ixm09LwcGTimV9jk8htKdmg/E6pbauikN2ETIxBJ4PxqC0t4iBYnaedB1hhMsKPXk u0pxjnU6o4NwiZDw== From: "tip-bot2 for Michael Ellerman" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: smp/core] cpu/SMT: Create topology_smt_thread_allowed() Cc: Thomas Gleixner , Michael Ellerman , Laurent Dufour , Zhang Rui , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230705145143.40545-7-ldufour@linux.ibm.com> References: <20230705145143.40545-7-ldufour@linux.ibm.com> MIME-Version: 1.0 Message-ID: <169053107371.28540.17441460087624163045.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1770593532590721957 X-GMAIL-MSGID: 1772657242011046063 The following commit has been merged into the smp/core branch of tip: Commit-ID: 38253464bc821d6de6bba81bb1412ebb36f6cbd1 Gitweb: https://git.kernel.org/tip/38253464bc821d6de6bba81bb1412ebb36f6cbd1 Author: Michael Ellerman AuthorDate: Wed, 05 Jul 2023 16:51:39 +02:00 Committer: Thomas Gleixner CommitterDate: Fri, 28 Jul 2023 09:53:37 +02:00 cpu/SMT: Create topology_smt_thread_allowed() Some architectures allows partial SMT states, i.e. when not all SMT threads are brought online. To support that, add an architecture helper which checks whether a given CPU is allowed to be brought online depending on how many SMT threads are currently enabled. Since this is only applicable to architecture supporting partial SMT, only these architectures should select the new configuration variable CONFIG_SMT_NUM_THREADS_DYNAMIC. For the other architectures, not supporting the partial SMT states, there is no need to define topology_cpu_smt_allowed(), the generic code assumed that all the threads are allowed or only the primary ones. Call the helper from cpu_smt_enable(), and cpu_smt_allowed() when SMT is enabled, to check if the particular thread should be onlined. Notably, also call it from cpu_smt_disable() if CPU_SMT_ENABLED, to allow offlining some threads to move from a higher to lower number of threads online. [ ldufour: Slightly reword the commit's description ] [ ldufour: Introduce CONFIG_SMT_NUM_THREADS_DYNAMIC ] Suggested-by: Thomas Gleixner Signed-off-by: Michael Ellerman Signed-off-by: Laurent Dufour Signed-off-by: Thomas Gleixner Tested-by: Zhang Rui Link: https://lore.kernel.org/r/20230705145143.40545-7-ldufour@linux.ibm.com --- arch/Kconfig | 3 +++ kernel/cpu.c | 24 +++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/arch/Kconfig b/arch/Kconfig index aff2746..63c5d6a 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -34,6 +34,9 @@ config ARCH_HAS_SUBPAGE_FAULTS config HOTPLUG_SMT bool +config SMT_NUM_THREADS_DYNAMIC + bool + # Selected by HOTPLUG_CORE_SYNC_DEAD or HOTPLUG_CORE_SYNC_FULL config HOTPLUG_CORE_SYNC bool diff --git a/kernel/cpu.c b/kernel/cpu.c index 70add05..9a8d068 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -645,9 +645,23 @@ static int __init smt_cmdline_disable(char *str) } early_param("nosmt", smt_cmdline_disable); +/* + * For Archicture supporting partial SMT states check if the thread is allowed. + * Otherwise this has already been checked through cpu_smt_max_threads when + * setting the SMT level. + */ +static inline bool cpu_smt_thread_allowed(unsigned int cpu) +{ +#ifdef CONFIG_SMT_NUM_THREADS_DYNAMIC + return topology_smt_thread_allowed(cpu); +#else + return true; +#endif +} + static inline bool cpu_smt_allowed(unsigned int cpu) { - if (cpu_smt_control == CPU_SMT_ENABLED) + if (cpu_smt_control == CPU_SMT_ENABLED && cpu_smt_thread_allowed(cpu)) return true; if (topology_is_primary_thread(cpu)) @@ -2642,6 +2656,12 @@ int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval) for_each_online_cpu(cpu) { if (topology_is_primary_thread(cpu)) continue; + /* + * Disable can be called with CPU_SMT_ENABLED when changing + * from a higher to lower number of SMT threads per core. + */ + if (ctrlval == CPU_SMT_ENABLED && cpu_smt_thread_allowed(cpu)) + continue; ret = cpu_down_maps_locked(cpu, CPUHP_OFFLINE); if (ret) break; @@ -2676,6 +2696,8 @@ int cpuhp_smt_enable(void) /* Skip online CPUs and CPUs on offline nodes */ if (cpu_online(cpu) || !node_online(cpu_to_node(cpu))) continue; + if (!cpu_smt_thread_allowed(cpu)) + continue; ret = _cpu_up(cpu, 0, CPUHP_ONLINE); if (ret) break;