From nobody Tue Dec 2 02:30:08 2025 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E7BE357A51 for ; Wed, 19 Nov 2025 12:46:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763556386; cv=none; b=sHu32in+vVcv10dbfPVE3IffK+mSpjgbssj6zKME/3gP2npK4stmmIsNMXE8wQn7Vp/ubdeI6VsqdPhyYm6yiOCtxSZ/LOlTR9xTsTY08Rx6uR1PhYDy3ZPQE6Hxs2U8BEBqlaA6w+tqUJqBaoe1xu0lMbFRapb0XW6dYRn8Pyo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763556386; c=relaxed/simple; bh=yxIqHl2ViEZIPEn/mGtdn9SguuLVGdUN4yqbPDpmwrU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=byOgudip+nm9scUD1bndFkdI/XN6SLekzW8iIVRf2aFlgWg4oaJyW92EK/acHP/maj38LkyXm8BAjciF3TUS2b+ZkTs5oO44saHMtLEoSO7730C+LL17sV4H5foKfPsCzq0jm1lBZFK3h1V1DdvBvbVynqf4pTveaPeDAhg6GN0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=kNvnXNzN; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="kNvnXNzN" Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5AJ89VUN026824; Wed, 19 Nov 2025 12:46:02 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=k1P52ymW6kaxc9Fum Uth9OoQ2+0WOk7K41d6063xHqU=; b=kNvnXNzNvvrGOAdxi1CcGVS+fBY5w/PU+ gIZufITYZkSXxCjP2Ol40CExf6RcXt4+ZA1995LR5SibG1ZKtG5CMgZCVZKzFMtj 0em9LWcODd9b6WtKX8Eh2bc3kGBZderUEGHHytAr0adw7oasZ+c1DBBm0DSK6uuO +lttuA5iE01r70qjk+d+WWYUTuNdgOdSgS8psKgkx6jUBGPqmiiX32N0/zK10wPi 3T1s3TNigg2l2e9+ySs9IosT8C78tzc5K4y7GC5PNTqwajhWyvkLMPE1qjZhqljv PJ89vi1S2O70BrZOClz98jaa2EsR4Wu0IAfUQSjxsZuxG7PAPFz+A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4aejka0d22-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Nov 2025 12:46:02 +0000 (GMT) Received: from m0353729.ppops.net (m0353729.ppops.net [127.0.0.1]) by pps.reinject (8.18.1.12/8.18.0.8) with ESMTP id 5AJCWDfM027897; Wed, 19 Nov 2025 12:46:01 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4aejka0d1v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Nov 2025 12:46:01 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 5AJB3Atb030851; Wed, 19 Nov 2025 12:46:00 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4af47y0rr9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Nov 2025 12:46:00 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 5AJCjuRf56951058 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Nov 2025 12:45:56 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4D96420043; Wed, 19 Nov 2025 12:45:56 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 422DF20040; Wed, 19 Nov 2025 12:45:52 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.25.220]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 19 Nov 2025 12:45:52 +0000 (GMT) From: Shrikanth Hegde To: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: sshegde@linux.ibm.com, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, tglx@linutronix.de, yury.norov@gmail.com, maddy@linux.ibm.com, srikar@linux.ibm.com, gregkh@linuxfoundation.org, pbonzini@redhat.com, seanjc@google.com, kprateek.nayak@amd.com, vschneid@redhat.com, iii@linux.ibm.com, huschle@linux.ibm.com, rostedt@goodmis.org, dietmar.eggemann@arm.com, christophe.leroy@csgroup.eu Subject: [PATCH 13/17] powerpc: enable/disable paravirt CPUs based on steal time Date: Wed, 19 Nov 2025 18:14:45 +0530 Message-ID: <20251119124449.1149616-14-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251119124449.1149616-1-sshegde@linux.ibm.com> References: <20251119124449.1149616-1-sshegde@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: MizLiqhS08QOdJAksgIXv1X_4BEsEoh6 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMiBTYWx0ZWRfX78MeoHp8dtkB L9J9hugshqdbYLG8cu8rPW3IID+mH4xwF1GrepvXxm7dnPEtaasmmiTlFyqH9MUqO4IOJpdHs97 m1ovNQi4yd3/hLpDyJGqubAsg5ZS/MUwHlU3A3pltYWxQkdJQ1Uahf2Pe8MY+A42o/scmWJK+oh qgDb6Q/GwIkKjXHwBYcm6zmd1Gg8xlrNoHzEqQ0VxTBq8Nc/gXu+ZoI0lfTcoGVyQEj762PQ8cp Wn9wZEOBOx6k6G5N4s3Iipw057IeVXdPSeY83MhWUhhtWEvrt+wNY5euOQjp//rnSPbiIJ0yfnC FPZ/VxcntsmOMjhzHCAq7oIrTXeaQKmG41cNplsejUusohZcx4HJVhMEEQcrM9d0eqdsE14axdK SjqQvt/U9GqkNvkljsMQcvGhqu109w== X-Proofpoint-ORIG-GUID: AQgkYdCtibiJzz9AEQYjshn9oa5s2sQ7 X-Authority-Analysis: v=2.4 cv=XtL3+FF9 c=1 sm=1 tr=0 ts=691dbc0a cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=VnNF1IyMAAAA:8 a=xVd_9023M5FCHxFdF00A:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-11-19_03,2025-11-18_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 spamscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 adultscore=0 lowpriorityscore=0 phishscore=0 suspectscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2510240000 definitions=main-2511150032 Content-Type: text/plain; charset="utf-8" available_cores - Number of cores LPAR(VM) can use at this moment. remaining cores will have CPUs marked as paravirt. This follow stepwise approach for reducing/increasing the number of available_cores. Very simple Logic. if (steal_time > high_threshold) available_cores-- if (steal_time < low_threshould) available_cores++ It also check previous direction taken to avoid un-necessary ping-pongs. Note: It works well only when CPUs are spread out equal numbered across NUMA nodes. Originally-by: Srikar Dronamraju Signed-off-by: Shrikanth Hegde --- arch/powerpc/platforms/pseries/lpar.c | 53 ++++++++++++++++++++++++ arch/powerpc/platforms/pseries/pseries.h | 1 + 2 files changed, 54 insertions(+) diff --git a/arch/powerpc/platforms/pseries/lpar.c b/arch/powerpc/platforms= /pseries/lpar.c index 935fced6e127..825b5b4e2b43 100644 --- a/arch/powerpc/platforms/pseries/lpar.c +++ b/arch/powerpc/platforms/pseries/lpar.c @@ -43,6 +43,7 @@ #include #include #include +#include =20 #include "pseries.h" =20 @@ -2056,6 +2057,58 @@ void pseries_init_ec_vp_cores(void) /* Initialize the available cores to all VP initially */ available_cores =3D max(entitled_cores, virtual_procs); } + +#define STEAL_RATIO_HIGH 400 +#define STEAL_RATIO_LOW 150 + +void update_soft_entitlement(unsigned long steal_ratio) +{ + static int prev_direction; + int cpu; + + if (!entitled_cores) + return; + + if (steal_ratio >=3D STEAL_RATIO_HIGH && prev_direction > 0) { + /* + * System entitlement was reduced earlier but we continue to + * see steal time. Reduce entitlement further. + */ + if (available_cores =3D=3D entitled_cores) + return; + + /* Mark them paravirt, enable tick if it is nohz_full */ + for (cpu =3D (available_cores - 1) * threads_per_core; + cpu < available_cores * threads_per_core; cpu++) { + set_cpu_paravirt(cpu, true); + if (tick_nohz_full_cpu(cpu)) + tick_nohz_dep_set_cpu(cpu, TICK_DEP_BIT_SCHED); + } + available_cores--; + + } else if (steal_ratio <=3D STEAL_RATIO_LOW && prev_direction < 0) { + /* + * System entitlement was increased but we continue to see + * less steal time. Increase entitlement further. + */ + if (available_cores =3D=3D virtual_procs) + return; + + /* mark them avaialble */ + for (cpu =3D available_cores * threads_per_core; + cpu < (available_cores + 1) * threads_per_core; cpu++) + set_cpu_paravirt(cpu, false); + + available_cores++; + } + if (steal_ratio >=3D STEAL_RATIO_HIGH) + prev_direction =3D 1; + else if (steal_ratio <=3D STEAL_RATIO_LOW) + prev_direction =3D -1; + else + prev_direction =3D 0; +} #else void pseries_init_ec_vp_cores(void) { return; } +void update_soft_entitlement(unsigned long steal_ratio) { return; } #endif diff --git a/arch/powerpc/platforms/pseries/pseries.h b/arch/powerpc/platfo= rms/pseries/pseries.h index 3968a6970fa8..d1f9ec77ff57 100644 --- a/arch/powerpc/platforms/pseries/pseries.h +++ b/arch/powerpc/platforms/pseries/pseries.h @@ -115,6 +115,7 @@ int dlpar_workqueue_init(void); =20 extern u32 pseries_security_flavor; void pseries_setup_security_mitigations(void); +void update_soft_entitlement(unsigned long steal_ratio); =20 #ifdef CONFIG_PPC_64S_HASH_MMU void pseries_lpar_read_hblkrm_characteristics(void); --=20 2.47.3