[PATCH v10 5/7] sched: Consolidate pick_*_task to task_is_pushable helper

John Stultz posted 7 patches 1 year, 9 months ago
[PATCH v10 5/7] sched: Consolidate pick_*_task to task_is_pushable helper
Posted by John Stultz 1 year, 9 months ago
From: Connor O'Brien <connoro@google.com>

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@google.com>
Cc: Qais Yousef <qyousef@layalina.io>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
Cc: Valentin Schneider <vschneid@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ben Segall <bsegall@google.com>
Cc: Zimuzo Ezeozue <zezeozue@google.com>
Cc: Youssef Esmat <youssefesmat@google.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Daniel Bristot de Oliveira <bristot@redhat.com>
Cc: Will Deacon <will@kernel.org>
Cc: Waiman Long <longman@redhat.com>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: "Paul E. McKenney" <paulmck@kernel.org>
Cc: Metin Kaya <Metin.Kaya@arm.com>
Cc: Xuewen Yan <xuewen.yan94@gmail.com>
Cc: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: kernel-team@android.com
Tested-by: K Prateek Nayak <kprateek.nayak@amd.com>
Tested-by: Metin Kaya <metin.kaya@arm.com>
Reviewed-by: Metin Kaya <metin.kaya@arm.com>
Reviewed-by: Valentin Schneider <vschneid@redhat.com>
Signed-off-by: Connor O'Brien <connoro@google.com>
[jstultz: split out from larger chain migration patch,
 renamed helper function]
Signed-off-by: John Stultz <jstultz@google.com>
---
v7:
* Split from chain migration patch
* Renamed function
---
 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 eaedc69c5e30..ae583a427539 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -2179,14 +2179,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:
@@ -2205,7 +2197,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) == 1)
 			return p;
 
 		next_node = rb_next(next_node);
diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index 975cb49a64dc..8b6fb77e095b 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -1791,15 +1791,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
@@ -1813,7 +1804,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) == 1)
 			return p;
 	}
 
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 2d41ebe200c7..e46f69ba9ba2 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -3490,6 +3490,16 @@ void move_queued_task_locked(struct rq *rq, struct rq *dst_rq, struct task_struc
 	set_task_cpu(task, dst_rq->cpu);
 	activate_task(dst_rq, task, 0);
 }
+
+static inline
+int 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 1;
+
+	return 0;
+}
 #endif
 
 #endif /* _KERNEL_SCHED_SCHED_H */
-- 
2.45.0.rc1.225.g2a3ae87e7f-goog
Re: [PATCH v10 5/7] sched: Consolidate pick_*_task to task_is_pushable helper
Posted by Qais Yousef 1 year, 8 months ago
On 05/06/24 21:54, John Stultz wrote:
> From: Connor O'Brien <connoro@google.com>
> 
> 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@google.com>
> Cc: Qais Yousef <qyousef@layalina.io>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Juri Lelli <juri.lelli@redhat.com>
> Cc: Vincent Guittot <vincent.guittot@linaro.org>
> Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
> Cc: Valentin Schneider <vschneid@redhat.com>
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: Ben Segall <bsegall@google.com>
> Cc: Zimuzo Ezeozue <zezeozue@google.com>
> Cc: Youssef Esmat <youssefesmat@google.com>
> Cc: Mel Gorman <mgorman@suse.de>
> Cc: Daniel Bristot de Oliveira <bristot@redhat.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Waiman Long <longman@redhat.com>
> Cc: Boqun Feng <boqun.feng@gmail.com>
> Cc: "Paul E. McKenney" <paulmck@kernel.org>
> Cc: Metin Kaya <Metin.Kaya@arm.com>
> Cc: Xuewen Yan <xuewen.yan94@gmail.com>
> Cc: K Prateek Nayak <kprateek.nayak@amd.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: kernel-team@android.com
> Tested-by: K Prateek Nayak <kprateek.nayak@amd.com>
> Tested-by: Metin Kaya <metin.kaya@arm.com>
> Reviewed-by: Metin Kaya <metin.kaya@arm.com>
> Reviewed-by: Valentin Schneider <vschneid@redhat.com>
> Signed-off-by: Connor O'Brien <connoro@google.com>
> [jstultz: split out from larger chain migration patch,
>  renamed helper function]
> Signed-off-by: John Stultz <jstultz@google.com>
> ---
> v7:
> * Split from chain migration patch
> * Renamed function
> ---
>  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 eaedc69c5e30..ae583a427539 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -2179,14 +2179,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:
> @@ -2205,7 +2197,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) == 1)

Any reason we're checking specifically for == 1? Could the function later
return something other than 0 or 1?

It's explaining if 1 could end up meaning something else in the commit message
and in function docs. Otherwise let's make it a bool and not do explicit check
for return value.

With this

Reviewed-by: Qais Yousef <qyousef@layalina.io>

