Re: [PATCH 3/9] sched/vtime: Handle nice updates under vtime
From: Peter Zijlstra
Date: Mon Nov 18 2019 - 08:05:40 EST
On Fri, Nov 15, 2019 at 04:27:04PM +0100, Frederic Weisbecker wrote:
> On Fri, Nov 15, 2019 at 11:18:31AM +0100, Peter Zijlstra wrote:
> > 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.
>
> Yeah indeed. I tend to sacrifice everything for correctness but perhaps we can live with
> small issues like nice accounting not being accounted to the right place if that
> can avoid disturbing nohz_full CPUs. Also who cares about renicing a task that is
> supposed to run alone.
>
> So here is what I can do: I'll make a simplified version of that set which accounts
> on top of the task_nice() value found on accounting time (context switch, user exit,
> guest exit) and if some user ever complains, I can still bring back that IPI solution.
Makes sense, thanks!