All of lore.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 02:51:36 +0200	[thread overview]
Message-ID: <20150707005135.GH4981@lerouge> (raw)
In-Reply-To: <20150702130701.GP18673@twins.programming.kicks-ass.net>

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.

  reply	other threads:[~2015-07-07  0:51 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 [this message]
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
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=20150707005135.GH4981@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 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.