From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932199AbcHOM3b (ORCPT ); Mon, 15 Aug 2016 08:29:31 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:34834 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752768AbcHOM3a (ORCPT ); Mon, 15 Aug 2016 08:29:30 -0400 Message-ID: <1471264165.4938.1.camel@gmail.com> Subject: Re: [patch] sched/cputime: Fix NO_HZ_FULL getrusage() monotonicity regression From: Mike Galbraith To: Peter Zijlstra Cc: LKML Date: Mon, 15 Aug 2016 14:29:25 +0200 In-Reply-To: <20160815085128.GA30192@twins.programming.kicks-ass.net> References: <1470827669.15624.16.camel@gmail.com> <20160810123033.GM30192@twins.programming.kicks-ass.net> <1470855448.4840.2.camel@gmail.com> <20160815085128.GA30192@twins.programming.kicks-ass.net> Content-Type: text/plain; charset="us-ascii" X-Mailer: Evolution 3.16.5 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: