From patchwork Fri Mar 31 15:39:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Dufour X-Patchwork-Id: 77826 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp663626vqo; Fri, 31 Mar 2023 08:56:13 -0700 (PDT) X-Google-Smtp-Source: AKy350ZlMwJfOKduESsJCTmISuIOGTM2RE149MCBYwzYVlp56HZHNeBRkGzVP/Rfk5DMn23EP5kk X-Received: by 2002:a17:907:c01a:b0:932:3d1b:b69d with SMTP id ss26-20020a170907c01a00b009323d1bb69dmr29598212ejc.47.1680278172891; Fri, 31 Mar 2023 08:56:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680278172; cv=none; d=google.com; s=arc-20160816; b=KofYT9neEg1DFfRWp+EB1AgBeyc37CTcrq60zVNEWY8Ge/WY99CljdZnPUU45LCnGZ sYw64sLEbDm3t0sRDcpjbCdqVnq9PfT9gKpZL+DbpwCuctbdisQEoAR8Yuga0Pnlmd9K MxhYycfrAZ9Ixy8dTq3NWW/lnPAFx76fPWeSUa3xSaV3WmktxPYAIA7pzEExDMIhQ5de i9a/CDbViAIMKZUJYF14OkiYsH7Hw0d0IMdpNeRs7e11FhFkRNYXToZiBi9jrl6TrUDN BzTLkn9rhKCyOFw9ee/EPoilG5Ymnl22oD47OBGP32BVMJsOeuFiapvk8z2bBQ21zDj2 8+qg== 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=QYQpr9VmLdqpeVZbTAb42z+J0T6n0Z4Ey3Cl/9VQzic=; b=PH4x3zF/qDkZM3GRjZ67xAD+ozDzziiVPmb6kAn6z54vxBcGlanw79zMKSAYZmHNA9 nACaabEIXb9cItsngJcO8PwCfPSNiSZCdRNv2uVp/FG2wrNSl4GwxcxV7GnoZPfeJYyA ksOcTsgq6B+0mwGjhbZ7M9J85Swo2vlGzbhf9MTN0/nIuok7ZSpT6xCoqpAyUWx16yNH dSrsiWtsYGnNUqYcfWSp88RBK9x/3TwFDEqWTaWyO6BScvs7GmYiYVWgVTdiR4J5OIY0 JpRNZCzCkmxXI0LCHnf0SXQunhf7ItddPgyOTaMBrcbiEHcK8kaWBC58S7uxz7l/nwTm 0x7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=h88zBcpY; 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 a23-20020a1709063e9700b008d78cb027b7si1775894ejj.667.2023.03.31.08.55.48; Fri, 31 Mar 2023 08:56:12 -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=h88zBcpY; 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 S232721AbjCaPjj (ORCPT + 99 others); Fri, 31 Mar 2023 11:39:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232735AbjCaPjh (ORCPT ); Fri, 31 Mar 2023 11:39:37 -0400 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D4391EFD1 for ; Fri, 31 Mar 2023 08:39:35 -0700 (PDT) Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32VF9aWQ022595; Fri, 31 Mar 2023 15:39:23 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=QYQpr9VmLdqpeVZbTAb42z+J0T6n0Z4Ey3Cl/9VQzic=; b=h88zBcpYxQZTuhlgnAdjVBHTOucunkwWXTKwCg8Fgh8RIEB2r9/cCyto6tLXMkrTfOvh JiIgXH6C9XktuQaQPhNJvEeSM2BwfjSI+XPJaIdbXwjS+wpVetOrS4Qks+XjW47yBSfY JSRqzbQJ6UPY1Z9YNCYTywkwY6YX9r9lUHjVs0Hz5U2sxF+sxOi5+I/qoj9XvfSl3L3m m0h9omnXutm344pLqa9Gx4BmLVDv1HMJYvI/4r0jtzwHnXT0aioPincFRgAyYClqlWQr WVuy6DD71H0/1dhJ3PYEmrT/Ba8ZPSd7d7x37tcoeYTpnUUuIz7KennAwfhBGdAA0qE/ Eg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3pp16d20rr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 31 Mar 2023 15:39:23 +0000 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 32VF9db8023005; Fri, 31 Mar 2023 15:39:23 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 3pp16d20qy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 31 Mar 2023 15:39:22 +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 32V1I3gi013053; Fri, 31 Mar 2023 15:39:21 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3phr7fpvyg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 31 Mar 2023 15:39:21 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 32VFdH8H64291314 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 31 Mar 2023 15:39:17 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AA3AE20043; Fri, 31 Mar 2023 15:39:17 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E846120040; Fri, 31 Mar 2023 15:39:16 +0000 (GMT) Received: from localhost.localdomain (unknown [9.179.0.144]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 31 Mar 2023 15:39:16 +0000 (GMT) From: Laurent Dufour To: mpe@ellerman.id.au, npiggin@gmail.com, christophe.leroy@csgroup.eu Cc: msuchanek@suse.de, nathanl@linux.ibm.com, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Srikar Dronamraju Subject: [PATCH 1/2] pseries/smp: export the smt level in the SYS FS. Date: Fri, 31 Mar 2023 17:39:04 +0200 Message-Id: <20230331153905.31698-2-ldufour@linux.ibm.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230331153905.31698-1-ldufour@linux.ibm.com> References: <20230331153905.31698-1-ldufour@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: PGc9QIzO_ZHUuoWKf1gThmRJW9B1TMUD X-Proofpoint-GUID: 3nWUCXfU9EBO2gnYWIsNv4wvaUa9ZIOj X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-31_07,2023-03-31_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1011 mlxlogscore=999 malwarescore=0 lowpriorityscore=0 suspectscore=0 spamscore=0 impostorscore=0 phishscore=0 priorityscore=1501 mlxscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2303310123 X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761899365577655326?= X-GMAIL-MSGID: =?utf-8?q?1761899365577655326?= There is no SMT level recorded in the kernel neither in user space. Indeed there is no real constraint about that and mixed SMT levels are allowed and system is working fine this way. However when new CPU are added, the kernel is onlining all the threads which is leading to mixed SMT levels and confuse end user a bit. To prevent this exports a SMT level from the kernel so user space application like the energy daemon, could read it to adjust their settings. There is no action unless recording the value when a SMT value is written into the new sysfs entry. User space applications like ppc64_cpu should update the sysfs when changing the SMT level to keep the system consistent. Suggested-by: Srikar Dronamraju Signed-off-by: Laurent Dufour --- arch/powerpc/platforms/pseries/pseries.h | 3 ++ arch/powerpc/platforms/pseries/smp.c | 39 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/arch/powerpc/platforms/pseries/pseries.h b/arch/powerpc/platforms/pseries/pseries.h index f8bce40ebd0c..af0a145af98f 100644 --- a/arch/powerpc/platforms/pseries/pseries.h +++ b/arch/powerpc/platforms/pseries/pseries.h @@ -23,7 +23,9 @@ extern int pSeries_machine_check_exception(struct pt_regs *regs); extern long pseries_machine_check_realmode(struct pt_regs *regs); void pSeries_machine_check_log_err(void); + #ifdef CONFIG_SMP +extern int pseries_smt; extern void smp_init_pseries(void); /* Get state of physical CPU from query_cpu_stopped */ @@ -34,6 +36,7 @@ int smp_query_cpu_stopped(unsigned int pcpu); #define QCSS_HARDWARE_ERROR -1 #define QCSS_HARDWARE_BUSY -2 #else +#define pseries_smt 1 static inline void smp_init_pseries(void) { } #endif diff --git a/arch/powerpc/platforms/pseries/smp.c b/arch/powerpc/platforms/pseries/smp.c index c597711ef20a..6c382922f8f3 100644 --- a/arch/powerpc/platforms/pseries/smp.c +++ b/arch/powerpc/platforms/pseries/smp.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -45,6 +46,8 @@ #include "pseries.h" +int pseries_smt; + /* * The Primary thread of each non-boot processor was started from the OF client * interface by prom_hold_cpus and is spinning on secondary_hold_spinloop. @@ -280,3 +283,39 @@ void __init smp_init_pseries(void) pr_debug(" <- smp_init_pSeries()\n"); } + +static ssize_t pseries_smt_store(struct class *class, + struct class_attribute *attr, + const char *buf, size_t count) +{ + int smt; + + if (kstrtou32(buf, 0, &smt) || !smt || smt > (u32) threads_per_core) { + pr_err("Invalid pseries_smt specified.\n"); + return -EINVAL; + } + + pseries_smt = smt; + + return count; +} + +static ssize_t pseries_smt_show(struct class *class, struct class_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "%d\n", pseries_smt); +} + +static CLASS_ATTR_RW(pseries_smt); + +static int __init pseries_smt_init(void) +{ + int rc; + + pseries_smt = smt_enabled_at_boot; + rc = sysfs_create_file(kernel_kobj, &class_attr_pseries_smt.attr); + if (rc) + pr_err("Can't create pseries_smt sysfs/kernel entry.\n"); + return rc; +} +machine_device_initcall(pseries, pseries_smt_init); From patchwork Fri Mar 31 15:39:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Dufour X-Patchwork-Id: 77827 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp663630vqo; Fri, 31 Mar 2023 08:56:13 -0700 (PDT) X-Google-Smtp-Source: AKy350aid8119woc1FzR1rvvjGWETjcGPZppCRtIhNwZGhNQA5snWiOAtMUcyUYaPwH43abxfSdM X-Received: by 2002:a17:906:13cd:b0:931:2306:f363 with SMTP id g13-20020a17090613cd00b009312306f363mr29204023ejc.21.1680278173432; Fri, 31 Mar 2023 08:56:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680278173; cv=none; d=google.com; s=arc-20160816; b=F6aTMPlH7gmxGbOqAtgvO6IZHt9ZXFrQnNQU1ma91JhxAiD9h+ov4ntKQ7Wt3ljKHJ rrNR7/JxAkVspY7biF/JEsaWUtq0jckVi4lKsvZnNw5ktYBf59hvBByMquX1aQRBW+93 yLJsvgZ71ZqThIHYFhG/9UDbXiXNhZMMLJQsonXO/yGJ32MUZZQ97h9tP6kYO32S1bqo HH7QkLoaABWH5H/yPHUVyRB7p029SD1Pxw9JlTWhbIgbhWiU0dbJXTGVD35qaz64b/NQ 3iD2fKeHBEoJn7gC+ufj0j+FFPJBA28IAMQPSYRSKb3kAG3T6C6GCOZqEJCM6ruDWAm3 mONg== 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=FdoNSkdZl5W6MhRIMFXPBEnEOg1f2E5cEytcW+wyPCo=; b=krI7F7EzCE6XqQK7TMtKGpwBsuUQIPnJP3GGlNiW2xZEYmGNtzyg5EEC3IsXlltnwK fV+WaLwtriCMtgUkPJ2Lr0AlsOXWywmN5h9kygBRuudO71O2ITuKUcuXBZkDrvMTspD/ 4PyGzcCHQ8yfyDqqpinBD1e6dONtOw9uTlfyrk5dEu3Wgt3nBmEty0Gl7jntA+c+Yhs+ /O0QqefijHtJ9LcBh6X119B06sjwxOafHU6khghwU8GO7WtFgSAJmrRAXaCiZa1lfLs+ KT3t5RHsbL2zkztWhrBK7A44Y0ksbUQrQx3GJOVcW0JQqGrdOclwV6pIvadeAIXb7nre +uIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=XBBYpAUd; 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 wb8-20020a170907d50800b00947c4925900si598476ejc.348.2023.03.31.08.55.49; Fri, 31 Mar 2023 08:56:13 -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=XBBYpAUd; 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 S233196AbjCaPjq (ORCPT + 99 others); Fri, 31 Mar 2023 11:39:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232735AbjCaPjm (ORCPT ); Fri, 31 Mar 2023 11:39:42 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CCDE1F7A9 for ; Fri, 31 Mar 2023 08:39:41 -0700 (PDT) Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32VEPx31005458; Fri, 31 Mar 2023 15:39:31 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=FdoNSkdZl5W6MhRIMFXPBEnEOg1f2E5cEytcW+wyPCo=; b=XBBYpAUdUD4Uc9EV71ZnOZ0q7Lnbc8Zy2HBdv6sMOgiETPxaKDPOEklUTm4ugZ5KQ/7g 4IJCMzTA6WSS7EN6z8IswtgTzmNG0K3Dmdtmj+/9QrXlvaxt5d1a5HSZ4B8xgxtD1x8d H2ymqRiSOlhuKL7UOatES49YN8I0V5HILvIZO5Ya3yRUf9qntWwGT+QdPtdDSwieCtAD MWyzl+BurVuIl5/ozUAwSTVIEMyAqIEEdeZ0UNGRV8/MMAp6rUjzRf/BqAaLJpPJmoGf 9UWV7vKbtIWvVM0RLUzVFZAOeRuBSx3Ul8z0mci3TA/Dc6kJgh6NMVArRpkIiGiYnrg2 GQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3pp19c9us5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 31 Mar 2023 15:39:30 +0000 Received: from m0098404.ppops.net (m0098404.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 32VEQlRs010922; Fri, 31 Mar 2023 15:39:30 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3pp19c9uns-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 31 Mar 2023 15:39:29 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 32ULo5t2005469; Fri, 31 Mar 2023 15:39:22 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma03ams.nl.ibm.com (PPS) with ESMTPS id 3phrk6pw6p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 31 Mar 2023 15:39:22 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 32VFdIGO31981848 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 31 Mar 2023 15:39:18 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8E90C20043; Fri, 31 Mar 2023 15:39:18 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C9A3B20040; Fri, 31 Mar 2023 15:39:17 +0000 (GMT) Received: from localhost.localdomain (unknown [9.179.0.144]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 31 Mar 2023 15:39:17 +0000 (GMT) From: Laurent Dufour To: mpe@ellerman.id.au, npiggin@gmail.com, christophe.leroy@csgroup.eu Cc: msuchanek@suse.de, nathanl@linux.ibm.com, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Srikar Dronamraju Subject: [PATCH 2/2] powerpc/pseries/cpuhp: respect current SMT when adding new CPU Date: Fri, 31 Mar 2023 17:39:05 +0200 Message-Id: <20230331153905.31698-3-ldufour@linux.ibm.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230331153905.31698-1-ldufour@linux.ibm.com> References: <20230331153905.31698-1-ldufour@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: H9apdsxfmK6GdWx27csX4-aUTx8w3LD6 X-Proofpoint-ORIG-GUID: qL5AAfG4VlfyGk0oo2RNr1iUO5wTj3Wq X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-31_07,2023-03-31_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 malwarescore=0 suspectscore=0 clxscore=1015 priorityscore=1501 mlxlogscore=999 phishscore=0 lowpriorityscore=0 mlxscore=0 bulkscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2303310123 X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761899365978204620?= X-GMAIL-MSGID: =?utf-8?q?1761899365978204620?= When a new CPU is added, the kernel is activating all its threads. This leads to weird, but functional, result when adding CPU on a SMT 4 system for instance. Here the newly added CPU 1 has 8 threads while the other one has 4 threads active (system has been booted with the 'smt-enabled=4' kernel option): ltcden3-lp12:~ # ppc64_cpu --info Core 0: 0* 1* 2* 3* 4 5 6 7 Core 1: 8* 9* 10* 11* 12* 13* 14* 15* We rely on the newly pseries_smt value which should be updated when changing the SMT level by ppc64_cpu --smt=x and at boot time using the smt-enabled kernel option. This way on a LPAR running in SMT=4, newly added CPU will be running 4 threads, which is what a end user would expect. Cc: Srikar Dronamraju Signed-off-by: Laurent Dufour --- arch/powerpc/platforms/pseries/hotplug-cpu.c | 18 +++++++++++++----- arch/powerpc/platforms/pseries/smp.c | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/arch/powerpc/platforms/pseries/hotplug-cpu.c b/arch/powerpc/platforms/pseries/hotplug-cpu.c index 1a3cb313976a..e623ed8649b3 100644 --- a/arch/powerpc/platforms/pseries/hotplug-cpu.c +++ b/arch/powerpc/platforms/pseries/hotplug-cpu.c @@ -382,7 +382,7 @@ static int dlpar_online_cpu(struct device_node *dn) { int rc = 0; unsigned int cpu; - int len, nthreads, i; + int len, nthreads, i, smt; const __be32 *intserv; u32 thread; @@ -392,6 +392,11 @@ static int dlpar_online_cpu(struct device_node *dn) nthreads = len / sizeof(u32); + smt = READ_ONCE(pseries_smt); + /* We should online at least one thread */ + if (smt < 1) + smt = 1; + cpu_maps_update_begin(); for (i = 0; i < nthreads; i++) { thread = be32_to_cpu(intserv[i]); @@ -400,10 +405,13 @@ static int dlpar_online_cpu(struct device_node *dn) continue; cpu_maps_update_done(); find_and_update_cpu_nid(cpu); - rc = device_online(get_cpu_device(cpu)); - if (rc) { - dlpar_offline_cpu(dn); - goto out; + /* Don't active CPU over the current SMT setting */ + if (smt-- > 0) { + rc = device_online(get_cpu_device(cpu)); + if (rc) { + dlpar_offline_cpu(dn); + goto out; + } } cpu_maps_update_begin(); diff --git a/arch/powerpc/platforms/pseries/smp.c b/arch/powerpc/platforms/pseries/smp.c index 6c382922f8f3..ef8070651846 100644 --- a/arch/powerpc/platforms/pseries/smp.c +++ b/arch/powerpc/platforms/pseries/smp.c @@ -295,7 +295,7 @@ static ssize_t pseries_smt_store(struct class *class, return -EINVAL; } - pseries_smt = smt; + WRITE_ONCE(pseries_smt, smt); return count; }