Re: [PATCH v10 6/7] sched: Split out __schedule() deactivate task logic into a helper

From: John Stultz
Date: Tue Jun 04 2024 - 15:35:08 EST


On Tue, Jun 4, 2024 at 6:29 AM Qais Yousef <qyousef@xxxxxxxxxxx> wrote:
>
> On 05/06/24 21:54, John Stultz wrote:
> > As we're going to re-use the deactivation logic,
> > split it into a helper.
> >
> > Cc: Joel Fernandes <joelaf@xxxxxxxxxx>
> > Cc: Qais Yousef <qyousef@xxxxxxxxxxx>
> > Cc: Ingo Molnar <mingo@xxxxxxxxxx>
> > Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> > Cc: Juri Lelli <juri.lelli@xxxxxxxxxx>
> > Cc: Vincent Guittot <vincent.guittot@xxxxxxxxxx>
> > Cc: Dietmar Eggemann <dietmar.eggemann@xxxxxxx>
> > Cc: Valentin Schneider <vschneid@xxxxxxxxxx>
> > Cc: Steven Rostedt <rostedt@xxxxxxxxxxx>
> > Cc: Ben Segall <bsegall@xxxxxxxxxx>
> > Cc: Zimuzo Ezeozue <zezeozue@xxxxxxxxxx>
> > Cc: Youssef Esmat <youssefesmat@xxxxxxxxxx>
> > Cc: Mel Gorman <mgorman@xxxxxxx>
> > Cc: Daniel Bristot de Oliveira <bristot@xxxxxxxxxx>
> > Cc: Will Deacon <will@xxxxxxxxxx>
> > Cc: Waiman Long <longman@xxxxxxxxxx>
> > Cc: Boqun Feng <boqun.feng@xxxxxxxxx>
> > Cc: "Paul E. McKenney" <paulmck@xxxxxxxxxx>
> > Cc: Metin Kaya <Metin.Kaya@xxxxxxx>
> > Cc: Xuewen Yan <xuewen.yan94@xxxxxxxxx>
> > Cc: K Prateek Nayak <kprateek.nayak@xxxxxxx>
> > Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> > Cc: kernel-team@xxxxxxxxxxx
> > Tested-by: K Prateek Nayak <kprateek.nayak@xxxxxxx>
> > Tested-by: Metin Kaya <metin.kaya@xxxxxxx>
> > Reviewed-by: Metin Kaya <metin.kaya@xxxxxxx>
> > Signed-off-by: John Stultz <jstultz@xxxxxxxxxx>
> > ---
> > v6:
> > * Define function as static to avoid "no previous prototype"
> > warnings as Reported-by: kernel test robot <lkp@xxxxxxxxx>
> > v7:
> > * Rename state task_state to be more clear, as suggested by
> > Metin Kaya
> > ---
> > kernel/sched/core.c | 72 +++++++++++++++++++++++++++------------------
> > 1 file changed, 43 insertions(+), 29 deletions(-)
> >
> > diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> > index 48f0d4b381d5..8bc5844ebab9 100644
> > --- a/kernel/sched/core.c
> > +++ b/kernel/sched/core.c
> > @@ -6572,6 +6572,48 @@ pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf)
> > # define SM_MASK_PREEMPT SM_PREEMPT
> > #endif
> >
> > +/*
> > + * Helper function for __schedule()
> > + *
> > + * If a task does not have signals pending, deactivate it and return true
> > + * Otherwise marks the task's __state as RUNNING and returns false
> > + */
> > +static bool try_to_deactivate_task(struct rq *rq, struct task_struct *p,
> > + unsigned long task_state)
> > +{
> > + if (signal_pending_state(task_state, p)) {
> > + WRITE_ONCE(p->__state, TASK_RUNNING);
>
> We can avoid extra indention for the other (lengthy) leg if we return here?
>
> The return value is ignored for now, I don't mind keeping it but better call it
> out in the commit message or when you add the new user later you can update the
> signature more easily.

Ah. Good point on both counts here. I've reworked it to use your
suggestions here.

> Generally I think patches 4, 5 and 6 could be sent as their own series with
> minor commit messages tweaks to make them more independent and I hope Ingo and
> Peter are okay to pick them up as they look a nice clean up in general.
>
> Anyway:
>
> Reviewed-by: Qais Yousef <qyousef@xxxxxxxxxxx>

Thanks so much for the review!
-john