Re: [RFC][PATCH 1/5] sched/fair: Fix select_idle_cpu()s cost accounting

From: Mel Gorman
Date: Fri Jan 08 2021 - 08:48:31 EST


On Fri, Jan 08, 2021 at 01:01:10PM +0000, Qais Yousef wrote:
> On 01/08/21 10:27, Mel Gorman wrote:
> > for_each_cpu_wrap(cpu, cpus, target) {
> > - if (available_idle_cpu(cpu) || sched_idle_cpu(cpu))
> > + if (available_idle_cpu(cpu) || sched_idle_cpu(cpu)) {
> > + /* Adjust cost of a successful scan */
> > + loops <<= 2;
> > +
> > break;
> > + }
> >
> > - if (loops >= nr) {
> > + if (++loops >= nr) {
> > cpu = -1;
> > break;
> > }
> > - loops++;
>
> Random (out of the blue) comment.
>
> Now this will increment loops before the comparison/break. ie: we're
> effectively doing one iteration less IIRC. Should loops be initialized to
> 0 instead of 1?
>

Yep, although in practice it'll make little difference except after a
rapid phase change when avg_idle still appears high on a per-rq basis
yet the domain is fully busy with no idle CPUs.

--
Mel Gorman
SUSE Labs