Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1317450rwd; Thu, 15 Jun 2023 09:00:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7pcI72tMZz4vYlOnH5GUxzokf/hzOva0nQwh9lOo0CegXB0YbeuZbRAEixPzgainpHhcrc X-Received: by 2002:a05:6a00:2d1f:b0:65c:2ea:2c5e with SMTP id fa31-20020a056a002d1f00b0065c02ea2c5emr6141624pfb.29.1686844842633; Thu, 15 Jun 2023 09:00:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686844842; cv=none; d=google.com; s=arc-20160816; b=Wf5CRNep8wToE3F8VtG0iBYgoT1eLorvDanYUlJfDKrbI3RfxLLr3ZK1mmupIzCDF8 4hkuM1Y+6y3F6iqL0wgjtxxBxd7KYLzX+qDJfbxPfpQrlISzh7xwYXZfF+x8jpbYDO+S uV88K7rrQalZnG3BgvxGWyGvFsg/KOU1qdFm81DICUSXYf3YZ6ebuIOUMXBOLNYdaa45 0bi6IIL3FK1YzurVF6T5KXQswrwGmZodmTWCKMsQOZKh+OjIngvAw1F1QjmOqU1tZ5rI 8jkdUX/TLnfM6zN/pY4bj7BGYV15IluM7BMOuIwDcPx3Ft4UPdrk/XzbsvTrENbAPND0 UJgg== 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=wbKWMXRRGa5vyPu1BMq76I9oqJnkegKDa9efg8kKjsM=; b=WQhOapdx0F/lMbyrOJmmk8n4iV96MeOCm6sZK4fnH5grPlCKF++ZFPFksIpguJWIAZ b5ST7Zcv2KFr3Iax5z3SHFTYpFp6kjpxcgvaNlBhPNdVemLjKe2kyoSd1ktMg0gb6SUe kpTWfl8ix/WyYavAOzid7rsGuifsnfSTpnWBMUFaoc0uZPPbGA2I+89+kbD/2NKcrOnQ n4WvHItyI29GtIAq9aBFbOZMQHiZdNFe6bUSnO3Ao0wMZP2qRvp8qAg7VDSdr7eoAfs0 mxIuA/eufSus97pu3uWSFr4y4rz+3VyuUsPYMvKrIe/8+50CUpnwDyWBHrGgiSBRMvLw 8RgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b="tYpFmp/J"; 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 e12-20020a63db0c000000b005533895d37dsi451106pgg.272.2023.06.15.09.00.23; Thu, 15 Jun 2023 09:00:42 -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="tYpFmp/J"; 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 S1344288AbjFOPrd (ORCPT + 99 others); Thu, 15 Jun 2023 11:47:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344150AbjFOPrT (ORCPT ); Thu, 15 Jun 2023 11:47:19 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29CDCEA; Thu, 15 Jun 2023 08:47:18 -0700 (PDT) Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35FFfmb7031929; Thu, 15 Jun 2023 15:46:46 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=wbKWMXRRGa5vyPu1BMq76I9oqJnkegKDa9efg8kKjsM=; b=tYpFmp/Ju4xjc0S27x4MgSnRBf4e8R+5fBo7oeu7fzta3jLmNqImHWg5yQ53Cvm/iOK2 kGBxRQaH6sVMCXnProqvSfghpnw6mfGxA2m2I/WEUMpdNTvDc7RjjDlHpxxmTMk4c7xm snuxv1zj81vk6IuWHSJL1mqVArHhHothv+u8awcfMbT1zHL+Ib3zemWdXH6bKW6HiHxm 2NmDsyGjdeww+XDdS3pxKAi88D+zkd+NYuaeHu10AQSMuIGq1AdftutN8Av3uI/jWvCk A+vAdVvJW2Mh2QkhJNcG14ZY86MNXxaLBar9VQd0mI0CfFTWY2Ebj7M5oqiSMhk+hF6g nQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3r84qb1yj5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 15 Jun 2023 15:46:45 +0000 Received: from m0356517.ppops.net (m0356517.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 35FF8CKc004844; Thu, 15 Jun 2023 15:46:45 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3r84qb1yg7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 15 Jun 2023 15:46:45 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35F3xVCY004542; Thu, 15 Jun 2023 15:46:42 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3r4gee3pnu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 15 Jun 2023 15:46:42 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35FFkeq438339324 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 15 Jun 2023 15:46:40 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0C0992004D; Thu, 15 Jun 2023 15:46:40 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8822A2004B; Thu, 15 Jun 2023 15:46:39 +0000 (GMT) Received: from localhost.localdomain (unknown [9.144.159.119]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 15 Jun 2023 15:46:39 +0000 (GMT) From: Laurent Dufour To: linux-kernel@vger.kernel.org Cc: linux-arch@vger.kernel.org, x86@kernel.org, linuxppc-dev@lists.ozlabs.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 06/10] cpu/SMT: Create topology_smt_thread_allowed() Date: Thu, 15 Jun 2023 17:46:31 +0200 Message-ID: <20230615154635.13660-7-ldufour@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230615154635.13660-1-ldufour@linux.ibm.com> References: <20230615154635.13660-1-ldufour@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: ytqGXektALhOy3kDGrIrOsDFy1c_j6zX X-Proofpoint-ORIG-GUID: ZkcHmknplZoVe3CraTjViA-20goyJKrE 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-15_12,2023-06-15_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 impostorscore=0 adultscore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=833 phishscore=0 spamscore=0 suspectscore=0 malwarescore=0 priorityscore=1501 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306150136 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 A subsequent patch will enable partial SMT states, ie. when not all SMT threads are brought online. To support that, add an arch helper which checks whether a given CPU is allowed to be brought online depending on how many SMT threads are currently enabled. 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 --- arch/x86/include/asm/topology.h | 2 ++ arch/x86/kernel/smpboot.c | 15 +++++++++++++++ kernel/cpu.c | 10 +++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/topology.h b/arch/x86/include/asm/topology.h index 232df5ffab34..4696d4566cb5 100644 --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -144,6 +144,7 @@ int topology_phys_to_logical_pkg(unsigned int pkg); int topology_phys_to_logical_die(unsigned int die, unsigned int cpu); bool topology_is_primary_thread(unsigned int cpu); bool topology_smt_threads_supported(unsigned int threads); +bool topology_smt_thread_allowed(unsigned int cpu); #else #define topology_max_packages() (1) static inline int @@ -157,6 +158,7 @@ static inline int topology_max_die_per_package(void) { return 1; } static inline int topology_max_smt_threads(void) { return 1; } static inline bool topology_is_primary_thread(unsigned int cpu) { return true; } static inline bool topology_smt_threads_supported(unsigned int threads) { return false; } +static inline bool topology_smt_thread_allowed(unsigned int cpu) { return false; } #endif static inline void arch_fix_phys_package_id(int num, u32 slot) diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index d163ef55577b..cfae55c2d1b0 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -290,6 +290,21 @@ bool topology_smt_threads_supported(unsigned int threads) return threads == 1 || threads == smp_num_siblings; } +/** + * topology_smt_thread_allowed - When enabling SMT check whether this particular + * CPU thread is allowed to be brought online. + * @cpu: CPU to check + */ +bool topology_smt_thread_allowed(unsigned int cpu) +{ + /* + * No extra logic s required here to support different thread values + * because threads will always == 1 or smp_num_siblings because of + * topology_smt_threads_supported(). + */ + return true; +} + /** * topology_phys_to_logical_pkg - Map a physical package id to a logical * diff --git a/kernel/cpu.c b/kernel/cpu.c index e354af92b2b8..ae2fa26a5b63 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -468,7 +468,7 @@ early_param("nosmt", smt_cmdline_disable); static inline bool cpu_smt_allowed(unsigned int cpu) { - if (cpu_smt_control == CPU_SMT_ENABLED) + if (cpu_smt_control == CPU_SMT_ENABLED && topology_smt_thread_allowed(cpu)) return true; if (topology_is_primary_thread(cpu)) @@ -2283,6 +2283,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 && topology_smt_thread_allowed(cpu)) + continue; ret = cpu_down_maps_locked(cpu, CPUHP_OFFLINE); if (ret) break; @@ -2317,6 +2323,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 (!topology_smt_thread_allowed(cpu)) + continue; ret = _cpu_up(cpu, 0, CPUHP_ONLINE); if (ret) break; -- 2.41.0