Re: [RFC PATCH v5 15/29] sched/rt: Update rt-cgroup schedulability checks

From: Peter Zijlstra

Date: Tue May 05 2026 - 10:43:00 EST


On Thu, Apr 30, 2026 at 11:38:19PM +0200, Yuri Andriaccio wrote:

> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -343,7 +343,39 @@ void cancel_inactive_timer(struct sched_dl_entity *dl_se)
> cancel_dl_timer(dl_se, &dl_se->inactive_timer);
> }
>
> +/*
> + * Used for dl_bw check and update, used under sched_rt_handler()::mutex and
> + * sched_domains_mutex.

Please try very hard to express locking constraints in code, rather than
comments. Compilers are very bad at verifying comments ;-)

> + */
> +u64 dl_cookie;
> +
> #ifdef CONFIG_RT_GROUP_SCHED
> +int dl_check_tg(unsigned long total)
> +{
> + int which_cpu;
> + int cap;
> + struct dl_bw *dl_b;
> + u64 gen = ++dl_cookie;

This probably wants to be something like:

lockdep_assert_held(sched_domain_mutex);

or something like that?

And if it really is sched_domain_mutex _AND_ sched_rt_handler()::mutex,
it might make sense to pull that mutex out from that function to give it
global visibility so we can test for it here.

For bonus points, you'll use __guarded_by() from the context analysis
bits; you'll need to add:

CONTEXT_ANALYSIS_deadline.o := y to kernel/sched/Makefile and build the
tree with clang-22 or later (although we'll be raising this to -23
soonish).

> +
> + for_each_possible_cpu(which_cpu) {
> + guard(rcu_sched)();
> +
> + if (!dl_bw_visited(which_cpu, gen)) {
> + cap = dl_bw_capacity(which_cpu);
> + dl_b = dl_bw_of(which_cpu);
> +
> + guard(raw_spinlock_irqsave)(&dl_b->lock);
> +
> + if (dl_b->bw != -1 &&
> + cap_scale(dl_b->bw, cap) < dl_b->total_bw + cap_scale(total, cap))
> + return 0;
> + }
> +
> + }
> +
> + return 1;
> +}