Reed Underwood wrote in
<[email protected]>:
|On 8/19/26 10:51, Ian Collier via Mutt-dev wrote:
|> On Wed, Aug 19, 2026 at 01:43:57PM +0200, Vincent Lefevre wrote:
|>> This is fine. However, I can reproduce the issue many times
|>> every second with
|> [redacted]
|>
|> That's bizarre. So it seems the output of time(2) is delayed by
|> at least one jiffy with respect to the real time. Vide:
|>
|>
|> #include <stdio.h>
|> #include <time.h>
|> #include <sys/time.h>
|>
|> int main(void) {
|> struct timeval tv;
|> time_t t;
|> while (1) {
|> gettimeofday(&tv, NULL);
|> t = time(NULL);
|> if (t < tv.tv_sec)
|> printf("%ld < %ld.%06d\n", (long)t, (long)tv.tv_sec, (int)tv.tv_us\
|> ec);
|>}
|>}
|>
|>
|> This produces output on every system I've tested so far, from Centos7
|> (3.10.0) upwards. But the generic 6.8.0 kernel on Ubuntu 24.04 (and
|> all earlier systems) does not produce output for the test that touches a
|> file. Whereas Ubuntu 24.04 systems running an OEM kernel (6.17.0) and
|> all Fedora systems do produce output from both tests.
|>
|> This seems to mean that the Linux kernel has changed something about
|> how the time is obtained when touching a file; but ultimately it is
|> the time(2) call that is to blame.
|>
|> Ian Collier.
|I can confirm the behavior you describe in Ubuntu 24.04 (6.8.0 kernel).
|
|For what it's worth, the behavior is not reproducible in FreeBSD.
Maybe it is because of some strange vdso(7) effect.
And i cannot reproduce it on the Musl C library based AlpineLinux.
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
int main(void){
struct timeval tv;
time_t t;
unsigned y, n;
for(y = n = 0; y < 10;){
gettimeofday(&tv, NULL);
t = time(NULL);
if(t < tv.tv_sec)
++y;
else
++n;
}
printf("%u EQ, %u non-EQ\n", n, y);
return 0;
}
results in
#?1300.00 1/120|sdaoden:tmp$ timeout 10 ./zt
Terminated
#?1430.00 1/120|sdaoden:tmp$ timeout 10 ./zt
Terminated timeout 10 ./zt
whereas on GNU based C library (both kernel 6.18), trimmed
#?0|lecce:tmp$ time ./zt
52512820 EQ, 10 non-EQ
real 0m0.915s
#?0|lecce:tmp$ time ./zt
6650069 EQ, 10 non-EQ
real 0m0.124s
#?0|lecce:tmp$ time ./zt
6192365 EQ, 10 non-EQ
real 0m0.118s
#?0|lecce:tmp$ time ./zt
14050552 EQ, 10 non-EQ
real 0m0.345s
#?0|lecce:tmp$ time ./zt
15367605 EQ, 10 non-EQ
real 0m0.377s
Musl impl is
#?0|lecce:musl.git$ git show master:src/time/time.c
#include <time.h>
#include "syscall.h"
time_t time(time_t *t)
{
struct timespec ts;
__clock_gettime(CLOCK_REALTIME, &ts);
if (t) *t = ts.tv_sec;
return ts.tv_sec;
}
I have not really looked into GNU C library since ~Y2K, and will
not visit that jungle.
--steffen
|
|Der Kragenbaer, The moon bear,
|der holt sich munter he cheerfully and one by one
|einen nach dem anderen runter wa.ks himself off
|(By Robert Gernhardt)