Introduce a new function finish_prev_task() to do the balance
when necessary, and then put previous task back to the run queue.
This function is extracted from pick_next_task() to prepare for
future usage by other type of task picking logic.
No functional change.
Suggested-by: Peter Zijlstra <[email protected]>
Signed-off-by: Chen Yu <[email protected]>
---
kernel/sched/core.c | 39 +++++++++++++++++++++++----------------
1 file changed, 23 insertions(+), 16 deletions(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 3a61a3b8eaa9..bf59a5cf030c 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3904,6 +3904,28 @@ static inline void schedule_debug(struct task_struct *prev, bool preempt)
schedstat_inc(this_rq()->sched_count);
}
+static void finish_prev_task(struct rq *rq, struct task_struct *prev,
+ struct rq_flags *rf)
+{
+ const struct sched_class *class;
+#ifdef CONFIG_SMP
+ /*
+ * We must do the balancing pass before put_next_task(), such
+ * that when we release the rq->lock the task is in the same
+ * state as before we took rq->lock.
+ *
+ * We can terminate the balance pass as soon as we know there is
+ * a runnable task of @class priority or higher.
+ */
+ for_class_range(class, prev->sched_class, &idle_sched_class) {
+ if (class->balance(rq, prev, rf))
+ break;
+ }
+#endif
+
+ put_prev_task(rq, prev);
+}
+
/*
* Pick up the highest-prio task:
*/
@@ -3937,22 +3959,7 @@ pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf)
}
restart:
-#ifdef CONFIG_SMP
- /*
- * We must do the balancing pass before put_next_task(), such
- * that when we release the rq->lock the task is in the same
- * state as before we took rq->lock.
- *
- * We can terminate the balance pass as soon as we know there is
- * a runnable task of @class priority or higher.
- */
- for_class_range(class, prev->sched_class, &idle_sched_class) {
- if (class->balance(rq, prev, rf))
- break;
- }
-#endif
-
- put_prev_task(rq, prev);
+ finish_prev_task(rq, prev, rf);
for_each_class(class) {
p = class->pick_next_task(rq);
--
2.17.1
On 20/04/20 16:01, Chen Yu wrote:
> Introduce a new function finish_prev_task() to do the balance
> when necessary, and then put previous task back to the run queue.
> This function is extracted from pick_next_task() to prepare for
> future usage by other type of task picking logic.
>
> No functional change.
>
With the absolutely tiny nit below:
Reviewed-by: Valentin Schneider <[email protected]>
> Suggested-by: Peter Zijlstra <[email protected]>
> Signed-off-by: Chen Yu <[email protected]>
> ---
> kernel/sched/core.c | 39 +++++++++++++++++++++++----------------
> 1 file changed, 23 insertions(+), 16 deletions(-)
>
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 3a61a3b8eaa9..bf59a5cf030c 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -3904,6 +3904,28 @@ static inline void schedule_debug(struct task_struct *prev, bool preempt)
> schedstat_inc(this_rq()->sched_count);
> }
>
> +static void finish_prev_task(struct rq *rq, struct task_struct *prev,
> + struct rq_flags *rf)
> +{
> + const struct sched_class *class;
> +#ifdef CONFIG_SMP
Nit: I would've put that declaration within the ifdef, given it isn't used
outside of it.
> + /*
> + * We must do the balancing pass before put_next_task(), such
> + * that when we release the rq->lock the task is in the same
> + * state as before we took rq->lock.
> + *
> + * We can terminate the balance pass as soon as we know there is
> + * a runnable task of @class priority or higher.
> + */
> + for_class_range(class, prev->sched_class, &idle_sched_class) {
> + if (class->balance(rq, prev, rf))
> + break;
> + }
> +#endif
> +
> + put_prev_task(rq, prev);
> +}
> +
> /*
> * Pick up the highest-prio task:
> */
Hi,
On Mon, Apr 20, 2020 at 06:44:29PM +0100, Valentin Schneider wrote:
>
> On 20/04/20 16:01, Chen Yu wrote:
> > Introduce a new function finish_prev_task() to do the balance
> > when necessary, and then put previous task back to the run queue.
> > This function is extracted from pick_next_task() to prepare for
> > future usage by other type of task picking logic.
> >
> > No functional change.
> >
>
> With the absolutely tiny nit below:
>
> Reviewed-by: Valentin Schneider <[email protected]>
>
> > Suggested-by: Peter Zijlstra <[email protected]>
> > Signed-off-by: Chen Yu <[email protected]>
> > ---
> > kernel/sched/core.c | 39 +++++++++++++++++++++++----------------
> > 1 file changed, 23 insertions(+), 16 deletions(-)
> >
> > diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> > index 3a61a3b8eaa9..bf59a5cf030c 100644
> > --- a/kernel/sched/core.c
> > +++ b/kernel/sched/core.c
> > @@ -3904,6 +3904,28 @@ static inline void schedule_debug(struct task_struct *prev, bool preempt)
> > schedstat_inc(this_rq()->sched_count);
> > }
> >
> > +static void finish_prev_task(struct rq *rq, struct task_struct *prev,
> > + struct rq_flags *rf)
> > +{
> > + const struct sched_class *class;
> > +#ifdef CONFIG_SMP
>
> Nit: I would've put that declaration within the ifdef, given it isn't used
> outside of it.
>
Okay, I'll do.
Thanks,
Chenyu