mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "J. Bruce Fields" <bfields@fieldses.org>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: "Christian Brauner" <christian.brauner@ubuntu.com>,
	"Michael Weiß" <michael.weiss@aisec.fraunhofer.de>,
	"Andrei Vagin" <avagin@gmail.com>,
	"Dmitry Safonov" <0x7f454c46@gmail.com>,
	linux-kernel@vger.kernel.org,
	"Chuck Lever" <chuck.lever@oracle.com>,
	"Trond Myklebust" <trond.myklebust@hammerspace.com>,
	"Anna Schumaker" <anna.schumaker@netapp.com>,
	"Arnd Bergmann" <arnd@arndb.de>
Subject: Re: [PATCH v2 2/4] time: make getboottime64 aware of time namespace
Date: Mon, 12 Oct 2020 17:13:08 -0400	[thread overview]
Message-ID: <20201012211308.GH26571@fieldses.org> (raw)
In-Reply-To: <878scfrwls.fsf@nanos.tec.linutronix.de>

On Fri, Oct 09, 2020 at 10:08:15PM +0200, Thomas Gleixner wrote:
> On Fri, Oct 09 2020 at 09:55, J. Bruce Fields wrote:
> > Looking at how it's used in net/sunrpc/cache.c....  All it's doing is
> > comparing times which have all been calculated relative to the time
> > returned by getboottime64().  So it doesn't really matter what
> > getboottime64() is, as long as it's always the same.
> >
> > So, I don't think this should change behavior of the sunrpc code at all.
> 
> You wish. That's clearly wrong because that code is not guaranteed to
> always run in a context which belongs to the root time namespace.

Argh, right, thanks.

> AFAICT, this stuff can run in softirq context which is context stealing
> and the interrupted task can belong to a different time name space.

Some of it runs in the context of a process doing IO to proc, some from
kthreads.  So, anyway, yes, it's not consistent in the way we'd need.

> In fact the whole thing can be simplified. You can just use time in
> nanoseconds retrieved via ktime_get_coarse_boottime() which does not
> read the clocksource and advances once per tick and does not contain a
> divison and is definitely faster than seconds_since_boot()
> 
> The expiry time is initialized via get_expiry() which does:
> 
>    getboottime64(&boot);
>    return rv - boot.tv_sec; 
> 
> The expiry value 'rv' which is read out of the buffer is wall time in
> seconds. So all you need is are function which convert real to boottime
> and vice versa. That's trivial to implement and again faster than
> getboottime64(). Something like this:
> 
> ktime_t ktime_real_to_boot(ktime_t real)
> {
>         struct timekeeper *tk = &tk_core.timekeeper;
>         ktime_t mono = ktime_sub(real, tk->offs_real);
>               
>         return ktime_add(mono, tk->offs_boot);
> }
> 
> so the above becomes:
> 
>    return ktime_real_to_boot(rv * NSEC_PER_SEC);
> 
> which is still faster than a division.
> 
> The nanoseconds value after converting back to wall clock will need a
> division to get seconds since the epoch, but that's not an issue because
> that backward conversion already has one today.
> 
> You'd obviously need to fixup CACHE_NEW_EXPIRY and the other place which
> add's '1' to the expiry value and some janitoring of function names and
> variable types, but no real big surgery AFAICT.

I'll give it a shot.

Thanks so much for taking a careful look at this.

--b.

  reply	other threads:[~2020-10-12 21:13 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-08  5:39 [PATCH v2 0/4] time namespace aware system boot time Michael Weiß
2020-10-08  5:39 ` [PATCH v2 1/4] timens: additional helper function to add boottime in nsec Michael Weiß
2020-10-08  5:39 ` [PATCH v2 2/4] time: make getboottime64 aware of time namespace Michael Weiß
2020-10-09 13:28   ` Christian Brauner
2020-10-09 13:55     ` J. Bruce Fields
2020-10-09 20:08       ` Thomas Gleixner
2020-10-12 21:13         ` J. Bruce Fields [this message]
2020-10-12 21:36           ` Thomas Gleixner
2020-10-14 22:05           ` J. Bruce Fields
2020-10-16 12:37             ` Thomas Gleixner
2020-10-10  7:19     ` Andrei Vagin
2020-10-10 11:50       ` Michael Weiß
2020-10-10 16:37         ` Thomas Gleixner
2020-10-13 20:05       ` Christian Brauner
2020-10-08  5:39 ` [PATCH v2 3/4] fs/proc: apply timens offset for start_boottime of processes Michael Weiß
2020-10-08  5:39 ` [PATCH v2 4/4] selftests/timens: added selftest for /proc/stat btime Michael Weiß
2020-10-09 13:21 ` [PATCH v2 0/4] time namespace aware system boot time Christian Brauner

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=20201012211308.GH26571@fieldses.org \
    --to=bfields@fieldses.org \
    --cc=0x7f454c46@gmail.com \
    --cc=anna.schumaker@netapp.com \
    --cc=arnd@arndb.de \
    --cc=avagin@gmail.com \
    --cc=christian.brauner@ubuntu.com \
    --cc=chuck.lever@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael.weiss@aisec.fraunhofer.de \
    --cc=tglx@linutronix.de \
    --cc=trond.myklebust@hammerspace.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

Powered by JetHome