All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thierry Bultel <thierry.bultel@wanadoo.fr>
To: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai] Target frozen with rtcan_virt
Date: Wed, 10 Oct 2012 09:38:54 +0200	[thread overview]
Message-ID: <5075260E.2050402@wanadoo.fr> (raw)
In-Reply-To: <50749C71.2020100@xenomai.org>

Hi Gilles,

Many thanks,
The first patch does not work, the second does.
I think the reason for 1st patch why is that in rtcan_virt, we have

rtdm_lock_get_irqsave(&rtcan_recv_list_lock, lock_ctx);
rtdm_lock_get(&rtcan_socket_lock);

...
--->        rtcan_rcv(rx_dev, &skb);
....

rtdm_lock_put(&rtcan_socket_lock);
rtdm_lock_put_irqrestore(&rtcan_recv_list_lock, lock_ctx);

and rtcan_rcv->rtcan_rcv_deliver->rtdm_sem_up(&sock->recv_sem);

thus the same re-scheduling stuff with interrupts locked.

Are you not not afraid of side effects with the second patch, 
since you change the overall behaviour ?
Won't you prefer a only locally modified rtcan_virt ?

eg something (not tested) like:

    xnpod_lock_sched()
    rtdm_lock_get_irqsave(&rtcan_recv_list_lock, lock_ctx);
    rtdm_lock_get(&rtcan_socket_lock);

...

                rtcan_rcv(rx_dev, &skb);

....

    rtdm_lock_put(&rtcan_socket_lock);
    rtdm_lock_put_irqrestore(&rtcan_recv_list_lock, lock_ctx);
    xnpod_unlock_sched()

Cheers
Thierry


Le 09/10/2012 23:51, Gilles Chanteperdrix a écrit :
> On 10/09/2012 11:41 PM, Gilles Chanteperdrix wrote:
>
>> 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.
>>
>
> IOW, something like:
>
> diff --git a/include/rtdm/rtdm_driver.h b/include/rtdm/rtdm_driver.h
> index 68135e4..7b18c34 100644
> --- a/include/rtdm/rtdm_driver.h
> +++ b/include/rtdm/rtdm_driver.h
> @@ -730,6 +730,7 @@ typedef unsigned long rtdm_lockctx_t;
>  	do {							\
>  		XENO_BUGON(RTDM, !rthal_local_irq_disabled());	\
>  		rthal_spin_lock(lock);				\
> +		xnpod_lock_sched();				\
>  	} while (0)
>  #endif
>  
> @@ -749,7 +750,11 @@ typedef unsigned long rtdm_lockctx_t;
>   *
>   * Rescheduling: never.
>   */
> -#define rtdm_lock_put(lock)	rthal_spin_unlock(lock)
> +#define rtdm_lock_put(lock)					\
> +	do {							\
> +		rthal_spin_unlock(lock);			\
> +		xnpod_unlock_sched();				\
> +	} while (0)
>  
>  /**
>   * Acquire lock and disable preemption
> @@ -768,8 +773,11 @@ typedef unsigned long rtdm_lockctx_t;
>   *
>   * Rescheduling: never.
>   */
> -#define rtdm_lock_get_irqsave(lock, context)	\
> -	rthal_spin_lock_irqsave(lock, context)
> +#define rtdm_lock_get_irqsave(lock, context)				\
> +	do {								\
> +		rthal_spin_lock_irqsave(lock, context);			\
> +		xnpod_lock_sched();					\
> +	} while (0)
>  
>  /**
>   * Release lock and restore preemption state
> @@ -788,8 +796,12 @@ typedef unsigned long rtdm_lockctx_t;
>   *
>   * Rescheduling: possible.
>   */
> -#define rtdm_lock_put_irqrestore(lock, context)	\
> -	rthal_spin_unlock_irqrestore(lock, context)
> +#define rtdm_lock_put_irqrestore(lock, context)			\
> +	do {							\
> +		rthal_spin_unlock(lock);			\
> +		xnpod_unlock_sched();				\
> +		rthal_local_irq_restore(context);		\
> +	} while (0)
>  
>  /**
>   * Disable preemption locally
>
>
>



  reply	other threads:[~2012-10-10  7:38 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <505EB99F.7050705@wanadoo.fr>
2012-09-23  7:42 ` [Xenomai] Target frozen with rtcan_virt Thierry Bultel
2012-09-23 13:23   ` Gilles Chanteperdrix
2012-09-23 14:57     ` Thierry Bultel
2012-09-23 14:59       ` Gilles Chanteperdrix
2012-10-09 12:45     ` Thierry Bultel
2012-10-09 21:34       ` Gilles Chanteperdrix
2012-10-09 21:41         ` Gilles Chanteperdrix
2012-10-09 21:51           ` Gilles Chanteperdrix
2012-10-10  7:38             ` Thierry Bultel [this message]
2012-10-10  7:51               ` Gilles Chanteperdrix
2012-10-10  7:56                 ` Jan Kiszka
2012-10-10  8:04                   ` Gilles Chanteperdrix
2012-10-10  8:10                     ` Jan Kiszka
2012-10-10  8:58                       ` Gilles Chanteperdrix
2012-10-10  9:01                         ` Jan Kiszka
2012-10-10  9:23                           ` Gilles Chanteperdrix
2012-10-10 10:04                             ` Jan Kiszka
2012-10-10 10:07                               ` Gilles Chanteperdrix
2012-10-10 10:25                                 ` Jan Kiszka
2012-10-10 10:54                                   ` Philippe Gerum
2012-10-10 11:30                                     ` Gilles Chanteperdrix
2012-10-10 12:09                                       ` Philippe Gerum
2012-10-10 12:33                                         ` Gilles Chanteperdrix
2012-10-10 12:41                                           ` Philippe Gerum
2012-10-10 12:43                                             ` Philippe Gerum
2012-10-10 12:45                                               ` Philippe Gerum
2012-10-10 12:55                                             ` Gilles Chanteperdrix
2012-10-10 12:57                                               ` Philippe Gerum
2012-10-10 13:01                                                 ` Gilles Chanteperdrix
2012-10-10 13:09                                                   ` Philippe Gerum
2012-10-10 13:16                                                     ` Gilles Chanteperdrix
2012-10-10 13:18                                                       ` Philippe Gerum
2012-10-10 13:19                                                         ` Gilles Chanteperdrix
2012-10-10 13:57                                                           ` Philippe Gerum
2012-10-10 14:52                                                             ` Gilles Chanteperdrix
2012-10-11  8:05                                                             ` Gilles Chanteperdrix
2012-11-05 13:33                                                               ` Thierry Bultel
2012-11-05 18:46                                                                 ` Gilles Chanteperdrix
2012-11-06  7:22                                                                   ` Thierry Bultel
2012-11-06 11:59                                                                   ` Philippe Gerum
2012-11-06 14:49                                                                     ` Gilles Chanteperdrix
2012-10-10 13:17                                                     ` 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=5075260E.2050402@wanadoo.fr \
    --to=thierry.bultel@wanadoo.fr \
    --cc=gilles.chanteperdrix@xenomai.org \
    --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.