Skip to contentSkip to conversation

sched/fair: document the slow path and fast path in select_task_rq_fair

PATCH Superseded Barry Song 2 participants 2 messages Oct 15, 2021 Scheduler

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Barry Song

author
#0 lore raw

PATCH 1/1 sched/fair: document the slow path and fast path in select_task_rq_fair

From: Barry Song <[email protected]>

All people I know including myself took a long time to understand typical wake_up will always go to fast path and never go to slow path except FORK and EXEC.
Vincent reminded me once in a linaro meeting and it made me understand slow path won't happen for WF_TTWU. But my other friends repeatedly wasted a lot of time on testing this path like me before I reminded them.
So obviously the code needs some document.

Cc Vincent Guittot <[email protected]>
---
 kernel/sched/fair.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
kernel/sched/fair.c +10 -1
index f6a05d9b5443..ccf8f73dd4d1 100644
@@ -6951,6 +6951,11 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int wake_flags)
 			break;
 		}
 
+		/*
+		 * This is usually true only for WF_EXEC and WF_FORK, for WF_TTWU
+		 * it is almost always false as sched_domain hasn't SD_BALANCE_WAKE
+		 * in default
+		 */
 		if (tmp->flags & sd_flag)
 			sd = tmp;
 		else if (!want_affine)
@@ -6958,7 +6963,11 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int wake_flags)
 	}
 
 	if (unlikely(sd)) {
-		/* Slow path */
+		/*
+		 * Slow path, usually only for WF_EXEC and WF_FORK; WF_TTWU almost
+		 * always goes to fast path as sched_domain hasn't SD_BALANCE_WAKE
+		 * in default
+		 */
 		new_cpu = find_idlest_cpu(sd, p, cpu, prev_cpu, sd_flag);
 	} else if (wake_flags & WF_TTWU) { /* XXX always ? */
 		/* Fast path */
Signature · 1 line
2.25.1
#1 lore raw

kernel/sched/fair.c select_task_rq_fair(struct task_struct *p, int prev_cpu, int wake_flags) · line 6957

Quoted 10 lines · On Fri, 15 Oct 2021 12:14:12 +0800 Barry Song <[email protected]> wrote:
kernel/sched/fair.c +4 -0
@@ -6951,6 +6951,11 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int wake_flags)
 			break;
 		}
 
+		/*
+		 * This is usually true only for WF_EXEC and WF_FORK, for WF_TTWU
+		 * it is almost always false as sched_domain hasn't SD_BALANCE_WAKE
+		 * in default

Comments are fine, but the above needs some grammar work.

		/*
		 * Usually only true for WF_EXEC and WF_FORK, as
		 * sched_domains usually do not have SD_BALANCE_WAKE set.
		 */

?

Quoted 5 lines
kernel/sched/fair.c +1 -0
+		 */
 		if (tmp->flags & sd_flag)
 			sd = tmp;
 		else if (!want_affine)

kernel/sched/fair.c select_task_rq_fair(struct task_struct *p, int prev_cpu, int wake_flags) · line 6970

Quoted 9 lines
kernel/sched/fair.c +5 -1
@@ -6958,7 +6963,11 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int wake_flags)
 	}
 
 	if (unlikely(sd)) {
-		/* Slow path */
+		/*
+		 * Slow path, usually only for WF_EXEC and WF_FORK; WF_TTWU almost
+		 * always goes to fast path as sched_domain hasn't SD_BALANCE_WAKE
+		 * in default
+		 */

As the only way to have sd set, is from the above if statement, I believe this comment is redundant.

-- Steve

Quoted 3 lines
kernel/sched/fair.c +0 -0
 		new_cpu = find_idlest_cpu(sd, p, cpu, prev_cpu, sd_flag);
 	} else if (wake_flags & WF_TTWU) { /* XXX always ? */
 		/* Fast path */