@@ -829,6 +829,8 @@ struct task_struct {
struct uclamp_se uclamp[UCLAMP_CNT];
#endif
+ unsigned long util_avg_dequeued;
+
struct sched_statistics stats;
#ifdef CONFIG_PREEMPT_NOTIFIERS
@@ -4331,6 +4331,8 @@ static void __sched_fork(unsigned long clone_flags, struct task_struct *p)
p->se.cfs_rq = NULL;
#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));
@@ -4832,6 +4832,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_runnable(struct task_struct *p)
{
return READ_ONCE(p->se.avg.runnable_avg);
@@ -4899,9 +4904,12 @@ static inline void util_est_update(struct cfs_rq *cfs_rq,
* quickly to settle down to our new util_avg.
*/
if (!task_sleep) {
- ewma &= ~UTIL_AVG_UNCHANGED;
- ewma = approximate_util_avg(ewma, p->se.delta_exec / 1000);
- goto done;
+ if (task_util(p) > task_util_dequeued(p)) {
+ ewma &= ~UTIL_AVG_UNCHANGED;
+ ewma = approximate_util_avg(ewma, p->se.delta_exec / 1000);
+ goto done;
+ }
+ return;
}
/*
@@ -4914,6 +4922,9 @@ static inline void util_est_update(struct cfs_rq *cfs_rq,
/* Get utilization at dequeue */
dequeued = task_util(p);
+ 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.
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@layalina.io> --- include/linux/sched.h | 2 ++ kernel/sched/core.c | 2 ++ kernel/sched/fair.c | 17 ++++++++++++++--- 3 files changed, 18 insertions(+), 3 deletions(-)