Re: [PATCH v7] sched: Consolidate cpufreq updates
From: Qais Yousef
Date: Sun Sep 01 2024 - 14:01:22 EST
On 08/13/24 12:02, Vincent Guittot wrote:
> > void wakeup_preempt(struct rq *rq, struct task_struct *p, int flags)
> > @@ -4913,6 +4923,93 @@ static inline void __balance_callbacks(struct rq *rq)
> >
> > #endif
> >
> > +static __always_inline void
> > +__update_cpufreq_ctx_switch(struct rq *rq, struct task_struct *prev)
> > +{
> > +#ifdef CONFIG_CPU_FREQ
> > + if (prev && prev->dl.flags & SCHED_FLAG_SUGOV) {
> > + /* Sugov just did an update, don't be too aggressive */
> > + return;
> > + }
> > +
> > + /*
> > + * RT and DL should always send a freq update. But we can do some
> > + * simple checks to avoid it when we know it's not necessary.
> > + *
> > + * iowait_boost will always trigger a freq update too.
> > + *
> > + * Fair tasks will only trigger an update if the root cfs_rq has
> > + * decayed.
> > + *
> > + * Everything else should do nothing.
> > + */
> > + switch (current->policy) {
> > + case SCHED_NORMAL:
> > + case SCHED_BATCH:
> > + case SCHED_IDLE:
> > + if (unlikely(current->in_iowait)) {
> > + cpufreq_update_util(rq, SCHED_CPUFREQ_IOWAIT | SCHED_CPUFREQ_FORCE_UPDATE);
> > + return;
> > + }
> > +
> > +#ifdef CONFIG_SMP
> > + /*
> > + * Send an update if we switched from RT or DL as they tend to
> > + * boost the CPU and we are likely able to reduce the freq now.
> > + */
> > + rq->cfs.decayed |= prev && (rt_policy(prev->policy) || dl_policy(prev->policy));
> > +
> > + if (unlikely(rq->cfs.decayed)) {
>
> My previous use case of a task non preempting current with large
> util_est is fixed with this version but I'm facing a new one a bit
> similar because of waiting for the context switch and the decay to try
> to update the frequency.
>
> When the task wakes up on an idle cpu, you wait for the decay to
> update the freq but if the freq is low and the pelt has been updated
> recently (less than 1024us) you can wait a long time before the next
> decay and the freq update. This is a problem if the task's util_est is
> large because you can stay several ms at low frequency before taking
> into account task's util_est
It is a symptom of the same problem. It seems we don't decay and we omit the
cpufreq update.
Why this was not a problem before? AFAICT we only send an update before my
patch if we had a decay and I didn't change this condition. Were we just
getting more lucky or did I change some behavior unwittingly?
The problem with my patch is that I do this unconditional only if we failed
preemption check. But looks like I must enforce a cpufreq update after every
enqueue. I think the overhead of not checking rq->cfs.decayed would be high if
we always call a cpufreq update.
I'll just set rq->cfs.decayaed in util_est_enqueue() which should address both
use cases.
Thanks!