mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Zev Levy Stevenson <zevlevys@gmail.com>
Cc: Arnd Bergmann <arnd@kernel.org>, musl@lists.openwall.com
Subject: Re: [musl] Question about musl's time() implementation in time.c
Date: Thu, 16 Jun 2022 10:57:22 -0400	[thread overview]
Message-ID: <20220616145721.GK7074@brightrain.aerifal.cx> (raw)
In-Reply-To: <CAFJhRnrWPC6pk67Xo9A9EeHFhoJCkE2PfwS4wFUep2JS3D9ujQ@mail.gmail.com>

On Fri, Jun 10, 2022 at 11:52:50AM +0300, Zev Levy Stevenson wrote:
> Thank you for the responses, those reasons make sense to me. We are using a
> very customized toolchain but the kernel itself is standard.
> We looked into it a bit further and we were able to reproduce the issue
> with a clean musl-gcc toolchain for x86_64 (version 1.2.2) on a Linux
> kernel that we took from a standard Ubuntu distribution.
> Specifically, tests in the libc-test suite (
> https://wiki.musl-libc.org/libc-test.html) using the time() function fail
> sometimes, e.g. src/functional/utime.c, which fails on about ~3-4 runs in
> every 1,000 runs. This can be reduced to this type of code failing:
> 
> t = time(0);
> if(futimens(fd, ((struct
> timespec[2]){{.tv_nsec=UTIME_NOW},{.tv_nsec=UTIME_OMIT}})) != 0) return 1;
> if (fstat(fd, &st) != 0) return 1;
> if (st.st_atim.tv_sec < t) printf("time inconsistency\n");
> 
> When replacing the call to time(0) with a raw call to the Linux time()
> syscall the issue seems to disappear. On the other hand, using the
> clock_gettime syscall results in the same issue.
> Perhaps this is an issue with the Linux implementation of these syscalls /
> vdso functions, in which case further research may be required, or maybe
> such consistency when using different methods for measuring the system time
> doesn't have to be guaranteed, in which case the tests should probably be
> modified to allow for small inaccuracies such as the one described above.

Going back to the issue that motivated this thread: perhaps libc-test
should not use time(0) here but instead a second tmpfile() with a
write to it followed by fstat, to get a timestamp out of the (same,
temp) filesystem. Then it's not encoding any assumption about correct
ordering between realtime clock and fs timestamps, which might be
broken by fs timestamp granularity or the kernel issue discussed in
this thread. It's only encoding an assumption that timestamps on the
same filesystem are correctly ordered with respect to each other
(which is necessary in order for make, etc. to work right).

Rich

      parent reply	other threads:[~2022-06-16 14:57 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-07 12:25 Zev Levy Stevenson
2022-06-07 14:29 ` Arnd Bergmann
2022-06-07 16:30   ` Rich Felker
2022-06-10  8:52     ` Zev Levy Stevenson
2022-06-14 16:50       ` Arnd Bergmann
2022-06-14 17:00         ` Rich Felker
2022-06-14 20:37           ` Arnd Bergmann
2022-06-14 20:49             ` Rich Felker
2022-06-14 21:11               ` Arnd Bergmann
2022-06-14 23:28                 ` Rich Felker
2022-06-15 12:09                   ` Arnd Bergmann
2022-06-15 16:55                     ` Adhemerval Zanella
2022-06-16  9:06                     ` Thomas Gleixner
2022-06-16 14:57       ` Rich Felker [this message]

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=20220616145721.GK7074@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=arnd@kernel.org \
    --cc=musl@lists.openwall.com \
    --cc=zevlevys@gmail.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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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).