Re: [PATCH v3 09/17] sched/deadline: Reset the deadline and the runtime with the parameters
From: sashiko-bot
Date: Thu Nov 19 2026 - 09:17:17 EST
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] sched/deadline: uncanceled dl_timer in __dl_clear_params()
- [Medium] sched/deadline: donor runtime and deadline retained after PI
deboost
--
commit f0775a38253db75f6dd935fb60d7593eb5b90b93
Author: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
sched/deadline: Reset the deadline and the runtime with the parameters
This commit resets a deadline entity's runtime and deadline in
__dl_clear_params() and in switched_from_dl() when a boosted task with no
parameters of its own leaves SCHED_DEADLINE, so that its next entry starts
a new period.
> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index 71b1c155c2424..d6d2657dcddd6 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -3569,6 +3569,16 @@ static void switched_from_dl(struct rq *rq, struct task_struct *p)
> if (task_on_rq_queued(p) && p->dl.dl_runtime)
> task_non_contending(&p->dl, false);
>
> + /*
> + * A task with no parameters of its own was boosted into the class.
> + * Its deadline and runtime are the donor's. Reset them, so that its
> + * next entry into the class starts a new period.
> + */
> + if (!p->dl.dl_runtime) {
> + p->dl.deadline = 0;
> + p->dl.runtime = 0;
> + }
> +
[Severity: Medium]
Can a task still keep its donor's runtime and deadline after a priority
inheritance deboost when p->dl.dl_runtime is non-zero?
If a task enters SCHED_DEADLINE via sched_setattr() while PI-boosted by a
deadline waiter, __sched_setscheduler() sees prev_class == next_class ==
&dl_sched_class and skips switched_from_dl() and switched_to_dl(), while
__setparam_dl() sets p->dl.dl_runtime without clearing the donor's
p->dl.deadline and p->dl.runtime. When the mutex is unlocked,
rt_mutex_setprio() keeps the task in dl_sched_class and restores
p->dl.pi_se = &p->dl without ENQUEUE_REPLENISH, and enqueue_dl_entity()
skips setup_new_dl_entity() because the donor's deadline is still in the
future:
kernel/sched/deadline.c:enqueue_dl_entity() {
...
} else if ((flags & ENQUEUE_MOVE) &&
!is_dl_boosted(dl_se) &&
dl_time_before(dl_se->deadline, rq_clock(rq_of_dl_se(dl_se)))) {
setup_new_dl_entity(dl_se);
}
...
}
The task then runs unboosted on the donor's remaining runtime and deadline
(and if it was sleeping during sched_setattr(), skipping switched_to_dl()
also skips add_rq_bw(), underflowing rq->dl.this_bw on dequeue).
Similarly, if a former SCHED_DEADLINE task is PI-boosted and deboosted
before its 0-lag inactive_timer fires, switched_to_dl() cancels
inactive_timer while p->dl.dl_runtime is still non-zero. On deboost,
switched_from_dl() skips the !p->dl.dl_runtime reset and passes the donor's
deadline and runtime to task_non_contending().
> @@ -3984,7 +3994,8 @@ bool __checkparam_dl(const struct sched_attr *attr)
> }
>
> /*
> - * This function clears the sched_dl_entity static params.
> + * Clear the static parameters of @dl_se. Also reset its deadline and its
> + * runtime, so that its next enqueue starts a new period.
> */
> static void __dl_clear_params(struct sched_dl_entity *dl_se)
> {
> @@ -3995,6 +4006,9 @@ static void __dl_clear_params(struct sched_dl_entity *dl_se)
> dl_se->dl_bw = 0;
> dl_se->dl_density = 0;
>
> + dl_se->deadline = 0;
> + dl_se->runtime = 0;
> +
> dl_se->dl_throttled = 0;
> dl_se->dl_yielded = 0;
> dl_se->dl_non_contending = 0;
[Severity: Medium]
Does clearing deadline, runtime, and dl_throttled here without canceling
dl_se->dl_timer leave a stale replenishment timer armed for the old period?
When a throttled task leaves SCHED_DEADLINE at a time when its 0-lag time is
earlier than dl_next_period() (for instance after sched_yield() with
remaining runtime, or with a constrained deadline dl_deadline < dl_period),
__dl_clear_params() runs at the 0-lag time while dl_se->dl_timer is still
queued for the old period end. If the task re-enters SCHED_DEADLINE before
that timer fires, enqueue_dl_entity() sees dl_se->deadline == 0 and starts a
new period without canceling dl_timer (because dl_throttled was cleared).
When the task throttles in its new period, start_dl_timer() sees
hrtimer_is_queued(&dl_se->dl_timer) and skips arming the timer for the new
replenishment time:
kernel/sched/deadline.c:start_dl_timer() {
...
if (!hrtimer_is_queued(timer)) {
if (!dl_server(dl_se))
get_task_struct(dl_task_of(dl_se));
hrtimer_start(timer, act, HRTIMER_MODE_ABS_HARD);
}
return 1;
}
When the old dl_timer fires at the old period boundary, dl_task_timer()
replenishes and unthrottles the task early, letting it consume an extra
budget slice in its new period.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795092090.git.mathieu.desnoyers@xxxxxxxxxxxx?part=9