Skip to contentSkip to conversation

sched/deadline: bandwidth accounting fixes and selftests

PATCH In review Mathieu Desnoyers 2 participants 73 messages Nov 20 – Nov 23 Page 2 of 2

Subsystems (7)
lore
Share & tools
lore
#23 lore raw

Re: [PATCH v10 16/40] sched/deadline: Keep the last CPU a task has in its root domain

In reply to Mathieu Desnoyers
Thank you for your contribution! Sashiko AI review found 5 potential issues to consider: - [Medium] cgroup/cpuset: partition_child_lost() picks last sibling after gone not first - [Medium]…

Thank you for your contribution! Sashiko AI review found 5 potential issues to consider:
- [Medium] cgroup/cpuset: partition_child_lost() picks last sibling after gone not first
- [Medium] cgroup/cpuset: upward cascade of gone across unpopulated parent partitions
- [Medium] cgroup/cpuset: missed root domain move for tasks in isolated partition gone
- [Medium] cgroup/cpuset: skipping a == lost in cpuset_offline_moves_dl() ignores subpartitions
- [Medium] cgroup/cpuset: dl_task_in_cpuset() falsely matches SCHED_FLAG_SUGOV kthreads
--

commit 38c9a6cf11adbb513d6b034865c486d38c14c195
Author: Mathieu Desnoyers <[email protected]>

sched/deadline: Keep the last CPU a task has in its root domain

This commit refuses to take a CPU offline with -EBUSY when doing so would leave a deadline task running in a different root domain that did not admit its bandwidth, either because the task loses its last CPU in its root domain or because the offline invalidates a cpuset partition.

Quoted 4 lines
kernel/cgroup/cpuset.c +0 -0
index 7bdb9e21a7edb..e3c42c63844ba 100644

[ ... ]

Quoted 3 lines
kernel/cgroup/cpuset.c +0 -0
@@ -4312,6 +4334,259 @@ void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask)
 	spin_unlock_irqrestore(&callback_lock, flags);
 }

[ ... ]

Quoted 17 lines
kernel/cgroup/cpuset.c +17 -0
+static struct cpuset *partition_child_lost(struct cpuset *p, int cpu,
+					   struct cpumask *new_cpus,
+					   struct cpuset *gone)
+{
+	bool populated = partition_populated_offline(p);
+	struct cgroup_subsys_state *css;
+	struct cpuset *child, *lost = NULL;
+
+	cpumask_and(new_cpus, p->effective_xcpus, cpu_active_mask);
+	cpumask_clear_cpu(cpu, new_cpus);
+	if (cpumask_empty(new_cpus))
+		return NULL;
+	cpuset_for_each_child(child, css, p) {
+		if (child == gone) {
+			populated = true;
+			continue;
+		}

kernel/cgroup/cpuset.c void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask) · line 4403

Quoted 10 lines
kernel/cgroup/cpuset.c +10 -0
+		if (!is_partition_valid(child))
+			continue;
+		if (populated && cpumask_subset(new_cpus, child->effective_xcpus)) {
+			lost = child;
+			continue;
+		}
+		cpumask_andnot(new_cpus, new_cpus, child->effective_xcpus);
+	}
+	return lost;
+}

[Severity: Medium]
When gone is set and p was initially unpopulated with no active CPUs of its own, does partition_child_lost() pick the last valid sibling partition after gone instead of the first?

During the pre-order walk in cpuset_handle_hotplug(), p is visited before gone is invalidated, so p->effective_cpus remains empty. Once gone is visited and invalidated, p becomes populated while p->effective_cpus is still empty. When cpuset_hotplug_update_tasks() visits the first valid sibling partition after gone, tasks_nocpu_error() checks cpumask_subset(parent->effective_cpus, xcpus), which is immediately true for an empty parent->effective_cpus:

kernel/cgroup/cpuset.c:tasks_nocpu_error() {
	return (cpumask_subset(parent->effective_cpus, xcpus) &&
		partition_is_populated(parent, cs)) ||
	       (!cpumask_intersects(xcpus, cpu_active_mask) &&
		partition_is_populated(cs, NULL));
}

That invalidates the first valid sibling partition after gone and gives its active CPUs to p->effective_cpus, leaving later sibling partitions valid. Here, new_cpus still holds the union of all remaining children's CPUs when visiting the first sibling after gone, so cpumask_subset(new_cpus, child->effective_xcpus) is false until the last valid sibling. If p has two valid sibling partitions after gone where the first holds a deadline task and the second does not, cpuset_offline_moves_dl() and cpuset_cpus_allowed_without() inspect the second sibling and accept the offline, merging the deadline tasks of gone and the first sibling into p's root domain without admission control.

Also, if every active CPU in p->effective_xcpus belongs to child partitions visited before gone, new_cpus becomes empty before gone, and cpumask_subset(new_cpus, child->effective_xcpus) then matches a later valid child partition whose effective_xcpus are all offline.

Quoted 8 lines
kernel/cgroup/cpuset.c +8 -0
+bool cpuset_cpus_allowed_without(struct task_struct *tsk, int cpu,
+				 struct cpumask *pmask)
+{
+	const struct cpumask *possible = task_cpu_possible_mask(tsk);
+	struct cpuset *cs = task_cs(tsk), *from, *gone = NULL;
+
+	guard(rcu)();
+	if (!is_in_v2_mode()) {

[ ... ]

Quoted 14 lines
kernel/cgroup/cpuset.c +14 -0
+	} else {
+		/*
+		 * cgroup v2 works out the CPUs of each cpuset from the top
+		 * down. A cpuset keeps those of its parent that cpuset.cpus
+		 * holds, or takes all of them if there are none. Start from
+		 * the nearest partition root that keeps an active CPU, or from
+		 * the top cpuset. A partition root left with no CPU of its own
+		 * can take those of a child partition. One left with tasks and
+		 * no CPU becomes invalid, and its tasks count in its parent.
+		 */
+		for (from = cs; ; from = parent_cs(from)) {
+			if (from != &top_cpuset && !is_partition_valid(from))
+				continue;
+			cpumask_and(pmask, from->effective_cpus, cpu_active_mask);

kernel/cgroup/cpuset.c void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask) · line 4465

Quoted 10 lines
kernel/cgroup/cpuset.c +10 -0
+			cpumask_clear_cpu(cpu, pmask);
+			if (cpumask_empty(pmask) && from != &top_cpuset &&
+			    !partition_child_lost(from, cpu, pmask, gone))
+				cpumask_clear(pmask);
+			if (!cpumask_empty(pmask) || from == &top_cpuset)
+				break;
+			gone = gone || partition_populated_offline(from) ? from : NULL;
+		}
+		effective_cpus_below(cs, from, pmask);
+	}

[Severity: Medium]
Can gone cascade upward across an unpopulated parent partition here and in cpuset_offline_moves_dl()?

Suppose an unpopulated partition P1 has no active CPUs of its own and only one valid child partition P2, which is populated and loses its last active CPU. cpuset_handle_hotplug() walks descendants in pre-order and visits P1 before P2; at that point P2 is still valid, so partition_is_populated(P1, NULL) is false and P1 remains a valid partition with empty effective_cpus when P2 is later invalidated. With gone || partition_populated_offline(from), once gone is set to P2, the next iteration at P1 sets gone = P1 and climbs to parent_cs(P1) (or top_cpuset), so cpuset_cpus_allowed_without() returns the ancestor's CPUs instead of taking the empty-mask fallback path, and cpuset_offline_moves_dl() checks sibling partitions of P1 that are not invalidated.

Quoted 1 line
kernel/cgroup/cpuset.c +1 -0
+	if (!cpumask_and(pmask, pmask, possible)) {

[ ... ]

kernel/cgroup/cpuset.c void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask) · line 4504

Quoted 13 lines
kernel/cgroup/cpuset.c +13 -0
+static bool dl_task_in_cpuset(struct cpuset *cs)
+{
+	struct css_task_iter it;
+	struct task_struct *task;
+	bool found = false;
+
+	css_task_iter_start(&cs->css, 0, &it);
+	while (!found && (task = css_task_iter_next(&it)))
+		found = task->policy == SCHED_DEADLINE &&
+			READ_ONCE(task->__state) != TASK_DEAD;
+	css_task_iter_end(&it);
+	return found;
+}

[Severity: Medium]
Does dl_task_in_cpuset() match sugov kthreads in top_cpuset that do not hold root-domain deadline bandwidth?

sugov_kthread_create() creates SCHED_DEADLINE kernel threads with SCHED_FLAG_SUGOV in top_cpuset, which dl_se_holds_bw() excludes from root-domain bandwidth accounting. When the last active CPU of top_cpuset goes offline while a partition exists and dl_nr_bw_tasks is non-zero, cpuset_offline_moves_dl() sets lost = &top_cpuset and calls dl_task_in_cpuset(&top_cpuset), refusing the offline with -EBUSY whenever a sugov kthread is present.

