From: Adrian Hunter <ext-adrian.hunter@nokia.com>
To: linux-fsdevel@vger.kernel.org
Subject: fs time granularity
Date: Wed, 09 Apr 2008 18:07:53 +0300 [thread overview]
Message-ID: <47FCDBC9.8030602@nokia.com> (raw)
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?
reply other threads:[~2008-04-09 15:12 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=47FCDBC9.8030602@nokia.com \
--to=ext-adrian.hunter@nokia.com \
--cc=linux-fsdevel@vger.kernel.org \
/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.