Skip to content

Commit 28ad542

Browse files
kudureranganathPeter Zijlstra
authored andcommitted
sched/fair: Call update_curr() before unthrottling the hierarchy
Subsequent commits will allow update_curr() to throttle the hierarchy when the runtime accounting exceeds allocated quota. Call update_curr() before the unthrottle event, and in tg_unthrottle_up() to catch up on any remaining runtime and stabilize the "runtime_remaining" and "throttle_count" for that cfs_rq. Doing an update_curr() early ensures the cfs_rq is not throttled right back up again when the unthrottle is in progress. Since all callers of unthrottle_cfs_rq(), except two, already update the rq_clock and call rq_clock_start_loop_update(), move the update_rq_clock() from unthrottle_cfs_rq() to the callers that don't update the rq_clock. Signed-off-by: K Prateek Nayak <kprateek.nayak@amd.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Benjamin Segall <bsegall@google.com> Tested-by: Aaron Lu <ziqianlu@bytedance.com> Link: https://patch.msgid.link/20260602052531.11450-1-kprateek.nayak@amd.com
1 parent 253edcf commit 28ad542

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

kernel/sched/core.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9859,11 +9859,14 @@ static int tg_set_cfs_bandwidth(struct task_group *tg,
98599859
struct rq *rq = cfs_rq->rq;
98609860

98619861
guard(rq_lock_irq)(rq);
9862+
98629863
cfs_rq->runtime_enabled = runtime_enabled;
98639864
cfs_rq->runtime_remaining = 1;
98649865

9865-
if (cfs_rq->throttled)
9866+
if (cfs_rq->throttled) {
9867+
update_rq_clock(rq);
98669868
unthrottle_cfs_rq(cfs_rq);
9869+
}
98679870
}
98689871

98699872
if (runtime_was_enabled && !runtime_enabled)

kernel/sched/fair.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6740,6 +6740,15 @@ static int tg_unthrottle_up(struct task_group *tg, void *data)
67406740
struct cfs_rq *cfs_rq = tg_cfs_rq(tg, cpu_of(rq));
67416741
struct task_struct *p, *tmp;
67426742

6743+
/*
6744+
* If cfs_rq->curr is set, the cfs_rq might not have caught up
6745+
* since the last clock update. Do it now before we begin
6746+
* queueing task onto it to save the need for unnecessarily
6747+
* unthrottle the hierarchy for this cfs_rq to be throttled
6748+
* right back again.
6749+
*/
6750+
update_curr(cfs_rq);
6751+
67436752
if (--cfs_rq->throttle_count)
67446753
return 0;
67456754

@@ -6882,14 +6891,16 @@ void unthrottle_cfs_rq(struct cfs_rq *cfs_rq)
68826891
* We can't unthrottle this cfs_rq without any runtime remaining because
68836892
* any enqueue in tg_unthrottle_up() will immediately trigger a throttle,
68846893
* which is not supposed to happen on unthrottle path.
6894+
*
6895+
* Catch up on the remaining runtime since last clock update before
6896+
* checking runtime remaining.
68856897
*/
6898+
update_curr(cfs_rq);
68866899
if (cfs_rq->runtime_enabled && cfs_rq->runtime_remaining <= 0)
68876900
return;
68886901

68896902
cfs_rq->throttled = 0;
68906903

6891-
update_rq_clock(rq);
6892-
68936904
scoped_guard(raw_spinlock, &cfs_b->lock) {
68946905
list_del_rcu(&cfs_rq->throttled_list);
68956906

@@ -6964,6 +6975,7 @@ static inline void __unthrottle_cfs_rq_async(struct cfs_rq *cfs_rq)
69646975
bool first;
69656976

69666977
if (rq == this_rq()) {
6978+
update_rq_clock(rq);
69676979
unthrottle_cfs_rq(cfs_rq);
69686980
return;
69696981
}
@@ -7017,6 +7029,11 @@ static bool distribute_cfs_runtime(struct cfs_bandwidth *cfs_b)
70177029
if (!list_empty(&cfs_rq->throttled_csd_list))
70187030
continue;
70197031

7032+
if (cfs_rq->curr) {
7033+
update_rq_clock(rq);
7034+
update_curr(cfs_rq);
7035+
}
7036+
70207037
/* By the above checks, this should never be true */
70217038
WARN_ON_ONCE(cfs_rq->runtime_remaining > 0);
70227039

0 commit comments

Comments
 (0)