All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@domain.hid>
To: rpm@xenomai.org
Cc: xenomai-core <xenomai@xenomai.org>
Subject: Re: [Xenomai-core] [RFC][PATCH 2/3] Switch to handle-based fast	mutex owners
Date: Fri, 29 Aug 2008 14:40:08 +0200	[thread overview]
Message-ID: <48B7EE28.3070101@domain.hid> (raw)
In-Reply-To: <48B7EBEC.3050809@domain.hid>

Philippe Gerum wrote:
> Jan Kiszka wrote:
>> Philippe Gerum wrote:
>>> Gilles Chanteperdrix wrote:
>>>> Jan Kiszka wrote:
>>>>> Gilles Chanteperdrix wrote:
>>>>>> Jan Kiszka wrote:
>>>>>>> Gilles Chanteperdrix wrote:
>>>>>>>> Jan Kiszka wrote:
>>>>>>>>> Gilles Chanteperdrix wrote:
>>>>>>>>>> Philippe Gerum wrote:
>>>>>>>>>>> Gilles Chanteperdrix wrote:
>>>>>>>>>>>> Jan Kiszka wrote:
>>>>>>>>>>>>> Gilles Chanteperdrix wrote:
>>>>>>>>>>>>>> Jan Kiszka wrote:
>>>>>>>>>>>>> ...
>>>>>>>>>>>>>>> I think I'm getting closer to the issue. Our actual problem comes from
>>>>>>>>>>>>>>> the fact that the xnsynch_owner is easily out of sync with the real
>>>>>>>>>>>>>>> owner, it even sometimes points to a former owner:
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Thread A releases a mutex on which thread B pends. It wakes up B,
>>>>>>>>>>>>>>> causing it to become the new xnsynch owner, and clears the claimed bit
>>>>>>>>>>>>>>> as there are no further sleepers. B returns, and when it wants to
>>>>>>>>>>>>>>> release the mutex, it does this happily in user space because claimed is
>>>>>>>>>>>>>>> not set. Now the fast lock variable is 'unlocked', while xnsynch still
>>>>>>>>>>>>>>> reports B being the owner. This is no problem as the next time two
>>>>>>>>>>>>>>> threads fight over this lock the waiter will simply overwrite the
>>>>>>>>>>>>>>> xnsynch_owner before it falls asleep. But this "trick" doesn't work for
>>>>>>>>>>>>>>> waiters that have been robbed. They will spin inside xnsynch_sleep_on
>>>>>>>>>>>>>>> and stumble over this inconsistency.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> I have two approaches in mind now: First one is something like
>>>>>>>>>>>>>>> XNSYNCH_STEALNOINFORM, i.e. causing xnsynch_sleep_on to not set XNROBBED
>>>>>>>>>>>>>>> so that the robbed thread spins one level higher in the skin code -
>>>>>>>>>>>>>>> which would have to be extended a bit.
>>>>>>>>>>>>>> No, the stealing is the xnsynch job.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Option two is to clear xnsynch_owner once a new owner is about to return
>>>>>>>>>>>>>>> from kernel with the lock held while there are no more xnsynch_sleepers.
>>>>>>>>>>>>>>> That should work with even less changes and save us one syscall in the
>>>>>>>>>>>>>>> robbed case. Need to think about it more, though.
>>>>>>>>>>>>>> In fact the only time when the owner is required to be in sync is when
>>>>>>>>>>>>>> PIP occurs, and this is guaranteed to work, because when PIP is needed a
>>>>>>>>>>>>>> syscall is emitted anyway. To the extent that xnsynch does not even
>>>>>>>>>>>>>> track the owner on non PIP synch (which is why the posix skin originally
>>>>>>>>>>>>>>  forcibly set the synch owner, and it was simply kept to get the fastsem
>>>>>>>>>>>>>> stuff working).
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Ok. And what about the idea of the xnsynch bit to tell him "hey, the
>>>>>>>>>>>>>> owner is tracked in the upper layer, go there to find it".
>>>>>>>>>>>>> I'm yet having difficulties to imagine how this should look like when
>>>>>>>>>>>>> it's implemented. Would it be simpler than my second idea?
>>>>>>>>>>>>>
>>>>>>>>>>>>> Anyway, here is a patch (on top of my handle-based lock series) for the
>>>>>>>>>>>>> approach that clears xnsynch_owner when there are no waiters. At least
>>>>>>>>>>>>> it causes no regression based on your test, but I haven't checked lock
>>>>>>>>>>>>> stealing yet. In theory, everything still appears to be fine to me. This
>>>>>>>>>>>>> approach basically restores the state we find when some thread just
>>>>>>>>>>>>> acquired the lock in user space.
>>>>>>>>>>>> Yes, I did not think about the stealing when writing my test, but I
>>>>>>>>>>>> think it could be a good idea to add it to the test, especially if you
>>>>>>>>>>>> want to port the test to the native API.
>>>>>>>>>>>>
>>>>>>>>>>>> I let Philippe decide here. He is the one who did the stealing stuff and
>>>>>>>>>>>> probably knows better.
>>>>>>>>>>>>
>>>>>>>>>>> Currently, the xnsynch strongly couples PIP and ownership, which seems to impede
>>>>>>>>>>> your various proposals. I would suggest to decouple that: the basic property of
>>>>>>>>>>> some xnsynch that we may want to handle is exclusiveness, then dynamic priority
>>>>>>>>>>> inheritance is another property, that could stack its own semantics on top of
>>>>>>>>>>> exclusiveness.
>>>>>>>>>>>
>>>>>>>>>>> XNSYNCH_EXCLUSIVE would cover all ownership-related actions, XNSYNCH_PIP would
>>>>>>>>>>> simply add dynamic priority management. Non exclusive object would not require
>>>>>>>>>>> any xnsynch_set_owner() handling.
>>>>>>>>>>>
>>>>>>>>>>> Just to give a clear signal here: I will happily consider any change to the
>>>>>>>>>>> xnsynch object that may ease the implementation of fast ownership handling (i.e.
>>>>>>>>>>> userland-to-userland transfer). The only thing is that such code is very much
>>>>>>>>>>> prone to regressions, so a testsuite must come with core changes in that area,
>>>>>>>>>>> but I guess you know that already.
>>>>>>>>>> Ok. I think unit_mutex.c is a good start. It only lacks testing
>>>>>>>>>> XNROBBED.
>>>>>>>>> My colleague sent me an extension. It's native-only so far, but it
>>>>>>>>> already pointed out a bug in my try-acquire implementation that should
>>>>>>>>> be present in posix as well (trylock must go through the slow path).
>>>>>>>> I do not see why. If mutex lock can lock without a syscall, the same
>>>>>>>> goes for trylock.
>>>>>>> Lock stealing requires the slow path.
>>>>>> Ah ok. I thought you mean that trylock had to go systematically through
>>>>>> syscall.
>>>>>>
>>>>>> As for lock stealing, I already said that it was not tested in the
>>>>>> current test.
>>>>> In fact, that bug is also present the current native skin (SVN, 2.4.x
>>>>> should suffer as well). Probably also current 2.4.x posix is affected,
>>>>> at least from a first glance.
>>>> Well, yes, now that you mention it, calling xnsynch_sleep_on does not
>>>> seem obvious for the implementation of a trylock.
>>>>
>>> Don't even try calling xnsynch_sleep_on with a nonblocking-type timeout.
>> Works nicely today (using (XN_NONBLOCK, XN_RELATIVE)) due to early
>> timeout checks in xntimer_start. You just have to translate XNTIMEO into
>> EWOULDBLOCK on return.
>>
> 
> It's very fundamentally crappy. Please don't do that. xnsynch_sleep_on() must do
> what it is supposed to mean.

