All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@domain.hid>
To: gilles.chanteperdrix@xenomai.org
Cc: xenomai-core <xenomai@xenomai.org>
Subject: Re: [Xenomai-core] [RFC][PATCH 2/3] Switch to handle-based fast mutex owners
Date: Wed, 27 Aug 2008 16:45:10 +0200	[thread overview]
Message-ID: <48B56876.3090601@domain.hid> (raw)
In-Reply-To: <48B56685.4060500@domain.hid>

Gilles Chanteperdrix wrote:
> Jan Kiszka wrote:
> 
>> -#define test_claimed(owner) ((long) (owner) & 1)
>> -#define clear_claimed(owner) ((xnthread_t *) ((long) (owner) & ~1))
>> -#define set_claimed(owner, bit) \
>> -        ((xnthread_t *) ((long) clear_claimed(owner) | !!(bit)))
>> +#define __CLAIMED_BIT		XN_HANDLE_SPARE3
>> +
>> +#define test_claimed(owner)	xnhandle_test_spare(owner, __CLAIMED_BIT)
>> +#define clear_claimed(owner)	xnhandle_mask_spare(owner)
>> +#define set_claimed(owner, bit) ({ \
>> +	xnhandle_t __tmp = xnhandle_mask_spare(owner); \
>> +	if (bit) \
>> +		xnhandle_set_spare(__tmp, __CLAIMED_BIT); \
>> +	__tmp; \
>> +})
> 
> I liked doing this with no conditional.

You mean let the caller pass 'bit' as 0 or __CLAIMED_BIT (the latter
would require some renaming then, I guess)?

> 
>> +	xnarch_atomic_set(mutex->owner,
>> +		 	  set_claimed(xnthread_handle(owner),
>> +				      xnsynch_nsleepers(&mutex->synchbase)));
> 
> Ok. I think you have spotted a bug here. This should be mutex->sleepers
> instead of xnsynch_nsleepers.

OK. Will you fix? I will rebase then.

> 
>> +	/* Consistency check for owner handle - is the object a thread? */
>> +	if (unlikely(xnthread_handle(owner) != clear_claimed(ownerh))) {
>> +		err = -EINVAL;
>> +		goto error;
>>  	}
> 
> What is this ?

This ensures that we are not dereferences some arbitrary registry object
due to a borken handle in the mutex variable: The the object registered
on this handle is an xnthread, we will find the very same handle value
at the well-known place in the object. Kind of magic for xnthread
objects (instead of adding a magic field to them).

> 
> 
>> Index: b/ksrc/skins/posix/thread.c
>> ===================================================================
>> --- a/ksrc/skins/posix/thread.c
>> +++ b/ksrc/skins/posix/thread.c
>> @@ -28,6 +28,7 @@
>>   * 
>>   *@{*/
>>  
>> +#include <nucleus/registry.h>
>>  #include <posix/thread.h>
>>  #include <posix/cancel.h>
>>  #include <posix/timer.h>
>> @@ -229,6 +230,13 @@ int pthread_create(pthread_t *tid,
>>  	appendq(thread->container, &thread->link);
>>  	xnlock_put_irqrestore(&nklock, s);
>>  
>> +#ifdef CONFIG_XENO_OPT_REGISTRY
>> +	/* We need an anonymous registry entry to obtain a handle for fast
>> +	   mutex locking. */
>> +	xnregistry_enter("", &thread->threadbase,
>> +			 &xnthread_handle(&thread->threadbase), NULL);
>> +#endif /* CONFIG_XENO_OPT_REGISTRY */
>> +
> 
> Since we need this for all threads (I want a thread from any skin to be
> able to use the posix skin mutexes), why doing it in the skin ?

Some skins register their threads unconditionally, some based on names,
some not at all. The "not at all" case has to be fixed, but we need to
respect the other two as well.

Jan

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


  reply	other threads:[~2008-08-27 14:45 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 [this message]
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
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=48B56876.3090601@domain.hid \
    --to=jan.kiszka@domain.hid \
    --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.