Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754201AbbGGMLf (ORCPT ); Tue, 7 Jul 2015 08:11:35 -0400 Received: from mail-la0-f43.google.com ([209.85.215.43]:36014 "EHLO mail-la0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756721AbbGGML2 (ORCPT ); Tue, 7 Jul 2015 08:11:28 -0400 MIME-Version: 1.0 In-Reply-To: <20150707080913.GT18673@twins.programming.kicks-ass.net> References: <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> <20150707005135.GH4981@lerouge> <20150707075954.GN3644@twins.programming.kicks-ass.net> <20150707080913.GT18673@twins.programming.kicks-ass.net> From: =?UTF-8?Q?Fredrik_Markstr=C3=B6m?= Date: Tue, 7 Jul 2015 14:10:56 +0200 Message-ID: Subject: Re: [PATCH 1/1] cputime: Make the reported utime+stime correspond to the actual runtime. To: Peter Zijlstra Cc: Frederic Weisbecker , mingo@redhat.com, linux-kernel@vger.kernel.org, Rik van Riel , Jason Low Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2018 Lines: 62 Just to let you know, I've tested your last patch and it solves all my original problems (which is should since the code is functionally equivalent). /Fredrik On Tue, Jul 7, 2015 at 10:09 AM, Peter Zijlstra wrote: > On Tue, Jul 07, 2015 at 09:59:54AM +0200, Peter Zijlstra wrote: >> > > + /* >> > > + * Make sure stime doesn't go backwards; this preserves monotonicity >> > > + * for utime because rtime is monotonic. >> > > + * >> > > + * utime_i+1 = rtime_i+1 - stime_i >> > > + * = rtime_i+1 - (rtime_i - stime_i) >> > > + * = (rtime_i+1 - rtime_i) + stime_i >> > > + * >= stime_i >> > > + */ > > Argh, just noticed I messed that up, it should read: > > + /* > + * Make sure stime doesn't go backwards; this preserves monotonicity > + * for utime because rtime is monotonic. > + * > + * utime_i+1 = rtime_i+1 - stime_i > + * = rtime_i+1 - (rtime_i - utime_i) > + * = (rtime_i+1 - rtime_i) + utime_i > + * >= utime_i > + */ > > I got some [us] confusion. Typing is hard. > > So we compute: utime = rtime - stime, which we'll denote as: > > utime_i+1 = rtime_i+1 - stime_i > > since: stime_i + utime_i = rtime_i, we can write: stime_i = rtime_i - > utime_i and substitute in the above: > > = rtime_i+1 - (rtime_i - utime_i) > > Rearrange terms: > > = (rtime_i+1 - rtime_i) + utime_i > > And since we have: rtime_i+1 >= rtime_i, which we can write like: > rtime_i+1 - rtime_i >= 0, substitution gives: > > >= utime_i > > And we've proven that the new utime must be equal or greater than the > previous utime, because rtime is monotonic. -- /Fredrik -- 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/