Skip to contentSkip to conversation

sched_ext: Don't warn on core-sched forced idle in put_prev_task_scx()

PATCH Applied Tejun Heo 3 participants 4 messages Jun 29 – Jun 30

Subsystems (2)
lore
Share & tools
lore

Tejun Heo

author reviewer
#0 lore raw

PATCH v3 1/1 sched_ext: Don't warn on core-sched forced idle in put_prev_task_scx()

put_prev_task_scx() warns when a runnable task drops to a lower sched_class without SCX_OPS_ENQ_LAST, on the assumption that balance_one() would have kept it running. Core scheduling breaks that: a forced-idle SMT sibling reschedules through the core_pick fast path in pick_next_task(), which skips pick_task_scx() and thus balance_one(), so a runnable task can drop to idle with ENQ_LAST unset.

Gate the warning on sched_cpu_cookie_match(): a cookie mismatch means core scheduling forced the idle, while a match (or core scheduling off) still catches a genuine missing-ENQ_LAST drop.

v3: Gate the warning on sched_cpu_cookie_match() so it is suppressed only on
the forced-idle CPU instead of whenever core scheduling is enabled, so a genuine missing-ENQ_LAST drop is still caught (Andrea Righi).
v2: Reworded the description (Kuba Piecuch).

Fixes 7c65ae81ea86 ("sched_ext: Don't call put_prev_task_scx() before picking the next task")
---
 kernel/sched/ext/ext.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
kernel/sched/ext/ext.c +6 -1
index 3b2e13bc924b..e75e2fd5ab7e 100644
@@ -3090,9 +3090,14 @@ static void put_prev_task_scx(struct rq *rq, struct task_struct *p,
 		 * sched_class, %SCX_OPS_ENQ_LAST must be set. Tell
 		 * ops.enqueue() that @p is the only one available for this cpu,
 		 * which should trigger an explicit follow-up scheduling event.
+		 *
+		 * Core scheduling can force this CPU idle while @p stays
+		 * runnable. @p's cookie then won't match the core's, so skip
+		 * the warning in that case.
 		 */
 		if (next && sched_class_above(&ext_sched_class, next->sched_class)) {
-			WARN_ON_ONCE(!(sch->ops.flags & SCX_OPS_ENQ_LAST));
+			WARN_ON_ONCE(sched_cpu_cookie_match(rq, p) &&
+				     !(sch->ops.flags & SCX_OPS_ENQ_LAST));
 			do_enqueue_task(rq, p, SCX_ENQ_LAST, -1);
 		} else {
 			do_enqueue_task(rq, p, 0, -1);
reviewer Reviewed-by on v3 1/1
#1 lore raw
Quoted 11 lines · Tejun Heo

put_prev_task_scx() warns when a runnable task drops to a lower sched_class without SCX_OPS_ENQ_LAST, on the assumption that balance_one() would have kept it running. Core scheduling breaks that: a forced-idle SMT sibling reschedules through the core_pick fast path in pick_next_task(), which skips pick_task_scx() and thus balance_one(), so a runnable task can drop to idle with ENQ_LAST unset.

Gate the warning on sched_cpu_cookie_match(): a cookie mismatch means core scheduling forced the idle, while a match (or core scheduling off) still catches a genuine missing-ENQ_LAST drop.

Quoted 7 lines

v3: Gate the warning on sched_cpu_cookie_match() so it is suppressed only on
the forced-idle CPU instead of whenever core scheduling is enabled, so a genuine missing-ENQ_LAST drop is still caught (Andrea Righi).
v2: Reworded the description (Kuba Piecuch).

Fixes 7c65ae81ea86 ("sched_ext: Don't call put_prev_task_scx() before picking the next task")

Looks good.

Thanks,
-Andrea

Quoted 24 lines
---
 kernel/sched/ext/ext.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
kernel/sched/ext/ext.c +6 -1
index 3b2e13bc924b..e75e2fd5ab7e 100644
@@ -3090,9 +3090,14 @@ static void put_prev_task_scx(struct rq *rq, struct task_struct *p,
 		 * sched_class, %SCX_OPS_ENQ_LAST must be set. Tell
 		 * ops.enqueue() that @p is the only one available for this cpu,
 		 * which should trigger an explicit follow-up scheduling event.
+		 *
+		 * Core scheduling can force this CPU idle while @p stays
+		 * runnable. @p's cookie then won't match the core's, so skip
+		 * the warning in that case.
 		 */
 		if (next && sched_class_above(&ext_sched_class, next->sched_class)) {
-			WARN_ON_ONCE(!(sch->ops.flags & SCX_OPS_ENQ_LAST));
+			WARN_ON_ONCE(sched_cpu_cookie_match(rq, p) &&
+				     !(sch->ops.flags & SCX_OPS_ENQ_LAST));
 			do_enqueue_task(rq, p, SCX_ENQ_LAST, -1);
 		} else {
 			do_enqueue_task(rq, p, 0, -1);
#2 lore raw
In reply to Tejun Heo
Quoted 7 lines · Tejun Heo

put_prev_task_scx() warns when a runnable task drops to a lower sched_class without SCX_OPS_ENQ_LAST, on the assumption that balance_one() would have kept it running. Core scheduling breaks that: a forced-idle SMT sibling reschedules through the core_pick fast path in pick_next_task(), which skips pick_task_scx() and thus balance_one(), so a runnable task can drop to idle with ENQ_LAST unset.

Quoted 8 lines

Gate the warning on sched_cpu_cookie_match(): a cookie mismatch means core scheduling forced the idle, while a match (or core scheduling off) still catches a genuine missing-ENQ_LAST drop.

v3: Gate the warning on sched_cpu_cookie_match() so it is suppressed only on
the forced-idle CPU instead of whenever core scheduling is enabled, so a genuine missing-ENQ_LAST drop is still caught (Andrea Righi).
v2: Reworded the description (Kuba Piecuch).

The version change log information don't need to be present here. Usually those kind of information will be present under --- and don't need to be added in the real commit message.

Quoted 28 lines
Fixes 7c65ae81ea86 ("sched_ext: Don't call put_prev_task_scx() before picking the next task")
---
 kernel/sched/ext/ext.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
kernel/sched/ext/ext.c +6 -1
index 3b2e13bc924b..e75e2fd5ab7e 100644
@@ -3090,9 +3090,14 @@ static void put_prev_task_scx(struct rq *rq, struct task_struct *p,
 		 * sched_class, %SCX_OPS_ENQ_LAST must be set. Tell
 		 * ops.enqueue() that @p is the only one available for this cpu,
 		 * which should trigger an explicit follow-up scheduling event.
+		 *
+		 * Core scheduling can force this CPU idle while @p stays
+		 * runnable. @p's cookie then won't match the core's, so skip
+		 * the warning in that case.
 		 */
 		if (next && sched_class_above(&ext_sched_class, next->sched_class)) {
-			WARN_ON_ONCE(!(sch->ops.flags & SCX_OPS_ENQ_LAST));
+			WARN_ON_ONCE(sched_cpu_cookie_match(rq, p) &&
+				     !(sch->ops.flags & SCX_OPS_ENQ_LAST));
 			do_enqueue_task(rq, p, SCX_ENQ_LAST, -1);
 		} else {
 			do_enqueue_task(rq, p, 0, -1);
Signature · 2 lines
Thx and BRs,
Aiqun(Maria) Yu