lkml.org 
[lkml]   [2010]   [Jul]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [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.



\
 
 \ /
  Last update: 2010-07-02 18:25    [W:3.956 / U:0.024 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site