* fs time granularity
@ 2008-04-09 15:07 Adrian Hunter
0 siblings, 0 replies; only message in thread
From: Adrian Hunter @ 2008-04-09 15:07 UTC (permalink / raw)
To: linux-fsdevel
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?
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2008-04-09 15:12 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-09 15:07 fs time granularity Adrian Hunter
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.