All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@domain.hid>
To: Maciek Godek <pstrychuj@domain.hid>
Cc: xenomai-help <xenomai@xenomai.org>
Subject: Re: [Xenomai-help] Getting mutex state/rt <-> non-rt communication
Date: Thu, 17 May 2007 11:02:40 +0200	[thread overview]
Message-ID: <464C1A30.6060306@domain.hid> (raw)
In-Reply-To: <e2ceda030705161103xf625855w3ff98016770ec37@domain.hid>

[-- Attachment #1: Type: text/plain, Size: 3229 bytes --]

Maciek Godek wrote:
> 2007/5/16, Jan Kiszka <jan.kiszka@domain.hid>:
>> Maciek Godek wrote:
>> > Hi,
>> > is it obligatory to use the rt_mutex_inquire in order to get the mutex
>> > state, or could I possibly use the field lockcnt from struct RT_MUTEX
>> > directly? (the test should be, as I believe, atomic - so should I
>> > worry?)
>>
>> UAAAH!!! Don't do this, never!
> 
> Oh, calm down, I was just joking :D

You wouldn't bet how much code if this kind is out there - in "real" use...

> 
>> Locking a mutex means more, e.g. assigning a _schedulable_ Xenomai
>> thread as owner so that one can raise its priority if a higher thread
>> contents for the same lock. It also means blocking if the mutex is
>> currently locked, also requiring Xenomai thread context.
> 
> OK. But! here I think the situation is straightforward - there is only
> one xenomai thread and one non-rt thread. There is only one claimant
> to the mutex and I can tell for sure that there won't be any more.

"Nothing can happen, I'm running this on UP, there will _never_ be any
second CPU." Kind of famous last words. It's simply weak design, and you
can count on someone not reading the instruction manual that defines
this restricted environment.

> 
>> > The thing is that I'm using mutices for IPC between an rt-task and a
>> > regular linux process. The rt code is critical, but in the
>> > non-realtime code I can pay the cost of low latency polling to find
>> > out if the realtime code has finished. (Perhaps there is a better way
>> > to do it? The code now looks like this:
>> >
>> > RT_MUTEX busy;
>> > RT_COND data_ready;
>> > // both are initialized (elsewhere)
>> >
>> > void realtime_thread(void *) {
>> >   rt_mutex_acquire(&busy, 0);
>> >   for(;;) {
>> >     rt_cond_wait(&data_ready, &busy, TM_INFINITE);
>> >     // here it does something critical - it actually communicates
>> >     // with an external device over serial port using the famous rtdm
>> >     // serial driver developed and maintained by Jan Kiszka.
>> >   }
>> > }
>> >  ...
>> > // there is only one thread that communicates with the realtime
>> > // thread above - and this code is invoked within it.
>> > rt_cond_signal(&data_ready);
>> > // now the rt-thread does something. I can estimate the upper time
>> limit
>> > // of the one iteration of that task.
>> > usleep(predicted_time);
>> > if(busy.lockcnt) {
>> >   // timeout - this is possible as it depends on the external
>> devices. Of course
>> >   // sooner or later the mutex will be released by the rt thread.
>> > }
>> >
>> > is there any wiser way to communicate these threads?)
>>
>> Kernel or user space?
> 
> User space (I wouldn't dare to call usleep from kernel)
> (the solution for the kernel space would also be quite interresting,
> though)

In user space, you can simply map the non-rt mutex locker on a Xenomai
thread of priority 0. That means it will be scheduled with SCHED_OTHER
in Linux mode and at lowest RT prio when holding the mutex (unless it
undergoes prio inheritance). Kernel space would have been tricky as
there are no shadow threads to move between both worlds.

Jan


PS: Reply-to-all...


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 249 bytes --]

  parent reply	other threads:[~2007-05-17  9:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-16 16:53 [Xenomai-help] Getting mutex state/rt <-> non-rt communication Maciek Godek
2007-05-16 17:13 ` Jan Kiszka
     [not found]   ` <e2ceda030705161103xf625855w3ff98016770ec37@domain.hid>
2007-05-17  9:02     ` Jan Kiszka [this message]
2007-05-21 14:38       ` Maciek Godek
2007-05-21 16:58         ` Jan Kiszka

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=464C1A30.6060306@domain.hid \
    --to=jan.kiszka@domain.hid \
    --cc=pstrychuj@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.