Commit a0e813f2 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar

sched/core: Further clarify sched_class::set_next_task()

It turns out there really is something special to the first
set_next_task() invocation. In specific the 'change' pattern really
should not cause balance callbacks.
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: bsegall@google.com
Cc: dietmar.eggemann@arm.com
Cc: juri.lelli@redhat.com
Cc: ktkhai@virtuozzo.com
Cc: mgorman@suse.de
Cc: qais.yousef@arm.com
Cc: qperret@google.com
Cc: rostedt@goodmis.org
Cc: valentin.schneider@arm.com
Cc: vincent.guittot@linaro.org
Fixes: f95d4eae ("sched/{rt,deadline}: Fix set_next_task vs pick_next_task")
Link: https://lkml.kernel.org/r/20191108131909.775434698@infradead.orgSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 2eeb01a2
...@@ -1743,13 +1743,16 @@ static void start_hrtick_dl(struct rq *rq, struct task_struct *p) ...@@ -1743,13 +1743,16 @@ static void start_hrtick_dl(struct rq *rq, struct task_struct *p)
} }
#endif #endif
static void set_next_task_dl(struct rq *rq, struct task_struct *p) static void set_next_task_dl(struct rq *rq, struct task_struct *p, bool first)
{ {
p->se.exec_start = rq_clock_task(rq); p->se.exec_start = rq_clock_task(rq);
/* You can't push away the running task */ /* You can't push away the running task */
dequeue_pushable_dl_task(rq, p); dequeue_pushable_dl_task(rq, p);
if (!first)
return;
if (hrtick_enabled(rq)) if (hrtick_enabled(rq))
start_hrtick_dl(rq, p); start_hrtick_dl(rq, p);
...@@ -1782,7 +1785,7 @@ static struct task_struct *pick_next_task_dl(struct rq *rq) ...@@ -1782,7 +1785,7 @@ static struct task_struct *pick_next_task_dl(struct rq *rq)
dl_se = pick_next_dl_entity(rq, dl_rq); dl_se = pick_next_dl_entity(rq, dl_rq);
BUG_ON(!dl_se); BUG_ON(!dl_se);
p = dl_task_of(dl_se); p = dl_task_of(dl_se);
set_next_task_dl(rq, p); set_next_task_dl(rq, p, true);
return p; return p;
} }
......
...@@ -10344,7 +10344,7 @@ static void switched_to_fair(struct rq *rq, struct task_struct *p) ...@@ -10344,7 +10344,7 @@ static void switched_to_fair(struct rq *rq, struct task_struct *p)
* This routine is mostly called to set cfs_rq->curr field when a task * This routine is mostly called to set cfs_rq->curr field when a task
* migrates between groups/classes. * migrates between groups/classes.
*/ */
static void set_next_task_fair(struct rq *rq, struct task_struct *p) static void set_next_task_fair(struct rq *rq, struct task_struct *p, bool first)
{ {
struct sched_entity *se = &p->se; struct sched_entity *se = &p->se;
......
...@@ -385,7 +385,7 @@ static void put_prev_task_idle(struct rq *rq, struct task_struct *prev) ...@@ -385,7 +385,7 @@ static void put_prev_task_idle(struct rq *rq, struct task_struct *prev)
{ {
} }
static void set_next_task_idle(struct rq *rq, struct task_struct *next) static void set_next_task_idle(struct rq *rq, struct task_struct *next, bool first)
{ {
update_idle_core(rq); update_idle_core(rq);
schedstat_inc(rq->sched_goidle); schedstat_inc(rq->sched_goidle);
...@@ -395,7 +395,7 @@ struct task_struct *pick_next_task_idle(struct rq *rq) ...@@ -395,7 +395,7 @@ struct task_struct *pick_next_task_idle(struct rq *rq)
{ {
struct task_struct *next = rq->idle; struct task_struct *next = rq->idle;
set_next_task_idle(rq, next); set_next_task_idle(rq, next, true);
return next; return next;
} }
......
...@@ -1515,13 +1515,16 @@ static void check_preempt_curr_rt(struct rq *rq, struct task_struct *p, int flag ...@@ -1515,13 +1515,16 @@ static void check_preempt_curr_rt(struct rq *rq, struct task_struct *p, int flag
#endif #endif
} }
static inline void set_next_task_rt(struct rq *rq, struct task_struct *p) static inline void set_next_task_rt(struct rq *rq, struct task_struct *p, bool first)
{ {
p->se.exec_start = rq_clock_task(rq); p->se.exec_start = rq_clock_task(rq);
/* The running task is never eligible for pushing */ /* The running task is never eligible for pushing */
dequeue_pushable_task(rq, p); dequeue_pushable_task(rq, p);
if (!first)
return;
/* /*
* If prev task was rt, put_prev_task() has already updated the * If prev task was rt, put_prev_task() has already updated the
* utilization. We only care of the case where we start to schedule a * utilization. We only care of the case where we start to schedule a
...@@ -1572,7 +1575,7 @@ static struct task_struct *pick_next_task_rt(struct rq *rq) ...@@ -1572,7 +1575,7 @@ static struct task_struct *pick_next_task_rt(struct rq *rq)
return NULL; return NULL;
p = _pick_next_task_rt(rq); p = _pick_next_task_rt(rq);
set_next_task_rt(rq, p); set_next_task_rt(rq, p, true);
return p; return p;
} }
......
...@@ -1716,7 +1716,7 @@ struct sched_class { ...@@ -1716,7 +1716,7 @@ struct sched_class {
struct task_struct *(*pick_next_task)(struct rq *rq); struct task_struct *(*pick_next_task)(struct rq *rq);
void (*put_prev_task)(struct rq *rq, struct task_struct *p); void (*put_prev_task)(struct rq *rq, struct task_struct *p);
void (*set_next_task)(struct rq *rq, struct task_struct *p); void (*set_next_task)(struct rq *rq, struct task_struct *p, bool first);
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
int (*balance)(struct rq *rq, struct task_struct *prev, struct rq_flags *rf); int (*balance)(struct rq *rq, struct task_struct *prev, struct rq_flags *rf);
...@@ -1768,7 +1768,7 @@ static inline void put_prev_task(struct rq *rq, struct task_struct *prev) ...@@ -1768,7 +1768,7 @@ static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
static inline void set_next_task(struct rq *rq, struct task_struct *next) static inline void set_next_task(struct rq *rq, struct task_struct *next)
{ {
WARN_ON_ONCE(rq->curr != next); WARN_ON_ONCE(rq->curr != next);
next->sched_class->set_next_task(rq, next); next->sched_class->set_next_task(rq, next, false);
} }
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
......
...@@ -29,7 +29,7 @@ check_preempt_curr_stop(struct rq *rq, struct task_struct *p, int flags) ...@@ -29,7 +29,7 @@ check_preempt_curr_stop(struct rq *rq, struct task_struct *p, int flags)
/* we're never preempted */ /* we're never preempted */
} }
static void set_next_task_stop(struct rq *rq, struct task_struct *stop) static void set_next_task_stop(struct rq *rq, struct task_struct *stop, bool first)
{ {
stop->se.exec_start = rq_clock_task(rq); stop->se.exec_start = rq_clock_task(rq);
} }
...@@ -39,7 +39,7 @@ static struct task_struct *pick_next_task_stop(struct rq *rq) ...@@ -39,7 +39,7 @@ static struct task_struct *pick_next_task_stop(struct rq *rq)
if (!sched_stop_runnable(rq)) if (!sched_stop_runnable(rq))
return NULL; return NULL;
set_next_task_stop(rq, rq->stop); set_next_task_stop(rq, rq->stop, true);
return rq->stop; return rq->stop;
} }
......
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