On Tue, Jul 19, 2011 at 11:44:43AM -0400, John Kasunich wrote:
> Are you sure that RTAI _always_ uses rdtsc and llimd?
In current versions, this appears to be the case, but with a caveat.
Here's the implementation of the function in rtai 3.6:
RTIME rt_get_cpu_time_ns(void)
{
return llimd(rdtsc(), 1000000000, tuned.cpu_freq);
}
With certain compilation options, you can #define rdstc into an
emulation function that emulates a tsc on the 8254 timer; I bet this is
the implementation with the terrible precision that one set of commits
alluded to. I don't know about its speed.
The 8254 option is used when !CONFIG_X86_TSC. But our 8.04 and 10.04
kernels have CONFIG_X86_TSC enabled, and we've relied on a working TSC
for rtapi_get_clocks for years as well. I can't imagine why we would
ever revert to a non-TSC configuration.
> Every HAL function has two parameters for execution time. [...]
I didn't specifically think about this, but everything you say is right.
So far, this is still in clocks.
It seems like there are a couple of possibilities for why
rt_get_cpu_time_ns is a few hundred ns (cycles) slower than rdtsc.
If it's because the cache is cold (only one call every 1ms), then
calling it 2 times per hal functions plus 2 times per hal thread might
be no big deal, as it is likely to stay in cache.
If it's because llimd is slow, that's another story. llimd looks like
it shouldn't be too slow -- it's 20 lines of inline asm, with 2 mull
instructions, 2 divl instructions and one conditional jump. It's been
too long for me to know how long that kind of code is expected to take
to execute.. (however, a reference I found indicates that 'divl' (divide
64-bit value by 32-bit value giving quotient and remainder) does have a
latency of most of 100 cycles even on the newest intel architectures, so
that could make most of the 300 cycles observed be real execution
time.. (by contrast, 64-bit mul is of course very fast -- latency of 7
cycles)
In that case, we should write our own rtapi_get_time in terms of rdtsc
but avoiding divisions...
(rdtsc() * scaled_khz_reciprocal) >> bits
with the product being computed in enough precision that there are still
64 bits of result left.
Jeff
------------------------------------------------------------------------------
10 Tips for Better Web Security
Learn 10 ways to better secure your business today. Topics covered include:
Web security, SSL, hacker attacks & Denial of Service (DoS), private keys,
security Microsoft Exchange, secure Instant Messaging, and much more.
http://www.accelacomm.com/jaw/sfnl/114/51426210/
_______________________________________________
Emc-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-developers