>  			return p;
>  
>  		next_node = rb_next(next_node);
> diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
> index 975cb49a64dc..8b6fb77e095b 100644
> --- a/kernel/sched/rt.c
> +++ b/kernel/sched/rt.c
> @@ -1791,15 +1791,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
> @@ -1813,7 +1804,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) == 1)
>  			return p;
>  	}
>  
> diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
> index 2d41ebe200c7..e46f69ba9ba2 100644
> --- a/kernel/sched/sched.h
> +++ b/kernel/sched/sched.h
> @@ -3490,6 +3490,16 @@ void move_queued_task_locked(struct rq *rq, struct rq *dst_rq, struct task_struc
>  	set_task_cpu(task, dst_rq->cpu);
>  	activate_task(dst_rq, task, 0);
>  }
> +
> +static inline
> +int 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 1;
> +
> +	return 0;
> +}
>  #endif
>  
>  #endif /* _KERNEL_SCHED_SCHED_H */
> -- 
> 2.45.0.rc1.225.g2a3ae87e7f-goog
>
Re: [PATCH v10 5/7] sched: Consolidate pick_*_task to task_is_pushable helper
Posted by Metin Kaya 1 year, 8 months ago
On 04/06/2024 2:18 pm, Qais Yousef wrote:
> On 05/06/24 21:54, John Stultz wrote:
>> From: Connor O'Brien <connoro@google.com>
>>
>> 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@google.com>
>> Cc: Qais Yousef <qyousef@layalina.io>
>> Cc: Ingo Molnar <mingo@redhat.com>
>> Cc: Peter Zijlstra <peterz@infradead.org>
>> Cc: Juri Lelli <juri.lelli@redhat.com>
>> Cc: Vincent Guittot <vincent.guittot@linaro.org>
>> Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
>> Cc: Valentin Schneider <vschneid@redhat.com>
>> Cc: Steven Rostedt <rostedt@goodmis.org>
>> Cc: Ben Segall <bsegall@google.com>
>> Cc: Zimuzo Ezeozue <zezeozue@google.com>
>> Cc: Youssef Esmat <youssefesmat@google.com>
>> Cc: Mel Gorman <mgorman@suse.de>
>> Cc: Daniel Bristot de Oliveira <bristot@redhat.com>
>> Cc: Will Deacon <will@kernel.org>
>> Cc: Waiman Long <longman@redhat.com>
>> Cc: Boqun Feng <boqun.feng@gmail.com>
>> Cc: "Paul E. McKenney" <paulmck@kernel.org>
>> Cc: Metin Kaya <Metin.Kaya@arm.com>
>> Cc: Xuewen Yan <xuewen.yan94@gmail.com>
>> Cc: K Prateek Nayak <kprateek.nayak@amd.com>
>> Cc: Thomas Gleixner <tglx@linutronix.de>
>> Cc: kernel-team@android.com
>> Tested-by: K Prateek Nayak <kprateek.nayak@amd.com>
>> Tested-by: Metin Kaya <metin.kaya@arm.com>
>> Reviewed-by: Metin Kaya <metin.kaya@arm.com>
>> Reviewed-by: Valentin Schneider <vschneid@redhat.com>
>> Signed-off-by: Connor O'Brien <connoro@google.com>
>> [jstultz: split out from larger chain migration patch,
>>   renamed helper function]
>> Signed-off-by: John Stultz <jstultz@google.com>
>> ---
>> v7:
>> * Split from chain migration patch
>> * Renamed function
>> ---
>>   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 eaedc69c5e30..ae583a427539 100644
>> --- a/kernel/sched/deadline.c
>> +++ b/kernel/sched/deadline.c
>> @@ -2179,14 +2179,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:
>> @@ -2205,7 +2197,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) == 1)
> 
> Any reason we're checking specifically for == 1? Could the function later
> return something other than 0 or 1?

I hear you, but just letting you know that `task_is_pushable()` will 
return different non-zero results per upcoming patches in the queue. The 
commit "sched: Fix rt/dl load balancing via chain level balance" will 
make the function look like below (excerpt from `kernel/sched/core.c`):

/*
  * Returns:
  * 1 if chain is pushable and affinity does not prevent pushing to cpu
  * 0 if chain is unpushable
  * -1 if chain is pushable but affinity blocks running on cpu.
  */
int task_is_pushable(struct rq *rq, struct task_struct *p, int cpu)

> 
> It's explaining if 1 could end up meaning something else in the commit message
> and in function docs. Otherwise let's make it a bool and not do explicit check
> for return value.
> 
> With this
> 
> Reviewed-by: Qais Yousef <qyousef@layalina.io>
> 
>>   			return p;
>>   
>>   		next_node = rb_next(next_node);
>> diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
>> index 975cb49a64dc..8b6fb77e095b 100644
>> --- a/kernel/sched/rt.c
>> +++ b/kernel/sched/rt.c
>> @@ -1791,15 +1791,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
>> @@ -1813,7 +1804,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) == 1)
>>   			return p;
>>   	}
>>   
>> diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
>> index 2d41ebe200c7..e46f69ba9ba2 100644
>> --- a/kernel/sched/sched.h
>> +++ b/kernel/sched/sched.h
>> @@ -3490,6 +3490,16 @@ void move_queued_task_locked(struct rq *rq, struct rq *dst_rq, struct task_struc
>>   	set_task_cpu(task, dst_rq->cpu);
>>   	activate_task(dst_rq, task, 0);
>>   }
>> +
>> +static inline
>> +int 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 1;
>> +
>> +	return 0;
>> +}
>>   #endif
>>   
>>   #endif /* _KERNEL_SCHED_SCHED_H */
>> -- 
>> 2.45.0.rc1.225.g2a3ae87e7f-goog
>>