From: Mike Galbraith <umgwanakikbuti@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: Re: [patch] sched/cputime: Fix NO_HZ_FULL getrusage() monotonicity regression
Date: Mon, 15 Aug 2016 14:29:25 +0200 [thread overview]
Message-ID: <1471264165.4938.1.camel@gmail.com> (raw)
In-Reply-To: <20160815085128.GA30192@twins.programming.kicks-ass.net>
On Mon, 2016-08-15 at 10:51 +0200, Peter Zijlstra wrote:
> On Wed, Aug 10, 2016 at 08:57:28PM +0200, Mike Galbraith wrote:
> >
> > +> > > > /*
> > +> > > > * sum_exec_runtime has moved, but nothing has yet been
> > +> > > > * accounted to the task, there's nothing to update.
> > +> > > > */
> > +> > > > if (utime + stime == 0)
> > +> > > > > > goto out;
>
> urgh...
>
> Valid scenario.. not sure about the solution though. This would mean the
> task has _no_ running time if it forever dodges the tick, which would be
> bad.
>
> Does something like so cure things too?
Yeah, it's a happy camper.
> ---
> kernel/sched/cputime.c | 15 ++++++++++-----
> 1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
> index 9858266fb0b3..2ee83b200504 100644
> --- a/kernel/sched/cputime.c
> +++ b/kernel/sched/cputime.c
> @@ -614,19 +614,25 @@ static void cputime_adjust(struct task_cputime *curr,
> > > stime = curr->stime;
> > > utime = curr->utime;
>
> -> > if (utime == 0) {
> -> > > stime = rtime;
> +> > /*
> +> > * If either stime or both stime and utime are 0, assume all runtime is
> +> > * userspace. Once a task gets some ticks, the monotonicy code at
> +> > * 'update' will ensure things converge to the observed ratio.
> +> > */
> +> > if (stime == 0) {
> +> > > utime = rtime;
> > > > goto update;
> > > }
>
> -> > if (stime == 0) {
> -> > > utime = rtime;
> +> > if (utime == 0) {
> +> > > stime = rtime;
> > > > goto update;
> > > }
>
> > > stime = scale_stime((__force u64)stime, (__force u64)rtime,
> > > > > (__force u64)(stime + utime));
>
> +update:
> > > /*
> > > * Make sure stime doesn't go backwards; this preserves monotonicity
> > > * for utime because rtime is monotonic.
> @@ -649,7 +655,6 @@ static void cputime_adjust(struct task_cputime *curr,
> > > > stime = rtime - utime;
> > > }
>
> -update:
> > > prev->stime = stime;
> > > prev->utime = utime;
> out:
prev parent reply other threads:[~2016-08-15 12:29 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-10 11:14 [patch] sched/cputime: Fix NO_HZ_FULL getrusage() monotonicity regression Mike Galbraith
2016-08-10 12:30 ` Peter Zijlstra
2016-08-10 12:47 ` Peter Zijlstra
2016-08-10 14:21 ` Mike Galbraith
2016-08-10 18:57 ` Mike Galbraith
2016-08-15 8:51 ` Peter Zijlstra
2016-08-15 12:29 ` Mike Galbraith [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1471264165.4938.1.camel@gmail.com \
--to=umgwanakikbuti@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.