Message-ID: <50749A03.9090607@xenomai.org> Date: Tue, 09 Oct 2012 23:41:23 +0200 From: Gilles Chanteperdrix MIME-Version: 1.0 References: <505EB99F.7050705@wanadoo.fr> <505EBD61.1050009@wanadoo.fr> <505F0D40.9030105@xenomai.org> <50741C5B.4060206@wanadoo.fr> <5074986C.8000509@xenomai.org> In-Reply-To: <5074986C.8000509@xenomai.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [Xenomai] Target frozen with rtcan_virt List-Id: Discussions about the Xenomai project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Thierry Bultel Cc: xenomai@xenomai.org On 10/09/2012 11:34 PM, Gilles Chanteperdrix wrote: > On 10/09/2012 02:45 PM, Thierry Bultel wrote: >> (snip) > >> (gdb) bt >> #0 __ticket_spin_lock (lock=) at >> /home/thierry/workspace/Buildroot/output/build/linux-3.2.21/arch/x86/include/asm/spinlock.h:63 >> #1 arch_spin_lock (lock=) at >> /home/thierry/workspace/Buildroot/output/build/linux-3.2.21/arch/x86/include/asm/spinlock.h:129 >> #2 rtcan_raw_recvmsg (context=0xc7ff0000, user_info=0xd00b2290, >> msg=0xd796df04, flags=) at >> drivers/xenomai/can/rtcan_raw.c:655 >> (snip) >> >> >> In my previous configuration, disabling CONFIG_SMP was enough to >> workaround it, but in that new case >> I have other bad side-effects (console and X server frozen at startup) >> that prevent me to work correctly. > > > That is essentially the same backtrace as in the first case. Could you > try the following patch? > > diff --git a/ksrc/drivers/can/rtcan_raw.c b/ksrc/drivers/can/rtcan_raw.c > index ded024e..b07f19c 100644 > --- a/ksrc/drivers/can/rtcan_raw.c > +++ b/ksrc/drivers/can/rtcan_raw.c > @@ -695,10 +695,7 @@ ssize_t rtcan_raw_recvmsg(struct rtdm_dev_context *context, > > /* Message completely read from the socket's ring buffer. Now check if > * caller is just peeking. */ > - if (flags & MSG_PEEK) > - /* Next one, please! */ > - rtdm_sem_up(&sock->recv_sem); > - else > + if ((flags & MSG_PEEK) == 0) > /* Adjust begin of first message in the ring buffer. */ > sock->recv_head = recv_buf_index; > > @@ -707,6 +704,11 @@ ssize_t rtcan_raw_recvmsg(struct rtdm_dev_context *context, > rtdm_lock_put_irqrestore(&rtcan_socket_lock, lock_ctx); > > > + if (flags & MSG_PEEK) > + /* Next one, please! */ > + rtdm_sem_up(&sock->recv_sem); > + > + > /* Create CAN socket address to give back */ > if (msg->msg_namelen) { > scan.can_family = AF_CAN; > > Another possible fix would be to lock xenomai scheduler when taking an rtdm_spin_lock, as it is almost always wrong to call xnpod_schedule in such a situation. It works for other RT-CAN drivers, because they call rtdm_sem_up from interrupt context where the scheduler is locked by the XNINIRQ bit. -- Gilles.