Quoted 33 lines
kernel/cgroup/cpuset.c +33 -0
+bool cpuset_offline_moves_dl(int cpu)
+{
+	struct cgroup_subsys_state *pos_css;
+	struct cpuset *cp, *a, *p = &top_cpuset, *lost = NULL;
+	bool found = false;
+
+	if (!is_in_v2_mode())
+		return false;
+	rcu_read_lock();
+	cpuset_for_each_descendant_pre(cp, pos_css, &top_cpuset) {
+		if (cp != &top_cpuset && is_partition_valid(cp) &&
+		    cpumask_test_cpu(cpu, cp->effective_cpus)) {
+			p = cp;
+			break;
+		}
+	}
+	if (p != &top_cpuset) {
+		struct cpuset *gone = NULL;
+
+		/*
+		 * A partition left with tasks and no CPU becomes invalid. Its
+		 * tasks then count in its parent, which can take the CPUs of a
+		 * later child partition. The parent is then the one that takes
+		 * CPUs.
+		 */
+		while (!(lost = partition_child_lost(p, cpu, &dl_offline_cpus, gone)) &&
+		       cpumask_empty(&dl_offline_cpus) &&
+		       (gone || partition_populated_offline(p)) &&
+		       parent_cs(p) != &top_cpuset && is_partition_valid(parent_cs(p))) {
+			gone = p;
+			p = parent_cs(p);
+		}
+	} else {

kernel/cgroup/cpuset.c void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask) · line 4567

Quoted 10 lines
kernel/cgroup/cpuset.c +10 -0
+		cpumask_and(&dl_offline_cpus, top_cpuset.effective_cpus, cpu_active_mask);
+		cpumask_clear_cpu(cpu, &dl_offline_cpus);
+		if (cpumask_empty(&dl_offline_cpus) && !cpumask_empty(subpartitions_cpus))
+			lost = &top_cpuset;
+	}
+	if (!lost) {
+		rcu_read_unlock();
+		return false;
+	}
+	cpuset_for_each_descendant_pre(cp, pos_css, lost) {

[Severity: Medium]
Can deadline tasks in gone change root domain undetected when gone is an isolated partition and its parent p is a non-isolated partition?

Suppose p is PRS_ROOT with no active CPUs of its own and has two PRS_ISOLATED child partitions: C1 on CPU 1 with deadline tasks (counted in def_root_domain) and C2 on CPU 2 with no deadline tasks. When CPU 1 goes offline, C1 becomes gone and C2 becomes lost. cpuset_offline_moves_dl() only walks descendants of lost (C2) and finds no deadline tasks, while dl_task_leaves_span() checks C1's tasks against the current def_root_domain span, which still includes CPU 2 because C2 has not been invalidated yet. Both checks pass, and hotplug then invalidates C1 and C2 into p, moving CPU 2 and C1's deadline tasks out of def_root_domain into p's PRS_ROOT root domain without admission control.

kernel/cgroup/cpuset.c void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask) · line 4576

Quoted 9 lines
kernel/cgroup/cpuset.c +9 -0
+		/* The partition that gives @cp its CPUs. */
+		for (a = cp; a != lost && !is_partition_valid(a); a = parent_cs(a))
+			;
+		if (lost != &top_cpuset &&
+		    ((a->partition_root_state == PRS_ISOLATED &&
+		      p->partition_root_state == PRS_ISOLATED) ||
+		     (a == lost && a->partition_root_state != PRS_ISOLATED &&
+		      p->partition_root_state != PRS_ISOLATED)))
+			continue;

[Severity: Medium]
Does skipping a == lost when neither lost nor p is PRS_ISOLATED hold when lost has a valid child partition of its own?

When lost is invalidated, any valid child partition under lost is also invalidated, so p's root domain takes all active CPUs of lost->effective_xcpus rather than just lost->effective_cpus. If lost had effective_xcpus = {1, 2} and effective_cpus = {1} because a valid child partition held CPU 2 (with no deadline tasks), a member cpuset under lost configured with cpuset.cpus = 2 previously had an empty intersection with lost->effective_cpus and inherited {1}, where its deadline task was admitted. Skipping a == lost lets the offline of p's last CPU succeed, and once p's effective_cpus becomes {1, 2}, the member cpuset's effective_cpus switches from {1} to {2} (or a deadline task in lost pinned to {1} no longer spans its {1, 2} root domain).

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=16
#47 lore raw

Re: [PATCH v10 28/40] sched/deadline: Start a period for a task that enters the class blocked

In reply to Mathieu Desnoyers
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] sched/deadline: dl_boost_blocked() skips departed tasks with dl_deadline --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] sched/deadline: dl_boost_blocked() skips departed tasks with dl_deadline
--

commit 83a90ad95f7f2d67e4562e7ef1ff35c08c85da9f
Author: Mathieu Desnoyers <[email protected]>

sched/deadline: Start a period for a task that enters the class blocked

This commit starts a deadline period for a task blocked on an rt_mutex when it enters the deadline class or receives a new priority-inheritance donor while having no deadline reservation of its own.

Quoted 4 lines
kernel/sched/deadline.c +0 -0
index aa12908aeaeab..ee3a08ff33458 100644

[ ... ]

Quoted 17 lines
kernel/sched/deadline.c +13 -0
@@ -1184,6 +1195,30 @@ static inline void replenish_dl_new_period(struct sched_dl_entity *dl_se,
 	trace_sched_dl_replenish_tp(dl_se, cpu_of(rq), dl_get_type(dl_se, rq));
 }
 
+#ifdef CONFIG_RT_MUTEXES
+/*
+ * Start a period from the new donor of @p, if @p has no reservation of its
+ * own and waits on an rt_mutex. The enqueue does this for a queued task, in
+ * replenish_dl_entity(). A blocked task is not enqueued, but the chain walk
+ * copies its deadline into its waiter.
+ *
+ * The caller calls it only when the donor changes. A new period changes the
+ * deadline, so the chain walk finds the waiter out of date and goes on. In a
+ * ww_mutex cycle, a new period at each step would never let the walk stop.
+ *
+ * The caller holds the rq lock and the pi_lock of @p, and has updated the
+ * rq clock.

kernel/sched/deadline.c static inline void replenish_dl_new_period(struct sched_dl_entity *dl_se, · line 1220

Quoted 10 lines
kernel/sched/deadline.c +10 -0
+ */
+void dl_boost_blocked(struct task_struct *p)
+{
+	struct sched_dl_entity *dl_se = &p->dl;
+
+	if (!dl_se->dl_deadline && !dl_se->dl_throttled &&
+	    dl_task_pi_blocked(p))
+		replenish_dl_new_period(dl_se, task_rq(p));
+}
+#endif

[Severity: Medium]
Can dl_boost_blocked() skip starting a period for a task that left SCHED_DEADLINE before its 0-lag time?

When a deadline task switches to a non-deadline policy before its 0-lag time, switched_from_dl() arms inactive_timer and leaves dl_se->dl_deadline and dl_se->deadline non-zero until that timer fires. If the task blocks on an rt_mutex and is boosted back into dl_sched_class before dl_se->deadline passes, switched_to_dl() cancels inactive_timer (so __dl_clear_params() never clears dl_se->dl_deadline while the task remains boosted) and skips replenish_dl_new_period() because dl_se->deadline has not passed yet.

Once dl_se->deadline does pass while the task is still blocked and boosted, a subsequent boost by a new donor calls dl_boost_blocked(p), which sees dl_se->dl_deadline != 0 and returns without replenishing. The chain walk then requeues the waiter with the expired dl_se->deadline ahead of waiters with current deadlines.

Checking !dl_prio(p->normal_prio) (or whether dl_se->deadline has passed) instead of !dl_se->dl_deadline would cover tasks still carrying parameters from before they left the class.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=28
#64 lore raw

Re: [PATCH v10 37/40] sched/deadline: Keep the start of the period across a change of dl_deadline

In reply to Mathieu Desnoyers
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] sched/deadline: replenish_dl_entity() keeps old dl_deadline across periods - [Medium]…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] sched/deadline: replenish_dl_entity() keeps old dl_deadline across periods
- [Medium] sched/deadline: dl_is_implicit() bypasses constrained gap on dl_deadline growth
--

commit f729f2d93fa31589edb8491dd221ca94c6da13fe
Author: Mathieu Desnoyers <[email protected]>

sched/deadline: Keep the start of the period across a change of dl_deadline

This commit records the start of each deadline period in sched_dl_entity::period_start and uses it in dl_next_period() and dl_in_constrained_gap() so that mid-period changes to dl_deadline via sched_setattr() do not shift the computed start of the next period.

Quoted 4 lines
kernel/sched/deadline.c +0 -0
index b9c206a59c164..e9b3d3ec71d77 100644

[ ... ]

kernel/sched/deadline.c static inline bool dl_in_constrained_gap(struct sched_dl_entity *dl_se) · line 108

Quoted 7 lines
kernel/sched/deadline.c +1 -1
@@ -103,7 +104,7 @@ static inline bool dl_in_constrained_gap(struct sched_dl_entity *dl_se)
 	u64 now = rq_clock(rq_of_dl_se(dl_se));
 
 	return !dl_is_implicit(dl_se) && dl_time_before(dl_se->deadline, now) &&
-	       dl_time_before(now, dl_se->deadline - dl_se->dl_deadline + dl_se->dl_period);
+	       dl_time_before(now, dl_se->period_start + dl_se->dl_period);
 }

[Severity: Medium]
Can a constrained task whose dl_deadline is increased to equal dl_period during an active period still bypass throttling in the gap between its current deadline and its next period?

When sched_setattr() sets dl_deadline == dl_period mid-period, dl_is_implicit(dl_se) becomes true while dl_se->deadline is still earlier than dl_next_period(dl_se). Because dl_in_constrained_gap(), enqueue_dl_entity(), update_dl_entity(), and dl_proxy_block() gate their constrained-deadline checks on !dl_is_implicit(dl_se), a task waking between dl_se->deadline and dl_next_period(dl_se) skips dl_check_constrained_dl() and receives a new period and full runtime early via replenish_dl_new_period():

kernel/sched/deadline.c:enqueue_dl_entity() {
	...
	if (!dl_se->dl_throttled && !dl_is_implicit(dl_se))
		dl_check_constrained_dl(dl_se);
	...
}

[ ... ]

kernel/sched/deadline.c static void replenish_dl_entity(struct sched_dl_entity *dl_se) · line 1434

Quoted 7 lines
kernel/sched/deadline.c +1 -0
@@ -1425,6 +1429,7 @@ static void replenish_dl_entity(struct sched_dl_entity *dl_se)
 	 */
 	while (dl_se->runtime <= 0) {
 		dl_se->deadline += period;
+		dl_se->period_start += period;
 		dl_se->runtime += runtime;
 	}

[Severity: High]
Does advancing dl_se->deadline by period here keep the old relative deadline offset across future periods after sched_setattr() changes dl_deadline?

With start_dl_timer() now arming the replenishment timer at dl_se->period_start + dl_se->dl_period instead of shifting by the old dl_deadline, dl_se->deadline at replenishment time is still period_start + old_dl_deadline. Adding period to both dl_se->period_start and dl_se->deadline leaves dl_se->deadline at
new_period_start + old_dl_deadline instead of dl_se->period_start + deadline, so subsequent periods continue using the old relative deadline and can falsely throttle the task in dl_check_constrained_dl() or grant a second replenishment mid-period in update_dl_entity().

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=37
#43 lore raw

