Messages in this thread | | | Date | Fri, 2 Jul 2010 18:20:34 +0200 | From | Oleg Nesterov <> | Subject | Re: [PATCH] time/fs - file's time race with vgettimeofday |
| |
On 07/02, Oleg Nesterov wrote: > > But, get_seconds() is also used by sys_time(), and we should have the > same problem with another trivial test-case: > > #include <stdio.h> > #include <sys/time.h> > #include <time.h> > > int main(void) > { > struct timeval tv; > int sec; > > do { > gettimeofday(&tv, NULL); > sec = time(NULL); > } while (tv.tv_sec <= sec); > > printf("gtod: %ld.%06ld\n", tv.tv_sec, tv.tv_usec); > printf("time: %d.000000\n", sec); > return 0; > } > > However, this test-case can't trigger the problem. Confused.
Aha. libc's time() doesn't use sys_time(), it uses __vsyscall(1) vtime()->do_vgettimeofday().
This one quickly triggers the "time goes backward" case.
#include <stdio.h> #include <sys/time.h> #include <time.h> #include <unistd.h> #include <sys/syscall.h>
int main(void) { struct timeval tv; int sec;
do { gettimeofday(&tv, NULL); sec = syscall(__NR_time, NULL); } while (tv.tv_sec <= sec);
printf("gtod: %ld.%06ld\n", tv.tv_sec, tv.tv_usec); printf("time: %d.000000\n", sec); return 0; }
Not that I think this "problem" should be fixed, just curious.
Oleg.
| |