[PATCH v3 07/10] sched/fair: util_est: Take into account periodic tasks
From: Qais Yousef
Date: Thu Nov 26 2026 - 00:15:10 EST
The new faster rampup is great for performance. But terrible for power.
We want the faster rampup to be only applied for tasks that are
transitioning from one periodic/steady state to another periodic/steady
state. But if they are stably periodic, then the faster rampup doesn't
make sense as util_avg describes their computational demand accurately
and we can rely on that to make accurate decision. And preserve the
power savings from being exact with the resources we give to this task
(ie: smaller DVFS headroom).
We detect periodic tasks based on util_avg across util_est_update()
calls. If it is rising, then the task is going through a transition.
We rely on util_avg being stable for periodic tasks with very little
variations around one stable point.
Signed-off-by: Qais Yousef <qyousef@xxxxxxxxxxx>
---
include/linux/sched.h | 2 ++
kernel/sched/core.c | 2 ++
kernel/sched/fair.c | 37 ++++++++++++++++++++++++++-----------
3 files changed, 30 insertions(+), 11 deletions(-)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index d54117ab4c882..ea3af512006ad 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -928,6 +928,8 @@ struct task_struct {
struct uclamp_se uclamp[UCLAMP_CNT];
#endif
+ unsigned long util_avg_dequeued;
+
struct sched_statistics stats;
#ifdef CONFIG_PREEMPT_NOTIFIERS
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index b8c0cf9153768..13a66045c5be5 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -4689,6 +4689,8 @@ static void __sched_fork(u64 clone_flags, struct task_struct *p)
#endif
#endif
+ p->util_avg_dequeued = 0;
+
#ifdef CONFIG_SCHEDSTATS
/* Even if schedstat is disabled, there should not be garbage */
memset(&p->stats, 0, sizeof(p->stats));
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index a8dbd81e71590..7129347746436 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -5980,6 +5980,9 @@ static void detach_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *s
#define UTIL_EST_MARGIN (SCHED_CAPACITY_SCALE / 100)
+static inline unsigned long task_util(struct task_struct *p);
+static inline unsigned long task_util_dequeued(struct task_struct *p);
+
static inline void util_est_update(struct sched_entity *se, bool running)
{
unsigned int ewma, dequeued, last_ewma_diff;
@@ -5997,18 +6000,22 @@ static inline void util_est_update(struct sched_entity *se, bool running)
* quickly to settle down to our new util_avg.
*/
if (running) {
- u64 delta = p->se.delta_exec;
- unsigned int prev_ewma = ewma & ~UTIL_AVG_UNCHANGED;
+ if (task_util(p) > task_util_dequeued(p) &&
+ task_util(p) - task_util_dequeued(p) > UTIL_EST_MARGIN) {
+ u64 delta = p->se.delta_exec;
+ unsigned int prev_ewma = ewma & ~UTIL_AVG_UNCHANGED;
- do_div(delta, 1000);
- ewma = approximate_util_avg(prev_ewma, delta);
- /*
- * Keep accumulating delta_exec if it is too small to cause
- * a change.
- */
- if (ewma != prev_ewma)
- p->se.delta_exec = 0;
- goto done_running;
+ do_div(delta, 1000);
+ ewma = approximate_util_avg(prev_ewma, delta);
+ /*
+ * Keep accumulating delta_exec if it is too small to cause
+ * a change.
+ */
+ if (ewma != prev_ewma)
+ p->se.delta_exec = 0;
+ goto done_running;
+ }
+ return;
} else {
p->se.delta_exec = 0;
}
@@ -6023,6 +6030,9 @@ static inline void util_est_update(struct sched_entity *se, bool running)
/* Get utilization at dequeue */
dequeued = READ_ONCE(se->avg.util_avg);
+ if (!task_on_rq_migrating(p))
+ p->util_avg_dequeued = dequeued;
+
/*
* Reset EWMA on utilization increases, the moving average is used only
* to smooth utilization decreases.
@@ -6185,6 +6195,11 @@ static inline unsigned long task_util(struct task_struct *p)
return READ_ONCE(p->se.avg.util_avg);
}
+static inline unsigned long task_util_dequeued(struct task_struct *p)
+{
+ return READ_ONCE(p->util_avg_dequeued);
+}
+
static inline unsigned long _task_util_est(struct task_struct *p)
{
return READ_ONCE(p->se.avg.util_est) & ~UTIL_AVG_UNCHANGED;
--
2.53.0