Re: [PATCH v10 26/40] sched/deadline: Replenish a throttled task boosted while asleep

In reply to Mathieu Desnoyers
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] sched/deadline: missing dl_note_donor_refill() in replenish_dl_entity() - [Medium] sched/deadline…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] sched/deadline: missing dl_note_donor_refill() in replenish_dl_entity()
- [Medium] sched/deadline: dl_task_timer() refills sleeping task from donor parameters
--

commit c9c72591d4a367d03f9bada51027022e7fbe7e42
Author: Mathieu Desnoyers <[email protected]>

sched/deadline: Replenish a throttled task boosted while asleep

This commit lets dl_task_timer() replenish a throttled task that was PI boosted while sleeping instead of returning early before clearing dl_throttled.

Quoted 9 lines
kernel/sched/deadline.c +0 -1
index 2912d13b60d60..9a4639ae676a4 100644
@@ -1705,10 +1705,13 @@ static enum hrtimer_restart dl_task_timer(struct hrtimer *timer)
 	}
 
 	/*
-	 * The task might have been boosted by someone else and might be in the

kernel/sched/deadline.c static enum hrtimer_restart dl_task_timer(struct hrtimer *timer) · line 1715

Quoted 10 lines
kernel/sched/deadline.c +6 -2
-	 * boosting/deboosting path, its not throttled.
+	 * A boost overrides the throttle. enqueue_task_dl() lifts it when the
+	 * boost enqueues the task, or when the task wakes up boosted. So a
+	 * queued task needs nothing here. A boost of a sleeping task does not
+	 * enqueue it, and it can end before the wakeup. Nothing would lift the
+	 * throttle then. So let a sleeping task reach the !queued case below.
 	 */
-	if (is_dl_boosted(dl_se) && task_on_rq_queued(p))
+	if (is_dl_boosted(dl_se) && task_on_rq_queued(p))
 		goto unlock;

[Severity: Medium]
Can replenish_dl_entity() leave dl_se->dl_donor_refill unset when a sleeping SCHED_DEADLINE task's donor has its parameters cleared before dl_task_timer() fires?

If the donor leaves SCHED_DEADLINE and reaches its 0-lag time before the rt_mutex chain walk finishes deboosting the sleeping owner, replenish_dl_entity() takes the cleared-parameter branch:

kernel/sched/deadline.c:replenish_dl_entity() {
	if (unlikely(!runtime || !deadline || !period)) {
		WARN_ON_ONCE(!is_dl_boosted(dl_se));
		if (!dl_se->dl_deadline) {
			dl_se->deadline = rq_clock(rq);
			dl_se->runtime = 0;
			dl_note_donor_refill(dl_se);
		}
		if (dl_se->runtime < 0 || dl_se->dl_yielded)
			dl_se->runtime = 0;
		dl_se->dl_yielded = 0;
		dl_se->dl_throttled = 0;
		return;
	}

Because a SCHED_DEADLINE owner has dl_se->dl_deadline != 0, it skips dl_note_donor_refill(dl_se) while zeroing runtime and clearing dl_throttled. When dl_deboost() then runs, dl_se->dl_donor_refill is 0, so it does not start a new period of the task's own reservation, leaving the owner with runtime == 0 and a stale past deadline that prevents remaining deadline waiters from re-boosting it. Calling dl_note_donor_refill(dl_se) and updating dl_se->deadline unconditionally in the cleared-parameter branch would ensure dl_deboost() resets the owner's reservation.

[Severity: Medium]
Does calling replenish_dl_entity() from dl_task_timer() refill a sleeping task's pre-boost runtime debt using the donor's parameters?

A boosted task is never throttled with dl_timer armed while boosted, so a task reaching dl_task_timer() with is_dl_boosted(dl_se) && !task_on_rq_queued(p) was throttled on its own reservation as it went to sleep and has consumed no runtime while boosted. However, replenish_dl_entity() reads runtime and period from pi_of(dl_se) and calls dl_note_donor_refill(dl_se):

kernel/sched/deadline.c:replenish_dl_entity() {
	if (dl_se->runtime <= 0)
		dl_note_donor_refill(dl_se);

	while (dl_se->runtime <= 0) {
		dl_se->deadline += period;
		dl_se->runtime += runtime;
	}

If the sleeping owner overran its own large runtime and is boosted by a waiter with a small dl_runtime, the loop pays back the owner's pre-boost overrun in increments of the donor's runtime and period, pushing dl_se->deadline multiple donor periods into the future so the owner runs with a far-future deadline upon wakeup instead of the donor's urgent deadline. Conversely, if the waiter times out before the owner wakes up, dl_deboost() sees dl_se->dl_donor_refill set, grants a fresh full period that erases the owner's pre-boost overrun, and cancels inactive_timer early to drop running_bw before the true 0-lag time. In addition, with later commit "sched/deadline: Boost an owner that cannot run on its own reservation", dl_boost_start() saves the throttled sleeping task's negative own_runtime and expired own_deadline with dl_boost_held = 1, and dl_deboost() restores those unreplenished values after dl_task_timer() has already cleared dl_throttled.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=26
#26 lore raw

Re: [PATCH v10 17/40] cgroup/cpuset: Refuse to take a deadline task out of its root domain

In reply to Mathieu Desnoyers
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] cgroup/cpuset: dl_tasks_keep_without() omits pending CPUs for PRS_ISOLATED - [Low] sched/deadline…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] cgroup/cpuset: dl_tasks_keep_without() omits pending CPUs for PRS_ISOLATED
- [Low] sched/deadline: dl_task_keeps_root_domain() does not skip TASK_DEAD tasks
--

commit 70ebc9e9b00f4d77522df69295e46140ef69f4bc
Author: Mathieu Desnoyers <[email protected]>

cgroup/cpuset: Refuse to take a deadline task out of its root domain

This commit rejects cpuset mask changes with -EBUSY or invalidates partitions with PERR_DLTASK when the new effective CPU mask would leave a SCHED_DEADLINE task without any CPUs in the root domain that accounts its bandwidth.

Quoted 4 lines
kernel/cgroup/cpuset.c +0 -0
index e3c42c63844ba..ea0962f69ba4f 100644

[ ... ]

Quoted 40 lines
kernel/cgroup/cpuset.c +36 -0
@@ -1148,6 +1181,91 @@ static void effective_cpus_below(struct cpuset *cp, struct cpuset *from,
 	}
 }
 
+/*
+ * A scratch mask for dl_tasks_keep_without(). Its callers still need each
+ * mask of their struct tmpmasks after the call. Protected by
+ * cpuset_mutex.
+ */
+static cpumask_var_t dl_keep_cpus, dl_pending_cpus;
+
+/*
+ * Return false if a partition that takes the CPUs of @xcpus makes a
+ * deadline task leave the root domain that counts its bandwidth. A cpuset
+ * can hold CPUs of two root domains: with isolcpus="domain", or on cgroup
+ * v1 with sched_load_balance off. Such a task would run in a root domain
+ * that did not admit it.
+ *
+ * @root is the partition root that gives the CPUs. @part is the cpuset
+ * that takes them. In the same change, @part can give the CPUs of @gives
+ * back to @root. @gives is NULL if it gives none back.
+ *
+ * Work out the new CPUs of each cpuset of @root from the top down, as
+ * update_cpumasks_hier() does, down to the next partition roots. If
+ * @enable, @part becomes a partition root. Then do the same for its own
+ * cpusets, starting from the active CPUs of @xcpus.
+ */
+static bool dl_tasks_keep_without(struct cpuset *root, struct cpuset *part,
+				  const struct cpumask *xcpus,
+				  const struct cpumask *gives, bool enable)
+{
+	struct cpumask *new_cpus = dl_keep_cpus, *pending = NULL;
+	struct cgroup_subsys_state *pos_css;
+	struct cpuset *cp;
+	bool keep = true;
+
+	lockdep_assert_cpuset_lock_held();
+	/*
+	 * The CPUs of @root can have changed before the rebuild of the
+	 * sched domains, which ends the change. Then the root domain of a

kernel/cgroup/cpuset.c static void effective_cpus_below(struct cpuset *cp, struct cpuset *from, · line 1229

Quoted 10 lines
kernel/cgroup/cpuset.c +10 -0
+	 * task of @root does not span them yet. The rebuild gives the CPUs
+	 * of a root partition to one root domain.
+	 */
+	if (root->partition_root_state == PRS_ROOT) {
+		pending = dl_pending_cpus;
+		cpumask_copy(pending, root->effective_cpus);
+		if (root == &top_cpuset)
+			cpumask_and(pending, pending,
+				    housekeeping_cpumask(HK_TYPE_DOMAIN_BOOT));
+	}

[Severity: Medium]
Should pending also be populated when root->partition_root_state is PRS_ISOLATED (for example via is_partition_valid(root))?

An isolated partition root can have an isolated child partition and hold SCHED_DEADLINE tasks whose bandwidth is counted in def_root_domain. When an isolated parent partition holding a deadline task grows by acquiring a new CPU, that CPU is not added to def_root_domain.span until rebuild_sched_domains_locked() runs at the end of the change. While update_cpumasks_hier() re-evaluates an invalid child isolated partition via update_parent_effective_cpumask() -> dl_tasks_keep_without(), pending is NULL, so dl_task_keeps_root_domain() only checks the pre-rebuild def_root_domain.span and leaves the child partition invalid with PERR_DLTASK.

Quoted 22 lines
kernel/sched/deadline.c +14 -0
index 604b105672103..d8a912ea13d18 100644
@@ -5287,6 +5287,42 @@ int dl_bw_deactivate(int cpu)
 	return ret;
 }
 
