Skip to content

Commit 253edcf

Browse files
kudureranganathPeter Zijlstra
authored andcommitted
sched/fair: Use throttled_csd_list for local unthrottle
When distribute_cfs_runtime() encounters a local cfs_rq, it adds it to a local list and unthrottles it at the end, when it is done unthrottling other cfs_rq(s) on cfs_b->throttled_cfs_rq until the bandwidth runs out. Instead of using a local list, reuse the local CPU's rq->throttled_csd_list and the __cfsb_csd_unthrottle() path for unthrottle. If this is the first cfs_rq to be queued on the "throttled_csd_list", it prevents the need for a remote CPUs to interrupt this local CPU if they themselves are performing async unthrottle. If this is not the first cfs_rq on the list, there is an async unthrottle operation pending on this local CPU and the unthrottle can be batched together. No functional changes intended. 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/20260602050005.11160-3-kprateek.nayak@amd.com
1 parent 1abbecd commit 253edcf

1 file changed

Lines changed: 15 additions & 17 deletions

File tree

kernel/sched/fair.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6991,12 +6991,11 @@ static void unthrottle_cfs_rq_async(struct cfs_rq *cfs_rq)
69916991

69926992
static bool distribute_cfs_runtime(struct cfs_bandwidth *cfs_b)
69936993
{
6994+
bool throttled = false, unthrottle_local = false;
69946995
int this_cpu = smp_processor_id();
69956996
u64 runtime, remaining = 1;
6996-
bool throttled = false;
6997-
struct cfs_rq *cfs_rq, *tmp;
6997+
struct cfs_rq *cfs_rq;
69986998
struct rq *rq;
6999-
LIST_HEAD(local_unthrottle);
70006999

70017000
guard(rcu)();
70027001

@@ -7047,24 +7046,23 @@ static bool distribute_cfs_runtime(struct cfs_bandwidth *cfs_b)
70477046
}
70487047

70497048
/*
7050-
* We currently only expect to be unthrottling
7051-
* a single cfs_rq locally.
7049+
* Allow a parallel async unthrottle to unthrottle
7050+
* this cfs_rq too via __cfsb_csd_unthrottle().
7051+
* If we are first, do it ourselves at the end and
7052+
* save on an IPI from remote CPUs.
70527053
*/
7053-
WARN_ON_ONCE(!list_empty(&local_unthrottle));
7054-
list_add_tail(&cfs_rq->throttled_csd_list, &local_unthrottle);
7054+
unthrottle_local = list_empty(&rq->cfsb_csd_list);
7055+
list_add_tail(&cfs_rq->throttled_csd_list, &rq->cfsb_csd_list);
70557056
}
70567057

7057-
list_for_each_entry_safe(cfs_rq, tmp, &local_unthrottle,
7058-
throttled_csd_list) {
7059-
struct rq *rq = rq_of(cfs_rq);
7060-
7061-
guard(rq_lock_irqsave)(rq);
7062-
7063-
list_del_init(&cfs_rq->throttled_csd_list);
7064-
if (cfs_rq_throttled(cfs_rq))
7065-
unthrottle_cfs_rq(cfs_rq);
7058+
if (unthrottle_local) {
7059+
/*
7060+
* Protect against an IPI that is also trying to flush
7061+
* the unthrottled cfs_rq(s) from this CPU's csd_list.
7062+
*/
7063+
scoped_guard(irqsave)
7064+
__cfsb_csd_unthrottle(cpu_rq(this_cpu));
70667065
}
7067-
WARN_ON_ONCE(!list_empty(&local_unthrottle));
70687066

70697067
return throttled;
70707068
}

0 commit comments

Comments
 (0)