From patchwork Wed Jun 28 10:05:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Dufour X-Patchwork-Id: 113781 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8818033vqr; Wed, 28 Jun 2023 03:32:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Nj+1x+PM8SzBqzVF0uX4ddaM/lfHQrfYr+yF5XFuPMBuU5LiwH+08OoFPJuLuIafq2Vdj X-Received: by 2002:a17:907:78cf:b0:97e:17cc:cc95 with SMTP id kv15-20020a17090778cf00b0097e17cccc95mr617091ejc.36.1687948335382; Wed, 28 Jun 2023 03:32:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687948335; cv=none; d=google.com; s=arc-20160816; b=RaRNTWiUBcl1Ka3tY9OasHZ1yxWnCshlQlKW+RQc9NclgM8/ACbf4is/+WKyXxUNy0 FCqN5XDffx0OVK1nGhFUD0+lrH3xRM9Tcmq0TN5x54emAHaLrVUnjCa3lBXPEQKEmXBB LMwyHLEy5oZdZErqbh1ipsQPsEnXY/FninTXxWqG102crJfixSQCOy8VhnJvjEcj4YVZ h2PoAqc8EkubRiAJLNMKMGIR64eOek46pEtIr5cJxlb4J3aKe+wCeYWSNxS/QkuTcHbG LWwEOaJj1hi3HkMq5UML5Iy+a+J6qKrrsO48DlXo4vgJ/KQdfrrsp7xzFGJpec2ij+zL 9mow== 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=41nfk7hVKk/WvuSxvNTVdQGB0w7rWokALwy7vmRvjrs=; fh=8cYd2FlVZORVk636/TRZSjcpEkmtW92vhqoVMGOqVio=; b=a60P2u7Pgcyhv3hWzUBx0uVaIDz0D7lySjQKF49blJAySQMRsddLdXo4TPfZLA0v7r FwTNOSp825ITlgXLncU9UBuxneNH7ll3AZzvCq3v1LVhjv5+bExoITWXxsPh+etwf3kw wAkJx92nquL4S1dHFiUiIy6LYUVI/JP/BfKhrmdmhnUgW7aTYWsq6p2aHohg2quFT3DZ FDm48N1P5rlk2FA18sO2rkXTznQzgFuWchudSFYZCsPs64p3B6+t8aCz7JMZEyfjedn7 6ItEBkrfWPeTihgVXe9cuz6Dm5YTGtUc/O/921f+JGPRR4mJLZo6mjaY+imEX0/+GfLz Y4sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=NFeYH0zu; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x26-20020a1709064a9a00b00988892c4fe4si4747688eju.903.2023.06.28.03.31.51; Wed, 28 Jun 2023 03:32:15 -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=NFeYH0zu; 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 S233247AbjF1KJy (ORCPT + 99 others); Wed, 28 Jun 2023 06:09:54 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:38668 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231607AbjF1KGc (ORCPT ); Wed, 28 Jun 2023 06:06:32 -0400 Received: from pps.filterd (m0353726.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35S9vpQj020594; Wed, 28 Jun 2023 10:06:08 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=41nfk7hVKk/WvuSxvNTVdQGB0w7rWokALwy7vmRvjrs=; b=NFeYH0zuxRGvfinKx/7D+eC2WUPXmVTwDstTkLH1s5p+RaMXgOnuEHL+FULl0t9L3BAW YYjQk1jVpGuIS92Zm5wYlQYueaBTNFTBjSD/LXM800ewINcLzfA2V5ih4U2fcInVXeyl iWd5HJNQtZ+ZXi16nsyQRQXdUtsgu/uPhLsDT1oL6TrJgI+dAc6nVVHkG/gYPiDBDGE7 8mOkChGfEabjx7qqwxZTfC1AlweuhGKA9eocSLru1tritkt9laUE9/6anx3yKowA4dyd e0Aoi30cEWutLpb6k3ws5j6rDmKO1nRu7bVbFviKoNSMGS/WFJXcHhuYfE8sUOywonja rg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rgjpq04u0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jun 2023 10:06:08 +0000 Received: from m0353726.ppops.net (m0353726.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 35SA5Z3f008617; Wed, 28 Jun 2023 10:06:07 GMT Received: from ppma01fra.de.ibm.com (46.49.7a9f.ip4.static.sl-reverse.com [159.122.73.70]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rgjpq04r3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jun 2023 10:06:07 +0000 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35S4nr78031028; Wed, 28 Jun 2023 10:06:03 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma01fra.de.ibm.com (PPS) with ESMTPS id 3rdr451w60-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jun 2023 10:06:03 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35SA61ac42140214 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Jun 2023 10:06:01 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 15AB52006A; Wed, 28 Jun 2023 10:06:01 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3FF7D20043; Wed, 28 Jun 2023 10:06:00 +0000 (GMT) Received: from localhost.localdomain (unknown [9.171.41.43]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 28 Jun 2023 10:06:00 +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 v2 1/9] cpu/SMT: Move SMT prototypes into cpu_smt.h Date: Wed, 28 Jun 2023 12:05:50 +0200 Message-ID: <20230628100558.43482-2-ldufour@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230628100558.43482-1-ldufour@linux.ibm.com> References: <20230628100558.43482-1-ldufour@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: KDTOaJTgfVuK_vNgo7AerV5pAP2AiqL6 X-Proofpoint-ORIG-GUID: Zx9JcONn37NdEngDFEJyyxZs09rknecH 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-28_06,2023-06-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 bulkscore=0 priorityscore=1501 spamscore=0 suspectscore=0 phishscore=0 impostorscore=0 mlxscore=0 lowpriorityscore=0 mlxlogscore=843 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306280088 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769942113651755050?= X-GMAIL-MSGID: =?utf-8?q?1769942113651755050?= From: Michael Ellerman In order to export the cpuhp_smt_control enum as part of the interface between generic and architecture code, the architecture code needs to include asm/topology.h. But that leads to circular header dependencies. So split the enum and related declarations into a separate header. Signed-off-by: Michael Ellerman [ldufour: rewording the commit's description] Signed-off-by: Laurent Dufour --- arch/x86/include/asm/topology.h | 2 ++ include/linux/cpu.h | 25 +------------------------ include/linux/cpu_smt.h | 29 +++++++++++++++++++++++++++++ kernel/cpu.c | 1 + 4 files changed, 33 insertions(+), 24 deletions(-) create mode 100644 include/linux/cpu_smt.h diff --git a/arch/x86/include/asm/topology.h b/arch/x86/include/asm/topology.h index 458c891a8273..66927a59e822 100644 --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -136,6 +136,8 @@ static inline int topology_max_smt_threads(void) return __max_smt_threads; } +#include + int topology_update_package_map(unsigned int apicid, unsigned int cpu); int topology_update_die_map(unsigned int dieid, unsigned int cpu); int topology_phys_to_logical_pkg(unsigned int pkg); diff --git a/include/linux/cpu.h b/include/linux/cpu.h index 8582a7142623..40548f3c201c 100644 --- a/include/linux/cpu.h +++ b/include/linux/cpu.h @@ -18,6 +18,7 @@ #include #include #include +#include struct device; struct device_node; @@ -202,30 +203,6 @@ void cpuhp_report_idle_dead(void); static inline void cpuhp_report_idle_dead(void) { } #endif /* #ifdef CONFIG_HOTPLUG_CPU */ -enum cpuhp_smt_control { - CPU_SMT_ENABLED, - CPU_SMT_DISABLED, - CPU_SMT_FORCE_DISABLED, - CPU_SMT_NOT_SUPPORTED, - CPU_SMT_NOT_IMPLEMENTED, -}; - -#if defined(CONFIG_SMP) && defined(CONFIG_HOTPLUG_SMT) -extern enum cpuhp_smt_control cpu_smt_control; -extern void cpu_smt_disable(bool force); -extern void cpu_smt_check_topology(void); -extern bool cpu_smt_possible(void); -extern int cpuhp_smt_enable(void); -extern int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval); -#else -# define cpu_smt_control (CPU_SMT_NOT_IMPLEMENTED) -static inline void cpu_smt_disable(bool force) { } -static inline void cpu_smt_check_topology(void) { } -static inline bool cpu_smt_possible(void) { return false; } -static inline int cpuhp_smt_enable(void) { return 0; } -static inline int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval) { return 0; } -#endif - extern bool cpu_mitigations_off(void); extern bool cpu_mitigations_auto_nosmt(void); diff --git a/include/linux/cpu_smt.h b/include/linux/cpu_smt.h new file mode 100644 index 000000000000..722c2e306fef --- /dev/null +++ b/include/linux/cpu_smt.h @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_CPU_SMT_H_ +#define _LINUX_CPU_SMT_H_ + +enum cpuhp_smt_control { + CPU_SMT_ENABLED, + CPU_SMT_DISABLED, + CPU_SMT_FORCE_DISABLED, + CPU_SMT_NOT_SUPPORTED, + CPU_SMT_NOT_IMPLEMENTED, +}; + +#if defined(CONFIG_SMP) && defined(CONFIG_HOTPLUG_SMT) +extern enum cpuhp_smt_control cpu_smt_control; +extern void cpu_smt_disable(bool force); +extern void cpu_smt_check_topology(void); +extern bool cpu_smt_possible(void); +extern int cpuhp_smt_enable(void); +extern int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval); +#else +# define cpu_smt_control (CPU_SMT_NOT_IMPLEMENTED) +static inline void cpu_smt_disable(bool force) { } +static inline void cpu_smt_check_topology(void) { } +static inline bool cpu_smt_possible(void) { return false; } +static inline int cpuhp_smt_enable(void) { return 0; } +static inline int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval) { return 0; } +#endif + +#endif /* _LINUX_CPU_SMT_H_ */ diff --git a/kernel/cpu.c b/kernel/cpu.c index f4a2c5845bcb..237394e0574a 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -413,6 +413,7 @@ static void lockdep_release_cpus_lock(void) void __weak arch_smt_update(void) { } #ifdef CONFIG_HOTPLUG_SMT + enum cpuhp_smt_control cpu_smt_control __read_mostly = CPU_SMT_ENABLED; void __init cpu_smt_disable(bool force) From patchwork Wed Jun 28 10:05:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Dufour X-Patchwork-Id: 113786 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8819104vqr; Wed, 28 Jun 2023 03:34:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Z2QHnk+2UjbkolDFreArxc49Nunu3u19ijz5k6k3BhHFarVeYGFeJBVUXReHC4BsPqAMK X-Received: by 2002:a17:907:60d6:b0:98d:264a:422e with SMTP id hv22-20020a17090760d600b0098d264a422emr16347205ejc.23.1687948460946; Wed, 28 Jun 2023 03:34:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687948460; cv=none; d=google.com; s=arc-20160816; b=ZuveoL+TZJrJUbw1l35u8W2MLuNpBCRnl80NoP4yLgb4GU2Tgk+0nnJz9ldTbB4Jzv FVVKYCx19nMbOJpklAl8budJVjhCB7OUTJ3QkKKED0ANaaGumcYW3wIBJ5msKrv0PCvu CmyUKqNs9MZ7tr9wPYXZq1fEDZ2aPSnry/3T4lMjS1cW8C6Sfd/bjRjiFMCEm8d1jlAP QO4k3V3dGMGDYg+JKRNkEpHSDPO0ub1WoIZHjwRbgvxxjG7HFALBvAGQNh7AN//LH78z o1cVJQC71EaVVbPM6OlTvAXu6Hj2GufYUpwbmvG7TAtoT/U/iB90l/zyqJ+Jez7+cLhi sPRQ== 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=Z3BXx87NONENKyRCVCG4NKF1gcn0Sn0umYhm4oYj4BE=; fh=8cYd2FlVZORVk636/TRZSjcpEkmtW92vhqoVMGOqVio=; b=rYFO57bMBebjU8Z1kD0fvcRtna2+Tzh7Fvh+/GjJqCbqDpVS2i7Y+sWbG44hH4UMJ4 LIQD1MxrEkiHF69NCIfZWDPXulSKe7kb1QQqNWKoJQB/BY1Ve+3OjlOAd0FMjyWsLNPj sPlKABZifsykBt6pMEubeScqDXk6MjIIGkqxuyMTNnPEkBqAPd18NpfbPn2hO/liU+uJ BJL1pl36/pl8uYtJVJN9Sja1vpCM8NsT/B/CBI/tka2fBcbwuFM7clkg4hXFgU8fY4Dt PVK/zCm+AwMczwVpkPI+8vypG3TNtndNQlGXEUn5uIFONOBL8enOL9ikOldvvScHilAn q7hA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=NQNl5MAj; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r7-20020a170906280700b00988c69cb451si5403083ejc.687.2023.06.28.03.33.57; Wed, 28 Jun 2023 03:34:20 -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=NQNl5MAj; 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 S231504AbjF1KNj (ORCPT + 99 others); Wed, 28 Jun 2023 06:13:39 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:10840 "EHLO mx0b-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231771AbjF1KGo (ORCPT ); Wed, 28 Jun 2023 06:06:44 -0400 Received: from pps.filterd (m0353724.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35SA3jP7026047; Wed, 28 Jun 2023 10:06:15 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=Z3BXx87NONENKyRCVCG4NKF1gcn0Sn0umYhm4oYj4BE=; b=NQNl5MAjG8hgzXhNR8F2xWnyWXKD7e1cElKoWaar3u6iSNw2DT5q8tS/OeeOuUlpFmIk DgP8KTOClusIHrM+ruW78dyWE5I2elZYRCb9hTOnsLS7rwKOM3VdSiIQbHR9O60oJDig oqJ7nQgAo/TSF9mvxSPYAqB3scnc15d9F1kyF0Hc5zmRSiazyTTVnSP6Gxmau5wEwaNA PaRHKqvYSO2qENBEEHA/Ez8YKRFF/pFNV1oUZwsd5vPKP6A0G4YbgYZjeqR3TH4BXzYq VzUGAVjfYEdlC6eMWk+4coVppnB996DIuVQe15ylSp5Ak/SJyCf95vvPLgrzKUC5Q0oj Dw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rgjs783xc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jun 2023 10:06:15 +0000 Received: from m0353724.ppops.net (m0353724.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 35SA3e9a025757; Wed, 28 Jun 2023 10:06:11 GMT Received: from ppma01fra.de.ibm.com (46.49.7a9f.ip4.static.sl-reverse.com [159.122.73.70]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rgjs783t2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jun 2023 10:06:11 +0000 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35S9fpja031089; Wed, 28 Jun 2023 10:06:04 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma01fra.de.ibm.com (PPS) with ESMTPS id 3rdr451w61-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jun 2023 10:06:04 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35SA62pD61931984 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Jun 2023 10:06:02 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0A8822004F; Wed, 28 Jun 2023 10:06:02 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 353FB20043; Wed, 28 Jun 2023 10:06:01 +0000 (GMT) Received: from localhost.localdomain (unknown [9.171.41.43]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 28 Jun 2023 10:06:01 +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 v2 2/9] cpu/SMT: Move smt/control simple exit cases earlier Date: Wed, 28 Jun 2023 12:05:51 +0200 Message-ID: <20230628100558.43482-3-ldufour@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230628100558.43482-1-ldufour@linux.ibm.com> References: <20230628100558.43482-1-ldufour@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: _w-Ak6pZWzSTbHGDTOjPLaJ5HY9Lyv-C X-Proofpoint-GUID: lCKXhyr9JqS8nNIGJlwKk66FW8lOmkhh 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-28_06,2023-06-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 clxscore=1015 mlxlogscore=999 suspectscore=0 bulkscore=0 spamscore=0 adultscore=0 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306280088 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769942245378398849?= X-GMAIL-MSGID: =?utf-8?q?1769942245378398849?= From: Michael Ellerman Move the simple exit cases, ie. which don't depend on the value written, earlier in the function. That makes it clearer that regardless of the input those states can not be transitioned out of. That does have a user-visible effect, in that the error returned will now always be EPERM/ENODEV for those states, regardless of the value written. Previously writing an invalid value would return EINVAL even when in those states. Signed-off-by: Michael Ellerman --- kernel/cpu.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/kernel/cpu.c b/kernel/cpu.c index 237394e0574a..c67049bb3fc8 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -2482,6 +2482,12 @@ __store_smt_control(struct device *dev, struct device_attribute *attr, { int ctrlval, ret; + if (cpu_smt_control == CPU_SMT_FORCE_DISABLED) + return -EPERM; + + if (cpu_smt_control == CPU_SMT_NOT_SUPPORTED) + return -ENODEV; + if (sysfs_streq(buf, "on")) ctrlval = CPU_SMT_ENABLED; else if (sysfs_streq(buf, "off")) @@ -2491,12 +2497,6 @@ __store_smt_control(struct device *dev, struct device_attribute *attr, else return -EINVAL; - if (cpu_smt_control == CPU_SMT_FORCE_DISABLED) - return -EPERM; - - if (cpu_smt_control == CPU_SMT_NOT_SUPPORTED) - return -ENODEV; - ret = lock_device_hotplug_sysfs(); if (ret) return ret; From patchwork Wed Jun 28 10:05:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Dufour X-Patchwork-Id: 113784 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8818853vqr; Wed, 28 Jun 2023 03:33:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5r6TQRsbtHExvFd6JpTZV4dHiUQY863aqozCglWscn3YrSZdbC+rdqLlIP0PjBKak0xtfI X-Received: by 2002:a17:907:25c2:b0:978:8a30:aaf with SMTP id ae2-20020a17090725c200b009788a300aafmr25924865ejc.64.1687948428334; Wed, 28 Jun 2023 03:33:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687948428; cv=none; d=google.com; s=arc-20160816; b=BFYts9r1p/Wf629Qt0o+RjIBvzCbH+ETkd6LJ1xKd9jhsAhzKNoznTiDysNnH/XzYy Jiw4RxvVt+Uo0beTMgieyhuG5f7602rXBMgiQquKaA7lfcgVYTva73X/2Tfu5EPqUZr1 gIhw3noDfp9IiMh7RaidkJ/xh0pYJHyMrNUiBHXHbpCCw4aP9IpXfYBYGsa+rmub9D3r vpSzTbHk1p1fUNg5JB3ypJgbD27MZdIx75IXo4JXy/S7ThS0dZssZQdDC1uhuzL27i7C 9zplPyLNIhfGi94hpOZBzp89gu1/XSYgPEHhTFmSPeuMrGKpYR67q0ZpuBaAQx55leqE Y5bg== 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=YBUEZfQnmnU49SY1UU2T/P4JNtQ0yZI9JbS9It2A1LQ=; fh=8cYd2FlVZORVk636/TRZSjcpEkmtW92vhqoVMGOqVio=; b=GAyhrXYdWqK73F+EgdROEr7hxhWIuqqaAfIBbHgWjy3IkZCEpYPK9F6/wnAqF1ddu9 SsUdmWIXuE/ysJFuhKgBg/cPO2+8f4HTlC4msHpE6gm0TFCoKdeC5MzqoctT6Nw/o8Pp 4e0UrSk/4PebmtAnt+ZzKupTYAmRYx+ft2Sj5JQxas7AYVkhaC3Z0O75twjrhknnzJA3 BnKX5gHmk6d2g6igQuRgruLS0CZEILiK9qZ4k0r02vLwzKC6G0z16u4Oeaqm5MzgwBTS p7Lv05xUV0ZQTAOFDhkXrlJBRi/ZnQAR/pGJUnnEWcIjLP0OkFH5lJWAFEudTI0xR9Wn VVoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=EZFRa9Fs; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id se1-20020a170906ce4100b0098dfdc3f2d9si4707142ejb.342.2023.06.28.03.33.24; Wed, 28 Jun 2023 03:33:48 -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=EZFRa9Fs; 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 S233280AbjF1KJ7 (ORCPT + 99 others); Wed, 28 Jun 2023 06:09:59 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:62004 "EHLO mx0b-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231737AbjF1KGj (ORCPT ); Wed, 28 Jun 2023 06:06:39 -0400 Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35S9lc3B009841; Wed, 28 Jun 2023 10:06:09 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=YBUEZfQnmnU49SY1UU2T/P4JNtQ0yZI9JbS9It2A1LQ=; b=EZFRa9Fsqag+RkWNsz1/pMzLTveZht4/OSQqDRn0vYlhUMlF8fTwJLcffGnpLQVi1dFz imIGzoelW6+TiIeDT4sVFiw6/sNIVsNDHvAFBqs9U29loHtqx93hEVaT1x5w1kLWxfar MwrzwaF4kzW5LxfIFWmJ5WsoXdlvYH1xWaB5ThD1Iu51f1+0RjrfNpIPs0aQNb4yA51U DtS1ZQtxMG6fIILVtQBwF2qK0oG9f6KftVbmL1IwnaC0w5X4BpGkOQhFryk80/8LERGt oh917u4eHQTWr9OdvMiWkzbQ/GZ9MbK//Qwons5XZGBHtTbltQl+Cnnd4esBqKeoiELU lg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rgjhngf3c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jun 2023 10:06:08 +0000 Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 35S9mApi011202; Wed, 28 Jun 2023 10:06:07 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 3rgjhngf1a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jun 2023 10:06:07 +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 35S8w64V015928; Wed, 28 Jun 2023 10:06:05 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma04ams.nl.ibm.com (PPS) with ESMTPS id 3rdr452f5b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jun 2023 10:06:05 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35SA631b16581256 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Jun 2023 10:06:03 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 078132005A; Wed, 28 Jun 2023 10:06:03 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2904E20065; Wed, 28 Jun 2023 10:06:02 +0000 (GMT) Received: from localhost.localdomain (unknown [9.171.41.43]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 28 Jun 2023 10:06:02 +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 v2 3/9] cpu/SMT: Store the current/max number of threads Date: Wed, 28 Jun 2023 12:05:52 +0200 Message-ID: <20230628100558.43482-4-ldufour@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230628100558.43482-1-ldufour@linux.ibm.com> References: <20230628100558.43482-1-ldufour@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: UTty2ojiXL_JMmv8XpSHOYQhxNAOilIC X-Proofpoint-GUID: O8pR_ZPFeNXL7ASN0yTeJ1yPz3qwF6Oo 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-28_06,2023-06-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 impostorscore=0 adultscore=0 mlxlogscore=967 bulkscore=0 priorityscore=1501 phishscore=0 mlxscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306280088 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769942211335486365?= X-GMAIL-MSGID: =?utf-8?q?1769942211335486365?= From: Michael Ellerman Some architectures allows partial SMT states at boot time, ie. when not all SMT threads are brought online. To support that the SMT code needs to know the maximum number of SMT threads, and also the currently configured number. The architecture code knows the max number of threads, so have the architecture code pass that value to cpu_smt_set_num_threads(). Note that although topology_max_smt_threads() exists, it is not configured early enough to be used here. As architecture, like PowerPC, allows the threads number to be set through the kernel command line, also pass that value. Signed-off-by: Michael Ellerman [ldufour: slightly reword the commit message] [ldufour: rename cpu_smt_check_topology and add a num_threads argument] Signed-off-by: Laurent Dufour --- arch/x86/kernel/cpu/bugs.c | 3 ++- include/linux/cpu_smt.h | 8 ++++++-- kernel/cpu.c | 21 ++++++++++++++++++++- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index 182af64387d0..ed71ad385ea7 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -34,6 +34,7 @@ #include #include #include +#include #include "cpu.h" @@ -133,7 +134,7 @@ void __init check_bugs(void) * identify_boot_cpu() initialized SMT support information, let the * core code know. */ - cpu_smt_check_topology(); + cpu_smt_set_num_threads(smp_num_siblings, smp_num_siblings); if (!IS_ENABLED(CONFIG_SMP)) { pr_info("CPU: "); diff --git a/include/linux/cpu_smt.h b/include/linux/cpu_smt.h index 722c2e306fef..0c1664294b57 100644 --- a/include/linux/cpu_smt.h +++ b/include/linux/cpu_smt.h @@ -12,15 +12,19 @@ enum cpuhp_smt_control { #if defined(CONFIG_SMP) && defined(CONFIG_HOTPLUG_SMT) extern enum cpuhp_smt_control cpu_smt_control; +extern unsigned int cpu_smt_num_threads; extern void cpu_smt_disable(bool force); -extern void cpu_smt_check_topology(void); +extern void cpu_smt_set_num_threads(unsigned int num_threads, + unsigned int max_threads); extern bool cpu_smt_possible(void); extern int cpuhp_smt_enable(void); extern int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval); #else # define cpu_smt_control (CPU_SMT_NOT_IMPLEMENTED) +# define cpu_smt_num_threads 1 static inline void cpu_smt_disable(bool force) { } -static inline void cpu_smt_check_topology(void) { } +static inline void cpu_smt_set_num_threads(unsigned int num_threads, + unsigned int max_threads) { } static inline bool cpu_smt_possible(void) { return false; } static inline int cpuhp_smt_enable(void) { return 0; } static inline int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval) { return 0; } diff --git a/kernel/cpu.c b/kernel/cpu.c index c67049bb3fc8..edca8b7bd400 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -415,6 +415,8 @@ void __weak arch_smt_update(void) { } #ifdef CONFIG_HOTPLUG_SMT enum cpuhp_smt_control cpu_smt_control __read_mostly = CPU_SMT_ENABLED; +static unsigned int cpu_smt_max_threads __ro_after_init; +unsigned int cpu_smt_num_threads __read_mostly = UINT_MAX; void __init cpu_smt_disable(bool force) { @@ -428,16 +430,33 @@ void __init cpu_smt_disable(bool force) pr_info("SMT: disabled\n"); cpu_smt_control = CPU_SMT_DISABLED; } + cpu_smt_num_threads = 1; } /* * The decision whether SMT is supported can only be done after the full * CPU identification. Called from architecture code. */ -void __init cpu_smt_check_topology(void) +void __init cpu_smt_set_num_threads(unsigned int num_threads, + unsigned int max_threads) { + WARN_ON(!num_threads || (num_threads > max_threads)); + if (!topology_smt_supported()) cpu_smt_control = CPU_SMT_NOT_SUPPORTED; + + cpu_smt_max_threads = max_threads; + + /* + * If SMT has been disabled via the kernel command line or SMT is + * not supported, set cpu_smt_num_threads to 1 for consistency. + * If enabled, take the architecture requested number of threads + * to bring up into account. + */ + if (cpu_smt_control != CPU_SMT_ENABLED) + cpu_smt_num_threads = 1; + else if (num_threads < cpu_smt_num_threads) + cpu_smt_num_threads = num_threads; } static int __init smt_cmdline_disable(char *str) From patchwork Wed Jun 28 10:05:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Dufour X-Patchwork-Id: 113769 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8811106vqr; Wed, 28 Jun 2023 03:18:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6qaKebbTtSJOFdod/09B0lZFLpOqlVvo7Z2YtZo8AvR5eeaeDkEgHAH5FnPp54VZhgNT5k X-Received: by 2002:a17:902:f545:b0:1b8:417d:d042 with SMTP id h5-20020a170902f54500b001b8417dd042mr979212plf.20.1687947508586; Wed, 28 Jun 2023 03:18:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687947508; cv=none; d=google.com; s=arc-20160816; b=dKvbjkZp8Dv7QbHD+Sz/RcjTCikqsEKkB5Rpe4Hzqy9ey5i4ph9xdNys7L601ad9/A SH+VAeCSgJhAspGwF1msc/0iF30zcc4Uo9uXffhBs+USR8baqTUotXRSEOVb7jebnQPt +c19UVHfpXUC6hWhfeJPN3Pur9eUSsxQNX678TY3xkfTUtW7avj2pxxhbM+akNKwuNaL eb4iLudWorv0Io/uK4lW83X/dTpLbbhhrkI3eRZu1KcE9WjjFlCUxFlxhWUgrGN1R9ZT 4dgvdmYOgCqIufyfsOQLqEsER4pVQnp6+YbIjcgTWd2YNFFcAM2BKnik02WgIqaKuhnk 7b5w== 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=tBJniILrv67rMmqL7C9oGbfvlECwbA5Rr3vj+TgxJL4=; fh=8cYd2FlVZORVk636/TRZSjcpEkmtW92vhqoVMGOqVio=; b=c10bxV8Mb72Cm+tbIniyKCFAMdqTfxEBwfGfKCywcQNEbOfvD1psgRD4ldRhLFLwtw BHvHz7OdIfhimgJ+JlDxyNPd5mmYU+8Xj3LTkPT+acdOixZUiM/l5z4OaLyi9jyrhmlF 8KfKeoS35nSSacVFjsOMd2mbZN6+Ej8UkPCzS+HNMyfJdWS9960lmYxRbuuZg5/TX0Hp SfbUp8Uam3eBc12Bmz9S52emufGiA1/FPPrAgks1gm20UWaU33vA1nWW0NlL5qYVd5SR 0UnC3Qusj3ScOhZCF4kwvBI8I1KKrhVAgRn4CH5/nYBf6sRsH0fOO4fjOljxsfLzuNiU Ftog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=HWRJg2u1; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u18-20020a170903125200b001b54cd227c0si8723792plh.115.2023.06.28.03.18.14; Wed, 28 Jun 2023 03:18:28 -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=HWRJg2u1; 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 S232201AbjF1KLU (ORCPT + 99 others); Wed, 28 Jun 2023 06:11:20 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:55748 "EHLO mx0b-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230458AbjF1KGu (ORCPT ); Wed, 28 Jun 2023 06:06:50 -0400 Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35SA340d000680; Wed, 28 Jun 2023 10:06:37 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=tBJniILrv67rMmqL7C9oGbfvlECwbA5Rr3vj+TgxJL4=; b=HWRJg2u1lwxVdlG6NU5q/mBljBJTGNCZEQJJJakJg9JxWy3KBzrScNXcxfWzk+0kAtzk LbhlNO3LnBtjUZtxIP+BHd1QeL8wYGRDt7EzVulZMZ2R4ZHccQgVh2V1p+41SiSaQM5l NQakTyYiaeEJ+7W+OJQiF5mkayoGWHW6HufDPWTm19hIaW6hSA0nOtDSG+sp6IWGQB3y OVCKXL/ygYPe7eDt/Vsdhl4f0il0mmU4oaB9Rb6ahPC7FgtsuwaUH87V7JpCD6Xv681i ygTJ4gMT5fPkhueORzoA7mKZScV58RpYVFlUqMiatwAbL/Tsag9SSGrrtQ23n7iA5EM6 hg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rgjs0r4kt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jun 2023 10:06:35 +0000 Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 35SA3HJg001801; Wed, 28 Jun 2023 10:06:24 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 3rgjs0r4b3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jun 2023 10:06:24 +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 35RNvb77026359; Wed, 28 Jun 2023 10:06:06 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3rdqre2faf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jun 2023 10:06:06 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35SA64nx20447786 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Jun 2023 10:06:04 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F17302005A; Wed, 28 Jun 2023 10:06:03 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2608720067; Wed, 28 Jun 2023 10:06:03 +0000 (GMT) Received: from localhost.localdomain (unknown [9.171.41.43]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 28 Jun 2023 10:06:03 +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 v2 4/9] cpu/SMT: Remove topology_smt_supported() Date: Wed, 28 Jun 2023 12:05:53 +0200 Message-ID: <20230628100558.43482-5-ldufour@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230628100558.43482-1-ldufour@linux.ibm.com> References: <20230628100558.43482-1-ldufour@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: hYi_HeAVfqzMW4iPjLnc1a-Hrswq_G9v X-Proofpoint-GUID: O6HFOq1oVYm6U4lM_DruPdAMcNVeWxvm 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-28_06,2023-06-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 suspectscore=0 priorityscore=1501 malwarescore=0 adultscore=0 spamscore=0 clxscore=1015 bulkscore=0 mlxscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306280088 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769941246626890451?= X-GMAIL-MSGID: =?utf-8?q?1769941246626890451?= Since the maximum number of threads is now passed to cpu_smt_set_num_threads(), checking that value is enough to know if SMT is supported. Cc: Michael Ellerman Suggested-by: Thomas Gleixner Signed-off-by: Laurent Dufour --- arch/x86/include/asm/topology.h | 2 -- arch/x86/kernel/smpboot.c | 8 -------- kernel/cpu.c | 2 +- 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/arch/x86/include/asm/topology.h b/arch/x86/include/asm/topology.h index 66927a59e822..87358a8fe843 100644 --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -143,7 +143,6 @@ int topology_update_die_map(unsigned int dieid, unsigned int cpu); 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_supported(void); #else #define topology_max_packages() (1) static inline int @@ -156,7 +155,6 @@ static inline int topology_phys_to_logical_die(unsigned int die, 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_supported(void) { 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 352f0ce1ece4..3052c171668d 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -278,14 +278,6 @@ bool topology_is_primary_thread(unsigned int cpu) return apic_id_is_primary_thread(per_cpu(x86_cpu_to_apicid, cpu)); } -/** - * topology_smt_supported - Check whether SMT is supported by the CPUs - */ -bool topology_smt_supported(void) -{ - return smp_num_siblings > 1; -} - /** * topology_phys_to_logical_pkg - Map a physical package id to a logical * diff --git a/kernel/cpu.c b/kernel/cpu.c index edca8b7bd400..e354af92b2b8 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -442,7 +442,7 @@ void __init cpu_smt_set_num_threads(unsigned int num_threads, { WARN_ON(!num_threads || (num_threads > max_threads)); - if (!topology_smt_supported()) + if (max_threads == 1) cpu_smt_control = CPU_SMT_NOT_SUPPORTED; cpu_smt_max_threads = max_threads; From patchwork Wed Jun 28 10:05:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Dufour X-Patchwork-Id: 113776 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8816606vqr; Wed, 28 Jun 2023 03:29:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4kRYVdHoMy08pu4P6RPYxbMrTKvJYylBBtjlIsWJ4qmus6z2INsElLFZiAPet469SZQmFV X-Received: by 2002:a50:ed02:0:b0:51d:9195:400f with SMTP id j2-20020a50ed02000000b0051d9195400fmr7154331eds.17.1687948188918; Wed, 28 Jun 2023 03:29:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687948188; cv=none; d=google.com; s=arc-20160816; b=IgoOjTV/xh2oPIJ9rihpqtHr/8nPdj6zax7lwXh/9jTyFiIMVIB1tDLIHfgobSx6J7 Zin+cIRpgC7fXnbxct02+Ot+yUQQKOc/z3i5V5t0vFgzchiyZAAMeN0zBUxRkP5Fdip5 dWYtANaP3AQDEA2tb6hAv6Pq3Jlr5AHG/PmWMwe81UkFz5V/pvkZqanriPL1B25DYw5w xtvSfkr/mbime44XNPC0t03DO1HfzNJ14b2JugHj30LSKKRjZswDNljfGkWtn7Hf460z nnB9JR4i7NAm9rdMbYLFS0EBe2TUBlZD139o7CqyWYQKyRmrODhJTx08V9aQeuwsw6Ff R8Rg== 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=wCZmDmrPdWLBsN1ALoE/Lm0P2tGbdj+ne/cU+LdpmaONnzH+2ow/W8+6xdAqiaNpH4 cCfeTO+P4ouOXDNfE8ZMQMzhr74omliPNs5UehH2UDxH9QrBYwinBlkvadhU1yk/k6YG QfOelF5cQdBS9oqC7dF+hQFvNP5YoKMoQNNPHoad9dnUrTd3ddv0r6+nmHg/wrTfIKQR tVp++Ie7BnXxh1SGiOdCbP/LHBaEIS/mUZZEh0yYml/izX4tTpf6hHV62bBLZZ/bCHB9 P/VCPrSTA9E4ty5Uio06AnbosLvpbi9hcvrqHAvvcGZiGFV1866xD+yN6Jsb8OIJCDcV u51w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=SvJakEzw; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n26-20020a056402061a00b0051bdd97e331si4908968edv.661.2023.06.28.03.29.24; Wed, 28 Jun 2023 03:29:48 -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=SvJakEzw; 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 S233086AbjF1KJY (ORCPT + 99 others); Wed, 28 Jun 2023 06:09:24 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:19722 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229964AbjF1KGd (ORCPT ); Wed, 28 Jun 2023 06:06:33 -0400 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 35S9wcMc002628; Wed, 28 Jun 2023 10:06:11 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=SvJakEzwCJKE+leFMKFMZkJfXCme71z1CkeJlEcKg1W94LeJem5/p1UV6fzSF2fqspXg QHXTp+B3C3yQse8TH49DAIds37NUpdNLftXNQwIKpQ7Pvy05YzU0h0aNDuGyVrhmMhiH 8UsR1i2tQbk4hoRA2sap94Y8O6sWh0tQsA5ZGu96n0XwX9PF7UiwjuuoPDlU0gOF8qdg sD1+QtDCbwmfOCY/NFAcFSrQwJP0J5M65AIsQvHSr2Kv+nNOvuFO/S7+Nmslw8+Cs/du 5cxZ/25SXE/rwjqvh1XWL+pxL7bxuwyJLe1yZ5s5kSI8+b7KwYy5xpXv2tJXm6SovKTd Yw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rgjps86x0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jun 2023 10:06:10 +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 35S9xrh7007119; Wed, 28 Jun 2023 10:06:10 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 3rgjps86ud-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jun 2023 10:06:09 +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 35S0WgYh022148; Wed, 28 Jun 2023 10:06:07 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3rdqre2fah-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jun 2023 10:06:07 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35SA65w645220458 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Jun 2023 10:06:05 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E76B320063; Wed, 28 Jun 2023 10:06:04 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1CE4520065; Wed, 28 Jun 2023 10:06:04 +0000 (GMT) Received: from localhost.localdomain (unknown [9.171.41.43]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 28 Jun 2023 10:06:04 +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 v2 5/9] cpu/SMT: Create topology_smt_thread_allowed() Date: Wed, 28 Jun 2023 12:05:54 +0200 Message-ID: <20230628100558.43482-6-ldufour@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230628100558.43482-1-ldufour@linux.ibm.com> References: <20230628100558.43482-1-ldufour@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: JzRn1H1YDd8NyxOEUyoOjpSqrGjoeAEy X-Proofpoint-ORIG-GUID: mpzW3XEdm9-icHNIVchv0PJper00EMFp 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-28_06,2023-06-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 priorityscore=1501 impostorscore=0 spamscore=0 malwarescore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306280088 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769941960033478202?= X-GMAIL-MSGID: =?utf-8?q?1769941960033478202?= 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; From patchwork Wed Jun 28 10:05:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Dufour X-Patchwork-Id: 113775 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8816442vqr; Wed, 28 Jun 2023 03:29:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5xRKK5DJZrMK2sZRmkkyQWml3b3j3s8ffm0kADofyDJPVYfAa5sRdCyYucQSK0GVFvUfkL X-Received: by 2002:a17:906:da81:b0:992:8892:141d with SMTP id xh1-20020a170906da8100b009928892141dmr521239ejb.22.1687948167629; Wed, 28 Jun 2023 03:29:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687948167; cv=none; d=google.com; s=arc-20160816; b=WVWW3TZHBwnZafHdFWDvwhl4856HiJh2thOJLMh2EbHfzt9o1i3XXg0vxVg03Hs71t lTTkUx+xWVlmxcoU0TaaVfsROkrXBpHEXJbYN0Db8OqL46ZXKoVx0LbmRPu3IkZdnNZE l9FB+FzAAV4ovGklk4UO5IwVy27AeWqQkQRJi+jxhcvoeRSuTZgM2r7lH50uG3W5eqh2 X8GPdSIdHa5dZ1Q1yHy8N4SqOXMcg6aNC7uvQtcy9/sUnzKo9VBSfFYVxXuFq7efY0/Y fShm7qYcEBHwYSfAtU/rHoFV1ePFVE6qz+ZWwywijbvI/Y+TH+Nc34yQnCvMbWU6z6Gd 7jfA== 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=XyTXGi5dDkMgiNgwSNnfdPOzG8/bxcLtUSBua5iss9Q=; fh=8cYd2FlVZORVk636/TRZSjcpEkmtW92vhqoVMGOqVio=; b=j8brmORdrfJSxJDxcGL3bXYbWv1Lcrv96cxgkhXDqNQmrWX1Nj+FxTva8GWX2aX0d7 Lwb8RL+UEfIzIpocQeh4FDGDn5Pon2ReA9AfytDMt73phFB4TLP+zU5fCUj+Pm6uoLb4 kZlJqqwtuWSCndKpfLTWUCuznsrrmS+d9LedwDAJnHw2TVQzhaZshiwgTyyx3IkuQXTW QinuGefJGctRhltSKnPI5HNlvown93eHCml7WY/1EF3uCny+Eg5siIrW/FyAMCyH0/LC 7EP1gcVx3hoouylY6bsSn/MRxZ7SFUih+je1KIriRl4sRzQhlB/iI93FUDm+rt+hxecx Ixsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=VrNRNZJR; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gv6-20020a170906f10600b0098d2f9279fcsi5379250ejb.498.2023.06.28.03.29.03; Wed, 28 Jun 2023 03:29:27 -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=VrNRNZJR; 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 S233201AbjF1KJq (ORCPT + 99 others); Wed, 28 Jun 2023 06:09:46 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:4842 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231609AbjF1KGc (ORCPT ); Wed, 28 Jun 2023 06:06:32 -0400 Received: from pps.filterd (m0353727.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35S9tYA1014948; Wed, 28 Jun 2023 10:06:19 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=XyTXGi5dDkMgiNgwSNnfdPOzG8/bxcLtUSBua5iss9Q=; b=VrNRNZJRXZId5cvve4gNmkezZ/hi7aLMY7UaaSzq6cq7v543uyFaKEE2pMt9hlrD+a0d JNlSMw2IDchqCVi2TKYa1nac1cyDUI6CZsECQ1wmW5IgI8COuivWgVxkwHmLxlEjil9T f4Hq/oxZ1xwrkKO2xaOn2+SM3vWKKaU1qkJ6m2c4YwuWNGM7TvgXbCP/hty1hUGQ9Jj1 /5ngu6DjyiY799UtgkkycWPfG5+bead86Lx6FClOjmy3g6tthjolRa1VLQmJA4tdRC5j egO+URILScP5A8fuy4Kw36aZPTpawYLFuqRR5t5ZqZN/TAnjZGKwlVSYpNODdoU78SvV tA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rgjnjrdp4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jun 2023 10:06:17 +0000 Received: from m0353727.ppops.net (m0353727.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 35S9tWIw014893; Wed, 28 Jun 2023 10:06:16 GMT Received: from ppma01fra.de.ibm.com (46.49.7a9f.ip4.static.sl-reverse.com [159.122.73.70]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rgjnjrden-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jun 2023 10:06:16 +0000 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35S9bSZp027083; Wed, 28 Jun 2023 10:06:08 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma01fra.de.ibm.com (PPS) with ESMTPS id 3rdr451w62-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jun 2023 10:06:08 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35SA65DY38994250 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Jun 2023 10:06:06 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DEECA20043; Wed, 28 Jun 2023 10:06:05 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 11DDC2004F; Wed, 28 Jun 2023 10:06:05 +0000 (GMT) Received: from localhost.localdomain (unknown [9.171.41.43]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 28 Jun 2023 10:06:04 +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 v2 6/9] cpu/SMT: Allow enabling partial SMT states via sysfs Date: Wed, 28 Jun 2023 12:05:55 +0200 Message-ID: <20230628100558.43482-7-ldufour@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230628100558.43482-1-ldufour@linux.ibm.com> References: <20230628100558.43482-1-ldufour@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: yoZpdj3kz_2G64vs7Z7XWWklIUvzxkC_ X-Proofpoint-ORIG-GUID: 05PDmMmyroMBZnXRdPjO5Sm0_onczHBV 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-28_06,2023-06-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 mlxscore=0 phishscore=0 suspectscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 clxscore=1015 mlxlogscore=999 bulkscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306280088 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769941937528001590?= X-GMAIL-MSGID: =?utf-8?q?1769941937528001590?= From: Michael Ellerman Add support to the /sys/devices/system/cpu/smt/control interface for enabling a specified number of SMT threads per core, including partial SMT states where not all threads are brought online. The current interface accepts "on" and "off", to enable either 1 or all SMT threads per core. This commit allows writing an integer, between 1 and the number of SMT threads supported by the machine. Writing 1 is a synonym for "off", 2 or more enables SMT with the specified number of threads. When reading the file, if all threads are online "on" is returned, to avoid changing behaviour for existing users. If some other number of threads is online then the integer value is returned. Architectures like x86 only supporting 1 thread or all threads, should not define CONFIG_SMT_NUM_THREADS_DYNAMIC. Architecture supporting partial SMT states, like PowerPC, should define it. Signed-off-by: Michael Ellerman [ldufour: slightly reword the commit's description] [ldufour: remove switch() in __store_smt_control()] Signed-off-by: Laurent Dufour --- .../ABI/testing/sysfs-devices-system-cpu | 1 + kernel/cpu.c | 58 ++++++++++++++----- 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-devices-system-cpu b/Documentation/ABI/testing/sysfs-devices-system-cpu index f54867cadb0f..3c4cfb59d495 100644 --- a/Documentation/ABI/testing/sysfs-devices-system-cpu +++ b/Documentation/ABI/testing/sysfs-devices-system-cpu @@ -555,6 +555,7 @@ Description: Control Symmetric Multi Threading (SMT) ================ ========================================= "on" SMT is enabled "off" SMT is disabled + "" SMT is enabled with N threads per core. "forceoff" SMT is force disabled. Cannot be changed. "notsupported" SMT is not supported by the CPU "notimplemented" SMT runtime toggling is not diff --git a/kernel/cpu.c b/kernel/cpu.c index 29bf310651c6..e0111c1a2f98 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -2517,11 +2517,19 @@ static const struct attribute_group cpuhp_cpu_root_attr_group = { #ifdef CONFIG_HOTPLUG_SMT +static bool cpu_smt_num_threads_valid(unsigned int threads) +{ + if (IS_ENABLED(CONFIG_SMT_NUM_THREADS_DYNAMIC)) + return threads >= 1 && threads <= cpu_smt_max_threads; + return threads == 1 || threads == cpu_smt_max_threads; +} + static ssize_t __store_smt_control(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - int ctrlval, ret; + int ctrlval, ret, num_threads, orig_threads; + bool force_off; if (cpu_smt_control == CPU_SMT_FORCE_DISABLED) return -EPERM; @@ -2529,30 +2537,39 @@ __store_smt_control(struct device *dev, struct device_attribute *attr, if (cpu_smt_control == CPU_SMT_NOT_SUPPORTED) return -ENODEV; - if (sysfs_streq(buf, "on")) + if (sysfs_streq(buf, "on")) { ctrlval = CPU_SMT_ENABLED; - else if (sysfs_streq(buf, "off")) + num_threads = cpu_smt_max_threads; + } else if (sysfs_streq(buf, "off")) { ctrlval = CPU_SMT_DISABLED; - else if (sysfs_streq(buf, "forceoff")) + num_threads = 1; + } else if (sysfs_streq(buf, "forceoff")) { ctrlval = CPU_SMT_FORCE_DISABLED; - else + num_threads = 1; + } else if (kstrtoint(buf, 10, &num_threads) == 0) { + if (num_threads == 1) + ctrlval = CPU_SMT_DISABLED; + else if (cpu_smt_num_threads_valid(num_threads)) + ctrlval = CPU_SMT_ENABLED; + else + return -EINVAL; + } else { return -EINVAL; + } ret = lock_device_hotplug_sysfs(); if (ret) return ret; - if (ctrlval != cpu_smt_control) { - switch (ctrlval) { - case CPU_SMT_ENABLED: - ret = cpuhp_smt_enable(); - break; - case CPU_SMT_DISABLED: - case CPU_SMT_FORCE_DISABLED: - ret = cpuhp_smt_disable(ctrlval); - break; - } - } + orig_threads = cpu_smt_num_threads; + cpu_smt_num_threads = num_threads; + + force_off = ctrlval != cpu_smt_control && ctrlval == CPU_SMT_FORCE_DISABLED; + + if (num_threads > orig_threads) + ret = cpuhp_smt_enable(); + else if (num_threads < orig_threads || force_off) + ret = cpuhp_smt_disable(ctrlval); unlock_device_hotplug(); return ret ? ret : count; @@ -2580,6 +2597,15 @@ static ssize_t control_show(struct device *dev, { const char *state = smt_states[cpu_smt_control]; + /* + * If SMT is enabled but not all threads are enabled then show the + * number of threads. If all threads are enabled show "on". Otherwise + * show the state name. + */ + if (cpu_smt_control == CPU_SMT_ENABLED && + cpu_smt_num_threads != cpu_smt_max_threads) + return sysfs_emit(buf, "%d\n", cpu_smt_num_threads); + return snprintf(buf, PAGE_SIZE - 2, "%s\n", state); } From patchwork Wed Jun 28 10:05:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Dufour X-Patchwork-Id: 113773 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8815818vqr; Wed, 28 Jun 2023 03:27:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7gNiD6r+bA4UHvFuPMsitQ1etpCTcGLUTOtVWK73jFsiua0hG15dCklo0qGT7KMElwyncf X-Received: by 2002:a17:906:e87:b0:98d:8c5b:2156 with SMTP id p7-20020a1709060e8700b0098d8c5b2156mr10991003ejf.19.1687948079140; Wed, 28 Jun 2023 03:27:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687948079; cv=none; d=google.com; s=arc-20160816; b=dOUEurhErCBOy0jlz+Lh4KeyGu825G64mggm5dKQvbsaopMZsbT07S3mo5+gU0xBZn forQDvfojRJimkiBQuZ+8GWsoRYFqRX3abiLRME8/XWU42+/BiyYXm3MEsv8fbvRfZ+D bUYFVIbOANZba/jtAE6O0eXp3ioxuNHek0C7zxcB9TXdb+oNQYKD28+hL8r0I9b5x3e5 afsfSkEk+mJ11LgtTF+72lvFCD9YO3XscaqP0zgWwB1+J3GnVjLyBy3MTIa8236UeVp2 I8H2yx0Ar0cLRvH7IbR50elQQg8AoySoZlOpEdACsGTAOXsMIXO/A3bf/UaoHEHLTZ7s 94Sg== 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=tx1at/2INEcqt7dGBW4108Z+7Xae9URY05LzYSvNwCU=; fh=8cYd2FlVZORVk636/TRZSjcpEkmtW92vhqoVMGOqVio=; b=1HR5WdLnGDWjI03bSa83/vpTuRtQI75S7CAeIr/SOjGNrPhSMj50POYsN869tKnuCQ QrIdGhPRSDAiGIxBAnFChBqseRnbBOx9ku0yLPRX6Nex6IjeIOuDLMDjYGpJIOghD7CC XEYhkdr183y7vA+oB+Cwu/5/KikUywBY9S9UBaHeD3xblQaOmgloGQx90Lh5Wil1D4ny iMG8TQELfTRX5DwB4Ih1Cdz/2k+F5uXLO92lVQDEdfg6b9OY1v5VOFxt1n8bVfPQSKde +7tgheXsvuuGjOGLasuK5jygbIIGQhE7jmQJWIhofk4WG0vCoqfGb5CI181lmiWRmH0r JjKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=lma21d8K; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e11-20020a170906c00b00b00982a3765028si5523019ejz.477.2023.06.28.03.27.35; Wed, 28 Jun 2023 03:27:59 -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=lma21d8K; 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 S233597AbjF1KLb (ORCPT + 99 others); Wed, 28 Jun 2023 06:11:31 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:18134 "EHLO mx0b-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231161AbjF1KHm (ORCPT ); Wed, 28 Jun 2023 06:07:42 -0400 Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35SA3WSC004140; Wed, 28 Jun 2023 10:07:22 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=tx1at/2INEcqt7dGBW4108Z+7Xae9URY05LzYSvNwCU=; b=lma21d8KFTD/wbAA3DST0KCF5/Tu2aBGYKDw23CqDknlZNlh+e/ADhB7XMWWSkAOk2ty S6FW+Mru2Yq9Xh8KUhF8u+AqU7nb3VLXaTaRKfI29Si1MqY21wknSx2q5P0Xw/cPdWEz PJj2zzYT7dU4C8q4HPwvmCE0/SGdKdBWsPxWufBGJyofC1AdBcWNfpYYkOXxNTKnqVsG 4GSIHXSDiG4rflxwPfRHE9giKPArsOWNJm0/uSzmihDGa/tveNXu3o8K4F+mFivb275D VGa8QdcYmF5VeSnOpbiKtUyf08WPRdPUB+BQek9vWbBIu1mz+YAX9hQargWv963q5D3G YQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rgjs5r3n1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jun 2023 10:07:17 +0000 Received: from m0353723.ppops.net (m0353723.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 35SA4NgP007121; Wed, 28 Jun 2023 10:06:32 GMT Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rgjs5r3ae-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jun 2023 10:06:32 +0000 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35S7Ggfj029896; Wed, 28 Jun 2023 10:06:09 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma05fra.de.ibm.com (PPS) with ESMTPS id 3rdr459vwh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jun 2023 10:06:09 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35SA66q520775460 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Jun 2023 10:06:07 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D360920063; Wed, 28 Jun 2023 10:06:06 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0A1D12004F; Wed, 28 Jun 2023 10:06:06 +0000 (GMT) Received: from localhost.localdomain (unknown [9.171.41.43]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 28 Jun 2023 10:06:05 +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 v2 7/9] powerpc/pseries: Initialise CPU hotplug callbacks earlier Date: Wed, 28 Jun 2023 12:05:56 +0200 Message-ID: <20230628100558.43482-8-ldufour@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230628100558.43482-1-ldufour@linux.ibm.com> References: <20230628100558.43482-1-ldufour@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: tNdRG1MZwSRL8y6XTcta2Q1Tb9CVW_Sk X-Proofpoint-ORIG-GUID: PZ3cq91lOw8k5B4BUjVGhqm9ryugHYP3 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-28_06,2023-06-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 mlxscore=0 impostorscore=0 adultscore=0 spamscore=0 lowpriorityscore=0 malwarescore=0 phishscore=0 mlxlogscore=999 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306280088 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769941845083660897?= X-GMAIL-MSGID: =?utf-8?q?1769941845083660897?= From: Michael Ellerman As part of the generic HOTPLUG_SMT code, there is support for disabling secondary SMT threads at boot time, by passing "nosmt" on the kernel command line. The way that is implemented is the secondary threads are brought partly online, and then taken back offline again. That is done to support x86 CPUs needing certain initialisation done on all threads. However powerpc has similar needs, see commit d70a54e2d085 ("powerpc/powernv: Ignore smt-enabled on Power8 and later"). For that to work the powerpc CPU hotplug callbacks need to be registered before secondary CPUs are brought online, otherwise __cpu_disable() fails due to smp_ops->cpu_disable being NULL. So split the basic initialisation into pseries_cpu_hotplug_init() which can be called early from setup_arch(). The DLPAR related initialisation can still be done later, because it needs to do allocations. Signed-off-by: Michael Ellerman --- arch/powerpc/platforms/pseries/hotplug-cpu.c | 22 ++++++++++++-------- arch/powerpc/platforms/pseries/pseries.h | 2 ++ arch/powerpc/platforms/pseries/setup.c | 2 ++ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/arch/powerpc/platforms/pseries/hotplug-cpu.c b/arch/powerpc/platforms/pseries/hotplug-cpu.c index 1a3cb313976a..61fb7cb00880 100644 --- a/arch/powerpc/platforms/pseries/hotplug-cpu.c +++ b/arch/powerpc/platforms/pseries/hotplug-cpu.c @@ -845,15 +845,9 @@ static struct notifier_block pseries_smp_nb = { .notifier_call = pseries_smp_notifier, }; -static int __init pseries_cpu_hotplug_init(void) +void __init pseries_cpu_hotplug_init(void) { int qcss_tok; - unsigned int node; - -#ifdef CONFIG_ARCH_CPU_PROBE_RELEASE - ppc_md.cpu_probe = dlpar_cpu_probe; - ppc_md.cpu_release = dlpar_cpu_release; -#endif /* CONFIG_ARCH_CPU_PROBE_RELEASE */ rtas_stop_self_token = rtas_function_token(RTAS_FN_STOP_SELF); qcss_tok = rtas_function_token(RTAS_FN_QUERY_CPU_STOPPED_STATE); @@ -862,12 +856,22 @@ static int __init pseries_cpu_hotplug_init(void) qcss_tok == RTAS_UNKNOWN_SERVICE) { printk(KERN_INFO "CPU Hotplug not supported by firmware " "- disabling.\n"); - return 0; + return; } smp_ops->cpu_offline_self = pseries_cpu_offline_self; smp_ops->cpu_disable = pseries_cpu_disable; smp_ops->cpu_die = pseries_cpu_die; +} + +static int __init pseries_dlpar_init(void) +{ + unsigned int node; + +#ifdef CONFIG_ARCH_CPU_PROBE_RELEASE + ppc_md.cpu_probe = dlpar_cpu_probe; + ppc_md.cpu_release = dlpar_cpu_release; +#endif /* CONFIG_ARCH_CPU_PROBE_RELEASE */ /* Processors can be added/removed only on LPAR */ if (firmware_has_feature(FW_FEATURE_LPAR)) { @@ -886,4 +890,4 @@ static int __init pseries_cpu_hotplug_init(void) return 0; } -machine_arch_initcall(pseries, pseries_cpu_hotplug_init); +machine_arch_initcall(pseries, pseries_dlpar_init); diff --git a/arch/powerpc/platforms/pseries/pseries.h b/arch/powerpc/platforms/pseries/pseries.h index f8bce40ebd0c..f8893ba46e83 100644 --- a/arch/powerpc/platforms/pseries/pseries.h +++ b/arch/powerpc/platforms/pseries/pseries.h @@ -75,11 +75,13 @@ static inline int dlpar_hp_pmem(struct pseries_hp_errorlog *hp_elog) #ifdef CONFIG_HOTPLUG_CPU int dlpar_cpu(struct pseries_hp_errorlog *hp_elog); +void pseries_cpu_hotplug_init(void); #else static inline int dlpar_cpu(struct pseries_hp_errorlog *hp_elog) { return -EOPNOTSUPP; } +static inline void pseries_cpu_hotplug_init(void) { } #endif /* PCI root bridge prepare function override for pseries */ diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c index e2a57cfa6c83..41451b76c6e5 100644 --- a/arch/powerpc/platforms/pseries/setup.c +++ b/arch/powerpc/platforms/pseries/setup.c @@ -816,6 +816,8 @@ static void __init pSeries_setup_arch(void) /* Discover PIC type and setup ppc_md accordingly */ smp_init_pseries(); + // Setup CPU hotplug callbacks + pseries_cpu_hotplug_init(); if (radix_enabled() && !mmu_has_feature(MMU_FTR_GTSE)) if (!firmware_has_feature(FW_FEATURE_RPT_INVALIDATE)) From patchwork Wed Jun 28 10:05:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Dufour X-Patchwork-Id: 113770 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8812569vqr; Wed, 28 Jun 2023 03:20:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6dJYgs2ubn+ivVmBT6m+yTa5wVH/HbwR3zfZ3stD+pXFCy3ggE6jx8MkG1GnBIQTokXZ5a X-Received: by 2002:a17:907:3e9a:b0:992:1964:cd57 with SMTP id hs26-20020a1709073e9a00b009921964cd57mr3559307ejc.75.1687947659510; Wed, 28 Jun 2023 03:20:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687947659; cv=none; d=google.com; s=arc-20160816; b=Ew6zo0Yi2F7TSaLbt+GUpwIkjtkkAuYXp7WgP8BckhGtzqsoRYYsHO6JUbN8kfxB5K zPoQr5Yx1FkRkpzfT0z7KQ8BHnAoG01iSC1et+jczRpU26tTombg3VL4XDtQHx8gO7Zb B5M1QShPivuaeKndds73QY7jQ7Nt3qn/ypuNvC+anihdxlvg9UiyH3BDgZpLdVsDGGo9 VpdacSyfeC9y2uxle8d7vPS38Ks1R10JayVW+mlasxrP3nfkWkdX0XSRwzdtfqyqLinn Uy6wtGouRiESJCPQ0vkbzTpj/E0eX8oDqN7VggLqCkgTyP0tUGBqHUBtZ3rIogkZ8jWv JJuw== 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=cI/uYcWliA0lDscgpvXhyRstakOSqS6a6NVTQTYILCg=; fh=8cYd2FlVZORVk636/TRZSjcpEkmtW92vhqoVMGOqVio=; b=ctaQIYQGritK66VCVJUJqGuRjKvzrS0A+MmSiOmyNGCxSpGFsjZGa8vOSkwCe6UfLf 6qYAgD3EvtDWElxuNfUdXjVm3EPbSupd2gZudscZkEU6DLd+CWo9I96d2FU2YQzNCP0y ib0NKn1VcWWDLbeIfKGWkulfzI2ewXpiwYoJdIgUlUH55imndn0J1D46uqpDoYmq7ipb oKkqOQnaFyB0Mz9QewOu65HCt44XJbJoFhvFnkzpymAV7BG7NQ/yT3985wOrVwYR6RZq cQ18WkUqlOV6pc9dJ8KbzQVfPZVD9P76/HtgR6/3qvaeWew4GTVTZr6oR/15R0PeXwlS TxTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=BXr907oO; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k23-20020a170906681700b00982c5ee4393si5175196ejr.828.2023.06.28.03.20.35; Wed, 28 Jun 2023 03:20:59 -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=BXr907oO; 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 S233156AbjF1KJh (ORCPT + 99 others); Wed, 28 Jun 2023 06:09:37 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:13318 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231626AbjF1KGe (ORCPT ); Wed, 28 Jun 2023 06:06:34 -0400 Received: from pps.filterd (m0353726.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35S9vpFU020511; Wed, 28 Jun 2023 10:06:14 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=cI/uYcWliA0lDscgpvXhyRstakOSqS6a6NVTQTYILCg=; b=BXr907oOhK4D+4xhVXBWlCLH9IFuBCiDIz/Ly59UDUehbWxUDfIwMc7n1XlWQZDo82S+ eXK0FRrfmmgy/jrJa6oyPdFkmOCQ3aBnEtT/Z0bhXNiHcV87ezNU+ctOexia9zj9W9VX 7ESpZD0+HJOji3peAA/PMOpYzY/NL33tdl9VCzM5pCrZdN7xCos8+GLFrm//YSHJpVuT FcXeSeZltTj7wW+kDcSjMMWIrvaDUWXcTDdrFZRz6fcfvYPlYaXtEN2VleYGreN6BLlu ilTs82J3W4A6pDM4hGShFjWSZw3oEE+9g8G47ziwW5DSTQ6MK3/DHdYy0xgpSEwLuON8 Kg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rgjpq04y7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jun 2023 10:06:13 +0000 Received: from m0353726.ppops.net (m0353726.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 35S9x072025432; Wed, 28 Jun 2023 10:06:13 GMT Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rgjpq04wh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jun 2023 10:06:13 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35S3gVgY010615; Wed, 28 Jun 2023 10:06:10 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma06fra.de.ibm.com (PPS) with ESMTPS id 3rdqre1vv1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jun 2023 10:06:10 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35SA67VI8651390 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Jun 2023 10:06:07 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CB9AD2005A; Wed, 28 Jun 2023 10:06:07 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F183B20043; Wed, 28 Jun 2023 10:06:06 +0000 (GMT) Received: from localhost.localdomain (unknown [9.171.41.43]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 28 Jun 2023 10:06:06 +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 v2 8/9] powerpc: Add HOTPLUG_SMT support Date: Wed, 28 Jun 2023 12:05:57 +0200 Message-ID: <20230628100558.43482-9-ldufour@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230628100558.43482-1-ldufour@linux.ibm.com> References: <20230628100558.43482-1-ldufour@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 6L5n7ua3NXeNNPuTIch9zHRZ5n9GxjdT X-Proofpoint-ORIG-GUID: VX8Rls4XOBwFrSgy5zXRyqRmt6LpkJUY 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-28_06,2023-06-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 bulkscore=0 priorityscore=1501 spamscore=0 suspectscore=0 phishscore=0 impostorscore=0 mlxscore=0 lowpriorityscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306280088 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769941405231783278?= X-GMAIL-MSGID: =?utf-8?q?1769941405231783278?= From: Michael Ellerman Add support for HOTPLUG_SMT, which enables the generic sysfs SMT support files in /sys/devices/system/cpu/smt, as well as the "nosmt" boot parameter. Implement the recently added hooks to allow partial SMT states, allow any number of threads per core. Tie the config symbol to HOTPLUG_CPU, which enables it on the major platforms that support SMT. If there are other platforms that want the SMT support that can be tweaked in future. Signed-off-by: Michael Ellerman [ldufour: pass current SMT level to cpu_smt_set_num_threads] [ldufour: remove topology_smt_supported] [ldufour: remove topology_smt_threads_supported] [ldufour: select CONFIG_SMT_NUM_THREADS_DYNAMIC] [ldufour: update kernel-parameters.txt] Signed-off-by: Laurent Dufour --- Documentation/admin-guide/kernel-parameters.txt | 4 ++-- arch/powerpc/Kconfig | 2 ++ arch/powerpc/include/asm/topology.h | 15 +++++++++++++++ arch/powerpc/kernel/smp.c | 8 +++++++- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 9e5bab29685f..5efb6c73a928 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -3838,10 +3838,10 @@ nosmp [SMP] Tells an SMP kernel to act as a UP kernel, and disable the IO APIC. legacy for "maxcpus=0". - nosmt [KNL,S390] Disable symmetric multithreading (SMT). + nosmt [KNL,S390,PPC] Disable symmetric multithreading (SMT). Equivalent to smt=1. - [KNL,X86] Disable symmetric multithreading (SMT). + [KNL,X86,PPC] Disable symmetric multithreading (SMT). nosmt=force: Force disable SMT, cannot be undone via the sysfs control file. diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 8b955bc7b59f..bacabc3d7f0c 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -273,6 +273,8 @@ config PPC select HAVE_SYSCALL_TRACEPOINTS select HAVE_VIRT_CPU_ACCOUNTING select HAVE_VIRT_CPU_ACCOUNTING_GEN + select HOTPLUG_SMT if HOTPLUG_CPU + select SMT_NUM_THREADS_DYNAMIC select HUGETLB_PAGE_SIZE_VARIABLE if PPC_BOOK3S_64 && HUGETLB_PAGE select IOMMU_HELPER if PPC64 select IRQ_DOMAIN diff --git a/arch/powerpc/include/asm/topology.h b/arch/powerpc/include/asm/topology.h index 8a4d4f4d9749..f4e6f2dd04b7 100644 --- a/arch/powerpc/include/asm/topology.h +++ b/arch/powerpc/include/asm/topology.h @@ -143,5 +143,20 @@ static inline int cpu_to_coregroup_id(int cpu) #endif #endif +#ifdef CONFIG_HOTPLUG_SMT +#include +#include + +static inline bool topology_is_primary_thread(unsigned int cpu) +{ + return cpu == cpu_first_thread_sibling(cpu); +} + +static inline bool topology_smt_thread_allowed(unsigned int cpu) +{ + return cpu_thread_in_core(cpu) < cpu_smt_num_threads; +} +#endif + #endif /* __KERNEL__ */ #endif /* _ASM_POWERPC_TOPOLOGY_H */ diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c index 406e6d0ffae3..eb539325dff8 100644 --- a/arch/powerpc/kernel/smp.c +++ b/arch/powerpc/kernel/smp.c @@ -1087,7 +1087,7 @@ static int __init init_big_cores(void) void __init smp_prepare_cpus(unsigned int max_cpus) { - unsigned int cpu; + unsigned int cpu, num_threads; DBG("smp_prepare_cpus\n"); @@ -1154,6 +1154,12 @@ void __init smp_prepare_cpus(unsigned int max_cpus) if (smp_ops && smp_ops->probe) smp_ops->probe(); + + // Initalise the generic SMT topology support + num_threads = 1; + if (smt_enabled_at_boot) + num_threads = smt_enabled_at_boot; + cpu_smt_set_num_threads(num_threads, threads_per_core); } void smp_prepare_boot_cpu(void) From patchwork Wed Jun 28 10:05:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Dufour X-Patchwork-Id: 113774 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8816251vqr; Wed, 28 Jun 2023 03:29:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5v5foyPtbUoZ+qNj8jQBvXZ0rIhGP2wv95+m5/1+i9kR7JdtLHyWDOh/FMnY77Rjfvl0Xu X-Received: by 2002:a17:907:7f23:b0:98f:450e:fc20 with SMTP id qf35-20020a1709077f2300b0098f450efc20mr602334ejc.17.1687948141466; Wed, 28 Jun 2023 03:29:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687948141; cv=none; d=google.com; s=arc-20160816; b=XS51NMj9YwVmLrJeXrfwEzpNF1jI0OMQVFSX3jNL9x2Pnc78FxmCkBEIcQUl4+nUdv cUXdkrH47JHvJJk1rbfDREQlf2T1PxaeuMvljOWjIKOIvTZJvMEtVUvtK9Dfy6n0UaS9 FHBQ365SKBzGQVIMFL4orBZ1KvcbaMXMVMHDtU1wJCp0QLzT8MNNP4UP6JkoObetix+O UTWjSOAX1eL5XkUe4cp5YL1NZ8whnhrb5Z4IwHTlJ+cIREZiRe0w27Dmyh8aA2sWfpxX J3q1HzS7BQXuR7Hl+vNgqsFpV2lE7eqNOiUHnqPA8Q94yDw1G29HEvekukd/VdQYhAHg stFQ== 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=jVW7yohLK9Vw3P0klRV5j1vQuRogcPT4LlvarI8f2XM=; fh=8cYd2FlVZORVk636/TRZSjcpEkmtW92vhqoVMGOqVio=; b=CCyoZifDlNM37HMY6rgTiTYE8evzHrs6ZFzWlDG45i8+3rvAJqIxTmwEimZ/Vjp1mH l+2juRjYhyRxzxw0FZRAvnVTO9Ym4SzKHKcT0iifAvsxofRfjPg9LlmrBZ5UwIRVGQxf 10p/scrgeVOdOcN1BQel7a2ZArIFfULh1jEU2eetVmRRqkwdPEfxh2PFhV/uZOpWoClL 3xlk27U6YT1e09Kxv9AAI60iNraJQxmk90kyTNbLFT/n7sO2EzB7+O6Xd0WouDuzp2q5 5baYfPlf3AQlESQTJldsnwmTAueftwtAI1pkJRQXHvIlDglAbmtTRZww+9qn0bjsMgZJ Tb/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=El6aNHXy; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ka20-20020a170907991400b0098e48ad11e8si4303531ejc.902.2023.06.28.03.28.38; Wed, 28 Jun 2023 03:29:01 -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=El6aNHXy; 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 S233329AbjF1KKR (ORCPT + 99 others); Wed, 28 Jun 2023 06:10:17 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:42386 "EHLO mx0b-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231742AbjF1KGl (ORCPT ); Wed, 28 Jun 2023 06:06:41 -0400 Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35S9lZlU009538; Wed, 28 Jun 2023 10:06:14 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=jVW7yohLK9Vw3P0klRV5j1vQuRogcPT4LlvarI8f2XM=; b=El6aNHXyD7OidD3+wLkh4BsZqv+UwtKYGGPZxB8BHaB/rw5A/JxZ+PbmrMyAyWcIMqql CpYM9JmQlpt4oTxSBV1+ROHIdhgopBCKaCqnYZE612zx2fIXndoVgVz5yzhzANHT7arD D+ODmfCuVOQ/NKquQdf1QVii7WwKUneOV0+600Dm2Vzf/U9anHBmSNX0BnaMQpUAwr8D xJ9v8miturkg9o13lPwplBBLB1BD5ZY3kR2YXHm4HnSqyW8e5OY5SpcjurNpxpX4ErYx F1zJVuu8p01yRt9Jdy2qZgvf4CpeWhce/QYQHc8IwBE0PW0FnGvjhKkbVmKI/+wz/w9R mA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rgjhngf8w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jun 2023 10:06:14 +0000 Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 35S9llFL010055; Wed, 28 Jun 2023 10:06:13 GMT Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rgjhngf76-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jun 2023 10:06:13 +0000 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35S4Po2X026876; Wed, 28 Jun 2023 10:06:11 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma05fra.de.ibm.com (PPS) with ESMTPS id 3rdr459vwj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jun 2023 10:06:11 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35SA68px42140226 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Jun 2023 10:06:08 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C8AFE2005A; Wed, 28 Jun 2023 10:06:08 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EA74C20063; Wed, 28 Jun 2023 10:06:07 +0000 (GMT) Received: from localhost.localdomain (unknown [9.171.41.43]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 28 Jun 2023 10:06:07 +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 v2 9/9] powerpc/pseries: Honour current SMT state when DLPAR onlining CPUs Date: Wed, 28 Jun 2023 12:05:58 +0200 Message-ID: <20230628100558.43482-10-ldufour@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230628100558.43482-1-ldufour@linux.ibm.com> References: <20230628100558.43482-1-ldufour@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 8_tmfXruTTgONMEKwR3a5L-81nS_vELJ X-Proofpoint-GUID: fJ_IgKow8TtJpPkgGY6GhgrDKIQlwdzY 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-28_06,2023-06-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 impostorscore=0 adultscore=0 mlxlogscore=880 bulkscore=0 priorityscore=1501 phishscore=0 mlxscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306280088 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769941910379615775?= X-GMAIL-MSGID: =?utf-8?q?1769941910379615775?= From: Michael Ellerman Integrate with the generic SMT support, so that when a CPU is DLPAR onlined it is brought up with the correct SMT mode. Signed-off-by: Michael Ellerman --- arch/powerpc/platforms/pseries/hotplug-cpu.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/powerpc/platforms/pseries/hotplug-cpu.c b/arch/powerpc/platforms/pseries/hotplug-cpu.c index 61fb7cb00880..e62835a12d73 100644 --- a/arch/powerpc/platforms/pseries/hotplug-cpu.c +++ b/arch/powerpc/platforms/pseries/hotplug-cpu.c @@ -398,6 +398,14 @@ static int dlpar_online_cpu(struct device_node *dn) for_each_present_cpu(cpu) { if (get_hard_smp_processor_id(cpu) != thread) continue; + + if (!topology_is_primary_thread(cpu)) { + if (cpu_smt_control != CPU_SMT_ENABLED) + break; + if (!topology_smt_thread_allowed(cpu)) + break; + } + cpu_maps_update_done(); find_and_update_cpu_nid(cpu); rc = device_online(get_cpu_device(cpu));