+/*
+ * Return false if @p has CPUs in the root domain that counts its
+ * bandwidth and @new_mask holds none of them. A cpuset refuses such a
+ * mask: only a move to another cpuset makes room in another root domain.
+ * Like __set_cpus_allowed_ptr(), keep @new_mask within the affinity set by
+ * the user, if they intersect. @pending is NULL, or holds the CPUs that
+ * the rebuild at the end of the change gives to the root domain of a
+ * partition root.
+ */
+bool dl_task_keeps_root_domain(struct task_struct *p,
+			       const struct cpumask *new_mask,
+			       const struct cpumask *pending)
+{
+	const struct cpumask *span, *user = cpu_possible_mask;

kernel/sched/deadline.c int dl_bw_deactivate(int cpu) · line 5313

Quoted 10 lines
kernel/sched/deadline.c +10 -0
+
+	if (!dl_bandwidth_enabled() || !task_has_dl_policy(p))
+		return true;
+	/* pi_lock also protects p->user_cpus_ptr. */
+	guard(raw_spinlock_irqsave)(&p->pi_lock);
+	guard(rcu)();
+	span = dl_task_bw_span(p);
+	/* A task in a migrate_disable() section has a cpus_ptr of one CPU. */
+	if (!span || !cpumask_intersects(span, &p->cpus_mask))
+		return true;

[Severity: Low]
Should dl_task_keeps_root_domain() ignore tasks with READ_ONCE(p->__state) == TASK_DEAD, the way dl_task_leaves_span() and dl_task_in_cpuset() do?

When a SCHED_DEADLINE thread in a multi-threaded process exits before its 0-lag time, it stays on dl_departed_list with a non-NULL dl_task_bw_span(p) and remains visible to css_task_iter_next() until do_cgroup_task_dead() unlinks it from cset->tasks. Evaluating that dead thread here can cause a cpuset.cpus write to fail with -EBUSY or a partition update to fail with PERR_DLTASK.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=17
#51 lore raw

Re: [PATCH v10 30/40] sched/deadline: Start a period for a task requeued onto an rt_mutex

In reply to Mathieu Desnoyers
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [Medium] sched/deadline: dl_proxy_block() skips period start for PI-boosted tasks - [Medium]…

Thank you for your contribution! Sashiko AI review found 4 potential issues to consider:
- [Medium] sched/deadline: dl_proxy_block() skips period start for PI-boosted tasks
- [Medium] locking/rtmutex: proxy lock steal uses stale deadline before dl_proxy_block()
- [Medium] sched/deadline: missing dl_entity_overflow() check in dl_proxy_block()
- [Medium] sched/deadline: dl_proxy_block() skips period start for zero constrained deadline
--

commit ccbb5e6cd761023e5e38a79f3d3be937fad4a331
Author: Mathieu Desnoyers <[email protected]>

sched/deadline: Start a period for a task requeued onto an rt_mutex

This commit adds dl_proxy_block() to start a new period for a sleeping SCHED_DEADLINE task when it is proxy-locked onto an rt_mutex, so the waiter node does not use a deadline of 0 or a deadline in the past.

Quoted 5 lines
kernel/locking/rtmutex.c +0 -0
index b09816977d4e5..5ff123d24b2a6 100644

kernel/locking/rtmutex.c static int __sched task_blocks_on_rt_mutex(struct rt_mutex_base *lock, · line 1253

Quoted 9 lines
kernel/locking/rtmutex.c +3 -0
@@ -1245,6 +1245,9 @@ static int __sched task_blocks_on_rt_mutex(struct rt_mutex_base *lock,
 		return -EDEADLK;
 
 	raw_spin_lock(&task->pi_lock);
+	/* A proxy lock: @task sleeps, and its deadline can be stale. */
+	if (task != current)
+		dl_proxy_block(task);
 	waiter->task = task;
 	waiter->lock = lock;
 	waiter_update_prio(waiter, task);

[Severity: Medium]
Can __rt_mutex_start_proxy_lock() steal the rt_mutex using a stale task->dl.deadline before task_blocks_on_rt_mutex() runs dl_proxy_block()?

__rt_mutex_start_proxy_lock() calls try_to_take_rt_mutex(lock, task, NULL) before calling task_blocks_on_rt_mutex(). When the target PI futex has just been unlocked and is in the handoff state with waiters, try_to_take_rt_mutex() tests rt_mutex_steal(task_to_waiter(task), rt_mutex_top_waiter(lock)), which reads task->dl.deadline before dl_proxy_block() refreshes it:

kernel/locking/rtmutex.c:try_to_take_rt_mutex() {
    ...
		if (rt_mutex_has_waiters(lock)) {
			/* Check whether the trylock can steal it. */
			if (!rt_mutex_steal(task_to_waiter(task),
					    rt_mutex_top_waiter(lock)))
				return 0;
    ...
}

A requeued task with a deadline of 0 or a passed deadline can then steal the lock from a woken top waiter with an earlier real deadline, and because try_to_take_rt_mutex() does not call rt_mutex_adjust_prio(), the new owner remains unboosted once wakeup assigns its real later deadline.

Quoted 17 lines
kernel/sched/deadline.c +9 -0
index b1346be9e81da..1c5888b1717de 100644
@@ -1573,6 +1573,36 @@ static inline u64 dl_next_period(struct sched_dl_entity *dl_se)
 	return dl_se->deadline - dl_se->dl_deadline + dl_se->dl_period;
 }
 
+#ifdef CONFIG_RT_MUTEXES
+/*
+ * FUTEX_CMP_REQUEUE_PI makes @p wait on an rt_mutex while @p sleeps.
+ * The waiter node of @p takes its deadline, before any wakeup. @p would
+ * not run with a deadline of 0, which it has if it entered the class
+ * asleep. Nor would it run with a deadline that has passed. Start a new
+ * period then, as its wakeup would. Leave a task past its deadline and
+ * before its next period: its wakeup throttles it until that period.
+ *

kernel/sched/deadline.c static inline u64 dl_next_period(struct sched_dl_entity *dl_se) · line 1594

Quoted 10 lines
kernel/sched/deadline.c +10 -0
+ * The caller holds the pi_lock of @p.
+ */
+void dl_proxy_block(struct task_struct *p)
+{
+	struct sched_dl_entity *dl_se = &p->dl;
+	struct rq_flags rf;
+	struct rq *rq;
+
+	if (!dl_task(p) || is_dl_boosted(dl_se) || !dl_se->dl_runtime)
+		return;

[Severity: Medium]
Does returning early on is_dl_boosted(dl_se) or !dl_se->dl_runtime leave p->dl.deadline at 0 (or expired) when p was PI-boosted while sleeping in FUTEX_WAIT_REQUEUE_PI?

While p sleeps in futex_wait_requeue_pi(), p is not queued and p->pi_blocked_on is NULL (so dl_task_pi_blocked(p) is false). If p holds another rt_mutex and a SCHED_DEADLINE waiter blocks on it, both dl_boost_blocked() and switched_to_dl() skip replenish_dl_new_period() because dl_task_pi_blocked(p) is false, leaving p->dl.deadline at 0 or at a passed deadline. When FUTEX_CMP_REQUEUE_PI then requeues p onto a second rt_mutex, dl_proxy_block() returns early instead of starting a period from pi_of(dl_se), and waiter_update_prio() copies the 0 or expired deadline into waiter->tree.deadline.

kernel/sched/deadline.c static inline u64 dl_next_period(struct sched_dl_entity *dl_se) · line 1601

Quoted 7 lines
kernel/sched/deadline.c +7 -0
+	rq = __task_rq_lock(p, &rf);
+	update_rq_clock(rq);
+	if (!task_on_rq_queued(p) && !dl_se->dl_throttled &&
+	    dl_time_before(dl_se->deadline, rq_clock(rq)) &&
+	    (dl_is_implicit(dl_se) ||
+	     !dl_time_before(rq_clock(rq), dl_next_period(dl_se))))
+		replenish_dl_new_period(dl_se, rq);

[Severity: Medium]
Should an implicit-deadline task also start a new period here when dl_entity_overflow(dl_se, rq_clock(rq)) is true?

When an implicit-deadline task sleeps in FUTEX_WAIT_REQUEUE_PI past its 0-lag time (or has its parameters shrunk via sched_setattr() while sleeping) and is requeued before its old dl_se->deadline passes, dl_entity_overflow(dl_se, rq_clock(rq)) is already true. Because the task is asleep, update_dl_entity() will unconditionally see dl_entity_overflow() (or a passed deadline) at wakeup and call replenish_dl_new_period(). Without checking dl_entity_overflow() in dl_proxy_block(), waiter_update_prio() copies the old dl_se->deadline that the task would never run with, causing it to sort ahead of waiters whose deadlines are earlier than its wakeup deadline.

[Severity: Medium]
What happens if a constrained-deadline task has dl_se->deadline == 0 when rq_clock(rq) is still before dl_next_period(dl_se)?

If sched_setattr() switches a task sleeping in FUTEX_WAIT_REQUEUE_PI to SCHED_DEADLINE with dl_deadline < dl_period, dl_se->deadline is 0. Because dl_is_implicit(dl_se) is false, dl_proxy_block() evaluates dl_next_period(dl_se), which computes dl_period - dl_deadline (or dl_period after commit "sched/deadline: Keep the start of the period across a change of dl_deadline") as if a period had started at t = 0. If rq_clock(rq) < dl_next_period(dl_se), dl_proxy_block() skips replenish_dl_new_period() and leaves waiter->tree.deadline at 0. Checking !dl_se->deadline before testing dl_next_period(dl_se) would avoid this.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=30
#40 lore raw

Re: [PATCH v10 25/40] sched/deadline: Reset the donor's runtime at a deboost in the class

In reply to Mathieu Desnoyers
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] sched/deadline: dl_deboost() starts period for sleeping constrained task --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] sched/deadline: dl_deboost() starts period for sleeping constrained task
--

commit 280104d364cfcdeb61df32b73bafd44ef91c8ae1
Author: Mathieu Desnoyers <[email protected]>

sched/deadline: Reset the donor's runtime at a deboost in the class

This commit records whether a boosted deadline entity had its runtime refilled from its donor's parameters in dl_donor_refill, and starts a new period from the entity's own reservation when deboosting within SCHED_DEADLINE if that flag is set.

Quoted 29 lines
kernel/sched/deadline.c +21 -0
index a566e9252a418..2912d13b60d60 100644
@@ -93,12 +93,62 @@ static inline bool is_dl_boosted(struct sched_dl_entity *dl_se)
 {
 	return pi_of(dl_se) != dl_se;
 }
+
+/*
+ * Record that @dl_se had its runtime refilled from the parameters of its
+ * donor, if it is boosted.
+ */
+static inline void dl_note_donor_refill(struct sched_dl_entity *dl_se)
+{
+	if (is_dl_boosted(dl_se))
+		dl_se->dl_donor_refill = 1;
+}
+
+static void task_non_contending(struct sched_dl_entity *dl_se, bool dl_task);
+
+/*
+ * End the boost of @dl_se, whose task stays in the class. If the boost
+ * refilled its runtime from the donor's parameters, start a new period
+ * now. The next enqueue is too late for a task blocked on another
+ * rt_mutex: the chain walk copies its deadline into its waiter node
+ * first. Without a refill, the task keeps the runtime and the deadline
+ * of its own reservation.
+ *

kernel/sched/deadline.c static inline bool is_dl_boosted(struct sched_dl_entity *dl_se) · line 126

Quoted 10 lines
kernel/sched/deadline.c +10 -0
+ * The caller holds the rq lock and the pi_lock of the task, and has
+ * updated the rq clock.
+ */
+void dl_deboost(struct sched_dl_entity *dl_se)
+{
+	struct rq *rq = rq_of_dl_se(dl_se);
+
+	if (dl_se->dl_donor_refill) {
+		dl_se->deadline = rq_clock(rq) + dl_se->dl_deadline;
+		dl_se->runtime = dl_se->dl_runtime;

[Severity: Medium]
Does starting a new period in dl_deboost() while the task is asleep cause a constrained-deadline task (dl_deadline < dl_period) to lose runtime or be throttled when it later wakes up?

If a deadline waiter times out on an rt_mutex held by a sleeping constrained-deadline task with dl_donor_refill set (and not blocked on another rt_mutex), dl_deboost() sets dl_se->deadline = t_deboost + dl_deadline and dl_se->runtime = dl_runtime while the task sleeps. When the task later wakes up at t_wake:

- if t_deboost < t_wake <= t_deboost + dl_deadline, dl_entity_overflow() is true because dl_se->runtime == dl_runtime while remaining time to deadline is less than dl_deadline, so update_dl_entity() calls update_dl_revised_wakeup() and scales down dl_se->runtime for the time spent sleeping since t_deboost;
- if t_deboost + dl_deadline < t_wake < t_deboost + dl_period, enqueue_dl_entity() -> dl_check_constrained_dl() sees deadline < t_wake < dl_next_period(dl_se) and throttles the waking task until t_deboost + dl_period, even though it did not run during that period.

Later in this series, commit "sched/deadline: Check the runtime of a task whose parameters change" avoids starting a period at deboost for dl_new_params when the task is neither queued nor pi-blocked, and commit "sched/deadline: Boost an owner that cannot run on its own reservation" restores the task's saved reservation when dl_boost_held is set, but the dl_donor_refill path in dl_deboost() still starts a period while asleep.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=25
#67 lore raw

Re: [PATCH v10 38/40] sched/deadline: Boost an owner that cannot run on its own reservation

In reply to Mathieu Desnoyers
Thank you for your contribution! Sashiko AI review found 6 potential issues to consider: - [High] sched/deadline: missing throttle restoration in dl_deboost() - [High] sched/deadline: donor period…

Thank you for your contribution! Sashiko AI review found 6 potential issues to consider:
- [High] sched/deadline: missing throttle restoration in dl_deboost()
- [High] sched/deadline: donor period added to own_deadline in replenish_dl_entity()
- [Medium] sched/deadline: missing dl_boost_held check in switched_from_dl()
- [Medium] sched/deadline: expired own_deadline restored in dl_deboost()
- [Medium] sched/deadline: stale deadline on PI chain in dl_boost_blocked()
- [Medium] sched/deadline: missing refill on boosted wakeup in enqueue_task_dl()
--

commit 59eba5619dd87ca592a528ffc0286ed100abcecc
Author: Mathieu Desnoyers <[email protected]>

sched/deadline: Boost an owner that cannot run on its own reservation

This commit updates deadline priority inheritance so that a deadline waiter boosts a lock owner that is throttled or past its deadline, saving and restoring the owner's parameters across the boost when it could not run on its own reservation.

Quoted 9 lines
kernel/sched/core.c +0 -1
index 0dce129b41468..cbe0dfe26de3d 100644
@@ -7974,10 +7974,13 @@ void rt_mutex_setprio(struct task_struct *p, struct task_struct *pi_task)
 			if (!dl_prio(p->normal_prio) ||
 			    (pi_task && dl_prio(pi_task->prio) &&
 			     !(p->dl.dl_new_params && p->dl.pi_se != &p->dl) &&
-			     dl_entity_preempt(&pi_task->dl, &p->dl))) {

kernel/sched/core.c void rt_mutex_setprio(struct task_struct *p, struct task_struct *pi_task) · line 7986

Quoted 10 lines
kernel/sched/core.c +4 -0
+			     dl_waiter_boosts(p, pi_task))) {
 				struct sched_dl_entity *old_donor = p->dl.pi_se;
 
 				dl_set_donor(&p->dl, pi_task);
+				if (dl_prio(p->normal_prio) && old_donor == &p->dl &&
+				    p->dl.pi_se != &p->dl)
+					dl_boost_start(&p->dl);
 				scope->flags |= ENQUEUE_REPLENISH;
 				if (!scope->queued && p->dl.pi_se != old_donor)
 					dl_boost_blocked(p);

[Severity: Medium]
When p is a deadline task blocked on another rt_mutex (!scope->queued), does dl_boost_blocked(p) leave p->dl.deadline stale for the rest of the PI chain walk?

sched_change_end() skips enqueue_task_dl() when !scope->queued, and dl_boost_blocked() only replenishes tasks with !dl_se->dl_deadline && !dl_se->dl_throttled:

kernel/sched/deadline.c:dl_boost_blocked() {
	struct sched_dl_entity *dl_se = &p->dl;

	if (!dl_se->dl_deadline && !dl_se->dl_throttled &&
	    dl_task_pi_blocked(p))
		replenish_dl_new_period(dl_se, task_rq(p));
}

When p has its own deadline parameters or is throttled, p->dl.deadline is not updated to the donor's deadline before rt_mutex_adjust_prio_chain() calls waiter_update_prio() and dl_waiter_boosts() on the next lock in the chain, so the boost fails to propagate across nested rt_mutexes.

Quoted 9 lines
kernel/sched/deadline.c +0 -1
index e9b3d3ec71d77..ff1c104f6afd8 100644
@@ -161,21 +165,32 @@ static inline bool dl_task_pi_blocked(struct task_struct *p)
 void dl_deboost(struct sched_dl_entity *dl_se)
 {
 	struct task_struct *p = dl_task_of(dl_se);
-

kernel/sched/deadline.c static inline bool dl_task_pi_blocked(struct task_struct *p) · line 177

Quoted 10 lines
kernel/sched/deadline.c +10 -0
+	bool own = false;
+
+	/* Put back what dl_boost_start() saved. */
+	if (dl_se->dl_boost_held) {
+		dl_se->deadline = dl_se->own_deadline;
+		dl_se->runtime = dl_se->own_runtime;
+		dl_se->period_start = dl_se->own_period_start;
+		dl_se->dl_donor_refill = 0;
+		own = true;
+	}

[Severity: High]
When a task that was boosted while throttled (own_runtime <= 0) is deboosted before own_deadline, does restoring own_runtime without restoring dl_throttled leave the task runnable on dl_rq with exhausted runtime?

When the boost started, enqueue_task_dl() canceled dl_timer and cleared dl_se->dl_throttled = 0. If the boost ends before own_deadline, dl_deboost() restores own_deadline and own_runtime <= 0 with dl_throttled still 0, and enqueue_dl_entity() only checks dl_check_constrained_dl() for past deadlines before calling __enqueue_dl_entity(dl_se). The exhausted owner is then enqueued as runnable with its earlier own_deadline, preventing the woken waiter from preempting it and running beyond its CBS budget until the next tick. If dl_new_params was set during the boost, the subsequent dl_waiter_boosts() and dl_boost_start() check in rt_mutex_setprio() also sees dl_throttled == 0 and misses that the owner cannot run on its own reservation.

[Severity: Medium]
Should switched_from_dl() also restore own_deadline, own_runtime and own_period_start when dl_boost_held is set?

If a task boosted with dl_boost_held changes policy to a non-deadline class while boosted and leaves dl_sched_class at deboost, rt_mutex_setprio() runs switched_from_dl() and dl_drop_boost() instead of dl_deboost():

kernel/sched/deadline.c:switched_from_dl() {
	bool own_period = p->dl.dl_runtime && p->dl.dl_donor_refill;
    ...
	if (own_period)
		dl_start_own_period(&p->dl);

	if (task_on_rq_queued(p) && p->dl.dl_runtime)
		task_non_contending(&p->dl, false);
}

Because dl_donor_refill was set when the boosted task replenished from its donor, switched_from_dl() calls dl_start_own_period() and resets runtime to full dl_runtime instead of restoring the exhausted own_* reservation. task_non_contending() then sees a 0-lag time of now and releases the task's root-domain bandwidth immediately instead of waiting until the true 0-lag time of the saved period.

[ ... ]

Quoted 22 lines
kernel/sched/deadline.c +18 -0
@@ -214,6 +229,62 @@ void dl_check_blocked_params(struct task_struct *p)
 		update_dl_entity(dl_se);
 	}
 }
+
+/*
+ * Return true if the deadline waiter @pi_task must boost the owner @p,
+ * which has a deadline policy of its own. Compare @pi_task with the
+ * deadline that @p would run on:
+ * - @p is throttled, or past its deadline and before its next period:
+ *   it cannot run on its own reservation. Boost it.
+ * - @p was boosted for that reason: keep the boost until its own next
+ *   period. After that period starts, compare with now + dl_deadline.
+ * - @p is past its deadline otherwise: its next enqueue starts a new
+ *   period. Compare with now + dl_deadline.
+ * - Else, compare with the deadline of @p.
+ * A special entity, such as a sugov kthread, always boosts @p.
+ *
+ * The caller holds the rq lock of @p and has updated the rq clock.
+ */
+bool dl_waiter_boosts(struct task_struct *p, struct task_struct *pi_task)
+{

kernel/sched/deadline.c void dl_check_blocked_params(struct task_struct *p) · line 259

Quoted 10 lines
kernel/sched/deadline.c +10 -0
+	struct sched_dl_entity *dl_se = &p->dl;
+	u64 now = rq_clock(task_rq(p));
+
+	if (dl_entity_is_special(&pi_task->dl))
+		return true;
+	if (dl_se->dl_boost_held) {
+		if (dl_time_before(now, dl_se->own_period_start + dl_se->dl_period))
+			return true;
+		return dl_time_before(pi_task->dl.deadline, now + dl_se->dl_deadline);
+	}

[Severity: Medium]
Once now reaches own_period_start + dl_period, dl_waiter_boosts() compares pi_task against now + dl_se->dl_deadline, but if it returns false and triggers a deboost while p is pi-blocked on another rt_mutex, does dl_deboost() restore the expired own_deadline instead of starting a new period?

In dl_deboost(), the dl_boost_held branch unconditionally restores dl_se->deadline = dl_se->own_deadline (which is now in the past) and clears dl_se->dl_donor_refill = 0 so dl_start_own_period() is skipped. When p is blocked on a second rt_mutex (!scope->queued), enqueue_task_dl() does not run in sched_change_end(), so rt_mutex_adjust_prio_chain() copies that expired past deadline into p's waiter node on the outer lock and orders p ahead of waiters with valid future deadlines. The same expired own_deadline is also exposed on the outer lock if p is deboosted while still in the constrained gap and pi-blocked.

Quoted 18 lines
kernel/sched/deadline.c +18 -0
+	if (!is_dl_boosted(dl_se)) {
+		if (dl_se->dl_throttled || dl_in_constrained_gap(dl_se))
+			return true;
+		if (dl_time_before(dl_se->deadline, now))
+			return dl_time_before(pi_task->dl.deadline,
+					      now + dl_se->dl_deadline);
+	}
+	return dl_entity_preempt(&pi_task->dl, dl_se);
+}
+
+/*
+ * Call this when @dl_se gets its first donor, after dl_set_donor()
+ * installed it. If @dl_se cannot run on its own reservation, save its
+ * deadline, runtime and period start in own_*. Then set dl_boost_held.
+ * dl_deboost() puts them back. A task with no parameters of its own has
+ * nothing to save. The caller holds the rq lock and has updated the rq
+ * clock.
+ */

kernel/sched/deadline.c void dl_check_blocked_params(struct task_struct *p) · line 287

Quoted 10 lines
kernel/sched/deadline.c +10 -0
+void dl_boost_start(struct sched_dl_entity *dl_se)
+{
+	if (!dl_se->dl_runtime ||
+	    (!dl_se->dl_throttled && !dl_in_constrained_gap(dl_se)))
+		return;
+	dl_se->own_deadline = dl_se->deadline;
+	dl_se->own_runtime = dl_se->runtime;
+	dl_se->own_period_start = dl_se->period_start;
+	dl_se->dl_boost_held = 1;
+}

[Severity: Medium]
If an owner is throttled while going to sleep, boosted while asleep, and then wakes up before own_deadline while still boosted, does enqueue_task_dl() fail to replenish it from the donor?

When the boost happens while !scope->queued, ENQUEUE_REPLENISH is not consumed by sched_change_end(). On the subsequent wakeup, enqueue_task_dl(rq, p, ENQUEUE_WAKEUP) cancels dl_timer and clears dl_se->dl_throttled = 0 without setting ENQUEUE_REPLENISH, so enqueue_dl_entity() calls update_dl_entity(dl_se):

kernel/sched/deadline.c:update_dl_entity() {
    ...
	if (dl_time_before(dl_se->deadline, rq_clock(rq)) ||
	    dl_entity_overflow(dl_se, rq_clock(rq))) {
    ...
		replenish_dl_new_period(dl_se, rq);
	}
}

Because rq_clock(rq) < own_deadline and dl_se->runtime <= 0 makes left <= 0 while right > 0 in dl_entity_overflow(), both checks are false and replenish_dl_new_period() is skipped, enqueuing the boosted owner with runtime <= 0 and its old own_deadline instead of the donor's parameters.

[ ... ]

Quoted 4 lines
kernel/sched/deadline.c +0 -0
@@ -1443,7 +1514,13 @@ static void replenish_dl_entity(struct sched_dl_entity *dl_se)
 	 * entity.
 	 */
 	if (dl_time_before(dl_se->deadline, rq_clock(rq))) {

kernel/sched/deadline.c static void replenish_dl_entity(struct sched_dl_entity *dl_se) · line 1525

Quoted 10 lines
kernel/sched/deadline.c +7 -1
-		printk_deferred_once("sched: DL replenish lagged too much\n");
+		/*
+		 * dl_waiter_boosts() boosts an owner past its deadline. Its
+		 * deadline is then expected to be in the past: do not warn.
+		 * The new period takes the donor's parameters.
+		 */
+		if (!is_dl_boosted(dl_se))
+			printk_deferred_once("sched: DL replenish lagged too much\n");
 		replenish_dl_new_period(dl_se, rq);
 	}

[Severity: High]
When a runnable throttled owner (runtime <= 0) is boosted, does the while (dl_se->runtime <= 0) loop right above this check advance dl_se->deadline from own_deadline by the donor's period instead of starting a donor period at rq_clock(rq)?

kernel/sched/deadline.c:replenish_dl_entity() {
    ...
	while (dl_se->runtime <= 0) {
		dl_se->deadline += period;
		dl_se->period_start += period;
		dl_se->runtime += runtime;
	}

	if (dl_time_before(dl_se->deadline, rq_clock(rq))) {
		if (!is_dl_boosted(dl_se))
			printk_deferred_once("sched: DL replenish lagged too much\n");
		replenish_dl_new_period(dl_se, rq);
	}
}

For any throttled owner whose own_deadline has not passed yet (or is within one donor period of rq_clock(rq)), adding the donor's period to own_deadline keeps dl_se->deadline >= rq_clock(rq), so replenish_dl_new_period() is never reached. The boosted owner runs with a deadline of own_deadline + pi_se->dl_period (later than its unboosted own_deadline) instead of rq_clock(rq) + pi_se->dl_deadline, and its own pre-boost overrun is deducted from the donor's runtime while also being restored from own_runtime at dl_deboost().

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=38
#60 lore raw

Re: [PATCH v10 35/40] sched/deadline: Check the runtime of a task whose parameters change

In reply to Mathieu Desnoyers
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] sched/deadline: dl_proxy_block() misses dl_new_params check on PI futex requeue - [Medium]…

Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [Medium] sched/deadline: dl_proxy_block() misses dl_new_params check on PI futex requeue
- [Medium] sched/deadline: missing PI boost when update_dl_entity() pushes owner deadline
- [Low] sched/deadline: __setparam_dl() skips dl_new_params on same-param re-entry
--

commit a68761d066fed61088f4cef94943c4d4d24b8d1f
Author: Mathieu Desnoyers <[email protected]>

sched/deadline: Check the runtime of a task whose parameters change

This commit tracks deadline parameter changes in dl_new_params so that the remaining runtime is checked against the new reservation at the next enqueue, at deboost, or immediately when blocked on an rt_mutex.

Quoted 4 lines
kernel/sched/deadline.c +0 -0
index 83aefe5ab671c..fe48137509ad8 100644

[ ... ]

Quoted 33 lines
kernel/sched/deadline.c +23 -3
@@ -145,12 +177,41 @@ void dl_deboost(struct sched_dl_entity *dl_se)
 		}
 	}
 	dl_drop_boost(dl_se);
