public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Frederic Weisbecker <fweisbec@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: "Fredrik Markström" <fredrik.markstrom@gmail.com>,
	mingo@redhat.com, linux-kernel@vger.kernel.org,
	"Rik van Riel" <riel@redhat.com>, "Jason Low" <jason.low2@hp.com>
Subject: Re: [PATCH 1/1] cputime: Make the reported utime+stime correspond to the actual runtime.
Date: Tue, 7 Jul 2015 18:26:49 +0200	[thread overview]
Message-ID: <20150707162647.GG20498@lerouge> (raw)
In-Reply-To: <20150707153413.GS3644@twins.programming.kicks-ass.net>

On Tue, Jul 07, 2015 at 05:34:13PM +0200, Peter Zijlstra wrote:
> On Tue, Jul 07, 2015 at 03:34:22PM +0200, Frederic Weisbecker wrote:
> > Imagine the following rounds:
> > 
> >     utime:2 stime:2 rtime:4 --> prev->utime = 2 prev->stime = 2
> > 
> >     utime:2 stime:6 rtime:8 --> prev->utime = 2 prev->stime = 6
> > 
> > So here if I apply your above formula we have:
> > 
> >      utime_i+1:2 = rtime_i+1:8 - stime_i:2
> > 
> > Which doesn't work, so probably I still misunderstand those _i things...
> 
> Yes :-)
> 
> So its an iterative definition, but a partial one, remember this is for
> the case where we preserve stime monotonicity. In your example we
> clearly do not take this branch.
> 
> I'll try to elucidate by giving the full function (either that or I'll
> confuse you more still). Lets define the whole thing as:
> 
>     {stime, utime}_i+1 = F(rtime_i+1, {ssamples, usamples}_i+1, {stime, utime}_i)
> 
> with the constraints:
> 
>     rtime_i+1 >= rtime_i
> 
> providing:
> 
>     stime + utime == rtime,
>     stime_i+1 >= stime_i,
>     utime_i+1 >= utime_i
> 
> That is an iterative function computing the new state: stime_i+1,
> utime_i+1, from the new input: rtime_i+1, ssamples_i+1, usamples_i+1 and
> the old state: stime_i, utime_i.
> 
> This function has a bunch of cases; the trivial ones (omitting the
> subscript when they're all the same):
> 
> A)  stime = 0, utime = rtime ; when ssamples == 0
> B)  utime = 0, stime = rtime ; when usamples == 0
> 
> And the complex ones:
> 
>     sfrac = ssamples * rtime / (ssamples + usamples)
> 
> C)  stime_i+1 = max(stime_i, sfrac_i+1)	; when rtime_i+1 - max(stime_i, sfrac_i+1) >= utime_i
>     utime_i+1 = rtime_i+1 - stime_i+1
> 
> D)  stime_i+1 = rtime_i+1 - utime_i	; when rtime_i+1 - max(stime_i, sfrac_i+1) < utime_i
>     utime_i+1 = utime_i
> 
> Note that we can further split C:
> 
> C1) stime_i+1 = stime_i			; when sfrac_i+1 < stime_i && ...
>     utime_i+1 = rtime_i+1 - stime_1
> 
> C2) stime_i+1 = sfrac_i+1		; when sfrac_i+1 >= stime_i && ...
>     utime_i+1 = rtime_i+1 - sfrac_i+1
> 
> This gives us a total of 5 cases, each selected purely on input.

Alright, when put it that way it makes perfect sense!

> Now, in your case, you end up in C2, because we advance stime but do not
> need to guard utime. In that case we have a different formula for
> utime_i+1 -- therefore your application of the formula was wrong, hence
> the wrong result.

Indeed!

> And the proof given was for C1, which in turn is analogous to the proof
> (not given) for D.
> 
> The proof for C2 should be evident at this point (stime is advanced,
> otherwise C1 and utime is advanced, otherwise D).
> 
> Did that help -- or did I hopelessly confuse you?

Makes perfect sense now! Thanks for your patience! :-)

  reply	other threads:[~2015-07-07 16:27 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-12  8:55 [PATCH 0/1] cputime: Make the reported utime+stime correspond to the actual runtime Fredrik Markstrom
2015-06-12  8:55 ` [PATCH 1/1] " Fredrik Markstrom
2015-06-12 10:16   ` Peter Zijlstra
2015-06-12 11:01     ` Peter Zijlstra
2015-06-15 15:34       ` Fredrik Markström
2015-06-16 14:35         ` Fredrik Markström
2015-06-29 14:58         ` Peter Zijlstra
2015-06-29 15:28           ` Fredrik Markström
2015-06-29 18:54             ` Jason Low
2015-06-29 19:08               ` Fredrik Markström
2015-06-29 22:11                 ` Jason Low
2015-06-30  9:30             ` Peter Zijlstra
2015-06-30 11:50               ` Fredrik Markström
2015-06-30 12:18                 ` Peter Zijlstra
2015-06-30 18:30                   ` Fredrik Markström
2015-07-02 12:11                     ` Peter Zijlstra
2015-07-02 13:07                       ` Peter Zijlstra
2015-07-07  0:51                         ` Frederic Weisbecker
2015-07-07  7:59                           ` Peter Zijlstra
2015-07-07  8:09                             ` Peter Zijlstra
2015-07-07 12:10                               ` Fredrik Markström
2015-07-07 15:37                                 ` Peter Zijlstra
2015-07-07 13:34                               ` Frederic Weisbecker
2015-07-07 15:34                                 ` Peter Zijlstra
2015-07-07 16:26                                   ` Frederic Weisbecker [this message]
2015-06-13 11:17     ` Fredrik Markström

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=20150707162647.GG20498@lerouge \
    --to=fweisbec@gmail.com \
    --cc=fredrik.markstrom@gmail.com \
    --cc=jason.low2@hp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=riel@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox