Skip to contentSkip to conversation

sched/fair: Optimize dequeue_task_fair()

PATCH In review Jiang Biao 3 participants 3 messages Aug 11, 2020 Scheduler

lore
Share & tools
lore

Jiang Biao

author
#0 lore raw

PATCH 1/1 sched/fair: Optimize dequeue_task_fair()

Similar optimization as what has been done in commit, 7d148be69e3a(sched/fair: Optimize enqueue_task_fair())

dequeue_task_fair jumps to dequeue_throttle label when cfs_rq_of(se) is throttled which means that se can't be NULL. We can move the label after the if (!se) statement and remove the if(!se) statment as se is always NULL when reaching this point.

Besides, trying to keep the same pattern with enqueue_task_fair can make it more readable.

---
 kernel/sched/fair.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/sched/fair.c +3 -3
index 04fa8dbcfa4d..cbbeafdfa8b7 100644
@@ -5618,10 +5618,10 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags)
 
 	}
 
-dequeue_throttle:
-	if (!se)
-		sub_nr_running(rq, 1);
+	/* At this point se is NULL and we are at root level*/
+	sub_nr_running(rq, 1);
 
+dequeue_throttle:
 	/* balance early to pull high priority tasks */
 	if (unlikely(!was_sched_idle && sched_idle_rq(rq)))
 		rq->next_balance = jiffies;
Signature · 1 line
2.21.0
#1 lore raw
Quoted 24 lines · Jiang Biao

Similar optimization as what has been done in commit, 7d148be69e3a(sched/fair: Optimize enqueue_task_fair())

dequeue_task_fair jumps to dequeue_throttle label when cfs_rq_of(se) is throttled which means that se can't be NULL. We can move the label after the if (!se) statement and remove the if(!se) statment as se is always NULL when reaching this point.

Besides, trying to keep the same pattern with enqueue_task_fair can make it more readable.

---
 kernel/sched/fair.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/sched/fair.c +0 -0
index 04fa8dbcfa4d..cbbeafdfa8b7 100644
@@ -5618,10 +5618,10 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags)
 
 	}
 

kernel/sched/fair.c static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags) · line 5627

Quoted 10 lines
kernel/sched/fair.c +3 -3
-dequeue_throttle:
-	if (!se)
-		sub_nr_running(rq, 1);
+	/* At this point se is NULL and we are at root level*/
+	sub_nr_running(rq, 1);
 
+dequeue_throttle:
 	/* balance early to pull high priority tasks */
 	if (unlikely(!was_sched_idle && sched_idle_rq(rq)))
 		rq->next_balance = jiffies;

There is already a similar patch in master.

423d02e1463b - sched/fair: Optimize dequeue_task_fair() (2020-06-25 Peng Wang)

#2 lore raw

Re: [PATCH] sched/fair: Optimize dequeue_task_fair()(Internet mail)

Hi,

Quoted 40 lines · Dietmar Eggemann
Quoted 24 lines · Jiang Biao

Similar optimization as what has been done in commit, 7d148be69e3a(sched/fair: Optimize enqueue_task_fair())

dequeue_task_fair jumps to dequeue_throttle label when cfs_rq_of(se) is throttled which means that se can't be NULL. We can move the label after the if (!se) statement and remove the if(!se) statment as se is always NULL when reaching this point.

Besides, trying to keep the same pattern with enqueue_task_fair can make it more readable.

---
kernel/sched/fair.c | 6 +++---

1 file changed, 3 insertions(+), 3 deletions(-)
kernel/sched/fair.c +0 -0
index 04fa8dbcfa4d..cbbeafdfa8b7 100644
@@ -5618,10 +5618,10 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags)
 
 	}
 

kernel/sched/fair.c static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags) · line 5627

Quoted 10 lines
kernel/sched/fair.c +3 -3
-dequeue_throttle:
-	if (!se)
-		sub_nr_running(rq, 1);
+	/* At this point se is NULL and we are at root level*/
+	sub_nr_running(rq, 1);
 
+dequeue_throttle:
 	/* balance early to pull high priority tasks */
 	if (unlikely(!was_sched_idle && sched_idle_rq(rq)))
 		rq->next_balance = jiffies;

There is already a similar patch in master.

Quoted 2 lines

423d02e1463b - sched/fair: Optimize dequeue_task_fair() (2020-06-25 Peng Wang)

Indeed, my local repo has been outdated, sorry for the interruption. :)

Thx.
Regards,
Jiang