+
+	if (!task_on_rq_queued(p) && !dl_task_pi_blocked(p))
+		return;
+	if (dl_se->dl_new_params && !dl_se->dl_throttled && dl_in_constrained_gap(dl_se))
+		return;
+	if (dl_se->dl_new_params) {
+		dl_se->dl_new_params = 0;
+		if (!dl_se->dl_throttled)
+			update_dl_entity(dl_se);
+	}
 }
 
-/* Return true if @p waits on an rt_mutex. The caller holds its pi_lock. */
-static inline bool dl_task_pi_blocked(struct task_struct *p)
+/*
+ * Check the runtime of @p against the parameters that sched_setattr() just
+ * gave it, if @p waits on an rt_mutex. Before any wakeup, its waiter node
+ * holds its deadline. The caller then calls rt_mutex_adjust_pi(), which
+ * requeues the waiter with the result. Other changes of @p, such as a
+ * cgroup move, do not requeue it: leave the check to sched_setattr().
+ *
+ * A boosted task, a throttled one, or one past its deadline and before
+ * its next period keeps the mark. Its deboost or its wakeup checks it.
+ * The caller holds the rq lock and the pi_lock of @p, and has updated the
+ * rq clock.
+ */
+void dl_check_blocked_params(struct task_struct *p)
 {
-	return p->pi_blocked_on;

kernel/sched/deadline.c void dl_deboost(struct sched_dl_entity *dl_se) · line 215

Quoted 10 lines
kernel/sched/deadline.c +9 -0
+	struct sched_dl_entity *dl_se = &p->dl;
+
+	if (!dl_task(p) || task_on_rq_queued(p) || !dl_task_pi_blocked(p))
+		return;
+	if (dl_se->dl_new_params && !is_dl_boosted(dl_se) &&
+	    !dl_se->dl_throttled && !dl_in_constrained_gap(dl_se)) {
+		dl_se->dl_new_params = 0;
+		update_dl_entity(dl_se);
+	}
 }

