Skip to contentSkip to conversation

sched/fair: enqueue_task_fair optimization

PATCH Applied Vincent Guittot 2 participants 3 messages May 13, 2020 – May 19, 2020 1 message not in the archive Scheduler

lore
Share & tools
lore

Vincent Guittot

author maintainer
#0 lore raw

PATCH v3 1/1 sched/fair: enqueue_task_fair optimization

enqueue_task_fair jumps to enqueue_throttle label when cfs_rq_of(se) is throttled which means that se can't be NULL in such case and we can move the label after the if (!se) statement. Futhermore, the latter can be removed because se is always NULL when reaching this point.

---

v3 changes:
- updated commit message
- removed an extra }

 kernel/sched/fair.c | 39 +++++++++++++++++++--------------------
 1 file changed, 19 insertions(+), 20 deletions(-)
kernel/sched/fair.c +19 -20
index 9a58874ef104..4e586863827b 100644
@@ -5512,28 +5512,27 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)
                        list_add_leaf_cfs_rq(cfs_rq);
 	}
 
-enqueue_throttle:
-	if (!se) {
-		add_nr_running(rq, 1);
-		/*
-		 * Since new tasks are assigned an initial util_avg equal to
-		 * half of the spare capacity of their CPU, tiny tasks have the
-		 * ability to cross the overutilized threshold, which will
-		 * result in the load balancer ruining all the task placement
-		 * done by EAS. As a way to mitigate that effect, do not account
-		 * for the first enqueue operation of new tasks during the
-		 * overutilized flag detection.
-		 *
-		 * A better way of solving this problem would be to wait for
-		 * the PELT signals of tasks to converge before taking them
-		 * into account, but that is not straightforward to implement,
-		 * and the following generally works well enough in practice.
-		 */
-		if (flags & ENQUEUE_WAKEUP)
-			update_overutilized_status(rq);
+	/* At this point se is NULL and we are at root level*/
+	add_nr_running(rq, 1);
 
-	}
+	/*
+	 * Since new tasks are assigned an initial util_avg equal to
+	 * half of the spare capacity of their CPU, tiny tasks have the
+	 * ability to cross the overutilized threshold, which will
+	 * result in the load balancer ruining all the task placement
+	 * done by EAS. As a way to mitigate that effect, do not account
+	 * for the first enqueue operation of new tasks during the
+	 * overutilized flag detection.
+	 *
+	 * A better way of solving this problem would be to wait for
+	 * the PELT signals of tasks to converge before taking them
+	 * into account, but that is not straightforward to implement,
+	 * and the following generally works well enough in practice.
+	 */
+	if (flags & ENQUEUE_WAKEUP)
+		update_overutilized_status(rq);
 
+enqueue_throttle:
 	if (cfs_bandwidth_used()) {
 		/*
 		 * When bandwidth control is enabled; the cfs_rq_throttled()
Signature · 1 line
2.17.1

A message that is not in the archive (sent off-list or not yet received): BL0PR14MB3779D98D96FA0D30B968B4519ABF0@BL0PR14MB3779.namprd14.prod.outlook.com

author maintainer
#2 lore raw
Quoted 53 lines · Tao Zhou

Hi Vincent,

Sorry for the duplicate.

Quoted 34 lines · Vincent Guittot

enqueue_task_fair jumps to enqueue_throttle label when cfs_rq_of(se) is throttled which means that se can't be NULL in such case and we can move the label after the if (!se) statement. Futhermore, the latter can be removed because se is always NULL when reaching this point.

---

v3 changes:
- updated commit message
- removed an extra }

 kernel/sched/fair.c | 39 +++++++++++++++++++--------------------
 1 file changed, 19 insertions(+), 20 deletions(-)
kernel/sched/fair.c +0 -10
index 9a58874ef104..4e586863827b 100644
@@ -5512,28 +5512,27 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)
                        list_add_leaf_cfs_rq(cfs_rq);
      }
 
-enqueue_throttle:
-     if (!se) {
-             add_nr_running(rq, 1);
-             /*
-              * Since new tasks are assigned an initial util_avg equal to
-              * half of the spare capacity of their CPU, tiny tasks have the
-              * ability to cross the overutilized threshold, which will
-              * result in the load balancer ruining all the task placement
-              * done by EAS. As a way to mitigate that effect, do not account
-              * for the first enqueue operation of new tasks during the

kernel/sched/fair.c enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags) · line 5515

Quoted 10 lines
kernel/sched/fair.c +1 -9
-              * overutilized flag detection.
-              *
-              * A better way of solving this problem would be to wait for
-              * the PELT signals of tasks to converge before taking them
-              * into account, but that is not straightforward to implement,
-              * and the following generally works well enough in practice.
-              */
-             if (flags & ENQUEUE_WAKEUP)
-                     update_overutilized_status(rq);
+     /* At this point se is NULL and we are at root level*/

The same as another patch, lack one blank at the end of above comment.

Quoted 3 lines

When apply v3 of 'sched/fair: Fix enqueue_task_fair warning some more' We need to edit to align to, I don't know why. When I tried to pull some thing to a function not done yet.

I forgot to mention that this patch has been done on top of Phil's one [email protected] and apply on top of it

Quoted 30 lines

Thanks,
Tao

Quoted 26 lines
kernel/sched/fair.c +18 -2
+     add_nr_running(rq, 1);
 
-     }
+     /*
+      * Since new tasks are assigned an initial util_avg equal to
+      * half of the spare capacity of their CPU, tiny tasks have the
+      * ability to cross the overutilized threshold, which will
+      * result in the load balancer ruining all the task placement
+      * done by EAS. As a way to mitigate that effect, do not account
+      * for the first enqueue operation of new tasks during the
+      * overutilized flag detection.
+      *
+      * A better way of solving this problem would be to wait for
+      * the PELT signals of tasks to converge before taking them
+      * into account, but that is not straightforward to implement,
+      * and the following generally works well enough in practice.
+      */
+     if (flags & ENQUEUE_WAKEUP)
+             update_overutilized_status(rq);
 
