From mboxrd@z Thu Jan 1 00:00:00 1970 From: Adrian Hunter Subject: fs time granularity Date: Wed, 09 Apr 2008 18:07:53 +0300 Message-ID: <47FCDBC9.8030602@nokia.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit To: linux-fsdevel@vger.kernel.org Return-path: Received: from smtp.nokia.com ([192.100.105.134]:30888 "EHLO mgw-mx09.nokia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753475AbYDIPMz (ORCPT ); Wed, 9 Apr 2008 11:12:55 -0400 Received: from esebh106.NOE.Nokia.com (esebh106.ntc.nokia.com [172.21.138.213]) by mgw-mx09.nokia.com (Switch-3.2.6/Switch-3.2.6) with ESMTP id m39FDdvV005427 for ; Wed, 9 Apr 2008 10:15:10 -0500 Sender: linux-fsdevel-owner@vger.kernel.org List-ID: I was trying different values for time granularity but did not get the results I expected, which I think is because of the function below: /** * timespec_trunc - Truncate timespec to a granularity * @t: Timespec * @gran: Granularity in ns. * * Truncate a timespec to a granularity. gran must be smaller than a second. * Always rounds down. * * This function should be only used for timestamps returned by * current_kernel_time() or CURRENT_TIME, not with do_gettimeofday() because * it doesn't handle the better resolution of the latter. */ struct timespec timespec_trunc(struct timespec t, unsigned gran) { /* * Division is pretty slow so avoid it for common cases. * Currently current_kernel_time() never returns better than * jiffies resolution. Exploit that. */ if (gran <= jiffies_to_usecs(1) * 1000) { /* nothing */ } else if (gran == 1000000000) { t.tv_nsec = 0; } else { t.tv_nsec -= t.tv_nsec % gran; } return t; } EXPORT_SYMBOL(timespec_trunc); The first condition gives no rounding, but although current_kernel_time() is only updated every jiffy, it is not rounded to that granularity. With HZ=250 and gran=1000000, I was expecting to see just 3 decimal places of time. But instead I get: # touch a # stat a File: `a' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: fc01h/64513d Inode: 65 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2008-04-09 17:05:38.032726306 +0300 Modify: 2008-04-09 17:05:38.032726306 +0300 Change: 2008-04-09 17:05:38.032726306 +0300 If I change gran to 10000000, it works: # touch a # stat a File: `a' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: fc01h/64513d Inode: 65 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2008-04-09 17:34:25.180000000 +0300 Modify: 2008-04-09 17:34:25.180000000 +0300 Change: 2008-04-09 17:34:25.180000000 +0300 Is this how it is meant to be?