Problem in measuring time!!

Tarik KHOUTAIF khoutaif at iut-blagnac.fr
Mon Oct 11 11:31:35 CEST 2004


Hi Hannes, Hi Philipe

That pleased to me to receive your answers. 
The rt_get_cpu_time_ns() returns time CPU, on the other hand the rt_get_time_ns() returns time in tick clock. 
I work in the periodic mode and not oneshot mode (When I use the one shot mode the value of lacapture of time is null).I my application I use 3 modules, module_init_port in which I initialize the serial port and the timer (rt_start_timer(1E1)), in the module module_send_and_wait "Master" I makes rt_get_time_ns() after writing and after reading in the serial port.  In the module module_wait_and_answer I make rt_get_time_ns() after reading and after writing in the serial port . 
Is what the fact of initializing the timer in another module other than this in which we does rt_get_time_ns(), does not pose problem? 
Is the function get_timeof_day() returns the real time value of time? 
Best regards,
Tarik



Message: 7
Date: Sat, 09 Oct 2004 21:13:51 +0200
From: Hannes Mayer <h.mayer at inode.at>
To: rpm at xenomai.org
CC: rtai at rtai.org
Subject: Re: Problem in measuring time!!

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:
>>    
>>
>>>>>>do_gettimeofday(&tv);
>>>>>>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.
>  
>

Hi Philippe!

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.

Best regards,
Hannes.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.rtai.org/pipermail/rtai/attachments/20041011/a1e6dfe8/attachment.htm 


More information about the Rtai mailing list