Date: Tue, 14 Jun 2022 16:49:00 -0400 From: Rich Felker <dalias@...c.org> To: Arnd Bergmann <arnd@...nel.org> Cc: musl@...ts.openwall.com Subject: Re: Question about musl's time() implementation in time.c On Tue, Jun 14, 2022 at 10:37:25PM +0200, Arnd Bergmann wrote: > On Tue, Jun 14, 2022 at 7:00 PM Rich Felker <dalias@...c.org> wrote: > > On Tue, Jun 14, 2022 at 06:50:40PM +0200, Arnd Bergmann wrote: > > > The coarse time can be up to one timer tick behind, so reading > > > CLOCK_REALTIME first > > > can give you the exact second with a small nanosecond value, while the > > > utime will still > > > set the previous value. > > > > > > Can you change the test case to check if the later time is less than > > > clock_getres(CLOCK_REALTIME_COARSE, ...) behind? > > > > This seems like a bug that the kernel uses the wrong clock for setting > > file timestamps. It can result in seeing events out-of-order (exactly > > as described in this thread). This should really be fixed or at least > > made switchable so users who care can fix it. > > I can't find any reference to what the correct clock is here, > are you sure that this is specified at all? The decision to use the coarse > time in the kernel is definitely intentional, as reading the hardware > clocksource can be expensive (depending on the hardware), and > changing the behavior would likely break applications that rely on > it being the coarse clock. POSIX specifies operations that set the file timestamps in terms of the system (CLOCK_REALTIME) clock, not a weird implementation-defined alternate clock. Maybe you're right that getting the correct clock is costly on some archs, but it's almost surely not on any arch that admits vdso clock_gettime. And "race that causes applications to see wrong ordering of filesystem operations with respect to other activity for the sake of performance" does not seem like a good idea. Rich
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.