linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next] sched/deadline: Add compare_task_rq helper
@ 2022-08-26  3:11 Shang XiaoJing
  2022-08-26  7:10 ` Daniel Bristot de Oliveira
  0 siblings, 1 reply; 3+ messages in thread
From: Shang XiaoJing @ 2022-08-26  3:11 UTC (permalink / raw)
  To: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
	rostedt, bsegall, mgorman, bristot, vschneid, linux-kernel
  Cc: shangxiaojing

Wrap repeated code in helper function compare_task_rq, which return true
if there is no deadline task on the rq at all, or task's deadline
earlier than the rq.

Signed-off-by: Shang XiaoJing <shangxiaojing@huawei.com>
---
 kernel/sched/deadline.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index d116d2b9d2f9..4a40a462717c 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -1810,6 +1810,13 @@ static void yield_task_dl(struct rq *rq)
 
 #ifdef CONFIG_SMP
 
+static inline bool compare_task_rq(struct task_struct *p, struct rq *rq)
+{
+	return (!rq->dl.dl_nr_running ||
+		dl_time_before(p->dl.deadline,
+			       rq->dl.earliest_dl.curr));
+}
+
 static int find_later_rq(struct task_struct *task);
 
 static int
@@ -1852,9 +1859,7 @@ select_task_rq_dl(struct task_struct *p, int cpu, int flags)
 		int target = find_later_rq(p);
 
 		if (target != -1 &&
-				(dl_time_before(p->dl.deadline,
-					cpu_rq(target)->dl.earliest_dl.curr) ||
-				(cpu_rq(target)->dl.dl_nr_running == 0)))
+		    compare_task_rq(p, cpu_rq(target)))
 			cpu = target;
 	}
 	rcu_read_unlock();
@@ -2221,9 +2226,7 @@ static struct rq *find_lock_later_rq(struct task_struct *task, struct rq *rq)
 
 		later_rq = cpu_rq(cpu);
 
-		if (later_rq->dl.dl_nr_running &&
-		    !dl_time_before(task->dl.deadline,
-					later_rq->dl.earliest_dl.curr)) {
+		if (!compare_task_rq(task, later_rq)) {
 			/*
 			 * Target rq has tasks of equal or earlier deadline,
 			 * retrying does not release any lock and is unlikely
@@ -2251,9 +2254,7 @@ static struct rq *find_lock_later_rq(struct task_struct *task, struct rq *rq)
 		 * its earliest one has a later deadline than our
 		 * task, the rq is a good one.
 		 */
-		if (!later_rq->dl.dl_nr_running ||
-		    dl_time_before(task->dl.deadline,
-				   later_rq->dl.earliest_dl.curr))
+		if (compare_task_rq(task, later_rq))
 			break;
 
 		/* Otherwise we try again. */
@@ -2424,9 +2425,7 @@ static void pull_dl_task(struct rq *this_rq)
 		 *  - it will preempt the last one we pulled (if any).
 		 */
 		if (p && dl_time_before(p->dl.deadline, dmin) &&
-		    (!this_rq->dl.dl_nr_running ||
-		     dl_time_before(p->dl.deadline,
-				    this_rq->dl.earliest_dl.curr))) {
+		    compare_task_rq(p, this_rq)) {
 			WARN_ON(p == src_rq->curr);
 			WARN_ON(!task_on_rq_queued(p));
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH -next] sched/deadline: Add compare_task_rq helper
  2022-08-26  3:11 [PATCH -next] sched/deadline: Add compare_task_rq helper Shang XiaoJing
@ 2022-08-26  7:10 ` Daniel Bristot de Oliveira
  2022-08-26  7:23   ` shangxiaojing
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Bristot de Oliveira @ 2022-08-26  7:10 UTC (permalink / raw)
  To: Shang XiaoJing
  Cc: mingo, peterz, vincent.guittot, juri.lelli, dietmar.eggemann,
	rostedt, bsegall, mgorman, vschneid, linux-kernel

On 8/26/22 05:11, Shang XiaoJing wrote:
> Wrap repeated code in helper function compare_task_rq, which return true
> if there is no deadline task on the rq at all, or task's deadline
> earlier than the rq.
> 
> Signed-off-by: Shang XiaoJing <shangxiaojing@huawei.com>
> ---
>  kernel/sched/deadline.c | 23 +++++++++++------------
>  1 file changed, 11 insertions(+), 12 deletions(-)
> 
> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index d116d2b9d2f9..4a40a462717c 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -1810,6 +1810,13 @@ static void yield_task_dl(struct rq *rq)
>  
>  #ifdef CONFIG_SMP

I see the value of this helper, but "compare_task_rq" is making things more confuse.

Choose a more descriptive name, like, dl_task_is_earliest_deadline() ?

> +static inline bool compare_task_rq(struct task_struct *p, struct rq *rq)
> +{
> +	return (!rq->dl.dl_nr_running ||
> +		dl_time_before(p->dl.deadline,
> +			       rq->dl.earliest_dl.curr));
> +}
> +

-- Daniel


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH -next] sched/deadline: Add compare_task_rq helper
  2022-08-26  7:10 ` Daniel Bristot de Oliveira
@ 2022-08-26  7:23   ` shangxiaojing
  0 siblings, 0 replies; 3+ messages in thread
From: shangxiaojing @ 2022-08-26  7:23 UTC (permalink / raw)
  To: Daniel Bristot de Oliveira
  Cc: mingo, peterz, vincent.guittot, juri.lelli, dietmar.eggemann,
	rostedt, bsegall, mgorman, vschneid, linux-kernel


On 2022/8/26 15:10, Daniel Bristot de Oliveira wrote:
> On 8/26/22 05:11, Shang XiaoJing wrote:
>> Wrap repeated code in helper function compare_task_rq, which return true
>> if there is no deadline task on the rq at all, or task's deadline
>> earlier than the rq.
>>
>> Signed-off-by: Shang XiaoJing <shangxiaojing@huawei.com>
>> ---
>>   kernel/sched/deadline.c | 23 +++++++++++------------
>>   1 file changed, 11 insertions(+), 12 deletions(-)
>>
>> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
>> index d116d2b9d2f9..4a40a462717c 100644
>> --- a/kernel/sched/deadline.c
>> +++ b/kernel/sched/deadline.c
>> @@ -1810,6 +1810,13 @@ static void yield_task_dl(struct rq *rq)
>>   
>>   #ifdef CONFIG_SMP
> I see the value of this helper, but "compare_task_rq" is making things more confuse.
>
> Choose a more descriptive name, like, dl_task_is_earliest_deadline() ?

ok, i'll find a better name, or take your advice directly in v2.

>> +static inline bool compare_task_rq(struct task_struct *p, struct rq *rq)
>> +{
>> +	return (!rq->dl.dl_nr_running ||
>> +		dl_time_before(p->dl.deadline,
>> +			       rq->dl.earliest_dl.curr));
>> +}
>> +
> -- Daniel

Thanks :-) ,

Shang XiaoJing


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-08-26  7:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-26  3:11 [PATCH -next] sched/deadline: Add compare_task_rq helper Shang XiaoJing
2022-08-26  7:10 ` Daniel Bristot de Oliveira
2022-08-26  7:23   ` shangxiaojing

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).