From: Philippe Gerum <rpm@xenomai.org>
To: "Ignacio García Pérez" <iggarpe@domain.hid>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-help] timeout in native API calls (cond, sem, mutex, etc).
Date: Fri, 21 Oct 2005 18:39:36 +0200 [thread overview]
Message-ID: <435919C8.6080906@domain.hid> (raw)
In-Reply-To: <4358C829.5050304@domain.hid>
Ignacio García Pérez wrote:
> Ok, so I took the time to delve a bit into the xenomai code to check out
> by myself how complex would it be to implement absolute timeouts. This
> is from a 1 hour walk around the code, so I'll post my thoughts so those
> truly knowledgeable can correct me.
>
> (BTW, here goes another praise: nice, readable, structured,
> understandable code, you know what's my reference for comparison)
>
> All synchronization primitive's blocking calls that take a timeout end
> up using
>
> xnsync_sleep_on()
>
> to suspend (delay, actually) the current thread. That function takes a
> relative timeout, just as passed to the blocking synchronization
> primitive call. After some magic, xsync_sleep_on() ends up calling
>
> xnpod_suspend_thread()
>
> again passign the timeout as a relative value. Eventually, the timeout
> is again passed in a call to:
>
> xntimer_start()
>
> which in turn calls xntimer_do_start_periodic() or
> xntimer_do_start_aperiodic() depending on the current timer operation
> mode. In xntimer_do_start_(a)periodic(), one can see, finally how the
> wakeup time (xntimer_t.date) is calculated from the current time and the
> requested sleep interval.
>
> So, we timeout trail is:
>
> rt_mutex_lock() --> xsync_sleep_on() ---> xnpod_suspend_thread() --->
> xntimer_start() ---> xntimer_do_start_(a)periodic()
>
> And my assumption that internally the scheduler works with absolute
> timeouts for delayed threads is true.
>
Yes.
> Now suppose that I want to implement absolute timeouts. There are two
> alternatives:
>
> 1- Write an absolute timeout alter ego of every "public" function in the
> native skin AND in the nucleus, except maybe for
> xntimer_do_start_(a)periodic.
>
> 2- Add a parmeter to every "public" function in the native skin AND in
> the nucleus which specifies if the timeout is absolute or relative.
>
> 3- Write an absolute timeout alter ego of every synchronization call in
> the native skin, and add a parameter in the nucleus calls to specify
> absolute/relative timeout.
>
> 4- Rewrite all functions that use a relatime timeout to use an absolute
> timeout.
>
> (1) Would mean copy&paste of code. Definitely a no-no.
>
Indeed.
> (2) Is very easy to implement. One downside is that, for example, the
> locking of a mutex requires three parameters when most of the time one
> would do (just the mutex). Another important downside is that it breaks
> the API of applications written over the native API.
>
No-go.
> (3) Best IMHO. Would keep the native API intact while providing all the
> absolute/relatime timeout flexibility in the nucleus.
>
Again, the nucleus internals are not the issue here. Actually, Xenomai 1.x
worked with both rel/abs timing modes on demand; the feature was removed because
no clear sign of usefulness went backing the decision to keep this duality at
that time. So let's keep this aside, there would be no problem adding the
feature at this level.
The real issue is only about extending the absolute timeout support to _all_
blocking primitives from the native API, or only to a single one for which there
exists a clear POSIX counterpart (i.e. rt_cond_wait -> pthread_cond_timedwait).
I'd like we focus on this issue instead. IOW, would rt_sem_p_abs() or
rt_queue_recv_abs() be of any use?
> (4) Worst IMHO. Would break the whole API, would be a nightmare to
> debug. However, I have to point out that this would probably have been
> my initial design choice. Work always with absolute timeouts, if the
> user wants a relative timeout, he should calculate it from current time.
> I cannot imagine a situation in which a preemption in between getting
> current time and issuing the blocking call would be undesirable. I'll
> explain:
>
> With the relatime timeout API, if I want this thread to wake up at
> t=1000, I must calculate delay as d = 1000 - current_time and then call
> rt_sem_p (or whatever). If the thread is preempted between getting
> current time and calling rt_sem_p, it will sleep for longer than desired
> and will end up waking up after t=1000, which is what I wanted exactly.
>
> In the absolute timeout scenatio, suppose that I want this thread to
> wake up in 100 ns. In 100 ns since when?... since current time?... then
> use the absolute timeout and you're done. Since some other operation
> like setting a digital output?, then there is anyway nothing you can do
> to prevent the possibility of being preempted in between the I/O
> operation and the actual rt_sem_p call, so why worry about that
> preemption happening in between getting current time and issuing the call?
>
In any case, changing the semantics of existing calls now is the last thing we
should do.
> Nacho.
>
> P.S: Not to be a purist, but I think that functions like
> xntimer_do_start_aperiodic and xntimer_do_start_periodic should be
> declared static, since they are only to be accessed through their
> pointers in the nktimer structure.
>
Indeed, they should.
> P.S: As a side note, wouldn't be a good practice to expand tabs to
> spaces in all the code?
>
> _______________________________________________
> Xenomai-help mailing list
> Xenomai-help@domain.hid
> https://mail.gna.org/listinfo/xenomai-help
>
--
Philippe.
next prev parent reply other threads:[~2005-10-21 16:39 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-10-20 16:20 [Xenomai-help] timeout in native API calls (cond, sem, mutex, etc) Ignacio García Pérez
2005-10-20 16:46 ` Jan Kiszka
2005-10-20 17:09 ` Ignacio García Pérez
2005-10-20 17:33 ` Jan Kiszka
2005-10-20 18:18 ` Philippe Gerum
2005-10-20 18:16 ` Philippe Gerum
2005-10-21 7:20 ` Ignacio García Pérez
2005-10-21 10:29 ` Philippe Gerum
2005-10-21 12:02 ` Ignacio García Pérez
2005-10-21 10:51 ` Ignacio García Pérez
2005-10-21 12:23 ` Jan Kiszka
2005-10-21 14:46 ` Ignacio García Pérez
2005-10-21 16:45 ` Philippe Gerum
2005-10-21 16:39 ` Philippe Gerum [this message]
2005-10-21 18:55 ` Ignacio García Pérez
2005-10-21 10:52 ` Ignacio García Pérez
2005-10-21 12:16 ` Jan Kiszka
2005-10-21 14:40 ` Ignacio García Pérez
2005-10-21 16:42 ` 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=435919C8.6080906@domain.hid \
--to=rpm@xenomai.org \
--cc=iggarpe@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.