Commit 20f9cd2a authored by Henrik Austad's avatar Henrik Austad Committed by Ingo Molnar

sched/core: Make policy-testing consistent

Most of the policy-tests are done via the <class>_policy() helpers with
the notable exception of idle. A new wrapper for valid_policy() has also
been added to improve readability  in set_load_weight().

This commit does not change the logical behavior of the scheduler core.
Signed-off-by: default avatarHenrik Austad <henrik@austad.us>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Link: http://lkml.kernel.org/r/1441810841-4756-1-git-send-email-henrik@austad.usSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 0c6a5b43
...@@ -817,7 +817,7 @@ static void set_load_weight(struct task_struct *p) ...@@ -817,7 +817,7 @@ static void set_load_weight(struct task_struct *p)
/* /*
* SCHED_IDLE tasks get minimal weight: * SCHED_IDLE tasks get minimal weight:
*/ */
if (p->policy == SCHED_IDLE) { if (idle_policy(p->policy)) {
load->weight = scale_load(WEIGHT_IDLEPRIO); load->weight = scale_load(WEIGHT_IDLEPRIO);
load->inv_weight = WMULT_IDLEPRIO; load->inv_weight = WMULT_IDLEPRIO;
return; return;
...@@ -3733,10 +3733,7 @@ static int __sched_setscheduler(struct task_struct *p, ...@@ -3733,10 +3733,7 @@ static int __sched_setscheduler(struct task_struct *p,
} else { } else {
reset_on_fork = !!(attr->sched_flags & SCHED_FLAG_RESET_ON_FORK); reset_on_fork = !!(attr->sched_flags & SCHED_FLAG_RESET_ON_FORK);
if (policy != SCHED_DEADLINE && if (!valid_policy(policy))
policy != SCHED_FIFO && policy != SCHED_RR &&
policy != SCHED_NORMAL && policy != SCHED_BATCH &&
policy != SCHED_IDLE)
return -EINVAL; return -EINVAL;
} }
...@@ -3792,7 +3789,7 @@ static int __sched_setscheduler(struct task_struct *p, ...@@ -3792,7 +3789,7 @@ static int __sched_setscheduler(struct task_struct *p,
* Treat SCHED_IDLE as nice 20. Only allow a switch to * Treat SCHED_IDLE as nice 20. Only allow a switch to
* SCHED_NORMAL if the RLIMIT_NICE would normally permit it. * SCHED_NORMAL if the RLIMIT_NICE would normally permit it.
*/ */
if (p->policy == SCHED_IDLE && policy != SCHED_IDLE) { if (idle_policy(p->policy) && !idle_policy(policy)) {
if (!can_nice(p, task_nice(p))) if (!can_nice(p, task_nice(p)))
return -EPERM; return -EPERM;
} }
......
...@@ -84,6 +84,10 @@ static inline void update_cpu_load_active(struct rq *this_rq) { } ...@@ -84,6 +84,10 @@ static inline void update_cpu_load_active(struct rq *this_rq) { }
*/ */
#define RUNTIME_INF ((u64)~0ULL) #define RUNTIME_INF ((u64)~0ULL)
static inline int idle_policy(int policy)
{
return policy == SCHED_IDLE;
}
static inline int fair_policy(int policy) static inline int fair_policy(int policy)
{ {
return policy == SCHED_NORMAL || policy == SCHED_BATCH; return policy == SCHED_NORMAL || policy == SCHED_BATCH;
...@@ -98,6 +102,11 @@ static inline int dl_policy(int policy) ...@@ -98,6 +102,11 @@ static inline int dl_policy(int policy)
{ {
return policy == SCHED_DEADLINE; return policy == SCHED_DEADLINE;
} }
static inline bool valid_policy(int policy)
{
return idle_policy(policy) || fair_policy(policy) ||
rt_policy(policy) || dl_policy(policy);
}
static inline int task_has_rt_policy(struct task_struct *p) static inline int task_has_rt_policy(struct task_struct *p)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment