From mboxrd@z Thu Jan 1 00:00:00 1970 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 11B7F3DD52E for ; Thu, 14 May 2026 15:25:34 +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=1778772336; cv=none; b=DjVYw/DxAwR6hV1kvhYf0CGNDc45sFznfmspb6fUoE0PFlFGdaVptf5+NTnKLZwzSar4VDfhrwFAmMy5UkoVtI0TrDoOfgxIh4pOe0yYlL6PwEGFG8e2916vEuQ87do2j7va32zffyMigiluFBqfRIJk8JdMcz3dGDRdFJZIK4g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778772336; c=relaxed/simple; bh=eCzUDZ5NQtrmgg90m9O7Km0EQTCzTUh6BPQlxgbymK4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iZtjzVOE3IWrklFy4IwUebZbb6Oe+8w84ElnW3JWu5PXgaJlB2AoTxyAKRc1o00OGMf8ZufIRy6hxYqFlTU+I0HY5qL77jt+PqpRP937AwoowDrYtgOSrYm/iwmPaR/GyFV21d9il9GfCF4gzD/FZBFW48mSn5dnwAGWLd+WJUU= 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=cl1mGum1; 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="cl1mGum1" Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 64E7V9EY2611889; Thu, 14 May 2026 15:25:12 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=/HsVO+n/0ATuEKuPL +OZdM5zpZyT/u0rhYOyqCYH0rM=; b=cl1mGum19ivDGP0v25j9qLDU7dfxhMG2p 1KyOCpjZqktcEIkIgkjp0GJMUjANIug1L09LxfK/NG1x4hy5i3MRt9VTx6b7N4J8 EvxxtSlelVZ0UWEzWrwi3r8L5EbrpBDS5T2wl7HMIqE2JjnCqSUZ+qf2CUWr0cgu AIzztsNCHwdhBZEVvnlaNqadkgTFk4JMhc+yt6F4r4+OLmbYtZHvcJ5nochXzO2e hrsn1BFGUeMUpxm8xavKKXf1NHYfHtqOgWIk4KVXrjuoAcii84372gjAjMpXFOUE d5IV7Ym/pANiPh53yx6DhrxrwGCgcz0C6E4ENYfB/pPDBy1ReiwyA== Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4e3nve54pc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 May 2026 15:25:11 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 64EF9Tef024303; Thu, 14 May 2026 15:25:10 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4e3nfgvxvy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 May 2026 15:25:10 +0000 (GMT) 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 64EFP65527918724 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 May 2026 15:25:06 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 705ED20043; Thu, 14 May 2026 15:25:06 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 428DC20040; Thu, 14 May 2026 15:24:58 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.124.213.185]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 14 May 2026 15:24:57 +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 v3 15/20] sched/core: Introduce a simple steal monitor Date: Thu, 14 May 2026 20:51:59 +0530 Message-ID: <20260514152204.481115-16-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260514152204.481115-1-sshegde@linux.ibm.com> References: <20260514152204.481115-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-Authority-Analysis: v=2.4 cv=Y/XIdBeN c=1 sm=1 tr=0 ts=6a05e958 cx=c_pps a=GFwsV6G8L6GxiO2Y/PsHdQ==:117 a=GFwsV6G8L6GxiO2Y/PsHdQ==:17 a=NGcC8JguVDcA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=U7nrCbtTmkRpXpFmAIza:22 a=VnNF1IyMAAAA:8 a=OdSMrRaz63idaxcbYwMA:9 X-Proofpoint-GUID: 9TVJhQ6OMU9R9ozC2IZdFySqP_SFOP_j X-Proofpoint-ORIG-GUID: kd2gFW5_TIcQ-UFtHScNmjpg1CEU0xAC X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTE0MDE1MyBTYWx0ZWRfX6R5qujLiE4aZ MrytIdjcq1IQU7MpfR6GFpGaFpJoiec0uZPPKt8Zh8j/FrjDrV+BEyRtSSGC4AVSsXkr/Pa6fts dtRR3MOdjzVpWJ2qGJ3AdW8aUQK2yXETF9MgFb7vEbOBGhFLPUYQl3MMxt/ShrgTXhEOgn9GHXR zjA5Io0uLCR2JPt4HoVd0EMYoK86EkZ95OHc3Evnw1PMefZG6ooG+WyirjyhuqR6cMEJ28oB5Cl PtB8JaF8VK6y+EDemQCiSOhVS0K6nGoo0XmGEvOpyZ5kjFOo+21lYiAP/4J7cZOsyB6BitMbql8 oGbeB/Zpey8R1EVflSU8jgKlPiqzoY/ujdbqoSnb5+a/KJewg6URz6y0CuuwlB9tjoBjTepzV1q 7VD1epy42/alKuOh8EK4QEWg+yEUXodhRvodSTQYYUrBsPyi9JbbhXSOKTYip3kcu3E+vSyQtAG O3/luALAB6gM46tQz7w== 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-05-14_03,2026-05-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 lowpriorityscore=0 phishscore=0 malwarescore=0 suspectscore=0 bulkscore=0 spamscore=0 adultscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2605050000 definitions=main-2605140153 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 thresholds 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 --- include/linux/sched.h | 13 +++++++++++++ kernel/sched/core.c | 24 ++++++++++++++++++++++++ kernel/sched/sched.h | 3 +++ 3 files changed, 40 insertions(+) diff --git a/include/linux/sched.h b/include/linux/sched.h index dcfb57c90850..ee5f19a96118 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -2516,4 +2516,17 @@ extern void migrate_enable(void); DEFINE_LOCK_GUARD_0(migrate, migrate_disable(), migrate_enable()) +#ifdef CONFIG_PREFERRED_CPU +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; +}; +#endif + #endif diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 1533a44d1a6b..907c6b38460b 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -9102,6 +9102,8 @@ void __init sched_init(void) preempt_dynamic_init(); + sched_init_steal_monitor(); + scheduler_running = 1; } @@ -11351,4 +11353,26 @@ void sched_push_current_non_preferred_cpu(struct rq *rq) push_task, this_cpu_ptr(&npc_push_task_work)); 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_KERNEL); + 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 bcc65c8b4ac6..d674f8e8e854 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -4143,8 +4143,11 @@ static inline bool task_has_preferred_cpus(struct task_struct *p) DECLARE_STATIC_KEY_FALSE(__sched_sm_enable); 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 /* !CONFIG_PREFERRED_CPU */ 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