All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@web.de>
To: Michael Haberler <haberlerm@gmail.com>, Steve B <sbattazzo@gmail.com>
Cc: xenomai <xenomai@xenomai.org>
Subject: Re: [Xenomai] RT-CAN question (was: CAN bus on beaglebone black)
Date: Fri, 20 Mar 2015 08:54:25 +0100	[thread overview]
Message-ID: <550BD231.5020002@web.de> (raw)
In-Reply-To: <CADvZd9ZGNcYTt4WNLPJRL+J+MgLpRPRZsyQ9MY4ammYh+7B5Rg@mail.gmail.com>

On 2015-03-20 08:26, Michael Haberler wrote:
>>>> As I understand it from a quick and simple question I recently asked of
>>>> the list, if you're using the RTDM driver then its interrupt will be among
>>>> the few things able to pre-empt your high priority Xenomai task (assuming
>>>> you have any running at the time). So if you really don't need the CAN bus
>>>> to be "rt-safe" then it may in some cases be better to have it set up with
>>>> the regular Linux driver so that the i-pipe doesn't prioritize it over your
>>>> RT tasks. That could also depend on how often you have frames coming in and
>>>> whether or not you have danger of overrunning the hardware receive buffer
>>>> if the interrupt service routine is neglected while your RT task is still
>>>> running.
>>>>
>>>> It could a bit tricky, though (modifications to the driver source), if
>>>> you wanted one CAN bus to be non-RT and one to be RT.
>>>>
>>>>
>>>> With the RTDM driver, I'm not sure if it uses a Xenomai system call to
>>>> open the socket (but I suspect that it may). If that's the case, then you
>>>> can open it from either a primary or secondary mode Xenomai thread, but
>>>> maybe not a regular Linux thread (i.e. a totally non-Xenomai application or
>>>> a thread opened with __real_pthread_create).
>>>>
>>>
>>> reading the rtcansend.c and rtcanrecv.c source, all the preliminaries
>>> (create socket, bind, ioctl etc) are done in a Linux thread. Only the read
>>> and write ops are done in an RT thread. Just to check, I added a command
>>> line option to do rt_dev_rec*/rt_dev_send* operations from a Linux thread,
>>> and that seems to block.
>>>
>>
>> correction: in this case rt_dev_send fails with EPERM
>>
>> This thread suggests it is not possible to call this function from a
>> non-Xenomai thread:
>> http://sourceforge.net/p/rtnet/mailman/message/19223387/
>>
>> someody else tried the same thing before, looks like he did not get an
>> answer: http://www.xenomai.org/pipermail/xenomai/2012-April/025744.html
>>
> 
> the reason for this is obviously the NULL definitions for recvmsg_nrt and
> sendmsg_nrt in lines 1017 and 1020 here:
> 
> https://git.xenomai.org/xenomai-2.6.git/tree/ksrc/drivers/can/rtcan_raw.c#n1017
> 
> To enable non-RT recvmsg/sendmsg, is it OK to just set the recvmsg_nrt and
> sendmsg_nrt pointers to rtcan_raw_recvmsg and rtcan_raw_sendmsg as is done
> for instance with rtcan_raw_ioctl?
> 
> Or am I violating some fundamental assumption?

You are: *_nrt handlers must not use any RTDM (or Xenomai) services
internally that may block the caller - because they will run over Linux
context. But that condition is clearly not fulfilled for blocking
recvmsg and probably also sendmsg (to sync on available CAN buffers etc.).

In general, if you have the need for some use cases to operate a piece
of hardware with an RT driver, all users of that hardware have to go
that path and at least have to be Xenomai threads - can also be SCHED_OTHER.

If you have a CAN adapter with multiple controllers that can be operated
separately, you may also use different drivers - if both (Linux and
RTDM) support to be attached only to a subset of controllers.

Jan


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: OpenPGP digital signature
URL: <http://www.xenomai.org/pipermail/xenomai/attachments/20150320/a167ca03/attachment.sig>

  reply	other threads:[~2015-03-20  7:54 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-19  9:57 [Xenomai] RT-CAN question (was: CAN bus on beaglebone black) Michael Haberler
2015-03-19 18:44 ` Steve B
2015-03-20  6:15   ` Michael Haberler
2015-03-20  6:58     ` Michael Haberler
2015-03-20  7:26       ` Michael Haberler
2015-03-20  7:54         ` Jan Kiszka [this message]
2015-03-20  8:02           ` Michael Haberler
2015-03-20 17:42             ` Steve B
2015-03-20 18:16               ` Gilles Chanteperdrix
2015-03-20 18:28                 ` Steve B
2015-03-20 18:39                   ` Gilles Chanteperdrix
2015-03-21  8:48                 ` Wolfgang Grandegger
2015-03-21  8:57 ` Wolfgang Grandegger
2015-03-21 14:56   ` Michael Haberler

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=550BD231.5020002@web.de \
    --to=jan.kiszka@web.de \
    --cc=haberlerm@gmail.com \
    --cc=sbattazzo@gmail.com \
    --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.