Re: [PATCH 3/9] sched/vtime: Handle nice updates under vtime

From: Peter Zijlstra
Date: Fri Nov 15 2019 - 05:18:52 EST


On Fri, Nov 15, 2019 at 11:16:48AM +0100, Peter Zijlstra wrote:
> On Wed, Nov 06, 2019 at 04:08:01AM +0100, Frederic Weisbecker wrote:
> > The cputime niceness is determined while checking the target's nice value
> > at cputime accounting time. Under vtime this happens on context switches,
> > user exit and guest exit. But nice value updates while the target is
> > running are not taken into account.
> >
> > So if a task runs tickless for 10 seconds in userspace but it has been
> > reniced after 5 seconds from -1 (not nice) to 1 (nice), on user exit
> > vtime will account the whole 10 seconds as CPUTIME_NICE because it only
> > sees the latest nice value at accounting time which is 1 here. Yet it's
> > wrong, 5 seconds should be accounted as CPUTIME_USER and 5 seconds as
> > CPUTIME_NICE.
> >
> > In order to solve this, we now cover nice updates withing three cases:
> >
> > * If the nice updater is the current task, although we are in kernel
> > mode there can be pending user or guest time in the cache to flush
> > under the prior nice state. Account these if any. Also toggle the
> > vtime nice flag for further user/guest cputime accounting.
> >
> > * If the target runs on a different CPU, we interrupt it with an IPI to
> > update the vtime state in place. If the task is running in user or
> > guest, the pending cputime is accounted under the prior nice state.
> > Then the vtime nice flag is toggled for further user/guest cputime
> > accounting.
>
> But but but, I thought the idea was to _never_ send interrupts to
> NOHZ_FULL cpus ?!?

That is, isn't the cure worse than the problem? I mean, who bloody cares
about silly accounting crud more than not getting interrupts on their
NOHZ_FULL cpus.