So we need xnsynch_try_to_steal + lots of new special-case code in the
skins to re-implement what is already there? No, I can't imagine that
this is what you want to see in the end.

Then lets better rename xnsynch_sleep_on to something like
xnsynch_acquire - will be logically needed anyway when we push fast
mutex maintenance into it.

Jan

-- 
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux


  reply	other threads:[~2008-08-29 12:40 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-27 13:39 [Xenomai-core] [RFC][PATCH 0/3] Handle-based fast mutex owner tracking Jan Kiszka
2008-08-27 13:42 ` [Xenomai-core] [RFC][PATCH 1/3] Always register threads by their base Jan Kiszka
2008-08-27 14:06 ` [Xenomai-core] [RFC][PATCH 2/3] Switch to handle-based fast mutex owners Jan Kiszka
2008-08-27 14:14   ` Gilles Chanteperdrix
2008-08-27 14:38     ` Jan Kiszka
2008-08-27 14:44       ` Gilles Chanteperdrix
2008-08-27 14:49         ` Jan Kiszka
2008-08-27 14:57           ` Gilles Chanteperdrix
2008-08-27 23:49           ` Gilles Chanteperdrix
2008-08-27 14:36   ` Gilles Chanteperdrix
2008-08-27 14:45     ` Jan Kiszka
2008-08-27 14:47       ` Gilles Chanteperdrix
2008-08-27 14:51         ` Jan Kiszka
2008-08-27 14:55           ` Gilles Chanteperdrix
2008-08-27 15:00             ` Jan Kiszka
2008-08-27 15:04               ` Gilles Chanteperdrix
2008-08-27 15:10                 ` Jan Kiszka
2008-08-27 15:13                   ` Gilles Chanteperdrix
2008-08-27 15:15                   ` Gilles Chanteperdrix
2008-08-27 15:18                     ` Jan Kiszka
2008-08-27 15:29                       ` Gilles Chanteperdrix
2008-08-27 15:34                         ` Jan Kiszka
2008-08-27 15:36                           ` Gilles Chanteperdrix
2008-08-27 15:37                             ` Jan Kiszka
2008-08-27 23:44                               ` Gilles Chanteperdrix
2008-08-27 14:48       ` Gilles Chanteperdrix
2008-08-27 14:50       ` Gilles Chanteperdrix
2008-08-27 15:20     ` Jan Kiszka
2008-08-27 15:28       ` Gilles Chanteperdrix
2008-08-27 15:43         ` Jan Kiszka
2008-08-27 15:46           ` Gilles Chanteperdrix
2008-08-27 16:08             ` Jan Kiszka
2008-08-27 16:13               ` Gilles Chanteperdrix
2008-08-27 18:15                 ` Jan Kiszka
2008-08-27 19:02                   ` Gilles Chanteperdrix
2008-08-27 19:04                     ` Gilles Chanteperdrix
2008-08-27 20:35                       ` Jan Kiszka
2008-08-27 21:26                         ` Gilles Chanteperdrix
2008-08-27 21:46                           ` Jan Kiszka
2008-08-27 21:55                             ` Gilles Chanteperdrix
2008-08-27 20:33                     ` Jan Kiszka
2008-08-27 22:45                       ` Gilles Chanteperdrix
2008-08-28 10:01                         ` Philippe Gerum
2008-08-28 10:37                           ` Jan Kiszka
2008-08-28 10:52                             ` Philippe Gerum
2008-08-28 12:21                           ` Gilles Chanteperdrix
2008-08-29  6:41                             ` Jan Kiszka
2008-08-29  7:00                               ` Gilles Chanteperdrix
2008-08-29  7:22                                 ` Jan Kiszka
2008-08-29  7:29                                   ` Gilles Chanteperdrix
2008-08-29  9:36                                     ` Jan Kiszka
2008-08-29  9:41                                       ` Gilles Chanteperdrix
2008-08-29 10:37                                         ` Jan Kiszka
2008-08-29 12:19                                           ` Gilles Chanteperdrix
2008-08-29 10:39                                         ` Philippe Gerum
2008-08-29 10:46                                           ` Jan Kiszka
2008-08-29 12:30                                             ` Philippe Gerum
2008-08-29 12:40                                               ` Jan Kiszka [this message]
2008-08-29 13:10                                                 ` Philippe Gerum
2008-08-29 13:25                                                   ` Jan Kiszka
2008-08-27 23:05                       ` Gilles Chanteperdrix
2008-08-28  7:29                         ` Jan Kiszka
2008-08-28  7:38                           ` Gilles Chanteperdrix
2008-08-27 23:14                       ` Gilles Chanteperdrix
2008-08-28  7:30                         ` Jan Kiszka
2008-08-28  8:20                           ` Gilles Chanteperdrix
2008-08-28  9:21                             ` Jan Kiszka
2008-08-27 14:08 ` [Xenomai-core] [RFC][PATCH 3/3] Remove xnarch_atomic_intptr wrappers 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=48B7EE28.3070101@domain.hid \
    --to=jan.kiszka@domain.hid \
    --cc=rpm@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.