Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756135AbbGGAvt (ORCPT ); Mon, 6 Jul 2015 20:51:49 -0400 Received: from mail-wg0-f54.google.com ([74.125.82.54]:36207 "EHLO mail-wg0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750873AbbGGAvl (ORCPT ); Mon, 6 Jul 2015 20:51:41 -0400 Date: Tue, 7 Jul 2015 02:51:36 +0200 From: Frederic Weisbecker To: Peter Zijlstra Cc: Fredrik =?iso-8859-1?Q?Markstr=F6m?= , mingo@redhat.com, linux-kernel@vger.kernel.org, Rik van Riel , Jason Low Subject: Re: [PATCH 1/1] cputime: Make the reported utime+stime correspond to the actual runtime. Message-ID: <20150707005135.GH4981@lerouge> References: <20150612110158.GA18673@twins.programming.kicks-ass.net> <20150629145837.GE3644@twins.programming.kicks-ass.net> <20150630093054.GK19282@twins.programming.kicks-ass.net> <20150630121812.GG3644@twins.programming.kicks-ass.net> <20150702121126.GP3644@twins.programming.kicks-ass.net> <20150702130701.GP18673@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150702130701.GP18673@twins.programming.kicks-ass.net> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2383 Lines: 77 On Thu, Jul 02, 2015 at 03:07:01PM +0200, Peter Zijlstra wrote: > @@ -606,22 +600,46 @@ static void cputime_adjust(struct task_c > > if (utime == 0) { > stime = rtime; > - } else if (stime == 0) { > - utime = rtime; > - } else { > - cputime_t total = stime + utime; > + goto update; > + } > > - stime = scale_stime((__force u64)stime, > - (__force u64)rtime, (__force u64)total); > - utime = rtime - stime; > + if (stime == 0) { > + utime = rtime; > + goto update; > } > > - cputime_advance(&prev->stime, stime); > - cputime_advance(&prev->utime, utime); > + stime = scale_stime((__force u64)stime, (__force u64)rtime, > + (__force u64)(stime + utime)); > + > + /* > + * Make sure stime doesn't go backwards; this preserves monotonicity > + * for utime because rtime is monotonic. > + * > + * utime_i+1 = rtime_i+1 - stime_i I'm not sure what is meant by _i+1. I guess stime_i means prev->stime. stime_i+1 the new update of prev->stime But then what is rtime_i and rtime_i+1 since we have no scaled rtime? > + * = rtime_i+1 - (rtime_i - stime_i) > + * = (rtime_i+1 - rtime_i) + stime_i > + * >= stime_i > + */ > + if (stime < prev->stime) > + stime = prev->stime; > + utime = rtime - stime; > + > + /* > + * Make sure utime doesn't go backwards; this still preserves > + * monotonicity for stime, analogous argument to above. > + */ > + if (utime < prev->utime) { > + utime = prev->utime; > + stime = rtime - utime; I see, so we are guaranteed that this final stime won't get below prev->stime because older prev->stime + prev->utime <= newest rtime. I guess that's more or less what's in the comments above :-) > + } > > +update: > + prev->stime = stime; > + prev->utime = utime; > out: > *ut = prev->utime; > *st = prev->stime; > + raw_spin_unlock(&prev->lock); > } > > void task_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime_t *st) Ok I scratched my head a lot on this patch and the issues behind and it looks good to me. I worried about introducing a spinlock but we had two cmpxchg before that. The overhead is close. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/