[RFC PATCH 12/22] sched/fair: Prepare bandwidth distribution to unthrottle partial throttles right away
From: K Prateek Nayak
Date: Thu Feb 20 2025 - 04:39:29 EST
Unthrottling a partially throttled hierarchy is cheap since it only
involves updating the cfs_rq's throttle status and does not involve
modifing the hierarchical indicators via tg_tree walks or enqueuing the
cfs_rq back.
Unthrottle a partially throttled cfs_rq right away. This also helps
avoiding a subtle race with async throttling, specifically:
distribute_cfs_runtime()
rq_lock_irqsave(rq)
# Replenish bandwidth schedule()
unthrottle_cfs_rq_async() local_irq_disable()
smp_call_function_single_async() -> # IPI pending
rq_unlock_irqrestore() rq_lock()
pick_task_fair()
check_cfs_rq_runtime()
# runtime_remaining > 0 but
# cfs_rq->throttled != 0
The above can lead pick_eevdf() failing to find a sched_entity which is
now avoided.
Signed-off-by: K Prateek Nayak <kprateek.nayak@xxxxxxx>
---
kernel/sched/fair.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 091493bc8506..8824e89a3ede 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -6320,6 +6320,17 @@ static bool distribute_cfs_runtime(struct cfs_bandwidth *cfs_b)
/* we check whether we're throttled above */
if (cfs_rq->runtime_remaining > 0) {
+ /*
+ * Partially throttled cfs_rq is cheap to unthrottle
+ * since they only require updating the throttled
+ * status of cfs_rq. Save the need for reacquiring the
+ * rq_lock and a possible IPI by unthrottling it here.
+ */
+ if (!cfs_rq_h_throttled(cfs_rq)) {
+ unthrottle_cfs_rq(cfs_rq, false);
+ goto next;
+ }
+
if (cpu_of(rq) != this_cpu) {
unthrottle_cfs_rq_async(cfs_rq);
} else {
--
2.43.0