[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20100702162034.GB31733@redhat.com>
Date:	Fri, 2 Jul 2010 18:20:34 +0200
From:	Oleg Nesterov <oleg@...hat.com>
To:	Jiri Olsa <jolsa@...hat.com>
Cc:	linux-kernel@...r.kernel.org, tglx@...utronix.de,
	eric.dumazet@...il.com, Alexander Viro <viro@...iv.linux.org.uk>
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.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Powered by blists - more mailing lists
 
