From: Philippe Gerum <rpm@xenomai.org>
To: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
Cc: Jan Kiszka <jan.kiszka@domain.hid>, xenomai@xenomai.org
Subject: Re: [Xenomai-help] rt_task_sleep_until question
Date: Thu, 17 Apr 2008 18:07:32 +0200 [thread overview]
Message-ID: <480775C4.2060302@domain.hid> (raw)
In-Reply-To: <2ff1a98a0804170846p2dddbea5k3b69dbbc57fb6761@domain.hid>
Gilles Chanteperdrix wrote:
> On Thu, Apr 17, 2008 at 5:30 PM, Gilles Chanteperdrix
> <gilles.chanteperdrix@xenomai.org> wrote:
>> On Thu, Apr 17, 2008 at 5:23 PM, Klaas Gadeyne <klaas.gadeyne@domain.hid> wrote:
>> >
>> > On Sat, 12 Apr 2008, Gilles Chanteperdrix wrote:
>> >
>> > > klaas.gadeyne@domain.hid wrote:
>> > > > > Klaas Gadeyne wrote:
>> > > > >> I've noticed that threads which, in my ignorant opinion, are supposed
>> > > > >> to be sleeping, get woken up much earlier than I expect them to be.
>> > > > >>
>> > > > >> Please find attached a modified version of the trivial-periodic.c
>> > > > >> application, which creates a RT_TASK that should sleep as long as
>> > > > >> possible (i.e. until unblocked by a signal handler). However, the
>> > > > >> task gets woken up much earlier (and many times) _before_ that time
>> > it
>> > > > >> seems.
>> > > > >>
>> > > > >> head /tmp/app.txt
>> > > > >> current_time = 1207928393295939429
>> > > > >> sleep until 18446744073709551615
>> > > > >> [TIMERLOOP] Total errors = 1, return code = -110
>> > > > >> current_time = 1207928393296000379
>> > > > >> sleep until 18446744073709551615
>> > > > >> [TIMERLOOP] Total errors = 2, return code = -110
>> > > > >> current_time = 1207928393296005409
>> > > > >> sleep until 18446744073709551615
>> > > > >> [TIMERLOOP] Total errors = 3, return code = -110
>> > > > >> current_time = 1207928393296009604
>> > > > >>
>> > > > >> What did I overlook here?
>> > > > >
>> > > > > Probably an overflow issue: (RTIME)~0 will be converted to TSCs, and
>> > if
>> > > > > your box runs at > 1GHZ, the result of this conversion will by
>> > something
>> > > > > < (RTIME)~0 due to the overflow. And this can result in an absolute
>> > > > > timeout date (in TSC units) before the current date -> ETIMEDOUT. Can
>> > > > > you confirm this?
>> > > >
>> > > > I have no linux box at hand, but I noticed that [*]
>> > > > xntimer_do_start_aperiodic() passes its xnticks_t interval argument
>> > (which
>> > > > is an unsigned long long) to xnarch_ns_to_tsc, and that one expects a
>> > > > (signed) long long.
>> > > >
>> > > > If I did not make any calculation errors (a very small chance...) in
>> > "my"
>> > > > case "interval" > LLONG_MAX so there's already an overflow there.
>> > >
>> > > The problem is that we can not change xnarch_ns_to_tsc to use
>> > > xnarch_ullimd instead of xnarch_llimd: xnarch_ns_to_tsc may be used to
>> > > convert negative differences. Anyway, I do not think there is an
>> > > overflow in llimd, otherwise you would get a processor exception, not a
>> > > silent truncation (at least on x86). To solve this issue, we should
>> > > probably switch to saturation arithmetic, but it would probably have a
>> > > huge impact on performance (and on code also, since we would have to use
>> > > xnarch_saturated_add(foo, bar) instead of foo + bar).
>> > >
>> >
>> > I see.
>> >
>> > I noticed that xnpod_suspend_thread offers the possibility to suspend
>> > a thread "indefinitely" (until unblocked) via the (in the 2.4.x API,
>> > that is)
>> >
>> > xnpod_suspend_thread(thread,XNDELAY,XN_INFINITE,XN_RELATIVE,NULL)
>> >
>> > call.
>> > However, since TM_INFINITE (and XN_INFINITE) are both defined as being
>> > zero, calls to rt_task_sleep(TM_INFINITE), are intercepted in the
>> > implementation of rt_task_sleep [1]. So in the latter case (which I
>> > would naively---i.e. without looking at API docs--- read as "sleep for
>> > an infinite amount of time), rt_task_sleep() returns *immediately*.
This behaviour is explicitly stated in the doc, though. So people should not be
surprised.
>> >
>> > Would it make sense to change the current behaviour of
>> > rt_task_sleep(TM_INFINITE) and call
>> > xnpod_suspend_thread(thread,XNDELAY,XN_INFINITE,XN_RELATIVE,NULL)
>> > instead of returning 0?
>> >
>> > One could either do that by
>> > - altering rt_task_sleep()'s behaviour (not returning zero if delay is
>> > zero)
>> > - redefining TM_INFINITE
No way. You don't want to change "magic" values that lightly. This is why they
are magic in the first place.
>> >
>> > Both changes might "break" existing applications however.
>> >
>> > Any thoughts?
>>
>> Well, I do not see how applications could find a useful use of the
>> "rt_task_sleep(0) returns 0 immediately" behaviour.
>
> Thinking more about it: there is a useful use, if the sleep duration
> is the result of rt_time_tsc2ns. Sleeping indefinitely would be a bit
> counter-intuitive.
>
Aside of this, the API has to be orthogonal, and having rt_task_sleep behave as
rt_task_suspend is also counter-intuitive. Think about applications doing tick
arithmetics to determine the remaining sleep time; at some point, they might
hang unexpectedly with delay == 0 == TM_INFINITE.
--
Philippe.
next prev parent reply other threads:[~2008-04-17 16:07 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-11 16:09 [Xenomai-help] rt_task_sleep_until question Klaas Gadeyne
2008-04-12 13:11 ` Jan Kiszka
2008-04-12 15:32 ` klaas.gadeyne
2008-04-12 16:01 ` Gilles Chanteperdrix
2008-04-17 15:23 ` Klaas Gadeyne
2008-04-17 15:30 ` Gilles Chanteperdrix
2008-04-17 15:46 ` Gilles Chanteperdrix
2008-04-17 16:07 ` Philippe Gerum [this message]
2008-04-17 16:39 ` Gilles Chanteperdrix
2008-04-22 13:45 ` Klaas Gadeyne
2008-04-22 13:49 ` Philippe Gerum
2008-04-22 14:25 ` Klaas Gadeyne
2008-04-22 20:56 ` Philippe Gerum
2008-04-23 11:27 ` Klaas Gadeyne
2008-04-23 11:37 ` Philippe Gerum
2008-04-23 12:53 ` Bosko Radivojevic
2008-04-23 17:43 ` Philippe Gerum
2008-08-01 23:07 ` [Xenomai-help] Recurring Interrupts Henry Bausley
2008-08-02 7:38 ` Philippe Gerum
2008-08-02 12:24 ` Philippe Gerum
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=480775C4.2060302@domain.hid \
--to=rpm@xenomai.org \
--cc=gilles.chanteperdrix@xenomai.org \
--cc=jan.kiszka@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.