public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Jan Stancek <jstancek@redhat.com>,
	linux-kernel@vger.kernel.org, ltp@lists.linux.it,
	viro@zeniv.linux.org.uk, kstewart@linuxfoundation.org,
	gregkh@linuxfoundation.org, rfontana@redhat.com
Subject: Re: [PATCH] kernel: use ktime_get_real_ts64() to calculate acct.ac_btime
Date: Thu, 7 Nov 2019 13:55:59 +0100	[thread overview]
Message-ID: <20191107125559.GI4131@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <alpine.DEB.2.21.1911071335320.4256@nanos.tec.linutronix.de>

On Thu, Nov 07, 2019 at 01:40:47PM +0100, Thomas Gleixner wrote:
> On Thu, 7 Nov 2019, Peter Zijlstra wrote:

> > +	mono = ktime_get_ns();
> > +	real = ktime_get_real_ns();
> > +	/*
> > +	 * Compute btime by subtracting the elapsed time from the current
> > +	 * CLOCK_REALTIME.
> > +	 *
> > +	 * XXX totally buggered, because it changes results across
> > +	 * adjtime() calls and suspend/resume.
> > +	 */
> > +	delta = mono - tsk->start_time; // elapsed in ns
> > +	btime = real - delta;		// real ns - elapsed ns
> > +	do_div(btime, NSEC_PER_SEC);	// truncated to seconds
> > +	stats->ac_btime = btime;
> 
> That has pretty much the same problem as just storing the CLOCK_REALTIME
> start time at fork and additionally it is wreckaged vs. suspend resume.

It's wrecked in general. It also jumps around for any REALTIME
adjustment.

> So a CLOCK_REALTIME time stamp at fork would at least be correct
> vs. suspend resume.

But still wrecked vs REALTIME jumps, as in, when DST flips the clock
back an hour, your timestamp is in the future.

Any which way around the whole thing is buggered.  The only real fix is
not using REALTIME anything. Which is why I'm loath to add that REALTIME
timestamp at fork(), it just encourages more use.

  parent reply	other threads:[~2019-11-07 12:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-01 23:39 [PATCH] kernel: use ktime_get_real_ts64() to calculate acct.ac_btime Jan Stancek
2019-11-07  8:56 ` Thomas Gleixner
2019-11-07 12:49   ` Peter Zijlstra
2019-11-07 12:32 ` Peter Zijlstra
2019-11-07 12:40   ` Thomas Gleixner
2019-11-07 12:46     ` Peter Zijlstra
2019-11-07 12:55     ` Peter Zijlstra [this message]
2019-11-07 14:37       ` Thomas Gleixner
2019-11-11  9:41       ` Jan Stancek

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=20191107125559.GI4131@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jstancek@redhat.com \
    --cc=kstewart@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ltp@lists.linux.it \
    --cc=rfontana@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=viro@zeniv.linux.org.uk \
    /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