Sched/fair: Block nohz tick_stop when cfs bandwidth in use
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.
---
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
@@ -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
@@ -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
@@ -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