mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] sched/fair: Warn against unbalanced util_est during dequeue
@ 2024-08-21 13:02 Hongyan Xia
  2024-08-22  2:21 ` kernel test robot
  2024-08-22  2:42 ` kernel test robot
  0 siblings, 2 replies; 3+ messages in thread
From: Hongyan Xia @ 2024-08-21 13:02 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider
  Cc: linux-kernel

The latest tip/sched/core seems to have an unbalanced util_est issue. As
I am debugging it, I found the logic util_est_dequeue() doesn't make
much sense. It guards against util_est underflow like this:

enqueued -= min_t(unsigned int, enqueued, _task_util_est(p));

However, this is misleading because when the number of tasks drops to 0,
util_est should be exactly 0, no more, no less, because
util_est_update() is done after util_est_dequeue() and there is no
change of util_est between util_est_enqueue() and dequeue(). Even if the
current logic guards against underflow, it doesn't guard against
overflow and may cause problems to go un-noticed.

Do not guard against underflow and add a warning to check that util_est
should be exactly 0 when queue is empty.

Signed-off-by: Hongyan Xia <hongyan.xia2@arm.com>
---
 kernel/sched/fair.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index fea057b311f6..574ef19df64b 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -4950,7 +4950,7 @@ static inline void util_est_dequeue(struct cfs_rq *cfs_rq,
 
 	/* Update root cfs_rq's estimated utilization */
 	enqueued  = cfs_rq->avg.util_est;
-	enqueued -= min_t(unsigned int, enqueued, _task_util_est(p));
+	enqueued -= _task_util_est(p);
 	WRITE_ONCE(cfs_rq->avg.util_est, enqueued);
 
 	trace_sched_util_est_cfs_tp(cfs_rq);
@@ -7176,10 +7176,14 @@ static bool dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags)
 	util_est_dequeue(&rq->cfs, p);
 
 	if (dequeue_entities(rq, &p->se, flags) < 0) {
+		if (!rq->cfs.h_nr_running)
+			SCHED_WARN_ON(rq->cfs.avg.util_est);
 		util_est_update(&rq->cfs, p, DEQUEUE_SLEEP);
 		return false;
 	}
 
+	if (!rq->cfs.h_nr_running)
+		SCHED_WARN_ON(rq->cfs.avg.util_est);
 	util_est_update(&rq->cfs, p, flags & DEQUEUE_SLEEP);
 	hrtick_update(rq);
 	return true;
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-08-22  2:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-21 13:02 [PATCH] sched/fair: Warn against unbalanced util_est during dequeue Hongyan Xia
2024-08-22  2:21 ` kernel test robot
2024-08-22  2:42 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®