Skip to contentSkip to conversation

Sched/fair: Block nohz tick_stop when cfs bandwidth in use

PATCH Superseded Phil Auld 1 participant 1 message Jun 28, 2023 Scheduler

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Phil Auld

author
#0 lore raw

PATCH v3 1/1 Sched/fair: Block nohz tick_stop when cfs bandwidth in use

CFS bandwidth limits and NOHZ full don't play well together. Tasks can easily run well past their quotas before a remote tick does accounting. This leads to long, multi-period stalls before such tasks can run again. Currentlyi, when presented with these conflicting requirements the scheduler is favoring nohz_full and letting the tick be stopped. However, nohz tick stopping is already best-effort, there are a number of conditions that can prevent it, whereas cfs runtime bandwidth is expected to be enforced.

Make the scheduler favor bandwidth over stopping the tick by setting TICK_DEP_BIT_SCHED when the only running task is a cfs task with runtime limit enabled.

Add sched_feat HZ_BW (off by default) to control this behavior.

Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Vincent Guittot <[email protected]>
Cc Juri Lelli <[email protected]>
Cc Dietmar Eggemann <[email protected]>
Cc Valentin Schneider <[email protected]>
Cc Ben Segall <[email protected]>

---

v2: Ben pointed out that the bit could get cleared in the dequeue path if we migrate a newly enqueued task without preempting curr. Added a check for that edge case to sched_can_stop_tick. Removed the call to sched_can_stop_tick from sched_fair_update_stop_tick since it was redundant.

v3: Moved sched_cfs_bandwidth_active() prototype to sched.h outside of guards to silence -Wmissing-prototypes.

 kernel/sched/core.c     | 10 +++++++++
 kernel/sched/fair.c     | 45 +++++++++++++++++++++++++++++++++++++++++
 kernel/sched/features.h |  2 ++
 kernel/sched/sched.h    |  1 +
 4 files changed, 58 insertions(+)
kernel/sched/core.c +10 -0
index a68d1276bab0..0d8bdd36f870 100644
@@ -1229,6 +1229,16 @@ bool sched_can_stop_tick(struct rq *rq)
 	if (rq->nr_running > 1)
 		return false;
 
+	/*
+	 * If there is one task and it has CFS runtime bandwidth constraints
+	 * and it's on the cpu now we don't want to stop the tick.
+	 */
+	if (sched_feat(HZ_BW) && rq->nr_running == 1 && rq->curr
+	    && rq->curr->sched_class == &fair_sched_class && task_on_rq_queued(rq->curr)) {
+		if (sched_cfs_bandwidth_active(task_cfs_rq(rq->curr)))
+			return false;
+	}
+
 	return true;
 }
 #endif /* CONFIG_NO_HZ_FULL */
kernel/sched/fair.c +45 -0

66 lines not on this page · raw message

kernel/sched/features.h +2 -0
index ee7f23c76bd3..6fdf1fdf6b17 100644
@@ -101,3 +101,5 @@ SCHED_FEAT(LATENCY_WARN, false)
 
 SCHED_FEAT(ALT_PERIOD, true)
 SCHED_FEAT(BASE_SLICE, true)
+
+SCHED_FEAT(HZ_BW, false)
kernel/sched/sched.h +1 -0
index ec7b3e0a2b20..f2bd4568472e 100644
@@ -2789,6 +2789,7 @@ extern void init_dl_rq(struct dl_rq *dl_rq);
 
 extern void cfs_bandwidth_usage_inc(void);
 extern void cfs_bandwidth_usage_dec(void);
+extern bool sched_cfs_bandwidth_active(struct cfs_rq *cfs_rq);
 
 #ifdef CONFIG_NO_HZ_COMMON
 #define NOHZ_BALANCE_KICK_BIT	0
Signature · 1 line
2.31.1