Problem in measuring time!!
h.mayer at inode.at
Sat Oct 9 21:13:51 CEST 2004
Philippe Gerum wrote:
> On Sat, 2004-10-09 at 19:12, Philippe Gerum wrote:
>>On Sat, 2004-10-09 at 18:49, Hannes Mayer wrote:
>>>time = tv.tv_sec+(1.0*tv.tv_usec)/1000000;
>>>That may be not the preferred way in RT context, but it seems to work.
>>It works but unsafely on x86 at least. do_gettimeofday() runs code which
>>needs to be interrupt-free, but since the interrupt masking is fully
>>virtualized for all of the vanilla kernel code, it happens to run hw
>>interrupts on when called on behalf a RT task. In UP mode, a preemption
>>of this code path by some RT task that calls it back is likely to cause
>>a wrong output at best; on SMP, a hard lockup due to an attempt to grab
>>a spinlock recursively is a potential outcome, unless your system has
>>the local APIC enabled (but in the latter case, you've just been lucky
>>with the current Linux implementation...).
>>So the conclusion of this is: do _not_ call do_gettimeofday() on behalf
>>a RT context.
> Which could even be extended to: do _not_ call any vanilla kernel
> routine on behalf of a RT context unless you have previously made sure
> that it does not depend on any mutual exclusion construct involving
> interrupt masking provided by the Linux kernel.
Thank you very much!!
I just tested rt_get_time_ns(); and rt_get_cpu_time_ns() for determining
time difference. Is there one preferred function for measuring time ?
Or is it just a matter of taste ?
Tarik, don't forget to rt_set_oneshot_mode();
Otherwise rt_get_time_ns doesn't work.
More information about the Rtai