Skip to content

Commit 7479f3c

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
sched: Move SCHED_RESET_ON_FORK into attr::sched_flags
I noticed the new sched_{set,get}attr() calls didn't properly deal with the SCHED_RESET_ON_FORK hack. Instead of propagating the flags in high bits nonsense use the brand spanking new attr::sched_flags field. Signed-off-by: Peter Zijlstra <peterz@infradead.org> Cc: Juri Lelli <juri.lelli@gmail.com> Cc: Dario Faggioli <raistlin@linux.it> Link: http://lkml.kernel.org/r/20140115162242.GJ31570@twins.programming.kicks-ass.net Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 0bb040a commit 7479f3c

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

include/uapi/linux/sched.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,13 @@
4040
/* SCHED_ISO: reserved but not implemented yet */
4141
#define SCHED_IDLE 5
4242
#define SCHED_DEADLINE 6
43+
4344
/* Can be ORed in to make sure the process is reverted back to SCHED_NORMAL on fork */
4445
#define SCHED_RESET_ON_FORK 0x40000000
4546

47+
/*
48+
* For the sched_{set,get}attr() calls
49+
*/
50+
#define SCHED_FLAG_RESET_ON_FORK 0x01
4651

4752
#endif /* _UAPI_LINUX_SCHED_H */

kernel/sched/core.c

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3267,8 +3267,7 @@ static int __sched_setscheduler(struct task_struct *p,
32673267
reset_on_fork = p->sched_reset_on_fork;
32683268
policy = oldpolicy = p->policy;
32693269
} else {
3270-
reset_on_fork = !!(policy & SCHED_RESET_ON_FORK);
3271-
policy &= ~SCHED_RESET_ON_FORK;
3270+
reset_on_fork = !!(attr->sched_flags & SCHED_FLAG_RESET_ON_FORK);
32723271

32733272
if (policy != SCHED_DEADLINE &&
32743273
policy != SCHED_FIFO && policy != SCHED_RR &&
@@ -3277,6 +3276,9 @@ static int __sched_setscheduler(struct task_struct *p,
32773276
return -EINVAL;
32783277
}
32793278

3279+
if (attr->sched_flags & ~(SCHED_FLAG_RESET_ON_FORK))
3280+
return -EINVAL;
3281+
32803282
/*
32813283
* Valid priorities for SCHED_FIFO and SCHED_RR are
32823284
* 1..MAX_USER_RT_PRIO-1, valid priority for SCHED_NORMAL,
@@ -3443,6 +3445,26 @@ static int __sched_setscheduler(struct task_struct *p,
34433445
return 0;
34443446
}
34453447

3448+
static int _sched_setscheduler(struct task_struct *p, int policy,
3449+
const struct sched_param *param, bool check)
3450+
{
3451+
struct sched_attr attr = {
3452+
.sched_policy = policy,
3453+
.sched_priority = param->sched_priority,
3454+
.sched_nice = PRIO_TO_NICE(p->static_prio),
3455+
};
3456+
3457+
/*
3458+
* Fixup the legacy SCHED_RESET_ON_FORK hack
3459+
*/
3460+
if (policy & SCHED_RESET_ON_FORK) {
3461+
attr.sched_flags |= SCHED_FLAG_RESET_ON_FORK;
3462+
policy &= ~SCHED_RESET_ON_FORK;
3463+
attr.sched_policy = policy;
3464+
}
3465+
3466+
return __sched_setscheduler(p, &attr, check);
3467+
}
34463468
/**
34473469
* sched_setscheduler - change the scheduling policy and/or RT priority of a thread.
34483470
* @p: the task in question.
@@ -3456,12 +3478,7 @@ static int __sched_setscheduler(struct task_struct *p,
34563478
int sched_setscheduler(struct task_struct *p, int policy,
34573479
const struct sched_param *param)
34583480
{
3459-
struct sched_attr attr = {
3460-
.sched_policy = policy,
3461-
.sched_priority = param->sched_priority,
3462-
.sched_nice = PRIO_TO_NICE(p->static_prio),
3463-
};
3464-
return __sched_setscheduler(p, &attr, true);
3481+
return _sched_setscheduler(p, policy, param, true);
34653482
}
34663483
EXPORT_SYMBOL_GPL(sched_setscheduler);
34673484

@@ -3487,12 +3504,7 @@ EXPORT_SYMBOL_GPL(sched_setattr);
34873504
int sched_setscheduler_nocheck(struct task_struct *p, int policy,
34883505
const struct sched_param *param)
34893506
{
3490-
struct sched_attr attr = {
3491-
.sched_policy = policy,
3492-
.sched_priority = param->sched_priority,
3493-
.sched_nice = PRIO_TO_NICE(p->static_prio),
3494-
};
3495-
return __sched_setscheduler(p, &attr, false);
3507+
return _sched_setscheduler(p, policy, param, false);
34963508
}
34973509

34983510
static int
@@ -3792,6 +3804,8 @@ SYSCALL_DEFINE3(sched_getattr, pid_t, pid, struct sched_attr __user *, uattr,
37923804
goto out_unlock;
37933805

37943806
attr.sched_policy = p->policy;
3807+
if (p->sched_reset_on_fork)
3808+
attr.sched_flags |= SCHED_FLAG_RESET_ON_FORK;
37953809
if (task_has_dl_policy(p))
37963810
__getparam_dl(p, &attr);
37973811
else if (task_has_rt_policy(p))

0 commit comments

Comments
 (0)