From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 6C1D03630B2 for ; Wed, 17 Jun 2026 17:44:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781718299; cv=none; b=KbV2Yv4EDaOo3CnGUcU9tiABhYoMON6+aIzm+jyBJAzL4/a9LslZX8BsiDjuL57bUufJ5opUyWOlJ2rbCPcSJtsURSK37XQpjbc981OuMp+tCkV+g4b04MrkTE2BMF/X9RR1T+KOcjkzSutxNcteHnufiQ2sajPhLKpnHae3nhc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781718299; c=relaxed/simple; bh=VsyPeibDWIa+GJZdbEfhGgXZhQFGhvLyPFhKFSxSxQ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UzUPLsrEphAqVQPptPjtPhAHctMOoDHJCXkADKJfN/mQ5khEGjj9KDnrUMmcEoUeeOzBKCx6Hz6Pm9Mvz3qhu1k4fTmIon9ZwTj9v5umToYxarUUkfRlDji+7NVSHJXPSZooaj8LpzSb83PVN8aIh+ckoKMKjVyO+l7o/q79yc8= 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=Ha5nKsZ+; arc=none smtp.client-ip=148.163.158.5 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="Ha5nKsZ+" Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 65HFpmON723842; Wed, 17 Jun 2026 17:44:44 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=tgoqsyWDhXOgzRG2H WvvQHLgXuR1H5dc3rZMTHVAbis=; b=Ha5nKsZ+tZZGKh22bgTeYTNyy5mADNYU0 ablInTBJ48AdWaIJEaZFLP9HImY4DeD5zH7wUSkRZQqx+PoyD3R/D832VFeQM48P I8wu1P0+dTgsxo3mf2VFx1TskObJ7CrdfMiNy2cUg1EWKpF5AEEJiciT44CWkjxx entzXDvKRx25VVWAo5funoobXYCs8o7f0s85TKQPKLRzCIs7apPP+3hfYM0b+hE5 AKa7zAKaslubU+/xZBHdLCDvwXe6xDNmyZN//4xLypLdiOuFhCIbWh8uB88VDfS5 2w7J5LFXqPVqDvH4Ow9rsG3cc4Mwgwv46LeX51RsMwSQXB1swFPpA== Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4eueqx46yn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 17 Jun 2026 17:44:43 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 65HHYdpW031088; Wed, 17 Jun 2026 17:44:42 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 4eudvacc7b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 17 Jun 2026 17:44:42 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 65HHida630802558 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Jun 2026 17:44:39 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id ECAF720049; Wed, 17 Jun 2026 17:44:38 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C474E20040; Wed, 17 Jun 2026 17:44:31 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.28.77]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 17 Jun 2026 17:44:31 +0000 (GMT) From: Shrikanth Hegde To: linux-kernel@vger.kernel.org, mingo@kernel.org, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, yury.norov@gmail.com, kprateek.nayak@amd.com, iii@linux.ibm.com Cc: sshegde@linux.ibm.com, tglx@kernel.org, gregkh@linuxfoundation.org, pbonzini@redhat.com, seanjc@google.com, vschneid@redhat.com, huschle@linux.ibm.com, rostedt@goodmis.org, dietmar.eggemann@arm.com, mgorman@suse.de, bsegall@google.com, maddy@linux.ibm.com, srikar@linux.ibm.com, hdanton@sina.com, chleroy@kernel.org, vineeth@bitbyteword.org, frederic@kernel.org, arighi@nvidia.com, pauld@redhat.com, christian.loehle@arm.com, tj@kernel.org, tommaso.cucinotta@gmail.com, maz@kernel.org, rafael@kernel.org Subject: [PATCH v4 17/20] sched/core: Handle steal values and mark CPUs as preferred Date: Wed, 17 Jun 2026 23:11:36 +0530 Message-ID: <20260617174139.155540-18-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260617174139.155540-1-sshegde@linux.ibm.com> References: <20260617174139.155540-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: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-GUID: qjQ_jBXzMuVEhgqRFMEaFqtd_CbPXk-V X-Authority-Analysis: v=2.4 cv=Le0MLDfi c=1 sm=1 tr=0 ts=6a32dd0b cx=c_pps a=AfN7/Ok6k8XGzOShvHwTGQ==:117 a=AfN7/Ok6k8XGzOShvHwTGQ==:17 a=FelO9ux0wxsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=RzCfie-kr_QcCd8fBx8p:22 a=VnNF1IyMAAAA:8 a=TM1EdS9gwypbLKwYSXwA:9 X-Proofpoint-Spam-Info: AW1haW4tMjYwNjE3MDE2NiBTYWx0ZWRfXxqbpy0QMYNSh FytV6iablclaYAjDhuN3Y25Kiw6Mir1uG2yggvej2VkLNMVXRACj0IcaLOdnMeAkQLGH2cYLRTR 1Hr6MFatRD8nGNsg1gzqproB1wKKHoQ= X-Proofpoint-ORIG-GUID: 0-rjxAMlRVnytYEV8xxcpTP_oPM7N6SN X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNjE3MDE2NiBTYWx0ZWRfX8o8/I3S7cWLg 3Gblu9BBptZYU7wzF5QrYnxJNR+soFSEr1LgMSa0H4bq00ab5CXROfL93DtnjEgn0wBFdzFF9kn xAOpx6Jd0z6Ig3YLdEDJhzqgH6+H8h+XJvrdYSvgVd9EVfmAS1zKHe+NWJfWuKqCjMNGZZucKbT JH/YT75XeRGbXw3BuLlF5PGD15+zuKmGpXhmwU3UMtVFlAIlcxP1jnOKwdujQD/ZNWTsS2eR0zV 8IaSpHNze/RbPcHVsSFwOr6zQKPpBs8POCqXBPKdv1VPAdfSNZwUO619tdgltakQ8kJzM9w6OJz el+Ea0mDPuTkIpAqfUWJjshFzXv9sP98kEbLSeTLJlHxL2vOek0h2ZmiYHhF9FaVA2X0zO1b7Bi eVPtwawW02pUuDXhrfJZG6DewLeCaP6IXLQAcohzCfNgJ6D5eaJPlyDDTstW6+iFXw4a3XfVqpU +6ax1KKfQtRPOC2IG+Q== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.125,FMLib:17.12.100.49 definitions=2026-06-17_02,2026-06-17_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 malwarescore=0 spamscore=0 suspectscore=0 impostorscore=0 phishscore=0 lowpriorityscore=0 bulkscore=0 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2606170166 This is the main periodic work which handles the steal time values. - Compute the steal time by looking CPUTIME_STEAL across all active CPUs - Compute steal ratio. It is multiplied by 100 to handle the fractional values. - Invoke callbacks for inc/dec preferred CPUs based on low/high steal time. Signed-off-by: Shrikanth Hegde --- kernel/sched/core.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index c77045055604..657c36a0e7ca 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -11461,15 +11461,34 @@ void arch_inc_preferred_cpus(struct steal_monitor_t *sm, u64 steal_ratio) } #endif -/* This is only a skeleton. Subsequent patches introduce more of it */ void sched_steal_detection_work(struct work_struct *work) { struct steal_monitor_t *sm = container_of(work, struct steal_monitor_t, work); + u64 steal_ratio, delta_steal, delta_ns, steal = 0; ktime_t now; + int tmp_cpu; + + for_each_cpu(tmp_cpu, cpu_active_mask) + steal += kcpustat_cpu(tmp_cpu).cpustat[CPUTIME_STEAL]; /* Update the prev_time for next iteration*/ now = ktime_get(); + delta_steal = steal > sm->prev_steal ? steal - sm->prev_steal : 0; + delta_ns = max_t(u64, ktime_to_ns(ktime_sub(now, sm->prev_time)), 1); + sm->prev_time = now; + sm->prev_steal = steal; + + /* Multiply by 100 to consider the fractional values of steal time */ + steal_ratio = (delta_steal * 100 * 100) / (delta_ns * num_active_cpus()); + + /* If the steal time values are high, reduce one core from preferred CPUs */ + if (steal_ratio > sm->high_threshold) + arch_dec_preferred_cpus(sm, steal_ratio); + + /* If the steal time values are low, increase one core as preferred CPUs */ + if (steal_ratio < sm->low_threshold) + arch_inc_preferred_cpus(sm, steal_ratio); } void sched_trigger_steal_computation(int cpu) -- 2.47.3