From: tip-bot for Darren Hart <dvhart@linux.intel.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@redhat.com,
a.p.zijlstra@chello.nl, dvhart@linux.intel.com,
richard.purdie@linuxfoundation.org, tglx@linutronix.de,
mingo@elte.hu
Subject: [tip:sched/core] sched: Allow users with sufficient RLIMIT_NICE to change from SCHED_IDLE policy
Date: Fri, 4 Mar 2011 11:49:46 GMT [thread overview]
Message-ID: <tip-c02aa73b1d18e43cfd79c2f193b225e84ca497c8@git.kernel.org> (raw)
In-Reply-To: <4D657BEE.4040608@linux.intel.com>
Commit-ID: c02aa73b1d18e43cfd79c2f193b225e84ca497c8
Gitweb: http://git.kernel.org/tip/c02aa73b1d18e43cfd79c2f193b225e84ca497c8
Author: Darren Hart <dvhart@linux.intel.com>
AuthorDate: Thu, 17 Feb 2011 15:37:07 -0800
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Fri, 4 Mar 2011 11:14:30 +0100
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>
---
kernel/sched.c | 11 +++++++----
1 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/kernel/sched.c b/kernel/sched.c
index 0c87126..f303070 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -4981,12 +4981,15 @@ recheck:
param->sched_priority > rlim_rtprio)
return -EPERM;
}
+
/*
- * Like positive nice levels, dont allow tasks to
- * move out of SCHED_IDLE either:
+ * Treat SCHED_IDLE as nice 20. Only allow a switch to
+ * SCHED_NORMAL if the RLIMIT_NICE would normally permit it.
*/
- if (p->policy == SCHED_IDLE && policy != SCHED_IDLE)
- return -EPERM;
+ if (p->policy == SCHED_IDLE && policy != SCHED_IDLE) {
+ if (!can_nice(p, TASK_NICE(p)))
+ return -EPERM;
+ }
/* can't change other user's priorities */
if (!check_same_owner(p))
prev parent reply other threads:[~2011-03-04 11:50 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-22 21:04 [PATCH 0/2] sched: SCHED_BATCH fixes Darren Hart
2011-02-22 21:04 ` [PATCH 1/2] sched: allow SCHED_BATCH to preempt SCHED_IDLE tasks Darren Hart
2011-02-23 4:20 ` Mike Galbraith
2011-02-23 5:31 ` Mike Galbraith
2011-02-23 5:33 ` Darren Hart
2011-03-04 11:49 ` [tip:sched/core] sched: Allow " tip-bot for Darren Hart
2011-02-22 21:04 ` [PATCH 2/2] sched: allow users with rtprio rlimit to change from SCHED_IDLE policy Darren Hart
2011-02-23 11:03 ` Peter Zijlstra
2011-02-23 11:13 ` Ingo Molnar
2011-02-23 11:17 ` Peter Zijlstra
2011-02-23 11:35 ` Ingo Molnar
2011-02-23 15:52 ` Darren Hart
2011-02-23 16:00 ` Peter Zijlstra
2011-02-23 16:07 ` Darren Hart
2011-02-23 21:28 ` Darren Hart
2011-02-24 11:49 ` Peter Zijlstra
2011-03-04 11:49 ` tip-bot for Darren Hart [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tip-c02aa73b1d18e43cfd79c2f193b225e84ca497c8@git.kernel.org \
--to=dvhart@linux.intel.com \
--cc=a.p.zijlstra@chello.nl \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=mingo@redhat.com \
--cc=richard.purdie@linuxfoundation.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox