All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@domain.hid>
To: Xenomai-core@domain.hid
Subject: [Xenomai-core] [PATCH 3/6] Consolidate xnlock_put debugging
Date: Sun, 02 Mar 2008 12:02:39 +0100	[thread overview]
Message-ID: <47CA894F.3060307@domain.hid> (raw)
In-Reply-To: <47C51A34.203@domain.hid>


[-- Attachment #1.1: Type: text/plain, Size: 426 bytes --]

The owner check on xnlock release looks light-weight in first sight, but
it isn't. It requires a processor-id lookup + it adds a conditional to
the otherwise unconditional release path. Moreover, this code is inlined
into every xnlock_put user, thus increases the text size of hot paths.

This patch therefore moves the check under the same switch
(XENO_OPT_DEBUG_NUCLEUS) as the rest of xnlock debugging already is.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: consolidate-xnlock_put-debugging.patch --]
[-- Type: text/x-patch; name="consolidate-xnlock_put-debugging.patch", Size: 2868 bytes --]

---
 include/asm-generic/system.h |   52 +++++++++++++++++++++++--------------------
 1 file changed, 28 insertions(+), 24 deletions(-)

Index: b/include/asm-generic/system.h
===================================================================
--- a/include/asm-generic/system.h
+++ b/include/asm-generic/system.h
@@ -164,11 +164,23 @@ xnlock_dbg_acquired(xnlock_t *lock, int 
 	lock->cpu = cpu;
 }
 
-static inline void xnlock_dbg_release(xnlock_t *lock)
+static inline int xnlock_dbg_release(xnlock_t *lock)
 {
 	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);
+		return 1;
+	}
 
 	lock->cpu = -lock->cpu;	/* File that we released it. */
 
@@ -179,15 +191,7 @@ static inline void xnlock_dbg_release(xn
 		stats->function = lock->function;
 		stats->line = lock->line;
 	}
-}
-
-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);
+	return 0;
 }
 
 #else /* !(CONFIG_SMP && XENO_DEBUG(NUCLEUS)) */
@@ -210,8 +214,10 @@ xnlock_dbg_spinning(xnlock_t *lock, int 
 static inline void
 xnlock_dbg_acquired(xnlock_t *lock, int cpu, unsigned long long *start)	{ }
 
-static inline void xnlock_dbg_release(xnlock_t *lock)			{ }
-static inline void xnlock_dbg_invalid_release(xnlock_t *lock)		{ }
+static inline int xnlock_dbg_release(xnlock_t *lock)
+{
+	return 0;
+}
 
 #endif /* !(CONFIG_SMP && XENO_DEBUG(NUCLEUS)) */
 
@@ -340,18 +346,16 @@ 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);
+	if (xnlock_dbg_release(lock))
+		return;
+
+	/*
+	 * Make sure all data written inside the lock is visible to
+	 * other CPUs before we release the lock.
+	 */
+	xnarch_memory_barrier();
 
-		/*
-		 * Make sure all data written inside the lock is visible to
-		 * other CPUs before we release the lock.
-		 */
-		xnarch_memory_barrier();
-
-		atomic_set(&lock->owner, ~0);
-	} else
-		xnlock_dbg_invalid_release(lock);
+	atomic_set(&lock->owner, ~0);
 }
 
 static inline spl_t


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 254 bytes --]

  parent reply	other threads:[~2008-03-02 11:02 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <47C51A34.203@domain.hid>
2008-03-02 10:38 ` [Xenomai-help] [PATCH 1/6] Refactor xnlock debugging Jan Kiszka
2008-03-02 10:38 ` [Xenomai-help] [PATCH 2/6] Whitespace fixes for asm-generic/system.h Jan Kiszka
2008-03-02 10:38 ` [Xenomai-help] [PATCH 3/6] Consolidate xnlock_put debugging Jan Kiszka
2008-03-02 10:38 ` [Xenomai-help] [PATCH 4/6] Move spinning code out-of-line Jan Kiszka
2008-03-02 10:38 ` [Xenomai-help] [PATCH 5/6] Introduce optional recursive ticket xnlock Jan Kiszka
2008-03-02 10:38 ` [Xenomai-help] [PATCH 6/6] Allow xnlock debugging on single-CPU systems Jan Kiszka
2008-03-02 11:02 ` [Xenomai-core] [PATCH 1/6] Refactor xnlock debugging Jan Kiszka
2008-03-02 11:02 ` [Xenomai-core] [PATCH 2/6] Whitespace fixes for asm-generic/system.h Jan Kiszka
2008-03-02 11:02 ` Jan Kiszka [this message]
2008-03-02 11:02 ` [Xenomai-core] [PATCH 4/6] Move spinning code out-of-line Jan Kiszka
2008-03-02 11:02 ` [Xenomai-core] [PATCH 5/6] Introduce optional recursive ticket xnlock Jan Kiszka
2008-03-02 11:02 ` [Xenomai-core] [PATCH 6/6] Allow xnlock debugging on single-CPU systems 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=47CA894F.3060307@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.