Skip to content

Commit 1da1843

Browse files
vireshkIngo Molnar
authored andcommitted
sched/core: Create task_has_idle_policy() helper
We already have task_has_rt_policy() and task_has_dl_policy() helpers, create task_has_idle_policy() as well and update sched core to start using it. While at it, use task_has_dl_policy() at one more place. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Vincent Guittot <vincent.guittot@linaro.org> Link: http://lkml.kernel.org/r/ce3915d5b490fc81af926a3b6bfb775e7188e005.1541416894.git.viresh.kumar@linaro.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent b5c0ce7 commit 1da1843

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

kernel/sched/core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ static void set_load_weight(struct task_struct *p, bool update_load)
697697
/*
698698
* SCHED_IDLE tasks get minimal weight:
699699
*/
700-
if (idle_policy(p->policy)) {
700+
if (task_has_idle_policy(p)) {
701701
load->weight = scale_load(WEIGHT_IDLEPRIO);
702702
load->inv_weight = WMULT_IDLEPRIO;
703703
p->se.runnable_weight = load->weight;
@@ -4199,7 +4199,7 @@ static int __sched_setscheduler(struct task_struct *p,
41994199
* Treat SCHED_IDLE as nice 20. Only allow a switch to
42004200
* SCHED_NORMAL if the RLIMIT_NICE would normally permit it.
42014201
*/
4202-
if (idle_policy(p->policy) && !idle_policy(policy)) {
4202+
if (task_has_idle_policy(p) && !idle_policy(policy)) {
42034203
if (!can_nice(p, task_nice(p)))
42044204
return -EPERM;
42054205
}

kernel/sched/debug.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ void proc_sched_show_task(struct task_struct *p, struct pid_namespace *ns,
974974
#endif
975975
P(policy);
976976
P(prio);
977-
if (p->policy == SCHED_DEADLINE) {
977+
if (task_has_dl_policy(p)) {
978978
P(dl.runtime);
979979
P(dl.deadline);
980980
}

kernel/sched/fair.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6529,7 +6529,7 @@ wakeup_preempt_entity(struct sched_entity *curr, struct sched_entity *se)
65296529

65306530
static void set_last_buddy(struct sched_entity *se)
65316531
{
6532-
if (entity_is_task(se) && unlikely(task_of(se)->policy == SCHED_IDLE))
6532+
if (entity_is_task(se) && unlikely(task_has_idle_policy(task_of(se))))
65336533
return;
65346534

65356535
for_each_sched_entity(se) {
@@ -6541,7 +6541,7 @@ static void set_last_buddy(struct sched_entity *se)
65416541

65426542
static void set_next_buddy(struct sched_entity *se)
65436543
{
6544-
if (entity_is_task(se) && unlikely(task_of(se)->policy == SCHED_IDLE))
6544+
if (entity_is_task(se) && unlikely(task_has_idle_policy(task_of(se))))
65456545
return;
65466546

65476547
for_each_sched_entity(se) {
@@ -6599,8 +6599,8 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int wake_
65996599
return;
66006600

66016601
/* Idle tasks are by definition preempted by non-idle tasks. */
6602-
if (unlikely(curr->policy == SCHED_IDLE) &&
6603-
likely(p->policy != SCHED_IDLE))
6602+
if (unlikely(task_has_idle_policy(curr)) &&
6603+
likely(!task_has_idle_policy(p)))
66046604
goto preempt;
66056605

66066606
/*
@@ -7021,7 +7021,7 @@ static int task_hot(struct task_struct *p, struct lb_env *env)
70217021
if (p->sched_class != &fair_sched_class)
70227022
return 0;
70237023

7024-
if (unlikely(p->policy == SCHED_IDLE))
7024+
if (unlikely(task_has_idle_policy(p)))
70257025
return 0;
70267026

70277027
/*

kernel/sched/sched.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ static inline bool valid_policy(int policy)
176176
rt_policy(policy) || dl_policy(policy);
177177
}
178178

179+
static inline int task_has_idle_policy(struct task_struct *p)
180+
{
181+
return idle_policy(p->policy);
182+
}
183+
179184
static inline int task_has_rt_policy(struct task_struct *p)
180185
{
181186
return rt_policy(p->policy);

0 commit comments

Comments
 (0)