[PATCH v3 19/20] sched/core: Mark the direction of steal values to avoid oscillations
From: Shrikanth Hegde
Date: Thu May 14 2026 - 11:40:44 EST
Cache the previous decision on steal time. So consecutive values of
high values or low values are taken for increase/decrease of preferred
CPUs.
Signed-off-by: Shrikanth Hegde <sshegde@xxxxxxxxxxxxx>
---
kernel/sched/core.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 955e74a41627..a9e8beb5108e 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -11448,12 +11448,20 @@ void sched_steal_detection_work(struct work_struct *work)
steal_ratio = (delta_steal * 100 * 100) / (delta_ns * num_online_cpus());
/* If the steal time values are high, reduce one core from preferred CPUs */
- if (steal_ratio > sm->high_threshold)
+ if (sm->previous_decision == 1 && 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)
+ if (sm->previous_decision == -1 && steal_ratio < sm->low_threshold)
arch_inc_preferred_cpus(sm, steal_ratio);
+
+ /* mark the direction. This helps to avoid ping-pongs */
+ if (steal_ratio > sm->high_threshold)
+ sm->previous_decision = 1;
+ else if (steal_ratio < sm->low_threshold)
+ sm->previous_decision = -1;
+ else
+ sm->previous_decision = 0;
}
void sched_trigger_steal_computation(int cpu)
--
2.47.3