[PATCH v3 0/2] sched/fork: fix timer_slack_ns for children of RT tasks

Guanyou.Chen posted 2 patches 2 days, 4 hours ago
kernel/fork.c       | 6 +++++-
kernel/sched/core.c | 1 +
2 files changed, 6 insertions(+), 1 deletion(-)
[PATCH v3 0/2] sched/fork: fix timer_slack_ns for children of RT tasks
Posted by Guanyou.Chen 2 days, 4 hours ago
v3:
- Patch 2: only fix RT/DL parent case, non-RT unchanged. Addresses
  concerns from Cunlong Li and K Prateek Nayak.
v2:
- Split into two patches per Peter's suggestion.

When an RT task with SCHED_RESET_ON_FORK creates child threads, the
children inherit timer_slack_ns=0 and can never recover a proper slack
value.

Per prctl(2), "Timer slack is not applied to threads that are scheduled
under a real-time scheduling policy." The RT parent's timer_slack_ns=0
is not a user-chosen value but a forced "not applicable" state.
Inheriting this as the child's default is a bug introduced by
ed4fb6d7ef68.

Patch 1 restores timer_slack_ns in sched_fork() when resetting from RT
to NORMAL policy.

Patch 2 fixes copy_process() to use default_timer_slack_ns (preserves
pre-RT value) instead of timer_slack_ns (forced 0) for RT/DL parents.

With both patches applied (RT parent, RESET_ON_FORK, 32 child threads
usleep(1)):
  Before: child slack=0, avg_sleep=38us, ~832K interrupts/s
  After:  child slack=50000, avg_sleep=88us, ~363K interrupts/s

Guanyou.Chen (2):
  sched: restore timer_slack_ns when resetting RT policy on fork
  fork: fix default_timer_slack_ns inheritance from RT parent

 kernel/fork.c       | 6 +++++-
 kernel/sched/core.c | 1 +
 2 files changed, 6 insertions(+), 1 deletion(-)

-- 
2.34.1