aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/sched.c
diff options
context:
space:
mode:
authorDarren Hart <dvhart@linux.intel.com>2011-02-17 18:37:07 -0500
committerIngo Molnar <mingo@elte.hu>2011-03-04 05:14:30 -0500
commitc02aa73b1d18e43cfd79c2f193b225e84ca497c8 (patch)
treebd36bf363e667a915e3ceda99221531362139d51 /kernel/sched.c
parenta2f5c9ab79f78e8b91ac993e0543d65b661dd19b (diff)
sched: Allow users with sufficient RLIMIT_NICE to change from SCHED_IDLE policy
The current scheduler implementation returns -EPERM when trying to change from SCHED_IDLE to SCHED_OTHER or SCHED_BATCH. Since SCHED_IDLE is considered to be a nice 20 on steroids, changing to another policy should be allowed provided the RLIMIT_NICE is accounted for. This patch allows the following test-case to pass with RLIMIT_NICE=40, but still fail with RLIMIT_NICE=10 when the calling process is run from a typical shell (nice 0, or 20 in rlimit terms). int main() { int ret; struct sched_param sp; sp.sched_priority = 0; /* switch to SCHED_IDLE */ ret = sched_setscheduler(0, SCHED_IDLE, &sp); printf("setscheduler IDLE: %d\n", ret); if (ret) return ret; /* switch back to SCHED_OTHER */ ret = sched_setscheduler(0, SCHED_OTHER, &sp); printf("setscheduler OTHER: %d\n", ret); return ret; } $ ulimit -e 40 $ ./test setscheduler IDLE: 0 setscheduler OTHER: 0 $ ulimit -e 10 $ ulimit -e 10 $ ./test setscheduler IDLE: 0 setscheduler OTHER: -1 Signed-off-by: Darren Hart <dvhart@linux.intel.com> Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Richard Purdie <richard.purdie@linuxfoundation.org> LKML-Reference: <4D657BEE.4040608@linux.intel.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel/sched.c')
-rw-r--r--kernel/sched.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/kernel/sched.c b/kernel/sched.c
index 0c8712630f05..f3030709d826 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -4981,12 +4981,15 @@ recheck:
4981 param->sched_priority > rlim_rtprio) 4981 param->sched_priority > rlim_rtprio)
4982 return -EPERM; 4982 return -EPERM;
4983 } 4983 }
4984
4984 /* 4985 /*
4985 * Like positive nice levels, dont allow tasks to 4986 * Treat SCHED_IDLE as nice 20. Only allow a switch to
4986 * move out of SCHED_IDLE either: 4987 * SCHED_NORMAL if the RLIMIT_NICE would normally permit it.
4987 */ 4988 */
4988 if (p->policy == SCHED_IDLE && policy != SCHED_IDLE) 4989 if (p->policy == SCHED_IDLE && policy != SCHED_IDLE) {
4989 return -EPERM; 4990 if (!can_nice(p, TASK_NICE(p)))
4991 return -EPERM;
4992 }
4990 4993
4991 /* can't change other user's priorities */ 4994 /* can't change other user's priorities */
4992 if (!check_same_owner(p)) 4995 if (!check_same_owner(p))