From: Philippe Gerum <rpm@xenomai.org>
To: Chris Stone <chris.linux@domain.hid>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-help] Xenomai and timers.
Date: Thu, 16 Dec 2010 19:40:10 +0100 [thread overview]
Message-ID: <1292524810.1837.261.camel@domain.hid> (raw)
In-Reply-To: <BAY149-w131A596DF2F2249BFEFAA3E4150@domain.hid>
On Thu, 2010-12-16 at 13:55 -0400, Chris Stone wrote:
> I am trying to determine if Xenomai will help me to solve a problem I
> am having with embedded Linux in a real time environment. To set the
> context of the problem I am trying to solve, some background is
> necessary.
>
> Our application area is telecommunications, we build cards for optical
> transport applications. We have recently transitioned from using Green
> Hills Velocity to embedded Linux as our real time operating system.
> Our applications are complex and multi-tasking and they use standard
> solutions such as semaphores to serialize access to shared data. In
> our first port of the Green Hills Velocity code to embedded Linux we
> often used sem_timedwait() to wait for a semaphore for a bounded
> amount of time. However, Linux appears to have an issue with timers
> when a task changes the clock with clock_settime().
>
> The POSIX specification for clock_settime() states that: “Setting the
> value of the CLOCK_REALTIME clock via clock_settime() shall have no
> effect on threads that are blocked waiting for a relative time service
> based upon this clock, including the nanosleep() function; nor on the
> expiration of relative timers based upon this clock. Consequently,
> these time services shall expire when the requested relative interval
> elapses, independently of the new or old value of the clock.”
>
> Additionally, the Linux man page for clock_settime() states that: “All
> implementations support the system-wide realtime clock, which is
> identified by CLOCK_REALTIME. Its time represents seconds and
> nanoseconds since the Epoch. When its time is changed, timers for a
> relative interval are unaffected, but timers for an absolute point in
> time are affected”. This indicates that the Linux implementation of
> clock_settime() follows the POSIX specification, as expected. Also the
> Linux implementation of nanosleep() uses relative timers, as expected.
>
> However, almost all Linux API functions use absolute timer intervals.
> For instance, the man page for sem_timedwait() states that the timeout
> is an absolute interval meaning that it will be affected by clock
> changes. Thus, if task A is blocked in a sem_timedwait() call, and
> task B moves time forward with clock_settime(), then task A will
> return from sem_timedwait() with ETIMEOUT prematurely.
>
> From my examination of the documentation on Xenomai, it would appear
> that Xenomai does not suffer from this problem, but I would like to
> confirm my impression. My question to this list is, in Xenomai, if one
> calls rt_sem_p() with a timeout, will that timeout be correct even if
> a task changes the clock with clock_settime()?
>
> Additionally, the documentation of the POSIX skin of Xenomai indicates
> that sem_timedwait() uses an absolute timeout. So, is the Xenomai
> version of sem_timedwait() vulnerable to clock changes? Do I have to
> use rt_sem_p() in order to avoid issues with clock changes?
Well, the POSIX behavior just makes sense, the kernel does not have to
figure out that in fact, your code is not immune to system time updates
so as to eventually consider absolute timeout specs as being relative
ones in disguise.
Therefore I would not speak about vulnerability here, it is just how
POSIX works, because absolute timeouts do have an advantage over
relative timeouts. Since Xenomai's POSIX skin wants to comply with the
standard, it does resume outstanding timers which end up having a
trigger date in the past due to a clock_settime() request.
The native Xenomai skin - which rt_sem_p is part of - has both relative
and absolute timeout forms. The relative form won't be sensitive to
system time updates, whilst the absolute form will. So you may want to
switch skins, or fix your POSIX code to explicitly deal with this issue.
YMMV. (I would probably fix my code actually).
>
> Thanks in advance.
> Christopher Stone
> Optelian, Inc.
>
>
>
> _______________________________________________
> Xenomai-help mailing list
> Xenomai-help@domain.hid
> https://mail.gna.org/listinfo/xenomai-help
--
Philippe.
next prev parent reply other threads:[~2010-12-16 18:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-16 17:55 [Xenomai-help] Xenomai and timers Chris Stone
2010-12-16 18:40 ` Philippe Gerum [this message]
2010-12-16 19:30 ` Chris Stone
2010-12-16 20:55 ` Gilles Chanteperdrix
2010-12-17 9:09 ` Philippe Gerum
2010-12-17 14:35 ` Chris Stone
2010-12-20 7:59 ` Richard Cochran
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1292524810.1837.261.camel@domain.hid \
--to=rpm@xenomai.org \
--cc=chris.linux@domain.hid \
--cc=xenomai@xenomai.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.