* [Xenomai] Function to get state of lock variable
@ 2015-08-18 12:14 Wolfgang Netbal
2015-08-18 12:48 ` Gilles Chanteperdrix
2015-08-24 7:36 ` Jan Kiszka
0 siblings, 2 replies; 5+ messages in thread
From: Wolfgang Netbal @ 2015-08-18 12:14 UTC (permalink / raw)
To: Xenomai Mailing List
Hi All,
is there a function te returns true or false if a rtdm_lock_t variable
is set ?
What I have to do is to check in an interrupt routine if the list is
locked,
if this is the case I leave the interrupt handler befor accessing the list.
I use the following code to lock the add and replace of list elements.
static rtdm_lock_t opendev_list_lock;
static int open(struct rtdm_dev_context *context, rtdm_user_info_t *
user_info, int oflags)
{
lrtdrv_context_t *ctx = (lrtdrv_context_t *) context->dev_private;
rtdm_lockctx_t s;
....
rtdm_lock_get_irqsave(&opendev_list_lock, s);
list_add_tail(&ctx->opendev_entry, &lrtdrv_opendev_list);
rtdm_lock_put_irqrestore(&opendev_list_lock, s);
return 0;
}
Kind regards
--
Wolfgang Netbal
Softwareentwicklung
________________________________
SIGMATEK GmbH & Co KG
Sigmatekstraße 1
5112 Lamprechtshausen
Österreich / Austria
Tel.: +43/6274/4321-0
Fax: +43/6274/4321-300
E-Mail: wolfgang.netbal@sigmatek.at
http://www.sigmatek-automation.at
****************************Please note: ****************************
This email and all attachments are confidential and intended solely
for the person or entity to whom it is addressed. If you are not the
named addressee you must not make this email and all attachments
accessible to any other person. If you have received this email in
error please delete it together with all attachments.
*********************************************************************
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [Xenomai] Function to get state of lock variable 2015-08-18 12:14 [Xenomai] Function to get state of lock variable Wolfgang Netbal @ 2015-08-18 12:48 ` Gilles Chanteperdrix 2015-08-18 13:29 ` Wolfgang Netbal 2015-08-24 7:36 ` Jan Kiszka 1 sibling, 1 reply; 5+ messages in thread From: Gilles Chanteperdrix @ 2015-08-18 12:48 UTC (permalink / raw) To: Wolfgang Netbal; +Cc: Xenomai Mailing List On Tue, Aug 18, 2015 at 02:14:26PM +0200, Wolfgang Netbal wrote: > Hi All, > > is there a function te returns true or false if a rtdm_lock_t variable is > set ? > What I have to do is to check in an interrupt routine if the list is > locked, > if this is the case I leave the interrupt handler befor accessing the list. > > I use the following code to lock the add and replace of list elements. > > static rtdm_lock_t opendev_list_lock; > static int open(struct rtdm_dev_context *context, rtdm_user_info_t * > user_info, int oflags) > { > lrtdrv_context_t *ctx = (lrtdrv_context_t *) context->dev_private; > rtdm_lockctx_t s; > > .... > > rtdm_lock_get_irqsave(&opendev_list_lock, s); > list_add_tail(&ctx->opendev_entry, &lrtdrv_opendev_list); > rtdm_lock_put_irqrestore(&opendev_list_lock, s); Well, if you are not running on a multiprocessor system, you can not take interrupt during that section. And on a multiprocessor system, the time this code will hold the lock is very short, so, it should not be a problem for an interrupt one core to spin while another core is holding the lock. But we can probably add rtdm_lock_is_locked, yes. -- Gilles. https://click-hack.org ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Xenomai] Function to get state of lock variable 2015-08-18 12:48 ` Gilles Chanteperdrix @ 2015-08-18 13:29 ` Wolfgang Netbal 2015-08-18 20:34 ` Gilles Chanteperdrix 0 siblings, 1 reply; 5+ messages in thread From: Wolfgang Netbal @ 2015-08-18 13:29 UTC (permalink / raw) To: gilles.chanteperdrix; +Cc: Xenomai Mailing List Am 2015-08-18 um 14:48 schrieb Gilles Chanteperdrix: > On Tue, Aug 18, 2015 at 02:14:26PM +0200, Wolfgang Netbal wrote: >> Hi All, >> >> is there a function te returns true or false if a rtdm_lock_t variable is >> set ? >> What I have to do is to check in an interrupt routine if the list is >> locked, >> if this is the case I leave the interrupt handler befor accessing the list. >> >> I use the following code to lock the add and replace of list elements. >> >> static rtdm_lock_t opendev_list_lock; >> static int open(struct rtdm_dev_context *context, rtdm_user_info_t * >> user_info, int oflags) >> { >> lrtdrv_context_t *ctx = (lrtdrv_context_t *) context->dev_private; >> rtdm_lockctx_t s; >> >> .... >> >> rtdm_lock_get_irqsave(&opendev_list_lock, s); >> list_add_tail(&ctx->opendev_entry, &lrtdrv_opendev_list); >> rtdm_lock_put_irqrestore(&opendev_list_lock, s); > Well, if you are not running on a multiprocessor system, you can not > take interrupt during that section. > > And on a multiprocessor system, the time this code will hold the > lock is very short, so, it should not be a problem for an interrupt > one core to spin while another core is holding the lock. > > But we can probably add rtdm_lock_is_locked, yes. > I'm working on a multiprocessor system and when I boot the system between 200 and 1000 times I get one error, because the add and remove from the list will be done on boot. I tried to add a function rtdm_lock_is_locked but the thing is that the variables in struct arch_spinlock_t are different for different architectures, for example on ARM it is "u32 slock" and on x86 it is "__ticketpair_t head_tail". If you have a hint for me which element of struct rtdm_lock_t I have to use to check if the list is locked I can add this on my own. If you think this the function rtdm_lock_is_locked should be added it would be great if you can add it for Xenomai 2.6.4 as well. Right now I use the following code to check this. static rtdm_lock_t* gListLocked = NULL; static int open(struct rtdm_dev_context *context, rtdm_user_info_t * user_info, int oflags) { lrtdrv_context_t *ctx = (lrtdrv_context_t *) context->dev_private; gListLocked = &opendev_list_lock; rtdm_lock_get_irqsave(gListLocked, s); list_add_tail(&ctx->opendev_entry, &lrtdrv_opendev_list); rtdm_lock_put_irqrestore(gListLocked, s); gListLocked = NULL; } int lrtdrv_is_opendev_list_locked(void) { int ret = 0; if(gListLocked != NULL) ret = 1; return ret; } Kind regards Wolfgang ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Xenomai] Function to get state of lock variable 2015-08-18 13:29 ` Wolfgang Netbal @ 2015-08-18 20:34 ` Gilles Chanteperdrix 0 siblings, 0 replies; 5+ messages in thread From: Gilles Chanteperdrix @ 2015-08-18 20:34 UTC (permalink / raw) To: Wolfgang Netbal; +Cc: Xenomai Mailing List On Tue, Aug 18, 2015 at 03:29:26PM +0200, Wolfgang Netbal wrote: > > > Am 2015-08-18 um 14:48 schrieb Gilles Chanteperdrix: > >On Tue, Aug 18, 2015 at 02:14:26PM +0200, Wolfgang Netbal wrote: > >>Hi All, > >> > >>is there a function te returns true or false if a rtdm_lock_t variable is > >>set ? > >>What I have to do is to check in an interrupt routine if the list is > >>locked, > >>if this is the case I leave the interrupt handler befor accessing the list. > >> > >>I use the following code to lock the add and replace of list elements. > >> > >>static rtdm_lock_t opendev_list_lock; > >>static int open(struct rtdm_dev_context *context, rtdm_user_info_t * > >>user_info, int oflags) > >>{ > >> lrtdrv_context_t *ctx = (lrtdrv_context_t *) context->dev_private; > >> rtdm_lockctx_t s; > >> > >>.... > >> > >> rtdm_lock_get_irqsave(&opendev_list_lock, s); > >> list_add_tail(&ctx->opendev_entry, &lrtdrv_opendev_list); > >> rtdm_lock_put_irqrestore(&opendev_list_lock, s); > >Well, if you are not running on a multiprocessor system, you can not > >take interrupt during that section. > > > >And on a multiprocessor system, the time this code will hold the > >lock is very short, so, it should not be a problem for an interrupt > >one core to spin while another core is holding the lock. > > > >But we can probably add rtdm_lock_is_locked, yes. > > > I'm working on a multiprocessor system and when I boot the system between > 200 and 1000 times I get one error, because the add and remove from the list > will be done on boot. I have read this sentence multiple times, but have not understood what your problem is and how testing whether the spinlock is locked will solve anything. So, again, note that: - adding or removing an element to/from a list is so fast that having to spin waiting for the lock in an interrupt handler is not a problem, at all; - doing if (!is_locked) lock() is racy: between the time you test and the time you lock, the other cpu may well have taken the lock and be in the process of updating the list, so, what you probably want is a "trylock" operation, which tries and acquire the lock and fails instead of spinning if it would have to wait. > I tried to add a function rtdm_lock_is_locked but the thing is that the > variables in struct arch_spinlock_t are different for different > architectures, for example on ARM it is "u32 slock" and on x86 it is > "__ticketpair_t head_tail". > > If you have a hint for me which element of struct rtdm_lock_t I have to use > to check if the list is locked I can add this on my own. > If you think this the function rtdm_lock_is_locked should be added it would > be great if you can add it for Xenomai 2.6.4 as well. You are looking at the wrong abstraction level, rtdm_lock_t is just a typedef for ipipe_spinlock_t, and all the spin* functions/macros of the spinlock API apply to ipipe_spinlock_t, this includes spin_is_locked() and spin_trylock(). Of course we need to add rtdm_lock_is_locked and rtdm_lock_trylock, but in the meantime, you can use the kernel functions directly. -- Gilles. https://click-hack.org ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Xenomai] Function to get state of lock variable 2015-08-18 12:14 [Xenomai] Function to get state of lock variable Wolfgang Netbal 2015-08-18 12:48 ` Gilles Chanteperdrix @ 2015-08-24 7:36 ` Jan Kiszka 1 sibling, 0 replies; 5+ messages in thread From: Jan Kiszka @ 2015-08-24 7:36 UTC (permalink / raw) To: wolfgang.netbal, Xenomai Mailing List On 2015-08-18 14:14, Wolfgang Netbal wrote: > Hi All, > > is there a function te returns true or false if a rtdm_lock_t variable > is set ? > What I have to do is to check in an interrupt routine if the list is > locked, > if this is the case I leave the interrupt handler befor accessing the list. Why? Why can't you simply spin until the lock is released - provided the section that holds it is as short as in the code below? Testing for a lock being held is usually only reasonable for debugging purposes. trylock services make some sense in complex nested locking scenarios or when creatively having to optimize the fast path. I dare to say trying to use those mechanisms in a real-time context indicates that the design has some other problem. Jan > > I use the following code to lock the add and replace of list elements. > > static rtdm_lock_t opendev_list_lock; > static int open(struct rtdm_dev_context *context, rtdm_user_info_t * > user_info, int oflags) > { > lrtdrv_context_t *ctx = (lrtdrv_context_t *) context->dev_private; > rtdm_lockctx_t s; > > .... > > rtdm_lock_get_irqsave(&opendev_list_lock, s); > list_add_tail(&ctx->opendev_entry, &lrtdrv_opendev_list); > rtdm_lock_put_irqrestore(&opendev_list_lock, s); > > > return 0; > } > > Kind regards -- Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-08-24 7:36 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2015-08-18 12:14 [Xenomai] Function to get state of lock variable Wolfgang Netbal 2015-08-18 12:48 ` Gilles Chanteperdrix 2015-08-18 13:29 ` Wolfgang Netbal 2015-08-18 20:34 ` Gilles Chanteperdrix 2015-08-24 7:36 ` Jan Kiszka
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.