freebsd-skq/sys/cddl/dev/dtrace
avg b898b874c6 dtrace_gethrtime: improve scaling of TSC ticks to nanoseconds
Currently dtrace_gethrtime uses formula similar to the following for
converting TSC ticks to nanoseconds:
rdtsc() * 10^9 / tsc_freq
The dividend overflows 64-bit type and wraps-around every 2^64/10^9 =
18446744073 ticks which is just a few seconds on modern machines.

Now we instead use precalculated scaling factor of
10^9*2^N/tsc_freq < 2^32 and perform TSC value multiplication separately
for each 32-bit half.  This allows to avoid overflow of the dividend
described above.
The idea is taken from OpenSolaris.
This has an added feature of always scaling TSC with invariant value
regardless of TSC frequency changes. Thus the timestamps will not be
accurate if TSC actually changes, but they are always proportional to
TSC ticks and thus monotonic. This should be much better than current
formula which produces wildly different non-monotonic results on when
tsc_freq changes.

Also drop write-only 'cp' variable from amd64 dtrace_gethrtime_init()
to make it identical to the i386 twin.

PR:		kern/127441
Tested by:	Thomas Backman <serenity@exscape.org>
Reviewed by:	jhb
Discussed with:	current@, bde, gnn
Silence from:	jb
Approved by:	re (gnn)
MFC after:	1 week
2009-07-15 17:07:39 +00:00
..
amd64 dtrace_gethrtime: improve scaling of TSC ticks to nanoseconds 2009-07-15 17:07:39 +00:00
i386 dtrace_gethrtime: improve scaling of TSC ticks to nanoseconds 2009-07-15 17:07:39 +00:00
dtrace_anon.c
dtrace_cddl.h
dtrace_clone.c
dtrace_debug.c
dtrace_hacks.c
dtrace_ioctl.c Merge latest DTrace changes from Perforce. 2008-11-05 19:39:11 +00:00
dtrace_load.c Merge latest DTrace changes from Perforce. 2008-11-05 19:39:11 +00:00
dtrace_modevent.c
dtrace_sysctl.c
dtrace_test.c
dtrace_unload.c Merge latest DTrace changes from Perforce. 2008-11-05 19:39:11 +00:00
dtrace_vtime.c