Skip to contentSkip to conversation

sched: Preserve timer slack default across RT reset-on-fork

PATCH New zhidao su (Xiaomi) 1 participant 1 message Jun 22

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched: Preserve timer slack default across RT reset-on-fork

RT and deadline policies force timer_slack_ns to zero while a task runs under the realtime policy. The original slack value is kept in default_timer_slack_ns so it can be restored when the task returns to a normal policy.

copy_process() initializes the child's default_timer_slack_ns from current->timer_slack_ns. For an RT/DL parent this copies the temporary zero value into the child's default. If the parent also uses SCHED_RESET_ON_FORK, sched_fork() resets the child to SCHED_NORMAL and restores timer_slack_ns from that already-poisoned default, leaving the child with zero slack.

Preserve current->default_timer_slack_ns when current->timer_slack_ns is zero so reset-on-fork children can restore a real default slack value.

Fixes ed4fb6d7ef68 ("hrtimer: Use and report correct timerslack values for realtime tasks")
---
 kernel/fork.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
kernel/fork.c +8 -1
index addc555a1077..39db7502379b 100644
@@ -2196,7 +2196,14 @@ __latent_entropy struct task_struct *copy_process(
 	retval = -EAGAIN;
 #endif
 
-	p->default_timer_slack_ns = current->timer_slack_ns;
+	/*
+	 * RT/DL tasks run with timer_slack_ns forced to zero, but their
+	 * default_timer_slack_ns still carries the value to restore when
+	 * returning to a normal policy. Preserve that default across fork so
+	 * SCHED_RESET_ON_FORK children can restore a real slack value.
+	 */
+	p->default_timer_slack_ns = current->timer_slack_ns ?:
+				    current->default_timer_slack_ns;
 
 #ifdef CONFIG_PSI
 	p->psi_flags = 0;

base-commit: e771677c937da5808f7b6c1f0e4a97ec1a84f8a8

Signature · 1 line
2.43.0