From: Jan Kiszka <jan.kiszka@domain.hid>
To: xenomai-core <xenomai@xenomai.org>
Subject: [Xenomai-core] [RFC][PATCH 7/9] Switch POSIX mutexes to XNSYNCH_FWDROB
Date: Mon, 01 Sep 2008 11:12:51 +0200 [thread overview]
Message-ID: <48BBB213.1090502@domain.hid> (raw)
In-Reply-To: <48BBA9E6.5070400@domain.hid>
Switch POSIX over to XNSYNCH_FWDROB, demonstrating the use of this flag
(and aligning the implementation for following native version). This can
save the syscall so far required on releasing a stolen mutex.
---
ksrc/skins/posix/mutex.c | 10 ++++++----
ksrc/skins/posix/mutex.h | 42 +++++++++++++++++++++++++-----------------
2 files changed, 31 insertions(+), 21 deletions(-)
Index: b/ksrc/skins/posix/mutex.c
===================================================================
--- a/ksrc/skins/posix/mutex.c
+++ b/ksrc/skins/posix/mutex.c
@@ -85,7 +85,7 @@ int pse51_mutex_init_internal(struct __s
xnarch_atomic_t *ownerp,
const pthread_mutexattr_t *attr)
{
- xnflags_t synch_flags = XNSYNCH_PRIO | XNSYNCH_NOPIP;
+ xnflags_t synch_flags = XNSYNCH_PRIO | XNSYNCH_NOPIP | XNSYNCH_FWDROB;
struct xnsys_ppd *sys_ppd;
pse51_kqueues_t *kq;
spl_t s;
@@ -117,7 +117,6 @@ int pse51_mutex_init_internal(struct __s
mutex->attr = *attr;
mutex->owner = ownerp;
mutex->owningq = kq;
- mutex->sleepers = 0;
xnarch_atomic_set(ownerp, XN_NO_HANDLE);
xnlock_get_irqsave(&nklock, s);
@@ -306,10 +305,8 @@ int pse51_mutex_timedlock_break(struct _
/* Attempting to relock a normal mutex, deadlock. */
xnlock_get_irqsave(&nklock, s);
for (;;) {
- ++mutex->sleepers;
xnsynch_sleep_on(&mutex->synchbase, timeout,
timeout_mode);
- --mutex->sleepers;
if (xnthread_test_info(cur, XNBREAK)) {
err = -EINTR;
@@ -326,6 +323,11 @@ int pse51_mutex_timedlock_break(struct _
break;
}
}
+ if (!xnsynch_nsleepers(&mutex->synchbase))
+ xnarch_atomic_set
+ (mutex->owner,
+ clear_claimed
+ (xnarch_atomic_get(mutex->owner)));
xnlock_put_irqrestore(&nklock, s);
break;
Index: b/ksrc/skins/posix/mutex.h
===================================================================
--- a/ksrc/skins/posix/mutex.h
+++ b/ksrc/skins/posix/mutex.h
@@ -57,7 +57,6 @@ typedef struct pse51_mutex {
xnarch_atomic_t *owner;
pthread_mutexattr_t attr;
- unsigned sleepers;
pse51_kqueues_t *owningq;
} pse51_mutex_t;
@@ -172,24 +171,30 @@ static inline int pse51_mutex_timedlock_
}
xnsynch_set_owner(&mutex->synchbase, owner);
- ++mutex->sleepers;
xnsynch_sleep_on(&mutex->synchbase, timeout, timeout_mode);
- --mutex->sleepers;
- if (xnthread_test_info(cur, XNBREAK)) {
- err = -EINTR;
- goto error;
- }
- if (xnthread_test_info(cur, XNRMID)) {
+ if (unlikely
+ (xnthread_test_info(cur, XNBREAK | XNRMID | XNROBBED | XNTIMEO))) {
+ if (xnthread_test_info(cur, XNROBBED)) {
+ xnlock_put_irqrestore(&nklock, s);
+ goto retry_lock;
+ }
+ if (xnthread_test_info(cur, XNTIMEO)) {
+ err = -ETIMEDOUT;
+ goto error;
+ }
+ if (xnthread_test_info(cur, XNBREAK)) {
+ err = -EINTR;
+ goto error;
+ }
+ /* XNRMID */
err = -EINVAL;
goto error;
}
- if (xnthread_test_info(cur, XNTIMEO)) {
- err = -ETIMEDOUT;
- goto error;
- }
- ownerh = set_claimed(xnthread_handle(cur), mutex->sleepers);
+ ownerh = xnthread_handle(cur);
+ if (xnsynch_nsleepers(&mutex->synchbase))
+ ownerh = set_claimed(ownerh, 1);
xnarch_atomic_set(mutex->owner, ownerh);
shadow->lockcnt = count;
xnlock_put_irqrestore(&nklock, s);
@@ -197,7 +202,7 @@ static inline int pse51_mutex_timedlock_
return 0;
error:
- if (!mutex->sleepers)
+ if (!xnsynch_nsleepers(&mutex->synchbase))
xnarch_atomic_set
(mutex->owner,
clear_claimed(xnarch_atomic_get(mutex->owner)));
@@ -218,10 +223,13 @@ static inline void pse51_mutex_unlock_in
xnlock_get_irqsave(&nklock, s);
owner = xnsynch_wakeup_one_sleeper(&mutex->synchbase);
- ownerh = set_claimed(xnthread_handle(owner), mutex->sleepers);
- xnarch_atomic_set(mutex->owner, ownerh);
- if (owner)
+ if (owner) {
+ ownerh = set_claimed(xnthread_handle(owner),
+ xnsynch_nsleepers(&mutex->synchbase));
+ xnarch_atomic_set(mutex->owner, ownerh);
xnpod_schedule();
+ } else
+ xnarch_atomic_set(mutex->owner, XN_NO_HANDLE);
xnlock_put_irqrestore(&nklock, s);
}
next prev parent reply other threads:[~2008-09-01 9:12 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-01 8:53 [Xenomai-core] [PATCH 0/9] Fast mutex rework, native support Jan Kiszka
2008-09-01 8:39 ` [Xenomai-core] [PATCH 1/9] Always register threads by their base Jan Kiszka
2008-09-01 8:44 ` [Xenomai-core] [PATCH 2/9] Switch to handle-based fast mutex owners Jan Kiszka
2008-09-01 11:58 ` Gilles Chanteperdrix
2008-09-01 13:48 ` Jan Kiszka
2008-09-01 14:00 ` Gilles Chanteperdrix
2008-09-01 14:03 ` Jan Kiszka
2008-09-01 14:08 ` Jan Kiszka
2008-09-02 12:31 ` Gilles Chanteperdrix
2008-09-05 8:34 ` [Xenomai-core] [PATCH 2/9] Switch to handle-based fast mutex owners - v2 Jan Kiszka
2008-09-05 9:40 ` Gilles Chanteperdrix
2008-09-05 9:46 ` Jan Kiszka
2008-09-05 9:50 ` Gilles Chanteperdrix
2008-09-05 9:55 ` Jan Kiszka
2008-09-05 9:57 ` Gilles Chanteperdrix
2008-09-01 8:45 ` [Xenomai-core] [PATCH 3/9] Remove xnarch_atomic_intptr wrappers Jan Kiszka
2008-09-01 8:47 ` [Xenomai-core] [PATCH 4/9] Spread xeno_set_current Jan Kiszka
2008-09-01 8:54 ` [Xenomai-core] [RFC][PATCH 5/9] Allow lock stealing via pthread_mutex_trylock Jan Kiszka
2008-09-01 9:58 ` Gilles Chanteperdrix
2008-09-01 8:57 ` [Xenomai-core] [RFC][PATCH 6/9] Add XNSYNCH_FWDROB Jan Kiszka
2008-09-01 10:00 ` Gilles Chanteperdrix
2008-09-01 9:01 ` [Xenomai-core] [RFC][PATCH 8/9] Native support for fast mutexes Jan Kiszka
2008-09-05 8:36 ` [Xenomai-core] [RFC][PATCH 8/9] Native support for fast mutexes - v2 Jan Kiszka
2008-09-01 9:06 ` [Xenomai-core] [RFC][PATCH 9/9] Optimize xnsynch_sleep_on for XN_NONBLOCK Jan Kiszka
2008-09-01 9:12 ` Jan Kiszka [this message]
2008-09-01 10:01 ` [Xenomai-core] [RFC][PATCH 7/9] Switch POSIX mutexes to XNSYNCH_FWDROB Gilles Chanteperdrix
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=48BBB213.1090502@domain.hid \
--to=jan.kiszka@domain.hid \
--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.