Re: [RESEND x2][PATCH v12 5/7] sched: Consolidate pick_*_task to task_is_pushable helper

From: Christian Loehle
Date: Thu Sep 12 2024 - 13:30:11 EST


On 9/10/24 23:12, John Stultz wrote:
> From: Connor O'Brien <connoro@xxxxxxxxxx>
>
> This patch consolidates rt and deadline pick_*_task functions to
> a task_is_pushable() helper
>
> This patch was broken out from a larger chain migration
> patch originally by Connor O'Brien.
>
> 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: Mel Gorman <mgorman@xxxxxxx>
> 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: Daniel Lezcano <daniel.lezcano@xxxxxxxxxx>
> 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>
> Reviewed-by: Valentin Schneider <vschneid@xxxxxxxxxx>
> Signed-off-by: Connor O'Brien <connoro@xxxxxxxxxx>
> [jstultz: split out from larger chain migration patch,
> renamed helper function]
> Signed-off-by: John Stultz <jstultz@xxxxxxxxxx>
> ---
> v7:
> * Split from chain migration patch
> * Renamed function
> v11:
> * Switched to bool (though later in the series it goes
> to a tri-state return) for now to simplify review.
> Will add tri-state handling later in the series when
> its needed. Suggested by Metin and others.
> ---
> kernel/sched/deadline.c | 10 +---------
> kernel/sched/rt.c | 11 +----------
> kernel/sched/sched.h | 10 ++++++++++
> 3 files changed, 12 insertions(+), 19 deletions(-)
>
> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index ac60d2819bd1d..d3050f6c2958d 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -2183,14 +2183,6 @@ static void task_fork_dl(struct task_struct *p)
> /* Only try algorithms three times */
> #define DL_MAX_TRIES 3
>
> -static int pick_dl_task(struct rq *rq, struct task_struct *p, int cpu)
> -{
> - if (!task_on_cpu(rq, p) &&
> - cpumask_test_cpu(cpu, &p->cpus_mask))
> - return 1;
> - return 0;
> -}
> -
> /*
> * Return the earliest pushable rq's task, which is suitable to be executed
> * on the CPU, NULL otherwise:
> @@ -2209,7 +2201,7 @@ static struct task_struct *pick_earliest_pushable_dl_task(struct rq *rq, int cpu
> if (next_node) {
> p = __node_2_pdl(next_node);
>
> - if (pick_dl_task(rq, p, cpu))
> + if (task_is_pushable(rq, p, cpu))
> return p;
>
> next_node = rb_next(next_node);
> diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
> index 496d3e6ab57d2..9f07f09641f7a 100644
> --- a/kernel/sched/rt.c
> +++ b/kernel/sched/rt.c
> @@ -1790,15 +1790,6 @@ static void put_prev_task_rt(struct rq *rq, struct task_struct *p)
> /* Only try algorithms three times */
> #define RT_MAX_TRIES 3
>
> -static int pick_rt_task(struct rq *rq, struct task_struct *p, int cpu)
> -{
> - if (!task_on_cpu(rq, p) &&
> - cpumask_test_cpu(cpu, &p->cpus_mask))
> - return 1;
> -
> - return 0;
> -}
> -
> /*
> * Return the highest pushable rq's task, which is suitable to be executed
> * on the CPU, NULL otherwise
> @@ -1812,7 +1803,7 @@ static struct task_struct *pick_highest_pushable_task(struct rq *rq, int cpu)
> return NULL;
>
> plist_for_each_entry(p, head, pushable_tasks) {
> - if (pick_rt_task(rq, p, cpu))
> + if (task_is_pushable(rq, p, cpu))
> return p;
> }
>
> diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
> index d2cc31c2457e5..10ef612c078f9 100644
> --- a/kernel/sched/sched.h
> +++ b/kernel/sched/sched.h
> @@ -3586,6 +3586,16 @@ void move_queued_task_locked(struct rq *src_rq, struct rq *dst_rq, struct task_s
> set_task_cpu(task, dst_rq->cpu);
> activate_task(dst_rq, task, 0);
> }
> +
> +static inline
> +bool task_is_pushable(struct rq *rq, struct task_struct *p, int cpu)
> +{
> + if (!task_on_cpu(rq, p) &&
> + cpumask_test_cpu(cpu, &p->cpus_mask))
> + return true;
> +
> + return false;
> +}

The slightly awkward
if (condition)
return true;
return false;

is more convenient for you for the tri-state later, I assume.
Fine by me FWIW.
Reviewed-by: Christian Loehle <christian.loehle@xxxxxxx>