Message-ID: Content-Type: multipart/alternative; boundary="_5d68e3b7-3661-4885-a687-fe0d4ddc7dda_" From: Chris Stone Date: Thu, 16 Dec 2010 15:30:47 -0400 In-Reply-To: <1292524810.1837.261.camel@domain.hid> References: , <1292524810.1837.261.camel@domain.hid> MIME-Version: 1.0 Subject: Re: [Xenomai-help] Xenomai and timers. List-Id: Help regarding installation and common use of Xenomai List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Xenomai Help --_5d68e3b7-3661-4885-a687-fe0d4ddc7dda_ Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable Thanks for your reply=2C and I realize that I am now getting off topic for = this list=2C but if the explanation is easy perhaps I could impose on you a= little further. How does one fix the POSIX code to deal with this issue? W= hen sem_timedwait() returns with ETIMEDOUT=2C how does one know that the ti= me was changed by another task and the timeout was not the duration that wa= s asked for?=20 Chris. > Subject: Re: [Xenomai-help] Xenomai and timers. > From: rpm@xenomai.org > To: chris.linux@domain.hid > CC: xenomai@xenomai.org > Date: Thu=2C 16 Dec 2010 19:40:10 +0100 >=20 > On Thu=2C 2010-12-16 at 13:55 -0400=2C 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=2C some background is > > necessary. > >=20 > > Our application area is telecommunications=2C we build cards for optica= l > > 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=2C Linux appears to have an issue with timers > > when a task changes the clock with clock_settime(). > >=20 > > The POSIX specification for clock_settime() states that: =93Setting 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=2C including the nanosleep() function=3B nor on t= he > > expiration of relative timers based upon this clock. Consequently=2C > > these time services shall expire when the requested relative interval > > elapses=2C independently of the new or old value of the clock.=94 > >=20 > > Additionally=2C the Linux man page for clock_settime() states that: =93= All > > implementations support the system-wide realtime clock=2C which is > > identified by CLOCK_REALTIME. Its time represents seconds and > > nanoseconds since the Epoch. When its time is changed=2C timers for a > > relative interval are unaffected=2C but timers for an absolute point in > > time are affected=94. This indicates that the Linux implementation of > > clock_settime() follows the POSIX specification=2C as expected. Also th= e > > Linux implementation of nanosleep() uses relative timers=2C as expected= . > >=20 > > However=2C almost all Linux API functions use absolute timer intervals. > > For instance=2C the man page for sem_timedwait() states that the timeou= t > > is an absolute interval meaning that it will be affected by clock > > changes. Thus=2C if task A is blocked in a sem_timedwait() call=2C and > > task B moves time forward with clock_settime()=2C then task A will > > return from sem_timedwait() with ETIMEOUT prematurely. > >=20 > > From my examination of the documentation on Xenomai=2C it would appear > > that Xenomai does not suffer from this problem=2C but I would like to > > confirm my impression. My question to this list is=2C in Xenomai=2C if = one > > calls rt_sem_p() with a timeout=2C will that timeout be correct even if > > a task changes the clock with clock_settime()? > >=20 > > Additionally=2C the documentation of the POSIX skin of Xenomai indicate= s > > that sem_timedwait() uses an absolute timeout. So=2C 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? >=20 >=20 > Well=2C the POSIX behavior just makes sense=2C the kernel does not have t= o > figure out that in fact=2C your code is not immune to system time updates > so as to eventually consider absolute timeout specs as being relative > ones in disguise. >=20 > Therefore I would not speak about vulnerability here=2C it is just how > POSIX works=2C because absolute timeouts do have an advantage over > relative timeouts. Since Xenomai's POSIX skin wants to comply with the > standard=2C it does resume outstanding timers which end up having a > trigger date in the past due to a clock_settime() request. >=20 > 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=2C whilst the absolute form will. So you may want to > switch skins=2C or fix your POSIX code to explicitly deal with this issue= . > YMMV. (I would probably fix my code actually). >=20 > >=20 > > Thanks in advance. > > Christopher Stone > > Optelian=2C Inc. > >=20 > >=20 > >=20 > > _______________________________________________ > > Xenomai-help mailing list > > Xenomai-help@domain.hid > > https://mail.gna.org/listinfo/xenomai-help >=20 > --=20 > Philippe. >=20 >=20 = --_5d68e3b7-3661-4885-a687-fe0d4ddc7dda_ Content-Type: text/html; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable Thanks for your reply=2C and I realize that I am now getting off topic for = this list=2C but if the explanation is easy perhaps I could impose on you a= little further. How does one fix the POSIX code to deal with this issue? W= hen sem_timedwait() returns with ETIMEDOUT=2C how does one know that the ti= me was changed by another task and the timeout was not the duration that wa= s asked for?

Chris.