[Severity: Medium]
Should dl_proxy_block() also check and clear dl_se->dl_new_params?

When a task sleeps in futex(FUTEX_WAIT_REQUEUE_PI), p->pi_blocked_on is NULL, so dl_check_blocked_params() returns early and leaves dl_se->dl_new_params set. If futex(FUTEX_CMP_REQUEUE_PI) then requeues the task onto an rt_mutex before its old deadline expires, task_blocks_on_rt_mutex() calls dl_proxy_block() before copying p->dl.deadline into the waiter node:

kernel/sched/deadline.c:dl_proxy_block() {
	...
	if (!task_on_rq_queued(p) && !dl_se->dl_throttled &&
	    dl_time_before(dl_se->deadline, rq_clock(rq)) &&
	    (dl_is_implicit(dl_se) ||
	     !dl_time_before(rq_clock(rq), dl_next_period(dl_se))))
		replenish_dl_new_period(dl_se, rq);
	...
}

Because dl_proxy_block() only checks whether dl_se->deadline has passed, a task whose reservation was shrunk while sleeping in FUTEX_WAIT_REQUEUE_PI is queued on the rt_mutex (and boosts the lock owner) with its stale earlier deadline, allowing it to acquire the lock ahead of waiters with earlier deadlines. Even when the old deadline has passed and dl_proxy_block() starts a new period, it leaves dl_se->dl_new_params set, so a later boost and deboost while blocked calls update_dl_entity() a second time.

