From: "Theodore Ts'o" <tytso@mit.edu>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Amir Goldstein <amir73il@gmail.com>,
Jeff Layton <jlayton@kernel.org>,
Christian Brauner <brauner@kernel.org>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Jan Kara <jack@suse.cz>, "Darrick J. Wong" <djwong@kernel.org>
Subject: Re: [GIT PULL v2] timestamp fixes
Date: Sat, 23 Sep 2023 15:30:42 -0400 [thread overview]
Message-ID: <ZQ884uCkKGu6xsDi@mit.edu> (raw)
In-Reply-To: <CAHk-=wjGJEgizkXwSWVCnsGnciCKHHsWg+dkw2XAhM+0Tnd0Jw@mail.gmail.com>
On Sat, Sep 23, 2023 at 10:48:51AM -0700, Linus Torvalds wrote:
>
> I feel like 100ns is a much more reasonable resolution, and is quite
> close to a single system call (think "one thousand cycles at 10GHz").
FWIW, UUID's (which originally came from Apollo Domain/OS in the
1980's, before getting adopted by OSF/DCE, and then by Linux and
Microsoft) use a 100ns granularity. And the smart folks at Apollo
figured this out some 4 decades ago, and *no* they didn't use units of
a single nanosecond. :-)
100ns granularity is also what what ext4 uses for our on-disk format
--- 2**30 just enough to cover 100ns granularity (with only 7% of
wasted number space), and those two bits are enough for us to encode
timestamps into 2446 using a 64-bit timestamp (and what we do past
2446 is pretty much something I'm happy to let someone else deal with,
as I expect I'll be long dead by then.)
(And if someone does happen to event some kind of life-extension
technology, I'm happy to fix it up... later. :-)
> That said, we don't have to do powers-of-ten. In fact, in many ways,
> it would probably be a good idea to think of the fractional seconds in
> powers of two. That tends to make it cheaper to do conversions,
> without having to do a full 64-bit divide (a constant divide turns
> into a fancy multiply, but it's still painful on 32-bit
> architectures).
It depends on what conversion we need to do. If we're converting to
userspace's timespec64 data structure, which is denominated in
nanosecods, it's actually much easier to use decimal 100ns units:
#define EXT4_EPOCH_BITS 2
#define EXT4_EPOCH_MASK ((1 << EXT4_EPOCH_BITS) - 1)
#define EXT4_NSEC_MASK (~0UL << EXT4_EPOCH_BITS)
static inline __le32 ext4_encode_extra_time(struct timespec64 *time)
{
u32 extra =((time->tv_sec - (s32)time->tv_sec) >> 32) & EXT4_EPOCH_MASK;
return cpu_to_le32(extra | (time->tv_nsec << EXT4_EPOCH_BITS));
}
static inline void ext4_decode_extra_time(struct timespec64 *time,
__le32 extra)
{
if (unlikely(extra & cpu_to_le32(EXT4_EPOCH_MASK)))
time->tv_sec += (u64)(le32_to_cpu(extra) & EXT4_EPOCH_MASK) << 32;
time->tv_nsec = (le32_to_cpu(extra) & EXT4_NSEC_MASK) >> EXT4_EPOCH_BITS;
}
> Of course, I might have screwed up the above conversion functions,
> they are untested garbage, but they look close enough to being in the
> right ballpark.
We actually have kunit tests for ext4_encode_extra_time() and
ext4_decode_extra_time(), mainly because people *have* screwed it up
when making architecture-specific optimizations or when making global
sweeps of VFS code. :-)
- Ted
next prev parent reply other threads:[~2023-09-23 19:31 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-21 11:20 [GIT PULL v2] timestamp fixes Christian Brauner
2023-09-21 18:24 ` Linus Torvalds
2023-09-21 18:51 ` Jeff Layton
2023-09-21 19:28 ` Linus Torvalds
2023-09-21 19:46 ` Linus Torvalds
2023-09-21 21:57 ` Jeff Layton
2023-09-22 12:28 ` Christian Brauner
2023-09-22 10:19 ` David Sterba
2023-09-23 6:36 ` Amir Goldstein
2023-09-23 17:48 ` Linus Torvalds
2023-09-23 19:30 ` Theodore Ts'o [this message]
2023-09-23 20:03 ` Linus Torvalds
2023-09-23 22:07 ` Theodore Ts'o
2023-09-23 23:31 ` Linus Torvalds
2023-09-23 21:29 ` Amir Goldstein
2023-09-24 10:26 ` Christian Brauner
2023-09-25 11:22 ` Jeff Layton
2023-09-25 16:02 ` Linus Torvalds
2023-09-22 12:24 ` Christian Brauner
2023-09-24 8:34 ` Amir Goldstein
2023-09-24 10:15 ` Christian Brauner
2023-09-22 12:16 ` Christian Brauner
2023-09-21 20:10 ` pr-tracker-bot
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=ZQ884uCkKGu6xsDi@mit.edu \
--to=tytso@mit.edu \
--cc=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=djwong@kernel.org \
--cc=jack@suse.cz \
--cc=jlayton@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/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.