Skip to contentSkip to conversation

Debian bug report #677633: Xenomai posix skin : bug with nanosleep function

Xenomai Roland Stigge 2 participants 3 messages Jun 15, 2012

lore
Share & tools
lore
#0 lore raw

Hi,

may I present the below bug report from Debian to the noble ranks of Xenomai developers.

See also http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=677633

Bug or feature? ;-)

Thanks in advance,

Roland

=========================================================================
Package: xenomai
Version: 2.6.0

Kernel:2.6.38.8 - Xenomai:2.6.0
arch:i686 i386 GNU/Linux

Hi,

The nanosleep_test.c code shows a malfunction of the nanosleep function when a timer periodically triggering a signal.
When nanosleep is interrupted the variable holding the rest of the time to sleep is immediately zero.

However, no bug is reported without the xenomai's posix skin.

Duchesne Alexandre
[email protected]

#2 lore raw
In reply to Roland Stigge
Quoted 11 lines · Roland Stigge

Hi,

The nanosleep_test.c code shows a malfunction of the nanosleep function when a timer periodically triggering a signal.
When nanosleep is interrupted the variable holding the rest of the time to sleep is immediately zero.

However, no bug is reported without the xenomai's posix skin.

The following patch should fix the bug:

ksrc/skins/posix/clock.c +2 -5
index 024260d..107ebb0 100644
@@ -336,15 +336,12 @@ int clock_nanosleep(clockid_t clock_id,
        if (xnthread_test_info(cur, XNBREAK)) {
 
                if (flags == 0 && rmtp) {
-                       xnticks_t now, expiry;
                        xnsticks_t rem;
 
-                       now = clock_get_ticks(clock_id);
-                       expiry = xntimer_get_date(&cur->rtimer);
+                       rem = xntimer_get_timeout_stopped(&cur->rtimer);
                        xnlock_put_irqrestore(&nklock, s);
-                       rem = expiry - now;
 
-                       ticks2ts(rmtp, rem > 0 ? rem : 0);
+                       ticks2ts(rmtp, rem > 1 ? rem : 0);
                } else
                        xnlock_put_irqrestore(&nklock, s);
 

Note however that with xenomai, a signal received during nanosleep will trigger a switch to secondary mode. So, this usage is only possible for a real-time thread in exceptional conditions (to handle an error for instance), not when latency matters.

Signature · 1 line
                                                                Gilles.