[ ... ]

kernel/sched/deadline.c void __setparam_dl(struct task_struct *p, const struct sched_attr *attr) · line 5268

Quoted 9 lines
kernel/sched/deadline.c +5 -0
@@ -5179,6 +5261,11 @@ void __setparam_dl(struct task_struct *p, const struct sched_attr *attr)
 	u64 period = attr->sched_period ?: attr->sched_deadline;
 	bool held;
 
+	if (attr->sched_runtime != dl_se->dl_runtime ||
+	    attr->sched_deadline != dl_se->dl_deadline ||
+	    period != dl_se->dl_period)
+		dl_se->dl_new_params = 1;
+

[Severity: Low]
Can __setparam_dl() leave dl_se->dl_new_params unset when a task leaves SCHED_DEADLINE before its 0-lag time and later re-enters the class with the same parameters?

When a task leaves SCHED_DEADLINE before its 0-lag time, switched_from_dl() leaves dl_runtime, dl_deadline and dl_period in dl_se until inactive_task_timer() runs __dl_clear_params(). If the task was PI-boosted back into dl_sched_class before the 0-lag time (without refilling from the donor), or if sched_setattr() races with inactive_task_timer() right after the 0-lag time while the task is blocked on an rt_mutex, calling sched_setattr() to restore SCHED_DEADLINE with identical parameters sees no change in dl_runtime, dl_deadline or dl_period and does not set dl_se->dl_new_params. switched_to_dl() then cancels inactive_timer without starting a new period if dl_se->deadline has not passed, and neither dl_check_blocked_params() nor dl_deboost() checks the remaining runtime against the new reservation.

Quoted 5 lines
kernel/sched/syscalls.c +0 -0
index 9884fa55538ac..b25504e8748be 100644

