From: Jan Kiszka <jan.kiszka@domain.hid>
To: Xenomai-core@domain.hid
Subject: [Xenomai-core] [PATCH 2/4] Fix and optimize xnlock_put
Date: Sat, 23 Feb 2008 14:36:03 +0100 [thread overview]
Message-ID: <47C02113.7070005@domain.hid> (raw)
In-Reply-To: <47C020A9.3050704@domain.hid>
[-- Attachment #1: Type: text/plain, Size: 711 bytes --]
As the #ifdef forest was cut down, I once again looked at xnlock_put.
Why do you have this safety check for the owner also in production code?
Let's move it into the debug section. That leaves up with
static inline void xnlock_put(xnlock_t *lock)
{
xnlock_dbg_release(lock);
atomic_set(&lock->owner, ~0);
}
Nice - but wait, where is the memory barrier here? Was it in the
original code? No! Neither atomic_read, atomic_set, nor the
rthal_processor_id imply any kind of barrier to ensure all memory writes
inside the protected region are committed before releasing the lock.
Cool, there was a real bug under all this dust, and this patch fixes it
+ it shortens the hot path on SMP production systems.
Jan
[-- Attachment #2: rework-xnlock_put.patch --]
[-- Type: text/x-patch, Size: 2359 bytes --]
---
include/asm-generic/system.h | 38 +++++++++++++++++++-------------------
1 file changed, 19 insertions(+), 19 deletions(-)
Index: b/include/asm-generic/system.h
===================================================================
--- a/include/asm-generic/system.h
+++ b/include/asm-generic/system.h
@@ -163,7 +163,20 @@ static inline void xnlock_dbg_release(xn
{
extern xnlockinfo_t xnlock_stats[];
unsigned long long lock_time = rthal_rdtsc() - lock->lock_date;
- xnlockinfo_t *stats = &xnlock_stats[xnarch_current_cpu()];
+ int cpu = xnarch_current_cpu();
+ xnlockinfo_t *stats = &xnlock_stats[cpu];
+
+ if (unlikely(atomic_read(&lock->owner) != cpu)) {
+ rthal_emergency_console();
+ printk(KERN_ERR "Xenomai: unlocking unlocked nucleus lock %p"
+ " on CPU #%d\n"
+ " owner = %s:%u (%s(), CPU #%d)\n",
+ lock, cpu, lock->file, lock->line, lock->function,
+ lock->cpu);
+ show_stack(NULL,NULL);
+ for (;;)
+ cpu_relax();
+ }
if (lock_time > stats->lock_time) {
stats->lock_time = lock_time;
@@ -174,17 +187,6 @@ static inline void xnlock_dbg_release(xn
}
}
-static inline void xnlock_dbg_invalid_release(xnlock_t *lock)
-{
- rthal_emergency_console();
- printk(KERN_ERR "Xenomai: unlocking unlocked nucleus lock %p\n"
- " owner = %s:%u (%s(), CPU #%d)\n",
- lock, lock->file, lock->line, lock->function, lock->cpu);
- show_stack(NULL,NULL);
- for (;;)
- cpu_relax();
-}
-
#else /* !(CONFIG_SMP && XENO_DEBUG(NUCLEUS)) */
typedef struct { atomic_t owner; } xnlock_t;
@@ -198,8 +200,7 @@ typedef struct { atomic_t owner; } xnloc
#define XNLOCK_DBG_SPINNING() do { } while (0)
#define XNLOCK_DBG_ACQUIRED() do { } while (0)
-static inline void xnlock_dbg_release(xnlock_t *lock) { }
-static inline void xnlock_dbg_invalid_release(xnlock_t *lock) { }
+static inline void xnlock_dbg_release(xnlock_t *lock) { }
#endif /* !(CONFIG_SMP && XENO_DEBUG(NUCLEUS)) */
@@ -325,11 +326,10 @@ static inline int __xnlock_get(xnlock_t
static inline void xnlock_put(xnlock_t *lock)
{
- if (likely(atomic_read(&lock->owner) == xnarch_current_cpu())) {
- xnlock_dbg_release(lock);
- atomic_set(&lock->owner, ~0);
- } else
- xnlock_dbg_invalid_release(lock);
+ xnarch_memory_barrier();
+
+ xnlock_dbg_release(lock);
+ atomic_set(&lock->owner, ~0);
}
static inline spl_t
next prev parent reply other threads:[~2008-02-23 13:36 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-23 13:33 [Xenomai-core] [PATCH 0/4] Fixes and improvements around xnlock Jan Kiszka
2008-02-23 13:36 ` Jan Kiszka [this message]
2008-02-23 17:41 ` [Xenomai-core] [PATCH 2/4] Fix and optimize xnlock_put Gilles Chanteperdrix
2008-02-23 18:05 ` Jan Kiszka
2008-02-23 18:29 ` Gilles Chanteperdrix
2008-02-23 18:57 ` Jan Kiszka
2008-02-23 19:41 ` Gilles Chanteperdrix
2008-02-23 23:50 ` Philippe Gerum
2008-02-23 13:37 ` [Xenomai-core] [PATCH 1/4] Refactor generic system.h Jan Kiszka
2008-02-23 17:38 ` Gilles Chanteperdrix
2008-02-23 18:03 ` Jan Kiszka
2008-02-23 18:59 ` Gilles Chanteperdrix
2008-03-01 18:54 ` Gilles Chanteperdrix
2008-03-01 19:22 ` Jan Kiszka
2008-02-23 13:38 ` [Xenomai-core] [PATCH 3/4] Uninline heavy locking functions Jan Kiszka
2008-02-23 17:51 ` Gilles Chanteperdrix
2008-02-23 18:13 ` Jan Kiszka
2008-02-23 18:33 ` Gilles Chanteperdrix
2008-02-23 18:58 ` Jan Kiszka
2008-02-23 21:36 ` Jeroen Van den Keybus
2008-02-23 13:50 ` [Xenomai-core] [RFC][PATCH 4/4] Recursive FIFO ticket xnlock Jan Kiszka
2008-02-23 17:54 ` Gilles Chanteperdrix
2008-02-23 18:20 ` Jan Kiszka
2008-02-23 18:43 ` Gilles Chanteperdrix
2008-02-23 19:13 ` 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=47C02113.7070005@domain.hid \
--to=jan.kiszka@domain.hid \
--cc=Xenomai-core@domain.hid \
/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.