Re: [PATCH 1/4] sched/fair: reorder enqueue/dequeue_task_fair path

From: Mel Gorman
Date: Wed Feb 12 2020 - 11:11:11 EST


On Wed, Feb 12, 2020 at 03:47:30PM +0100, Vincent Guittot wrote:
> > I'm having trouble reconciling the patch with the description and the
> > comments explaining the intent behind the code are unhelpful.
> >
> > There are two loops before and after your patch -- the first dealing with
> > sched entities that are not on a runqueue and the second for the remaining
> > entities that are. The intent appears to be to update the load averages
> > once the entity is active on a runqueue.
> >
> > I'm not getting why the changelog says everything related to cfs is
> > now done in one loop because there are still two. But even if you do
> > get throttled, it's not clear why you jump to the !se check given that
> > for_each_sched_entity did not complete. What it *does* appear to do is
> > have all the h_nr_running related to entities being enqueued updated in
> > one loop and all remaining entities stats updated in the other.
>
> Let's take the example of 2 levels in addition to root so we have :
> root->cfs1->cfs2
> Now we enqueue a task T1 on cfs2 but cfs1 is throttled, we will have
> the sequence:
>
> In 1st for_each_sched_entity loop:
> loop 1
> enqueue_entity (T1->se, cfs2) which calls update load_avg(cfs2)
> cfs2->h_nr_running++;
> loop 2
> enqueue_entity (cfs2->gse, cfs1) which calls update load_avg(cfs1)
> break because cfs1 is throttled
>
> In 2nd for_each_sched_entity loop:
> loop 1
> cfs1->h_nr_running++
> break because throttled
>
> Using the 2nd loop for incrementing h_nr_running of the throttled cfs
> is useless and we could do that directly in 1st loop and skip the 2nd
> loop
>
> With this patch we have :
>
> In 1st for_each_sched_entity loop:
> loop 1
> enqueue_entity (T1->se, cfs2) which update load_avg(cfs2)
> cfs2->h_nr_running++;
> loop 2
> enqueue_entity (cfs2->gse, cfs1) which update load_avg(cfs1)
> cfs1->h_nr_running++
> skip the 2nd for_each_sched_entity entirely
>
> Then the patch also reorders the call to update_load_avg() and the
> increment of h_nr_running
>
> Before the patch we had different order between the to
> for_each_sched_entity which is not a problem because there is
> currently no relation between both. But the following patches make
> PELT using h_nr_running so we must have the same ordering to prevent
> updating pelt with the wrong h_nr_running value
>

Ok, understood. Thanks for clearing that up!

--
Mel Gorman
SUSE Labs