kernel/sched/syscalls.c static inline void __setscheduler_dl_pi(int newprio, int policy, · line 319

Quoted 9 lines
kernel/sched/syscalls.c +3 -0
@@ -311,6 +311,9 @@ static inline void __setscheduler_dl_pi(int newprio, int policy,
 	 */
 	if (!dl_prio(newprio))
 		dl_drop_boost(&p->dl);
+
+	/* rt_mutex_adjust_pi() then requeues the waiter of a blocked task. */
+	dl_check_blocked_params(p);
 }
 #else /* !CONFIG_RT_MUTEXES */
 static inline void __setscheduler_dl_pi(int newprio, int policy,

[Severity: Medium]
What happens if p owns an rt_mutex with a deadline waiter whose deadline was later than p's old deadline, and shrinking p's reservation pushes p->dl.deadline past that waiter's deadline?

In __setscheduler_dl_pi(), rt_mutex_get_top_task(p) is only checked when !dl_policy(policy):

kernel/sched/syscalls.c:__setscheduler_dl_pi() {
	if (dl_prio(newprio) && !dl_policy(policy)) {
		struct task_struct *pi_task = rt_mutex_get_top_task(p);

		if (pi_task) {
			dl_set_donor(&p->dl, pi_task);
			scope->flags |= ENQUEUE_REPLENISH;
		}
	}
	...
}

When an unboosted deadline task p stays in SCHED_DEADLINE and shrinks its reservation, update_dl_entity() (in dl_check_blocked_params() or in enqueue_dl_entity() during sched_change_end()) can start a new period and move p->dl.deadline after its top waiter's deadline. Unlike rt_mutex_setprio(), which rechecks whether pi_task preempts p after dl_deboost() updates p->dl, __sched_setscheduler() never boosts p with its top waiter. If p is running, it will throttle when its reduced runtime expires while holding the lock instead of running on the waiter's donor parameters; if p is blocked on another rt_mutex, rt_mutex_adjust_pi() will propagate p's own unboosted deadline up the PI chain instead of the waiter's.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=35
#5 lore raw

Re: [PATCH v10 03/40] sched/deadline: Record the root domain holding a task's bandwidth

In reply to [email protected]
Quoted 2 lines

Can dl_task_admit_cpu() return an offline CPU when p is asleep on a CPU that went offline?

Yes. In the top cpuset, or without cpusets, the offline does not remove the CPU from cpus_mask. v11 will also fall back to an active CPU of the mask when task_cpu() is not active. A new case, hotplug_asleep_setattr, will make a deadline task of a task asleep on a CPU that went offline. Without the fix, sched_setattr() fails with EBUSY. v7.4-rc2 charges the root domain of task_cpu() too.

Quoted 2 lines

When p->dl.dl_bw is 0 and p was moved to another cpuset partition while asleep, doesn't task_cpu(p) still point to the old root domain that p left?

Yes, by reading. v11 will check such a task against dl_task_admit_cpu(), as sched_setattr() does: the CPU the task runs on once it wakes. It needs a bandwidth that rounds to 0, so no case will test it.

Thanks,

Mathieu

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
#9 lore raw

Re: [PATCH v10 05/40] selftests/sched: Test SCHED_DEADLINE bandwidth across a root domain rebuild

In reply to [email protected]
Quoted 2 lines

Should pick_cpus() or main() also call sched_setaffinity() to pin the test process to the non-isolated online CPUs, as deadline_bw_test does?

Yes. In v11, deadline_rebuild_test will run on the online CPUs that are not isolated.

Thanks,

Mathieu

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
#19 lore raw

Re: [PATCH v10 13/40] sched/deadline: Make a rebuild count a task in the root domain it runs in

In reply to [email protected]
Quoted 3 lines

Can this early return drop the departing bandwidth of a task that was migrated outside its mask by dl_task_offline_migration() and exited during the rebuild?

Yes, by reading. It needs admission control off, every CPU of the mask offline, and an exit during the rebuild. In v11, the check for a task with no active CPU will come after the check for a departed task, under dl_departed_lock. A departed task will then be counted on the CPU recorded with it. No case will test it.

Thanks,

Mathieu

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
#24 lore raw

Re: [PATCH v10 16/40] sched/deadline: Keep the last CPU a task has in its root domain

In reply to [email protected]
Quoted 3 lines

When gone is set and p was initially unpopulated with no active CPUs of its own, does partition_child_lost() pick the last valid sibling partition after gone instead of the first?

Yes. cpuset invalidates the siblings after gone in the order of its hotplug walk, until one gives p an active CPU. The model picked the last sibling that covers the CPUs left. With mixed partition types, a deadline task could then change root domain unadmitted.

Your second, fourth and fifth points come from the same model. So v11 will stop modelling the order of the walk. Take a partition left with tasks and no CPU, under a parent with no CPU of its own. The parent can also stay valid with tasks and no CPU. A later hotplug event can then make it invalid. So v11 will take the topmost partition above that child that has no CPU of its own. The offline will be refused if a deadline task is in one of its cpusets. That can refuse an offline that would be harmless. Three new cases will test it:
hotplug_first_sibling_refused (your first point), hotplug_nested_partition_refused (your second) and hotplug_isolated_child_refused (your fourth).

One hole stays. The check sees the deadline tasks present at the offline. A deadline task can enter such a partition after an accepted offline. A later hotplug event can then move it to another root domain with no check for room. v11 will list it as a known limit.

Quoted 2 lines

Can gone cascade upward across an unpopulated parent partition here and in cpuset_offline_moves_dl()?

Yes. But that climb refused a real move, by luck. A later hotplug event can make cpuset invalidate the parent left valid with no CPU. In v11, cpuset_offline_moves_dl() will climb on purpose, as above. cpuset_cpus_allowed_without() will climb one level at most.

Quoted 2 lines

Does dl_task_in_cpuset() match sugov kthreads in top_cpuset that do not hold root-domain deadline bandwidth?

Yes. In v11, it will skip a task whose bandwidth no root domain counts, with a new dl_task_holds_bw(). It needs schedutil, so no case will test it.

Quoted 2 lines

Can deadline tasks in gone change root domain undetected when gone is an isolated partition and its parent p is a non-isolated partition?

Yes. The rule above refuses it. hotplug_isolated_child_refused will test it.

Quoted 2 lines

Does skipping a == lost when neither lost nor p is PRS_ISOLATED hold when lost has a valid child partition of its own?

The root domain of p does span lost's exclusive CPUs, not only its effective ones. But the bandwidth that moves was all admitted on fewer CPUs, so nothing is overcommitted. The child partitions of lost are checked on their own. v11 will correct the comment and the message, which said "the same CPUs".

Thanks,

Mathieu

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
#27 lore raw

Re: [PATCH v10 17/40] cgroup/cpuset: Refuse to take a deadline task out of its root domain

In reply to [email protected]
Quoted 2 lines

Should pending also be populated when root->partition_root_state is PRS_ISOLATED (for example via is_partition_valid(root))?

Yes, by reading. It is a false refusal: the child stays invalid until its next update. It refuses too much, but it never lets a task move unadmitted. v11 will keep it for isolated roots. Extending the pending span to them is left for later.

Quoted 3 lines

Should dl_task_keeps_root_domain() ignore tasks with READ_ONCE(p->__state) == TASK_DEAD, the way dl_task_leaves_span() and dl_task_in_cpuset() do?

Yes. A dead task runs no more. v11 will accept it.

Thanks,

Mathieu

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
#30 lore raw

Re: [PATCH v10 18/40] selftests/sched: Test the root domain of a task in deadline_bw_test

In reply to [email protected]
Quoted 1 line

Should the second call pass 0 for tell: partition_has(cs_c, "invalid", 0)?

Yes. v11 will pass 0.

Quoted 1 line

Should this also skip when !cpu_hotpluggable(x)?

Yes. v11 will skip then.

Quoted 1 line

Should the partition_grows_child_valid entry set no_hp to 1?

Yes. v11 will set it.

Thanks,

Mathieu

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
#38 lore raw

Re: [PATCH v10 24/40] selftests/sched: Test the rtmutex chain walk in deadline_bw_test

In reply to [email protected]
Quoted 2 lines

Should top_moves() return KSFT_SKIP instead of KSFT_FAIL when sched_setscheduler(0, SCHED_FIFO, &sp) fails with EPERM?

Yes. In v11, pi_chain_top_moves_rt will skip when SCHED_FIFO is refused with EPERM in P.

Thanks,

Mathieu

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
#41 lore raw

Re: [PATCH v10 25/40] sched/deadline: Reset the donor's runtime at a deboost in the class

In reply to [email protected]
Quoted 3 lines

Does starting a new period in dl_deboost() while the task is asleep cause a constrained-deadline task (dl_deadline < dl_period) to lose runtime or be throttled when it later wakes up?

Yes, by reading, for a task asleep on anything but an rt_mutex. Its wakeup then trims the runtime of that period, or throttles it in its gap. The task can lose part of a period. It never gains any. Moving the period to the wakeup needs a design of its own. v11 will leave it, and list it as a known limit.

Thanks,

Mathieu

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
#44 lore raw

Re: [PATCH v10 26/40] sched/deadline: Replenish a throttled task boosted while asleep

In reply to [email protected]
Quoted 3 lines

Can replenish_dl_entity() leave dl_se->dl_donor_refill unset when a sleeping SCHED_DEADLINE task's donor has its parameters cleared before dl_task_timer() fires?

Yes, by reading. In v11, that branch will note a donor refill for any boosted entity. The deboost then starts a period of the task's own.

Quoted 2 lines

Does calling replenish_dl_entity() from dl_task_timer() refill a sleeping task's pre-boost runtime debt using the donor's parameters?

Yes in v10. v11 will close it with your patch 38 findings. A boost of a throttled owner will start a period of its donor at once. The deboost will put back the owner's saved values. It will throttle the owner again if its runtime is used up.

Thanks,

Mathieu

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
#48 lore raw

Re: [PATCH v10 28/40] sched/deadline: Start a period for a task that enters the class blocked

In reply to [email protected]
Quoted 2 lines

Can dl_boost_blocked() skip starting a period for a task that left SCHED_DEADLINE before its 0-lag time?

Yes, by reading. This is the waiter that keeps an expired deadline, which you found on v9. v7.4-rc2 sorts such a waiter the same way. v11 will keep it as a known limit, with the question to Juri in the cover letter.

Thanks,

Mathieu

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
#52 lore raw

Re: [PATCH v10 30/40] sched/deadline: Start a period for a task requeued onto an rt_mutex

In reply to [email protected]
Quoted 2 lines

Can __rt_mutex_start_proxy_lock() steal the rt_mutex using a stale task->dl.deadline before task_blocks_on_rt_mutex() runs dl_proxy_block()?

Yes, by reading. v11 will call dl_proxy_block() in __rt_mutex_start_proxy_lock(), before the trylock.

Quoted 3 lines

Does returning early on is_dl_boosted(dl_se) or !dl_se->dl_runtime leave p->dl.deadline at 0 (or expired) when p was PI-boosted while sleeping in FUTEX_WAIT_REQUEUE_PI?

Yes. In v11, dl_proxy_block() will start a period of the donor for a boosted task whose deadline is 0 or has passed.

Quoted 2 lines

Should an implicit-deadline task also start a new period here when dl_entity_overflow(dl_se, rq_clock(rq)) is true?

Yes. In v11, dl_proxy_block() will apply the wakeup rule to a task not in its gap: update_dl_entity(). That covers the overflow.

Quoted 2 lines

What happens if a constrained-deadline task has dl_se->deadline == 0 when rq_clock(rq) is still before dl_next_period(dl_se)?

Yes, it keeps the deadline of 0. That needs an rq clock still under one period after boot. v11 will start a new period for a deadline of 0 first.

No case will test these four changes.

Thanks,

Mathieu

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
#55 lore raw

Re: [PATCH v10 31/40] selftests/sched: Test deadline boosts in deadline_bw_test

In reply to [email protected]
Quoted 2 lines

Will join(d) hang on these two error paths if aslp_read_done is not posted?

Yes. v11 will post aslp_read_done on both paths.

Quoted 2 lines

Does FUTEX_WAKE wake W when it is sleeping in FUTEX_WAIT_REQUEUE_PI on rq_cond?

No. In v11, the error path will wake W with FUTEX_CMP_REQUEUE_PI, which gives it rq_pi. It will then set rq_cond, in case W has not started its wait.

Thanks,

Mathieu

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
#61 lore raw

Re: [PATCH v10 35/40] sched/deadline: Check the runtime of a task whose parameters change

In reply to [email protected]
Quoted 1 line

Should dl_proxy_block() also check and clear dl_se->dl_new_params?

Yes. In v11, dl_proxy_block() will clear the mark and check the runtime left, with update_dl_entity().

Quoted 3 lines

Can __setparam_dl() leave dl_se->dl_new_params unset when a task leaves SCHED_DEADLINE before its 0-lag time and later re-enters the class with the same parameters?

Yes, by reading. In v11, a task that enters the deadline policy will get the mark, even with the same parameters.

Quoted 3 lines

What happens if p owns an rt_mutex with a deadline waiter whose deadline was later than p's old deadline, and shrinking p's reservation pushes p->dl.deadline past that waiter's deadline?

p is not boosted. A boost never gives the owner the deadline of its waiter. It stops the throttle, and the refills use the donor's parameters. v7.4-rc2 does the same. v11 will not change this.

Thanks,

Mathieu

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
#65 lore raw

Re: [PATCH v10 37/40] sched/deadline: Keep the start of the period across a change of dl_deadline

In reply to [email protected]
Quoted 3 lines

Can a constrained task whose dl_deadline is increased to equal dl_period during an active period still bypass throttling in the gap between its current deadline and its next period?

Yes. We answered "not a bug" on v9: with period_start kept, it is one. In v11, sched_setattr() will keep the end of a period in progress, and move its deadline to period_start plus the new dl_deadline. A new case, deadline_widened_asleep, will test it. In testing without the fix, the task got 10ms in its period instead of the 2ms it had left.

Quoted 3 lines

Does advancing dl_se->deadline by period here keep the old relative deadline offset across future periods after sched_setattr() changes dl_deadline?

Yes. This patch introduced it: v7.4-rc2 shifted the period instead. v11 will set the deadline to period_start plus dl_deadline when the loop runs, for an entity that is not boosted. A new case, deadline_grows_running, will test it. In testing without the fix, the task ran 69ms after its wakeup.

The same change covers a shorter dl_period while the task is throttled. The refill would otherwise print "sched: DL replenish lagged too much". A new case, period_shrunk_throttled, will test it.

Thanks,

Mathieu

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
#68 lore raw

Re: [PATCH v10 38/40] sched/deadline: Boost an owner that cannot run on its own reservation

In reply to [email protected]
Quoted 3 lines

When p is a deadline task blocked on another rt_mutex (!scope->queued), does dl_boost_blocked(p) leave p->dl.deadline stale for the rest of the PI chain walk?

p keeps its own deadline in its waiter node. A boost never gives the owner the deadline of its waiter. For an owner that cannot run on its own reservation, v11 will start a period of the donor at the boost. Its waiter node then gets that deadline.

Quoted 3 lines

When a task that was boosted while throttled (own_runtime <= 0) is deboosted before own_deadline, does restoring own_runtime without restoring dl_throttled leave the task runnable on dl_rq with exhausted runtime?

Yes. In v11, the deboost will throttle it again until its own next period, and reschedule it if it runs. A new case, pi_owner_held_new_params, will test it. In testing without the fix, the waiter got the lock at 103ms, instead of before 60ms.

Quoted 2 lines

Should switched_from_dl() also restore own_deadline, own_runtime and own_period_start when dl_boost_held is set?

Yes. In v11, it will put back the saved values, as dl_deboost() does.

Quoted 5 lines

Once now reaches own_period_start + dl_period, dl_waiter_boosts() compares pi_task against now + dl_se->dl_deadline, but if it returns false and triggers a deboost while p is pi-blocked on another rt_mutex, does dl_deboost() restore the expired own_deadline instead of starting a new period?

Yes. In v11, the deboost will start a period of the task's own once its saved period has ended. A new case, pi_owner_held_long, will test it. Without the fix, the refill prints "sched: DL replenish lagged too much".

Quoted 3 lines

If an owner is throttled while going to sleep, boosted while asleep, and then wakes up before own_deadline while still boosted, does enqueue_task_dl() fail to replenish it from the donor?

Yes in v10. In v11, it gets runtime from the donor period that the boost starts: see your last point.

Quoted 4 lines

When a runnable throttled owner (runtime <= 0) is boosted, does the while (dl_se->runtime <= 0) loop right above this check advance dl_se->deadline from own_deadline by the donor's period instead of starting a donor period at rq_clock(rq)?

Yes. In v11, dl_boost_start() will start a period of the donor. A new case, pi_owner_throttled_rival, will test it. In testing without the fix, a deadline task between the two deadlines ran first. The waiter got the lock at 53ms, instead of before 35ms.

Thanks,

Mathieu

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
#72 lore raw

Re: [PATCH v10 40/40] selftests/sched: Share the helpers of the deadline tests

In reply to [email protected]
Quoted 1 line

Does this pattern rule ever take effect?

No. v11 will add the header to LOCAL_HDRS instead.

Quoted 3 lines

This isn't a bug, but removing now_ns() leaves its comment attached to reap(). Also, cpu_time_ns() in this file is identical to thread_time_ns() in deadline_util.h and could be replaced by it.

Yes. v11 will remove the comment and use thread_time_ns().

Thanks,

Mathieu

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com