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 B7F48359703 for ; Tue, 7 Apr 2026 19:21:36 +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=1775589700; cv=none; b=KWrTfbxG04sIs2DzaxtUiOaHiKdRPVuUJ7HWEncAj+fbyLbuxWJO0aSMEbbEh4LpjeZcKDtGFl8BrWqwakjAGuXylFQYflP/umLVhS+JjtxzTTDFRHXRl35wkCLFTpycBEzKIW/LeRmbxJTWxv22viBeeImVyI5/UWqfFKJTzoE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775589700; c=relaxed/simple; bh=jjjqSfQ4T4tZXqdjDotyz+hXG+k4hbYaDz1j156rQMg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AiuacDkv9+APofkkkdbVfTI7TTlcbBC/pcPX1YqBFbStsGlmtCuiG4cS1zZbxHWkR1uuKd29X1AeM79CjXqtaeZP9afz6z6OsEzzRdgh7T60FTiUqqF9lPtJ4TQ5iIWmfhqle63fUy9Ov6hyk4EwbXEBfSu9QnWClhsjk5B5IfM= 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=ABZKmf/w; 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="ABZKmf/w" Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 637DY8eA2212394; Tue, 7 Apr 2026 19:21:21 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=S3z0471z5ysK5N0xe 8ysjJW2AvETKUijyYYVKGQeT6c=; b=ABZKmf/woK0iy62SgAWnB9QZ2D0qPw3Cf TesVhnVwSMBTTsoc5swsCu6Pk9Qb4ESkOTX7O10+X8CCkjytsusx+rayIJi//czt /Rn8Y3vfuPLxO06OB0xf/BL0lC536iEixBUf85rPTt72+GcuiXqtuM1+lZEaMCgi hJTfQfOKrEPi/9NKcVEaPApMq7of3ZdaJh20VQ0/9nd1E5Blw//glUfMdsU9KV3I XvHHDNAE0nXQHZ7T7fxf/uzYZVHeedN2mXxe5DisVDtJBvpJgKGtkTZJGkp0wk3L VFrUdDqj/JrNt9dRtykJKrnMXu7mpRfXi6hpk17K1nF0YAMLeKf5Q== Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4dcn2hccg1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 07 Apr 2026 19:21:20 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 637IqPim013827; Tue, 7 Apr 2026 19:21:19 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4dcmf44jvb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 07 Apr 2026 19:21:19 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 637JLFir34603312 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 7 Apr 2026 19:21:15 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B16AA20043; Tue, 7 Apr 2026 19:21:15 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 27D4D20040; Tue, 7 Apr 2026 19:21:11 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.20.194]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 7 Apr 2026 19:21:10 +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, tglx@linutronix.de, yury.norov@gmail.com, gregkh@linuxfoundation.org Cc: sshegde@linux.ibm.com, 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, mgorman@suse.de, bsegall@google.com, maddy@linux.ibm.com, srikar@linux.ibm.com, hdanton@sina.com, chleroy@kernel.org, vineeth@bitbyteword.org, joelagnelf@nvidia.com Subject: [PATCH v2 13/17] sched/core: Introduce a simple steal monitor Date: Wed, 8 Apr 2026 00:49:46 +0530 Message-ID: <20260407191950.643549-14-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260407191950.643549-1-sshegde@linux.ibm.com> References: <20260407191950.643549-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-Spam-Details-Enc: AW1haW4tMjYwNDA3MDE3NSBTYWx0ZWRfX5OArtw227tYu kzZ1+9ATowVrNPFMT6MxVGs+EAJvgjRlA79hywmOfeTDbNh1IjJcp3+ThQpNQkhsh6DvkWpg/vl ZON0ylSVkaaHKVFXO4rbpjHQpL9i0/JqgYrAgjhlsNAckdblldignJdqoWhMIvc1GM3PWOIx2al 6sanwhLDutnF5Kpq9+IR3gC79eZzKMjHfyjrOBiIW43+0S9/4uQyRJJNJAnx1DUQbLEF0qD8+48 iDbRCDxY45hYJsECVRLorI1pUG0dtA5l5M22pceAuUYNEVvQvN/+/Pw4u6M6/QRFewq2PlSGVLR Xne/RpzmeXO9fB0a2GZVNTsle0+t0V9B480FegmHpmHDxas2YRyE4QPXH5yYRXWk+XxeS0aTvn4 YF0gTR9/KxG39C1fNWnDAJhTVaRRF2tb7hkvFIplNeSeT+j5xVivRO8jhkFrswduaJa3+cCwjkU TQHo6WrJYvs5JzW9rLA== X-Proofpoint-GUID: OHU5A-KRldxKZaSEUIF8W6jLyazekOZM X-Authority-Analysis: v=2.4 cv=a/wAM0SF c=1 sm=1 tr=0 ts=69d55930 cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VnNF1IyMAAAA:8 a=OdSMrRaz63idaxcbYwMA:9 X-Proofpoint-ORIG-GUID: rscypStRwJus-ZYxeWFwWYgMqkA9sKA3 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-07_04,2026-04-07_05,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 clxscore=1015 spamscore=0 impostorscore=0 priorityscore=1501 phishscore=0 lowpriorityscore=0 adultscore=0 malwarescore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604010000 definitions=main-2604070175 Start with a simple steal monitor. It is meant to look at steal time and make the decision to reduce/increase the preferred CPUs. It has - work function to execute the steal time calculations and decision making periodically. - temporary cpumask, which will be used in the work function. This helps to avoid cpumask allocation in periodic work function. - low and high thesholds for steal time. - sampling period to control the frequency of steal time calculations. - cache the previous decision to avoid oscillations Signed-off-by: Shrikanth Hegde --- kernel/sched/core.c | 23 +++++++++++++++++++++++ kernel/sched/sched.h | 14 ++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 7a9442439eb2..8c80600ddd28 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -9083,6 +9083,8 @@ void __init sched_init(void) preempt_dynamic_init(); + sched_init_steal_monitor(); + scheduler_running = 1; } @@ -11332,4 +11334,25 @@ void sched_push_current_non_preferred_cpu(struct rq *rq) local_irq_restore(flags); } +struct steal_monitor_t steal_mon; + +void sched_init_steal_monitor(void) +{ + INIT_WORK(&steal_mon.work, sched_steal_detection_work); + zalloc_cpumask_var(&steal_mon.tmp_mask, GFP_NOWAIT); + steal_mon.low_threshold = 200; /* 2% steal time */ + steal_mon.high_threshold = 500; /* 5% steal time */ + steal_mon.sampling_period_ms = 1000; /* once per second */ +} + +/* 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); + ktime_t now; + + /* Update the prev_time for next iteration*/ + now = ktime_get(); + sm->prev_time = now; +} #endif diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index c1d037f11c62..c0fbfb04eda3 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -4138,12 +4138,25 @@ DEFINE_CLASS_IS_UNCONDITIONAL(sched_change) #include "ext.h" #ifdef CONFIG_PARAVIRT +struct steal_monitor_t { + struct work_struct work; + cpumask_var_t tmp_mask; + ktime_t prev_time; + u64 prev_steal; + int previous_decision; + unsigned int low_threshold; + unsigned int high_threshold; + unsigned int sampling_period_ms; +}; + static inline bool task_can_run_on_preferred_cpu(struct task_struct *p) { return cpumask_intersects(p->cpus_ptr, cpu_preferred_mask); } void sched_push_current_non_preferred_cpu(struct rq *rq); +void sched_init_steal_monitor(void); +void sched_steal_detection_work(struct work_struct *work); #else static inline bool task_can_run_on_preferred_cpu(struct task_struct *p) { @@ -4151,6 +4164,7 @@ static inline bool task_can_run_on_preferred_cpu(struct task_struct *p) } static inline void sched_push_current_non_preferred_cpu(struct rq *rq) { } +static inline void sched_init_steal_monitor(void) { } #endif #endif /* _KERNEL_SCHED_SCHED_H */ -- 2.47.3