Skip to contentSkip to conversation

sched: deadline: Remove unnecessary goto label in pick_earliest_pushable_dl_task

RFC PATCH Superseded John Stultz 6 participants 8 messages Dec 5, 2024 – Dec 13, 2024 Scheduler

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 sched: deadline: Remove unnecessary goto label in pick_earliest_pushable_dl_task

Commit 8b5e770ed7c0 ("sched/deadline: Optimize pull_dl_task()") added an odd goto label that seems to be unnecssary, given its called unconditionally from the bottom of a while loop and the label is at the top.

Thus, clean it up and remove the label/goto.

Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Juri Lelli <[email protected]>
Cc Vincent Guittot <[email protected]>
Cc Dietmar Eggemann <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Ben Segall <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Valentin Schneider <[email protected]>
Cc Wanpeng Li <[email protected]>
Cc Todd Kjos <[email protected]>
Fixes 8b5e770ed7c0 ("sched/deadline: Optimize pull_dl_task()")
---
 kernel/sched/deadline.c | 3 ---
 1 file changed, 3 deletions(-)
kernel/sched/deadline.c +0 -3
index d9d5a702f1a61..566a05efa4e57 100644
@@ -2501,8 +2501,6 @@ static struct task_struct *pick_earliest_pushable_dl_task(struct rq *rq, int cpu
 		return NULL;
 
 	next_node = rb_first_cached(&rq->dl.pushable_dl_tasks_root);
-
-next_node:
 	if (next_node) {
 		p = __node_2_pdl(next_node);
 
@@ -2510,7 +2508,6 @@ static struct task_struct *pick_earliest_pushable_dl_task(struct rq *rq, int cpu
 			return p;
 
 		next_node = rb_next(next_node);
-		goto next_node;
 	}
 
 	return NULL;
Signature · 1 line
2.47.0.338.g60cca15819-goog
#1 lore raw

Le 05/12/2024 à 22:16, John Stultz a écrit :

Quoted 2 lines

Commit 8b5e770ed7c0 ("sched/deadline: Optimize pull_dl_task()") added an odd goto label that seems to be unnecssary, given its

s/unnecssary/unnecessary/

Quoted 2 lines

called unconditionally from the bottom of a while loop and the label is at the top.

Except that it is not a while loop, but only an if.

Maybe, changing this if into a while would save a few lines of code and be more readable as-well.

CJ

Quoted 43 lines

Thus, clean it up and remove the label/goto.

Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Juri Lelli <[email protected]>
Cc Vincent Guittot <[email protected]>
Cc Dietmar Eggemann <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Ben Segall <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Valentin Schneider <[email protected]>
Cc Wanpeng Li <[email protected]>
Cc Todd Kjos <[email protected]>
Fixes 8b5e770ed7c0 ("sched/deadline: Optimize pull_dl_task()")
---
  kernel/sched/deadline.c | 3 ---
  1 file changed, 3 deletions(-)
kernel/sched/deadline.c +0 -3
index d9d5a702f1a61..566a05efa4e57 100644
@@ -2501,8 +2501,6 @@ static struct task_struct *pick_earliest_pushable_dl_task(struct rq *rq, int cpu
  		return NULL;
 
  	next_node = rb_first_cached(&rq->dl.pushable_dl_tasks_root);
-
-next_node:
  	if (next_node) {
  		p = __node_2_pdl(next_node);
 
@@ -2510,7 +2508,6 @@ static struct task_struct *pick_earliest_pushable_dl_task(struct rq *rq, int cpu
  			return p;
 
  		next_node = rb_next(next_node);
-		goto next_node;
  	}
 
  	return NULL;
#2 lore raw
Quoted 11 lines · Christophe JAILLET
Quoted 2 lines · John Stultz

Commit 8b5e770ed7c0 ("sched/deadline: Optimize pull_dl_task()") added an odd goto label that seems to be unnecssary, given its

s/unnecssary/unnecessary/

Quoted 2 lines

called unconditionally from the bottom of a while loop and the label is at the top.

Except that it is not a while loop, but only an if.

Ah! Apologies. I need to get my eyes checked. :P Thank you for catching me there.

Quoted 2 lines

Maybe, changing this if into a while would save a few lines of code and be more readable as-well.

Yeah, Todd pointed out the unconventional usage, but my brain mis-read the code as being a while(). I'll resend with that change.

thanks
-john

#3 lore raw

PATCH v2 1/1 sched: deadline: Cleanup goto label in pick_earliest_pushable_dl_task

In reply to John Stultz

Commit 8b5e770ed7c0 ("sched/deadline: Optimize pull_dl_task()") added a goto label seems would be better written as a while loop.

So replace the goto with a while loop, to make it easier to read.

Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Juri Lelli <[email protected]>
Cc Vincent Guittot <[email protected]>
Cc Dietmar Eggemann <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Ben Segall <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Valentin Schneider <[email protected]>
Cc Wanpeng Li <[email protected]>
Cc Christophe JAILLET <[email protected]>
Cc Todd Kjos <[email protected]>

---
v2:
* Corrects my misreading of the code (as pointed out by Christophe JAILLET) as already having a while loop, and switches the if to a while.

---
 kernel/sched/deadline.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
kernel/sched/deadline.c +1 -4
index d9d5a702f1a61..b2cc71984176a 100644
@@ -2501,16 +2501,13 @@ static struct task_struct *pick_earliest_pushable_dl_task(struct rq *rq, int cpu
 		return NULL;
 
 	next_node = rb_first_cached(&rq->dl.pushable_dl_tasks_root);
-
-next_node:
-	if (next_node) {
+	while (next_node) {
 		p = __node_2_pdl(next_node);
 
 		if (task_is_pushable(rq, p, cpu))
 			return p;
 
 		next_node = rb_next(next_node);
-		goto next_node;
 	}
 
 	return NULL;
Signature · 1 line
2.47.0.338.g60cca15819-goog
#4 lore raw

Re: [PATCH v2] sched: deadline: Cleanup goto label in pick_earliest_pushable_dl_task

Hello John,

Quoted 6 lines · John Stultz

Commit 8b5e770ed7c0 ("sched/deadline: Optimize pull_dl_task()") added a goto label seems would be better written as a while loop.

So replace the goto with a while loop, to make it easier to read.

Quoted 15 lines
Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Juri Lelli <[email protected]>
Cc Vincent Guittot <[email protected]>
Cc Dietmar Eggemann <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Ben Segall <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Valentin Schneider <[email protected]>
Cc Wanpeng Li <[email protected]>
Cc Christophe JAILLET <[email protected]>
Cc Todd Kjos <[email protected]>

Gave it a spin on my box. Feel free to add:

Signature · 2 lines
Thanks and Regards,
Prateek
Quoted 31 lines

---
v2:
* Corrects my misreading of the code (as pointed out by Christophe JAILLET) as already having a while loop, and switches the if to a while.

---
  kernel/sched/deadline.c | 5 +----
  1 file changed, 1 insertion(+), 4 deletions(-)
kernel/sched/deadline.c +1 -4
index d9d5a702f1a61..b2cc71984176a 100644
@@ -2501,16 +2501,13 @@ static struct task_struct *pick_earliest_pushable_dl_task(struct rq *rq, int cpu
  		return NULL;
 
  	next_node = rb_first_cached(&rq->dl.pushable_dl_tasks_root);
-
-next_node:
-	if (next_node) {
+	while (next_node) {
  		p = __node_2_pdl(next_node);
 
  		if (task_is_pushable(rq, p, cpu))
  			return p;
 
  		next_node = rb_next(next_node);
-		goto next_node;
  	}
 
  	return NULL;
maintainer Acked-by on v2 1/1
#5 lore raw

Re: [PATCH v2] sched: deadline: Cleanup goto label in pick_earliest_pushable_dl_task

In reply to John Stultz

Hi John,

Quoted 6 lines · John Stultz

Commit 8b5e770ed7c0 ("sched/deadline: Optimize pull_dl_task()") added a goto label seems would be better written as a while loop.

So replace the goto with a while loop, to make it easier to read.

Quoted 15 lines
Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Juri Lelli <[email protected]>
Cc Vincent Guittot <[email protected]>
Cc Dietmar Eggemann <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Ben Segall <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Valentin Schneider <[email protected]>
Cc Wanpeng Li <[email protected]>
Cc Christophe JAILLET <[email protected]>
Cc Todd Kjos <[email protected]>

Thanks!
Juri

maintainer
#6 lore raw

Re: [PATCH v2] sched: deadline: Cleanup goto label in pick_earliest_pushable_dl_task

In reply to John Stultz
Quoted 6 lines · John Stultz

Commit 8b5e770ed7c0 ("sched/deadline: Optimize pull_dl_task()") added a goto label seems would be better written as a while loop.

So replace the goto with a while loop, to make it easier to read.

Thanks!

merge bot Applied
#7 lore raw

[tip: sched/core] sched: deadline: Cleanup goto label in pick_earliest_pushable_dl_task

In reply to John Stultz
The following commit has been merged into the sched/core branch of tip:

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     7675361ff9a1d9038025c05267600d0c762c0236
Gitweb:        https://git.kernel.org/tip/7675361ff9a1d9038025c05267600d0c762c0236
Author:        John Stultz <[email protected]>
AuthorDate:    Thu, 05 Dec 2024 15:59:35 -08:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Tue, 10 Dec 2024 15:07:06 +01:00

sched: deadline: Cleanup goto label in pick_earliest_pushable_dl_task

Commit 8b5e770ed7c0 ("sched/deadline: Optimize pull_dl_task()") added a goto label seems would be better written as a while loop.

So replace the goto with a while loop, to make it easier to read.

---
 kernel/sched/deadline.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
kernel/sched/deadline.c +1 -4
index 33b4646..643d101 100644
@@ -2516,16 +2516,13 @@ static struct task_struct *pick_earliest_pushable_dl_task(struct rq *rq, int cpu
 		return NULL;
 
 	next_node = rb_first_cached(&rq->dl.pushable_dl_tasks_root);
-
-next_node:
-	if (next_node) {
+	while (next_node) {
 		p = __node_2_pdl(next_node);
 
 		if (task_is_pushable(rq, p, cpu))
 			return p;
 
 		next_node = rb_next(next_node);
-		goto next_node;
 	}
 
 	return NULL;