* BUG: Is it a bug in Linux time() function or Linux OS calls?
@ 2010-03-10 7:59 Srinivas Nayak
2010-03-10 8:47 ` David Newall
2010-03-10 17:19 ` john stultz
0 siblings, 2 replies; 5+ messages in thread
From: Srinivas Nayak @ 2010-03-10 7:59 UTC (permalink / raw)
To: linux-kernel
Dear All,
I wrote a small program, that creates files at an interval of 1 minute. But the time at which the file is created and last written and the last modification time of the file as shown by ls command differs by 1 second. The code and the output is presented below. please let me know where could be the bug?
root@new:/home/srinivas# cat b.c
#include <time.h>
#include <stdio.h>
#include <sys/stat.h>
#include <dirent.h>
#include <fcntl.h>
int main ()
{
int fd;
int i=0;
time_t initial_time = time(NULL);
time_t interval = 60;
time_t curr_time = time(NULL);
fd=open ("test1.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);
write(fd,"abcd1",5);
while(1)
{
curr_time = time(NULL);
if(curr_time >= initial_time)
{
if(i==0)
{
close(fd);
printf("\ntime before test2.txt fileopen= %d\n", time(NULL));
fd=open ("test2.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);
write(fd,"abcd2",5);
printf("time after test2.txt filewrite= %d\n", time(NULL));
system("ls -l --time-style=+%s test2.txt");
initial_time += interval;
i=1;
}
else
{
close(fd);
printf("\ntime before test1.txt fileopen= %d\n", time(NULL));
fd=open ("test1.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);
write(fd,"abcd1",5);
printf("time after test1.txt filewrite= %d\n", time(NULL));
system("ls -l --time-style=+%s test1.txt");
initial_time += interval;
i=0;
}
}
usleep(1000);
}
return 0;
}
root@new:/home/srinivas# gcc b.c
root@new:/home/srinivas# ./a.out
time before test2.txt fileopen= 1268203133
time after test2.txt filewrite= 1268203133
-rw-r--r-- 1 root root 5 1268203133 test2.txt
time before test1.txt fileopen= 1268203193
time after test1.txt filewrite= 1268203193
-rw-r--r-- 1 root root 5 1268203192 test1.txt
time before test2.txt fileopen= 1268203253
time after test2.txt filewrite= 1268203253
-rw-r--r-- 1 root root 5 1268203252 test2.txt
time before test1.txt fileopen= 1268203313
time after test1.txt filewrite= 1268203313
-rw-r--r-- 1 root root 5 1268203312 test1.txt
time before test2.txt fileopen= 1268203373
time after test2.txt filewrite= 1268203373
-rw-r--r-- 1 root root 5 1268203372 test2.txt
root@new:/home/srinivas# ls -ltr --time-style=+%s
total 40
-rwxrwxrwx 1 root root 1095 1268202457 b.c
-rwxr-xr-x 1 root root 10300 1268202459 a.out
-rw-r--r-- 1 root root 5 1268203312 test1.txt
-rw-r--r-- 1 root root 5 1268203372 test2.txt
root@new:/home/srinivas#
Some system info:
===========
Linux new 2.6.24-19-server #1 SMP Wed Jun 18 14:44:47 UTC 2008 x86_64 GNU/Linux
Gnu C 4.2.4
Linux C Library 2.7
binutils 2.18.0.20080103
util-linux 2.13.1
Console-tools 0.2.3
Sh-utils 6.10
===========
With best regards,
Yours sincerely,
Srinivas Nayak
My Home page: http://www.mathmeth.com/sn/
My Blog: http://srinivas-nayak.blogspot.com
The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: BUG: Is it a bug in Linux time() function or Linux OS calls?
2010-03-10 7:59 BUG: Is it a bug in Linux time() function or Linux OS calls? Srinivas Nayak
@ 2010-03-10 8:47 ` David Newall
2010-03-10 9:13 ` Srinivas Nayak
2010-03-10 17:19 ` john stultz
1 sibling, 1 reply; 5+ messages in thread
From: David Newall @ 2010-03-10 8:47 UTC (permalink / raw)
To: Srinivas Nayak; +Cc: linux-kernel
Dear Srinivas Nayak,
I don't suppose you're writing to a network mounted disk, with the
network device's clock about half a second behind your test machine?
Otherwise -- and I'm just guessing here, and will leave it to you to
UTSL -- this could be explained by use of two different algorithms for
converting a higher-resolution time source to the one-second
resolution. A truncation algorithm versus a rounding algorithm could
produce the result you demonstrate.
Regards,
David
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: BUG: Is it a bug in Linux time() function or Linux OS calls?
2010-03-10 8:47 ` David Newall
@ 2010-03-10 9:13 ` Srinivas Nayak
0 siblings, 0 replies; 5+ messages in thread
From: Srinivas Nayak @ 2010-03-10 9:13 UTC (permalink / raw)
To: David Newall; +Cc: linux-kernel
Dear David,
I am not writing to network mounted disk. This is locally mounted and filesystem is ext3.
With best regards,
Yours sincerely,
Srinivas Nayak
My Home page: http://www.mathmeth.com/sn/
My Blog: http://srinivas-nayak.blogspot.com
--- On Wed, 10/3/10, David Newall <davidn@davidnewall.com> wrote:
> From: David Newall <davidn@davidnewall.com>
> Subject: Re: BUG: Is it a bug in Linux time() function or Linux OS calls?
> To: "Srinivas Nayak" <sinu_nayak2001@yahoo.co.in>
> Cc: linux-kernel@vger.kernel.org
> Date: Wednesday, 10 March, 2010, 2:17 PM
> Dear Srinivas Nayak,
>
> I don't suppose you're writing to a network mounted disk,
> with the network device's clock about half a second behind
> your test machine? Otherwise -- and I'm just guessing
> here, and will leave it to you to UTSL -- this could be
> explained by use of two different algorithms for converting
> a higher-resolution time source to the one-second
> resolution. A truncation algorithm versus a rounding
> algorithm could produce the result you demonstrate.
>
> Regards,
>
> David
>
The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: BUG: Is it a bug in Linux time() function or Linux OS calls?
2010-03-10 7:59 BUG: Is it a bug in Linux time() function or Linux OS calls? Srinivas Nayak
2010-03-10 8:47 ` David Newall
@ 2010-03-10 17:19 ` john stultz
2010-03-11 6:10 ` Srinivas Nayak
1 sibling, 1 reply; 5+ messages in thread
From: john stultz @ 2010-03-10 17:19 UTC (permalink / raw)
To: Srinivas Nayak; +Cc: linux-kernel
On Tue, Mar 9, 2010 at 11:59 PM, Srinivas Nayak
<sinu_nayak2001@yahoo.co.in> wrote:
> I wrote a small program, that creates files at an interval of 1 minute. But the time at which the file is created and last written and the last modification time of the file as shown by ls command differs by 1 second. The code and the output is presented below. please let me know where could be the bug?
>
[snip]
> Some system info:
> ===========
> Linux new 2.6.24-19-server #1 SMP Wed Jun 18 14:44:47 UTC 2008 x86_64 GNU/Linux
> Gnu C 4.2.4
> Linux C Library 2.7
> binutils 2.18.0.20080103
> util-linux 2.13.1
> Console-tools 0.2.3
> Sh-utils 6.10
> ===========
Hrm. Is CONFIG_NO_HZ enabled? If so this is a known issue. The
filesystem timestamps use xtime, which is normally updated every HZ.
However to reduce overhead with NO_HZ we changed the update to be a
half-second, which can cause issues like what you describe.
The issue has since been resolved, so I'd be interested to hear if you
can still reproduce it on a more recent kernel.
thanks
-john
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: BUG: Is it a bug in Linux time() function or Linux OS calls?
2010-03-10 17:19 ` john stultz
@ 2010-03-11 6:10 ` Srinivas Nayak
0 siblings, 0 replies; 5+ messages in thread
From: Srinivas Nayak @ 2010-03-11 6:10 UTC (permalink / raw)
To: john stultz; +Cc: linux-kernel
Dear John,
Thanks for your answer. This is informative.
With best regards,
Yours sincerely,
Srinivas Nayak
My Home page: http://www.mathmeth.com/sn/
My Blog: http://srinivas-nayak.blogspot.com
--- On Wed, 10/3/10, john stultz <johnstul@us.ibm.com> wrote:
> From: john stultz <johnstul@us.ibm.com>
> Subject: Re: BUG: Is it a bug in Linux time() function or Linux OS calls?
> To: "Srinivas Nayak" <sinu_nayak2001@yahoo.co.in>
> Cc: linux-kernel@vger.kernel.org
> Date: Wednesday, 10 March, 2010, 10:49 PM
> On Tue, Mar 9, 2010 at 11:59 PM,
> Srinivas Nayak
> <sinu_nayak2001@yahoo.co.in>
> wrote:
> > I wrote a small program, that creates files at an
> interval of 1 minute. But the time at which the file is
> created and last written and the last modification time of
> the file as shown by ls command differs by 1 second. The
> code and the output is presented below. please let me know
> where could be the bug?
> >
> [snip]
> > Some system info:
> > ===========
> > Linux new 2.6.24-19-server #1 SMP Wed Jun 18 14:44:47
> UTC 2008 x86_64 GNU/Linux
> > Gnu C 4.2.4
> > Linux C Library 2.7
> > binutils 2.18.0.20080103
> > util-linux 2.13.1
> > Console-tools 0.2.3
> > Sh-utils 6.10
> > ===========
>
> Hrm. Is CONFIG_NO_HZ enabled? If so this is a known
> issue. The
> filesystem timestamps use xtime, which is normally updated
> every HZ.
> However to reduce overhead with NO_HZ we changed the update
> to be a
> half-second, which can cause issues like what you
> describe.
>
> The issue has since been resolved, so I'd be interested to
> hear if you
> can still reproduce it on a more recent kernel.
>
> thanks
> -john
>
Your Mail works best with the New Yahoo Optimized IE8. Get it NOW! http://downloads.yahoo.com/in/internetexplorer/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-03-11 6:10 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-10 7:59 BUG: Is it a bug in Linux time() function or Linux OS calls? Srinivas Nayak
2010-03-10 8:47 ` David Newall
2010-03-10 9:13 ` Srinivas Nayak
2010-03-10 17:19 ` john stultz
2010-03-11 6:10 ` Srinivas Nayak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox