[LinuxPPS] Recommendation / Re: Stats & architectures
James Boddington
boddingt at internode.on.net
Tue Mar 18 11:53:13 CET 2008
Bernhard Schiffner wrote:
> Am Dienstag, 18. März 2008 00:06 schrieb clemens at dwf.com:
> ...
>>> Linuxpps uses getnstimeofday() so a nanosecond time stamp is
>>> available.
>> I hate to break it to you, but if you look at the kernel code,
>> getnstimeofday is a dmy routine,- it just multiplies the us value by
>> 1000 and returns it. It does NO interpolation.
>>
>> That DOES mean that you dont have to change code when a REAL ns clock
>> becomes available, but thats about it...
>
> Once I used getnstimeofday() for some debugging. The readout showed the
> full 10^-9 resolution and no visible *1000 steps. NTPD was not active this
> time.
> From this time on I was a beliver in increased numerical resolution
> provided by this call.
>
> Can you prove this on your machine please?
> (Which clocksoure is used?)
>
> Do you see an easy way to determine getnstimeofday() "grain"?
I have not seen the email where I was quoted so I'll reply here.
I tried the following module
#include <linux/module.h>
int init_module(void)
{
struct timespec ts;
int loop;
for (loop = 0; loop < 10; loop++) {
getnstimeofday(&ts);
printk("%lu %09lu\n", ts.tv_sec, ts.tv_nsec);
}
return 0;
}
void cleanup_module(void)
{
}
MODULE_AUTHOR("James");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("play with getnstimeofday()");
Checking dmesg afterwards I get 10 time stamps that are not us * 1000
1205832048 169178484
1205832048 169493048
1205832048 169586077
1205832048 169674356
1205832048 169760679
1205832048 169846165
1205832048 169931092
1205832048 170015460
1205832048 170100107
1205832048 170185313
Replacing the loop with
getnstimeofday(&ts1);
getnstimeofday(&ts2);
getnstimeofday(&ts3);
printk("%lu %09lu\n", ts1.tv_sec, ts1.tv_nsec);
printk("%lu %09lu\n", ts2.tv_sec, ts2.tv_nsec);
printk("%lu %09lu\n", ts3.tv_sec, ts3.tv_nsec);
gives me 3 time stamps that increase in less than 1us increments
1205832931 266274358
1205832931 266274637
1205832931 266275196
Looking at kernel/time/timekeeping.c
getnstimeofday() calls __get_realtime_clock_ts()
__get_realtime_clock_ts() calls __get_nsec_offset()
The comment for __get_nsec_offset() is
/**
* __get_nsec_offset - Returns nanoseconds since last call to periodic_hook
*
* private function, must hold xtime_lock lock when being
* called. Returns the number of nanoseconds since the
* last call to update_wall_time() (adjusted by NTP scaling)
*/
__get_nsec_offset() calculates nanoseconds
I get the same results for tsc, acpi_pm and pit but not jiffies. For jiffies I
got the same time stamp 10 times.
Digging a little deeper I found kernel/time.c also has a getnstimeofday(). It
depends on whether CONFIG_GENERIC_TIME is defined.
#ifdef CONFIG_GENERIC_TIME you get __get_nsec_offset() returning nanoseconds
and getnstimeofday() returning nanoseconds.
#ifndef CONFIG_GENERIC_TIME you get __get_nsec_offset() returning 0 and
getnstimeofday() returning us * 1000.
I have CONFIG_GENERIC_TIME=y in .config
--
James
More information about the LinuxPPS
mailing list