All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
To: Henri Roosen <henriroosen@gmail.com>
Cc: "Xenomai@xenomai.org" <xenomai@xenomai.org>
Subject: Re: [Xenomai] Rescnt imbalance in rtdm_mutex_timedlock
Date: Thu, 27 Mar 2014 00:07:06 +0100	[thread overview]
Message-ID: <53335D9A.9040902@xenomai.org> (raw)
In-Reply-To: <CANKLDmuMDpiUC7Z7dsXa5K3LYNA4LNwA7mhAicJ_Dey+2S9PCg@mail.gmail.com>

On 03/26/2014 05:49 PM, Henri Roosen wrote:
> On Tue, Mar 25, 2014 at 12:45 PM, Erwin Pranz <erwin.pranz@sigmatek.at>wrote:
> 
>> Hello,
>>
>> I am using rtdm_mutex_lock/rtdm_mutex_unlock in a rtdm driver and I get a
>> signal SIGDEBUG_MIGRATE_PRIOINV when I call the driver from a priority-0
>> thread.The signal is sent in xnsynch_release_thread when rescnt is 0 on a
>> XNOTHER thread, which means that rescnt is not balanced.
>>
>> I think the reason why rescnt is not balanced is in rtdm_mutex_timedlock:
>> when the owner of the mutex is NULL, the owner is changed to the calling
>> thread, but rescnt is not increased.
>>
>> I suggest the following fix in rtdm_mutex_timedlock:
>> -       else if (likely(xnsynch_owner(&mutex->synch_base) == NULL))
>> +       else if (likely(xnsynch_owner(&mutex->synch_base) == NULL)) {
>>                 xnsynch_set_owner(&mutex->synch_base, curr_thread);
>> +               if (xnthread_test_state(curr_thread, XNOTHER))
>> +                       xnthread_inc_rescnt(curr_thread);
>> +       }
>>
>>
> Hi Gilles,
> 
> Could you maybe elaborate on this? It seems the resource counting is not in
> balance. It would be great to know if this the correct way to fix it.
> 
> The problem should be easily reproducible by having just one shadowed
> priority 0 thread that somehow calls rtdm_mutex_lock directly followed by
> rtdm_mutex_unlock. This will trigger the code in ksrc/nucleus/synch.c that
> was added by commit-486afd15, which sends SIGDEBUG_MIGRATE_PRIOINV on
> Xenomai v2.6.2.1. It shouldn't send any signal in that case, as nothing is
> wrong.
> 
> Note we are on Xenomai v2.6.2.1. Xenomai v2.6.3 sends (the better name for
> it) SIGDEBUG_RESCNT_IMBALANCE.

To be completely frank, I expected Jan to answer this mail as this
concerns RTDM. Anyway, I had a look into it, and:
- the RTDM skin is not alone in this case, several skins implement the
same pattern (if owner == NULL, set owner, then return);
- adding calls to xnthread_inc_rescnt everywhere does not seem right, I
would prefer to move this inside some xnsynch_ service. The best
candidate I found for that is xnsynch_set_owner, though I am not sure if
this will work, especially with fastsynchs.


-- 
                                                                Gilles.


  reply	other threads:[~2014-03-26 23:07 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-25 11:45 [Xenomai] Rescnt imbalance in rtdm_mutex_timedlock Erwin Pranz
2014-03-26 16:49 ` Henri Roosen
2014-03-26 23:07   ` Gilles Chanteperdrix [this message]
2014-03-27  9:41     ` Philippe Gerum
2014-03-27 15:02       ` Henri Roosen
2014-03-27 16:26         ` Philippe Gerum
2014-03-27 18:04           ` Jan Kiszka
2014-03-27 18:24             ` Philippe Gerum
2014-03-27 18:31               ` Jan Kiszka
2014-03-27 18:39                 ` Gilles Chanteperdrix
2014-03-27 20:18                 ` Lowell Gilbert
2014-03-28  8:32                 ` Philippe Gerum
2014-03-27 18:35               ` Gilles Chanteperdrix
2014-03-28  9:52           ` Erwin Pranz
2014-03-28 10:14             ` Philippe Gerum
2014-03-28 11:14               ` Erwin Pranz

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=53335D9A.9040902@xenomai.org \
    --to=gilles.chanteperdrix@xenomai.org \
    --cc=henriroosen@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.