On 2026-08-19 16:22:53 +0200, Vincent Lefevre wrote:
> On 2026-08-19 15:50:16 +0200, Salvatore Bonaccorso wrote:
> > I think this is a consequence of 4e40eff0b5737c ("fs: add
> > infrastructure for multigrain timestamps") and following in 6.13-rc1.
Probably not (or not entirely), as there is another issue not involving
the filesystem (see below).
> > time(2) has only an accurancy in second, so the code might need to
> > use clock_gettime(2).
>
> The accuracy does not matter. This is a question of consistency.
> If an event A occurs before an event B, one expects to have
> time(A) <= time(B).
Now, comparing time(NULL) and clock_gettime(CLOCK_REALTIME, &ts):
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
while (1)
{
struct timespec ts;
time_t t;
clock_gettime(CLOCK_REALTIME, &ts);
t = time(NULL);
if (ts.tv_nsec < 0)
exit(1);
if (t < ts.tv_sec)
printf("%ld %ld\n", (long) t, (long) ts.tv_sec);
}
}
Since clock_gettime is called before time(NULL), one expects that
its time (including nanoseconds) is <= t, and since the number of
nanoseconds is non-negative (which is checked by the above code),
one should have ts.tv_sec <= t, i.e. the test t < ts.tv_sec should
be always false. But I get output at each second!
--
Vincent Lefèvre <[email protected]> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Pascaline project (LIP, ENS-Lyon)