All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Jiri Olsa <jolsa@redhat.com>
Cc: linux-kernel@vger.kernel.org, tglx@linutronix.de,
	eric.dumazet@gmail.com, Alexander Viro <viro@zeniv.linux.org.uk>
Subject: Re: [PATCH] time/fs - file's time race with vgettimeofday
Date: Fri, 2 Jul 2010 18:20:34 +0200	[thread overview]
Message-ID: <20100702162034.GB31733@redhat.com> (raw)
In-Reply-To: <20100702161422.GA31733@redhat.com>

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.


  reply	other threads:[~2010-07-02 16:22 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-02  7:41 [PATCH] time/fs - file's time race with vgettimeofday Jiri Olsa
2010-07-02 16:14 ` Oleg Nesterov
2010-07-02 16:20   ` Oleg Nesterov [this message]
2010-07-02 23:58   ` Jiri Olsa
2010-07-06 23:03 ` john stultz
2010-07-06 23:11   ` john stultz
2010-07-07 10:47     ` Jiri Olsa
2010-07-07 16:20       ` john stultz
2010-07-07 17:11     ` Jiri Olsa
2010-07-07 17:20       ` john stultz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100702162034.GB31733@redhat.com \
    --to=oleg@redhat.com \
    --cc=eric.dumazet@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.