>=3B Subject: Re: [Xenomai-help] Xenom= ai and timers.
>=3B From: rpm@xenomai.org
>=3B To: chris.linux@domain.hid= tmail.com
>=3B CC: xenomai@xenomai.org
>=3B Date: Thu=2C 16 Dec = 2010 19:40:10 +0100
>=3B
>=3B On Thu=2C 2010-12-16 at 13:55 -040= 0=2C Chris Stone wrote:
>=3B >=3B I am trying to determine if Xenoma= i will help me to solve a problem I
>=3B >=3B am having with embedde= d Linux in a real time environment. To set the
>=3B >=3B context of = the problem I am trying to solve=2C some background is
>=3B >=3B nec= essary.
>=3B >=3B
>=3B >=3B Our application area is telecomm= unications=2C we build cards for optical
>=3B >=3B transport applica= tions. We have recently transitioned from using Green
>=3B >=3B Hill= s Velocity to embedded Linux as our real time operating system.
>=3B &= gt=3B Our applications are complex and multi-tasking and they use standard<= br>>=3B >=3B solutions such as semaphores to serialize access to shared= data. In
>=3B >=3B our first port of the Green Hills Velocity code = to embedded Linux we
>=3B >=3B often used sem_timedwait() to wait fo= r a semaphore for a bounded
>=3B >=3B amount of time. However=2C Lin= ux appears to have an issue with timers
>=3B >=3B when a task change= s the clock with clock_settime().
>=3B >=3B
>=3B >=3B The PO= SIX specification for clock_settime() states that: =93Setting the
>=3B= >=3B value of the CLOCK_REALTIME clock via clock_settime() shall have no=
>=3B >=3B effect on threads that are blocked waiting for a relative= time service
>=3B >=3B based upon this clock=2C including the nanos= leep() function=3B nor on the
>=3B >=3B expiration of relative timer= s based upon this clock. Consequently=2C
>=3B >=3B these time servic= es shall expire when the requested relative interval
>=3B >=3B elaps= es=2C independently of the new or old value of the clock.=94
>=3B >= =3B
>=3B >=3B Additionally=2C the Linux man page for clock_settime(= ) states that: =93All
>=3B >=3B implementations support the system-w= ide realtime clock=2C which is
>=3B >=3B identified by CLOCK_REALTIM= E. Its time represents seconds and
>=3B >=3B nanoseconds since the E= poch. When its time is changed=2C timers for a
>=3B >=3B relative in= terval are unaffected=2C but timers for an absolute point in
>=3B >= =3B time are affected=94. This indicates that the Linux implementation of>=3B >=3B clock_settime() follows the POSIX specification=2C as expec= ted. Also the
>=3B >=3B Linux implementation of nanosleep() uses rel= ative timers=2C as expected.
>=3B >=3B
>=3B >=3B However=2C = almost all Linux API functions use absolute timer intervals.
>=3B >= =3B For instance=2C the man page for sem_timedwait() states that the timeou= t
>=3B >=3B is an absolute interval meaning that it will be affected= by clock
>=3B >=3B changes. Thus=2C if task A is blocked in a sem_t= imedwait() call=2C and
>=3B >=3B task B moves time forward with cloc= k_settime()=2C then task A will
>=3B >=3B return from sem_timedwait(= ) with ETIMEOUT prematurely.
>=3B >=3B
>=3B >=3B From my exa= mination of the documentation on Xenomai=2C it would appear
>=3B >= =3B that Xenomai does not suffer from this problem=2C but I would like to>=3B >=3B confirm my impression. My question to this list is=2C in Xe= nomai=2C if one
>=3B >=3B calls rt_sem_p() with a timeout=2C will th= at timeout be correct even if
>=3B >=3B a task changes the clock wit= h clock_settime()?
>=3B >=3B
>=3B >=3B Additionally=2C the d= ocumentation of the POSIX skin of Xenomai indicates
>=3B >=3B that s= em_timedwait() uses an absolute timeout. So=2C is the Xenomai
>=3B >= =3B version of sem_timedwait() vulnerable to clock changes? Do I have to>=3B >=3B use rt_sem_p() in order to avoid issues with clock changes?<= br>>=3B
>=3B
>=3B Well=2C the POSIX behavior just makes sense= =2C the kernel does not have to
>=3B figure out that in fact=2C your c= ode is not immune to system time updates
>=3B so as to eventually cons= ider absolute timeout specs as being relative
>=3B ones in disguise.>=3B
>=3B Therefore I would not speak about vulnerability here=2C= it is just how
>=3B POSIX works=2C because absolute timeouts do have = an advantage over
>=3B relative timeouts. Since Xenomai's POSIX skin w= ants to comply with the
>=3B standard=2C it does resume outstanding ti= mers which end up having a
>=3B trigger date in the past due to a cloc= k_settime() request.
>=3B
>=3B The native Xenomai skin - which r= t_sem_p is part of - has both relative
>=3B and absolute timeout forms= . The relative form won't be sensitive to
>=3B system time updates=2C = whilst the absolute form will. So you may want to
>=3B switch skins=2C= or fix your POSIX code to explicitly deal with this issue.
>=3B YMMV.= (I would probably fix my code actually).
>=3B
>=3B >=3B
&= gt=3B >=3B Thanks in advance.
>=3B >=3B Christopher Stone
>= =3B >=3B Optelian=2C Inc.
>=3B >=3B
>=3B >=3B
>=3B &= gt=3B
>=3B >=3B _______________________________________________
= >=3B >=3B Xenomai-help mailing list
>=3B >=3B Xenomai-help@domain.hid= rg
>=3B >=3B https://mail.gna.org/listinfo/xenomai-help
>=3B >=3B --
>=3B Philippe.
>=3B
>=3B
= --_5d68e3b7-3661-4885-a687-fe0d4ddc7dda_--