+enqueue_throttle:
      if (cfs_bandwidth_used()) {
              /*
               * When bandwidth control is enabled; the cfs_rq_throttled()
--

2.17.1

#3 lore raw

[tip: sched/core] sched/fair: Optimize enqueue_task_fair()

In reply to Vincent Guittot
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:     7d148be69e3a0eaa9d029a3c51b545e322116a99
Gitweb:        https://git.kernel.org/tip/7d148be69e3a0eaa9d029a3c51b545e322116a99
Author:        Vincent Guittot <[email protected]>
AuthorDate:    Wed, 13 May 2020 15:55:02 +02:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Tue, 19 May 2020 20:34:13 +02:00

sched/fair: Optimize enqueue_task_fair()

enqueue_task_fair jumps to enqueue_throttle label when cfs_rq_of(se) is throttled which means that se can't be NULL in such case and we can move the label after the if (!se) statement. Futhermore, the latter can be removed because se is always NULL when reaching this point.

---
 kernel/sched/fair.c | 39 +++++++++++++++++++--------------------
 1 file changed, 19 insertions(+), 20 deletions(-)
kernel/sched/fair.c +19 -20
index 9a58874..4e58686 100644
@@ -5512,28 +5512,27 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)
                        list_add_leaf_cfs_rq(cfs_rq);
 	}
 
-enqueue_throttle:
-	if (!se) {
-		add_nr_running(rq, 1);
-		/*
-		 * Since new tasks are assigned an initial util_avg equal to
-		 * half of the spare capacity of their CPU, tiny tasks have the
-		 * ability to cross the overutilized threshold, which will
-		 * result in the load balancer ruining all the task placement
-		 * done by EAS. As a way to mitigate that effect, do not account
-		 * for the first enqueue operation of new tasks during the
-		 * overutilized flag detection.
-		 *
-		 * A better way of solving this problem would be to wait for
-		 * the PELT signals of tasks to converge before taking them
-		 * into account, but that is not straightforward to implement,
-		 * and the following generally works well enough in practice.
-		 */
-		if (flags & ENQUEUE_WAKEUP)
-			update_overutilized_status(rq);
+	/* At this point se is NULL and we are at root level*/
+	add_nr_running(rq, 1);
 
-	}
+	/*
+	 * Since new tasks are assigned an initial util_avg equal to
+	 * half of the spare capacity of their CPU, tiny tasks have the
+	 * ability to cross the overutilized threshold, which will
+	 * result in the load balancer ruining all the task placement
+	 * done by EAS. As a way to mitigate that effect, do not account
+	 * for the first enqueue operation of new tasks during the
+	 * overutilized flag detection.
+	 *
+	 * A better way of solving this problem would be to wait for
+	 * the PELT signals of tasks to converge before taking them
+	 * into account, but that is not straightforward to implement,
+	 * and the following generally works well enough in practice.
+	 */
+	if (flags & ENQUEUE_WAKEUP)
+		update_overutilized_status(rq);
 
+enqueue_throttle:
 	if (cfs_bandwidth_used()) {
 		/*
 		 * When bandwidth control is enabled; the cfs_rq_throttled()