在EXT4时间戳精度(子millsecond) [英] timestamp accuracy on EXT4 (sub millsecond)

查看:127
本文介绍了在EXT4时间戳精度(子millsecond)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的一些瓦拉code在那里我会先得到系统时间,然后创建一个文件,然后检索该文件的时间戳。时间戳将永远是前面的系统时间,地方500和1500微秒,这没有任何意义的。

I was writing some code in Vala where I would first get the system time, then create a file, then retrieve the time stamp of that file. The timestamp would always be earlier that the system time, somewhere between 500 and 1500 micro seconds which didn't make sense.

然后我写了一个简单的shell脚本:

I then wrote a simple shell script:

while true; do
touch ~/tmp/fred.txt
stat ~/tmp/fred.txt|grep ^C
done

随着以下结果:

Change: 2013-01-18 16:02:44.290787250 +1100
Change: 2013-01-18 16:02:44.293787250 +1100
Change: 2013-01-18 16:02:44.296787250 +1100
Change: 2013-01-18 16:02:44.298787248 +1100
Change: 2013-01-18 16:02:44.301787248 +1100
Change: 2013-01-18 16:02:44.304787248 +1100
Change: 2013-01-18 16:02:44.306787248 +1100
Change: 2013-01-18 16:02:44.309787248 +1100
Change: 2013-01-18 16:02:44.312787248 +1100
Change: 2013-01-18 16:02:44.315787248 +1100

正如你可以看到小数点(毫秒)后的第3位似乎确定预期,因为它们是递增的,但第4位和以后不看的权利。第4至第9位似乎是在做一个缓慢的倒计时来代替。是否有任何理由,我虽然ext4的高达precision纳米第二支持。访问和修改时间戳的行为以同样的方式。

As you can see the first 3 digits after the decimal point (milli seconds) seem ok as they are incrementing as expected, but the 4th digit and beyond does not look right. The 4th to 9th digits seems to be doing a slow count down instead. Is there any reason for this as I though ext4 supports up to the nano second in precision. The Access and Modify timestamps behave in the same way.

推荐答案

ext4文件系统做存储时间支持纳秒的分辨率,如果索引节点是大到足以支持较长时间信息(256字节或更大)。你的情况,因为有比第二名的分辨率更大,这是没有问题的。

The ext4 file system does support nanosecond resolution on stored times if the inodes are big enough to support the extended time information (256 bytes or larger). In your case, since there is greater than second resolution, this is not a problem.

在内部,EXT4文件系统code调用 current_fs_time()这是截断到文件系统的超级块中指定的时间粒度当前缓存的内核时间,这对ext4的为1ns的。

Internally, the ext4 filesystem code calls current_fs_time() which is the current cached kernel time truncated to the time granularity specified in the file system's superblock which for ext4 is 1ns.

在Linux内核中的当前时间被缓存,并且一般只更新定时器中断。因此,如果您的定时器中断是在10毫秒运行时,缓存时间将只使用一次,每10毫秒更新一次。当确实发生更新时,得到的时间精度将取决于您的硬件提供的时钟源。

The current time within the Linux kernel is cached, and generally only updated on a timer interrupt. So if your timer interrupt is running at 10 milliseconds, the cached time will only be updated once every 10 milliseconds. When an update does occur, the accuracy of the resulting time will depend on the clock source available on your hardware.

试试这个,看看是否你也可以得到类似的结果在您的stat调用:

Try this and see if you also get similar results to your stat calls:

while true; do date --rfc-3339=ns; done

在我的机器上(AMD64,英特尔的VirtualBox)没有量化。

On my machine (amd64, intel virtualbox) there is no quantization.

例如

2013-01-18 17:04:21.097211836+11:00
2013-01-18 17:04:21.098354731+11:00
2013-01-18 17:04:21.099282128+11:00
2013-01-18 17:04:21.100276327+11:00
2013-01-18 17:04:21.101348507+11:00
2013-01-18 17:04:21.102516837+11:00

更新

使用日期以上检查并没有真正表现出这种情况什么。这是因为日期将调用 gettimeofday的系统调用,这将始终返回基于缓存的内核提供最准确的时间时间,由CPU周期时间调整(如果可用)给纳秒的分辨率。存储在但是文件系统的时间戳,仅基于缓存的内核的时间。即在最后的定时器中断中计算的时间

The above check using date doesn't really show anything for this situation. This is because date will call the gettimeofday system call which will always return the most accurate time available based on the cached kernel time, adjusted by the CPU cycle time if available to give nanosecond resolution. The timestamps stored in the file system however, are only based on the cached kernel time. ie The time calculated at the last timer interrupt.

这篇关于在EXT4时间戳精度(子millsecond)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