Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp20856516rwd; Thu, 29 Jun 2023 07:52:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5pUGlqgBwYR04wWXB/13agZldOnhII7IUAYN6AHN9Mkc+nlEGvdoEiKHWmMsGy3KBvj33I X-Received: by 2002:a17:90b:2352:b0:262:db59:3e29 with SMTP id ms18-20020a17090b235200b00262db593e29mr10503860pjb.34.1688050349607; Thu, 29 Jun 2023 07:52:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688050349; cv=none; d=google.com; s=arc-20160816; b=ayW5qUI6tRm9Oos0uCDbRjf2fzQ6CxcmcLgHbKs4VxIBAnwBM3JpyRSE3P4NAOJfM/ ObMuPNh3a0W9VjMAoO+6NmiefRnCyUZ5rnlwU37FUhI+GiCvxjuyLDxtCLxo1Yw+CIl9 XWSMEscFN7kM21W1bQuvs3/QqsQ14hY0vZaPC/QGSmSZcapbQBx1aIfmWoXefRTvyNL4 gArGphO45wFeoE4JjRI2n/VDed+BfO5DJa6jMVFoY1tOmmLSHtYULjOeqBj2j0rSwGbl 4NQcRgrtHmYhcnNUPS4MBtVOOEzCsz4jHdBeHHn6QxxompDyaT2O3uc7kB5clppcvDp2 LrQQ== 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 :dkim-signature; bh=ab3NqT1eN5qPIMRWWy0PIsxg+fHYQaOZWEASX1j+nMY=; fh=8cYd2FlVZORVk636/TRZSjcpEkmtW92vhqoVMGOqVio=; b=tc5T/CghlQHliFpZQ49Os2d5xYJ0/6QpqG0nVfxl8n2PM0ODEWEj+NZ1IBaDHVLW7c bxkBwTDB9rwimKbqKjyoJd8qaKQL4HT8p2Gi7uvI8DlCnhJTpEILRXhApXWD9ePyTSfj Z50aemKr1aouWuw7u7cLZegb/9W/HXFltAbn3OxiF9giPAtrxVLQOc/+04Etbdu0pjtI yZqEfrIHTMg0Td5XSJDwXAPNqIsLYRCnoH3+NNYEvoR+GI3KQUWL/DmPCTmp+hB7+vte b3SYjH5yc6B20nCpa5T9jdaYblrcfdplt/1LJTyJEz369XBdQg8sWmohra4M7KEHtSfP xm+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=ckrljgCz; 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=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pf12-20020a17090b1d8c00b002501d633225si13965189pjb.11.2023.06.29.07.52.17; Thu, 29 Jun 2023 07:52:29 -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=@ibm.com header.s=pp1 header.b=ckrljgCz; 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=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232754AbjF2Oej (ORCPT + 99 others); Thu, 29 Jun 2023 10:34:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232504AbjF2OeC (ORCPT ); Thu, 29 Jun 2023 10:34:02 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AA1D2D71; Thu, 29 Jun 2023 07:33:35 -0700 (PDT) Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35TEM2n8020137; Thu, 29 Jun 2023 14:33:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=ab3NqT1eN5qPIMRWWy0PIsxg+fHYQaOZWEASX1j+nMY=; b=ckrljgCzpntj6bclNufa9IDNoWirAuAqR9uSrm6eVQGap39BZf0wqD9JHtytrIM6Bw1G sAayz9nmKH+LJIgWWr8K8ilhZII4AgI+wqG24oJhdQsRNHhsFh3UP4fCFT0djTMmEYsK wp92+7PvyRsRTGM8uy51DHOkpJN3U/3BYjDMh6+ZxvUbIOOTIXqKN9bLN0iK9ZBD5IBt CvzAJ5Hldz24voSz+iZWa89HKLJYLav7yMupxzMSNoP5O10J6AX8ZqKLFoqygo/0SFkV qqgFrLEYmt+u3CabVtjS53cAhPrtG5ChHQ9i6jo+lotUurRMYZKsRmsmWvi6mRekbhQ2 2A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rhbnbg96d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 29 Jun 2023 14:33:20 +0000 Received: from m0353729.ppops.net (m0353729.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 35TENJD5025668; Thu, 29 Jun 2023 14:33:13 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rhbnbg8ck-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 29 Jun 2023 14:33:13 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35TBTiQq016288; Thu, 29 Jun 2023 14:31:56 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma04ams.nl.ibm.com (PPS) with ESMTPS id 3rdr453d0p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 29 Jun 2023 14:31:56 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35TEVsB956230302 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 29 Jun 2023 14:31:54 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1C78820040; Thu, 29 Jun 2023 14:31:54 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A44EE2004D; Thu, 29 Jun 2023 14:31:53 +0000 (GMT) Received: from pomme.tlslab.ibm.com (unknown [9.101.4.33]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 29 Jun 2023 14:31:53 +0000 (GMT) From: Laurent Dufour To: linuxppc-dev@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, mpe@ellerman.id.au, npiggin@gmail.com, christophe.leroy@csgroup.eu, tglx@linutronix.de, dave.hansen@linux.intel.com, mingo@redhat.com, bp@alien8.de Subject: [PATCH v3 5/9] cpu/SMT: Create topology_smt_thread_allowed() Date: Thu, 29 Jun 2023 16:31:45 +0200 Message-ID: <20230629143149.79073-6-ldufour@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230629143149.79073-1-ldufour@linux.ibm.com> References: <20230629143149.79073-1-ldufour@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: KxcTcGvIZ6tUIcw1cIql_noGNEavi-_1 X-Proofpoint-ORIG-GUID: BOffcTQBVUqthzI7--mnQjyWUSJhlr7R X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-29_03,2023-06-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 impostorscore=0 phishscore=0 mlxlogscore=999 lowpriorityscore=0 spamscore=0 bulkscore=0 adultscore=0 clxscore=1015 priorityscore=1501 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306290132 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,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 From: Michael Ellerman Some architectures allows partial SMT states, ie. 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. Signed-off-by: Michael Ellerman Suggested-by: Thomas Gleixner [ldufour: slightly reword the commit's description] [ldufour: introduce CONFIG_SMT_NUM_THREADS_DYNAMIC] Signed-off-by: Laurent Dufour --- arch/Kconfig | 3 +++ kernel/cpu.c | 24 +++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/arch/Kconfig b/arch/Kconfig index 205fd23e0cad..c69e9c662a87 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 + config GENERIC_ENTRY bool diff --git a/kernel/cpu.c b/kernel/cpu.c index e354af92b2b8..29bf310651c6 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -466,9 +466,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)) @@ -2283,6 +2297,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; @@ -2317,6 +2337,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; -- 2.41.0