linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: y2038@lists.linaro.org
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-sh@vger.kernel.org, Baolin Wang <baolin.wang@linaro.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	John Stultz <john.stultz@linaro.org>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Thomas Gleixner <tglx@linutronix.de>,
	Rich Felker <dalias@libc.org>,
	Yoshinori Sato <ysato@users.sourceforge.jp>,
	Arnd Bergmann <arnd@arndb.de>
Subject: [PATCH 7/8] vfs: replace current_kernel_time64 with ktime equivalent
Date: Fri,  7 Dec 2018 14:48:23 +0100	[thread overview]
Message-ID: <20181207134824.300024-8-arnd@arndb.de> (raw)
In-Reply-To: <20181207134824.300024-1-arnd@arndb.de>

current_time is the last remaining caller of current_kernel_time64(),
which is a wrapper around ktime_get_coarse_real_ts64().  This calls the
latter directly for consistency with the rest of the kernel that is moving
to the ktime_get_ family of time accessors, as now documented in
Documentation/core-api/timekeeping.rst.

An open questions is whether we may want to actually call the more
accurate ktime_get_real_ts64() for file systems that save high-resolution
timestamps in their on-disk format.  This would add a small overhead to
each update of the inode stamps but lead to inode timestamps to actually
have a usable resolution better than one jiffy (1 to 10 milliseconds
normally).  Experiments on a variety of hardware platforms show a typical
time of around 100 CPU cycles to read the cycle counter and calculate the
accurate time from that.  On old platforms without a cycle counter, this
can be signiciantly higher, up to several microseconds to access a
hardware clock, but those have become very rare by now.

I traced the original addition of the current_kernel_time() call to set
the nanosecond fields back to linux-2.5.48, where Andi Kleen added a patch
with subject "nanosecond stat timefields".  Andi explains that the
motivation was to introduce as little overhead as possible back then.  At
this time, reading the clock hardware was also more expensive when most
architectures did not have a cycle counter.

One side effect of having more accurate inode timestamp would be having to
write out the inode every time that mtime/ctime/atime get touched on most
systems, whereas many file systems today only write it when the timestamps
have changed, i.e.  at most once per jiffy unless something else changes
as well.  That change would certainly be noticed in some workloads, which
is enough reason to not do it without a good reason, regardless of the
cost of reading the time.

One thing we could still consider however would be to round the timestamps
from current_time() to multiples of NSEC_PER_JIFFY, e.g.  full
milliseconds rather than having six or seven meaningless but confusing
digits at the end of the timestamp.

Link: http://lkml.kernel.org/r/20180726130820.4174359-1-arnd@arndb.de
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 fs/inode.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/inode.c b/fs/inode.c
index 9e198f00b64c..73432e64f874 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -2146,7 +2146,9 @@ EXPORT_SYMBOL(timespec64_trunc);
  */
 struct timespec64 current_time(struct inode *inode)
 {
-	struct timespec64 now = current_kernel_time64();
+	struct timespec64 now;
+
+	ktime_get_coarse_real_ts64(&now);
 
 	if (unlikely(!inode->i_sb)) {
 		WARN(1, "current_time() called with uninitialized super_block in the inode");
-- 
2.18.0


  parent reply	other threads:[~2018-12-07 13:49 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-07 13:48 [PATCH 0/8] timekeeping: cleanups Arnd Bergmann
2018-12-07 13:48 ` [PATCH 1/8] sh: dreamcast: rtc: push down rtc class ops into driver Arnd Bergmann
2018-12-07 15:45   ` Christoph Hellwig
2018-12-07 16:41     ` Arnd Bergmann
2018-12-07 13:48 ` [PATCH 2/8] sh: sh03: " Arnd Bergmann
2018-12-07 13:48 ` [PATCH 3/8] sh: remove unused rtc_sh_get/set_time infrastructure Arnd Bergmann
2018-12-07 13:48 ` [PATCH 4/8] sh: remove board_time_init() callback Arnd Bergmann
2018-12-07 13:48 ` [PATCH 5/8] timekeeping: remove unused {read,update}_persistent_clock Arnd Bergmann
2018-12-07 16:56   ` John Stultz
2018-12-07 13:48 ` [PATCH 6/8] timekeeping: remove timespec_add/timespec_del Arnd Bergmann
2018-12-07 16:57   ` John Stultz
2018-12-07 13:48 ` Arnd Bergmann [this message]
2018-12-07 13:48 ` [PATCH 8/8] timekeeping: remove obsolete time accessors Arnd Bergmann
2018-12-07 16:58   ` John Stultz

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=20181207134824.300024-8-arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=akpm@linux-foundation.org \
    --cc=baolin.wang@linaro.org \
    --cc=dalias@libc.org \
    --cc=john.stultz@linaro.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sh@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=viro@zeniv.linux.org.uk \
    --cc=y2038@lists.linaro.org \
    --cc=ysato@users.sourceforge.jp \
    /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;
as well as URLs for NNTP newsgroup(s).