Skip to content

Commit

Permalink
Add support for reset-on-fork scheduling flag
Browse files Browse the repository at this point in the history
This patch extends CRIU with support for SCHED_RESET_ON_FORK.

If the SCHED_RESET_ON_FORK flag is set, the following rules apply for
subsequently created children:

- If the calling thread has a scheduling policy of SCHED_FIFO or
SCHED_RR, the policy is reset to SCHED_OTHER in child processes.

- If the calling process has a negative nice value, the nice value
is reset to zero in child processes.

(See 'man 7 sched')

Fixes: #2359

Signed-off-by: Radostin Stoyanov <[email protected]>
  • Loading branch information
rst0git committed Mar 4, 2024
1 parent cb39c62 commit f5ed2ac
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion criu/cr-dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ static int dump_sched_info(int pid, ThreadCoreEntry *tc)
tc->has_sched_policy = true;
tc->sched_policy = ret;

if ((ret == SCHED_RR) || (ret == SCHED_FIFO)) {
if ((ret == SCHED_RR) || (ret == SCHED_FIFO) ||
(ret == (SCHED_RR | SCHED_RESET_ON_FORK)) || (ret == (SCHED_FIFO | SCHED_RESET_ON_FORK))) {
ret = syscall(__NR_sched_getparam, pid, &sp);
if (ret < 0) {
pr_perror("Can't get sched param for %d", pid);
Expand Down
2 changes: 2 additions & 0 deletions criu/cr-restore.c
Original file line number Diff line number Diff line change
Expand Up @@ -3060,6 +3060,8 @@ static int validate_sched_parm(struct rst_sched_param *sp)
switch (sp->policy) {
case SCHED_RR:
case SCHED_FIFO:
case (SCHED_RR | SCHED_RESET_ON_FORK):
case (SCHED_FIFO | SCHED_RESET_ON_FORK):
return ((sp->prio > 0) && (sp->prio < 100));
case SCHED_IDLE:
case SCHED_OTHER:
Expand Down
4 changes: 2 additions & 2 deletions test/zdtm/static/sched_policy00.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int main(int argc, char **argv)
}

p.sched_priority = param;
if (sched_setscheduler(pid, SCHED_RR, &p)) {
if (sched_setscheduler(pid, SCHED_RR | SCHED_RESET_ON_FORK, &p)) {
pr_perror("Can't set policy");
kill(pid, SIGKILL);
return -1;
Expand All @@ -61,7 +61,7 @@ int main(int argc, char **argv)
test_waitsig();

ret = sched_getscheduler(pid);
if (ret != SCHED_RR) {
if (ret != (SCHED_RR | SCHED_RESET_ON_FORK)) {
fail("Broken/No policy");
err++;
}
Expand Down

0 comments on commit f5ed2ac

Please sign in to comment.