All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] Get current wallclock time from RT task
@ 2012-02-03 20:07 Patrick Doyle
  2012-02-03 21:22 ` Gilles Chanteperdrix
  0 siblings, 1 reply; 3+ messages in thread
From: Patrick Doyle @ 2012-02-03 20:07 UTC (permalink / raw)
  To: xenomai

What is the easiest way to determine the current wallclock time from
within an RT task?

I see that I can call rt_timer_inquire() and get back an RT_TIMER_INFO
structure containing an RTIME type field labeled "date" and a very
promising comment "Current wallclock time".

But how do I convert that to e.g. something I could pass to ctime() to
get something reasonably close to the current wallclock time?

--wpd


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Xenomai-help] Get current wallclock time from RT task
  2012-02-03 20:07 [Xenomai-help] Get current wallclock time from RT task Patrick Doyle
@ 2012-02-03 21:22 ` Gilles Chanteperdrix
       [not found]   ` <CAF_dkJB+NeaX5QK=xHhNU7Oe0TYM8im_XFwzym22UxJBJ2KWrA@mail.gmail.com>
  0 siblings, 1 reply; 3+ messages in thread
From: Gilles Chanteperdrix @ 2012-02-03 21:22 UTC (permalink / raw)
  To: Patrick Doyle; +Cc: xenomai

On 02/03/2012 09:07 PM, Patrick Doyle wrote:
> What is the easiest way to determine the current wallclock time from
> within an RT task?
> 
> I see that I can call rt_timer_inquire() and get back an RT_TIMER_INFO
> structure containing an RTIME type field labeled "date" and a very
> promising comment "Current wallclock time".
> 
> But how do I convert that to e.g. something I could pass to ctime() to
> get something reasonably close to the current wallclock time?

You need to divide it by one billion. But for the result to be
reasonably accurate, you should either:
- compile xenomai as module
- or having synchronized xenomai clock with linux clock at some earlier
point in time by calling timer_settime(CLOCK_REALTIME) (from posix skin).

If your architecture supports it you may also use
clock_gettime(CLOCK_HOST_REALTIME) then you will get a result with very
good accuracy possibly without even a syscall.

-- 
                                                                Gilles.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Xenomai-help] Get current wallclock time from RT task
       [not found]   ` <CAF_dkJB+NeaX5QK=xHhNU7Oe0TYM8im_XFwzym22UxJBJ2KWrA@mail.gmail.com>
@ 2012-02-03 21:39     ` Gilles Chanteperdrix
  0 siblings, 0 replies; 3+ messages in thread
From: Gilles Chanteperdrix @ 2012-02-03 21:39 UTC (permalink / raw)
  To: Patrick Doyle; +Cc: Xenomai help

On 02/03/2012 10:33 PM, Patrick Doyle wrote:
> On Fri, Feb 3, 2012 at 4:22 PM, Gilles Chanteperdrix
> <gilles.chanteperdrix@xenomai.org> wrote:
>> On 02/03/2012 09:07 PM, Patrick Doyle wrote:
>>> What is the easiest way to determine the current wallclock time from
>>> within an RT task?
>>>
>>> I see that I can call rt_timer_inquire() and get back an RT_TIMER_INFO
>>> structure containing an RTIME type field labeled "date" and a very
>>> promising comment "Current wallclock time".
>>>
>>> But how do I convert that to e.g. something I could pass to ctime() to
>>> get something reasonably close to the current wallclock time?
>>
>> You need to divide it by one billion. But for the result to be
>> reasonably accurate, you should either:
>> - compile xenomai as module
>> - or having synchronized xenomai clock with linux clock at some earlier
>> point in time by calling timer_settime(CLOCK_REALTIME) (from posix skin).
>>
>> If your architecture supports it you may also use
>> clock_gettime(CLOCK_HOST_REALTIME) then you will get a result with very
>> good accuracy possibly without even a syscall.
> 
> Hmmm...
> Is there any way to do this without using the posix skin?
> We are currently using the native skin quite happily, and I'm somewhat
> concerned that pulling in the posix skin (if it's even possible to mix
> and match skins) will lead to more problems than it will solve.

There is should be no problem mixing the skins.

> 
> How accurate is "unreasonably" accurate?  Accurate to within a second
> or so since we last booted should be plenty accurate for what I need
> this for.

The problem is that xenomai clock is synchronized with linux clock when
xenomai starts. When xenomai is build statically with the kernel, this
happens before linux clock is set with hwclock or ntp, so, xenomai clock
is completely off.

Anyway, you can create a binary using the posix skin which does just:

__real_clock_gettime(CLOCK_REALTIME, &ts);
clock_settime(CLOCK_REALTIME, &ts);

and launch it in an init script after Linux clock has been synchronized
with whatever clock you use.

> 
> --wpd
> 


-- 
                                                                Gilles.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-02-03 21:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-03 20:07 [Xenomai-help] Get current wallclock time from RT task Patrick Doyle
2012-02-03 21:22 ` Gilles Chanteperdrix
     [not found]   ` <CAF_dkJB+NeaX5QK=xHhNU7Oe0TYM8im_XFwzym22UxJBJ2KWrA@mail.gmail.com>
2012-02-03 21:39     ` Gilles Chanteperdrix

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.