[rtems commit] score: Improve SMP lock debug support

Sebastian Huber sebh at rtems.org
Wed Jan 11 12:52:46 UTC 2017


Module:    rtems
Branch:    master
Commit:    3d35bc00d8483a748c819012c860550271c37b9a
Changeset: http://git.rtems.org/rtems/commit/?id=3d35bc00d8483a748c819012c860550271c37b9a

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Jan 11 13:41:55 2017 +0100

score: Improve SMP lock debug support

The CPU index starts with zero.  Increment it by one, to allow global
SMP locks to reside in the BSS section.

---

 cpukit/score/include/rtems/score/smplock.h     | 17 ++++++++++++++---
 cpukit/score/include/rtems/score/threadqimpl.h |  2 +-
 cpukit/score/src/smplock.c                     |  2 +-
 cpukit/score/src/threadq.c                     |  4 ++--
 4 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/cpukit/score/include/rtems/score/smplock.h b/cpukit/score/include/rtems/score/smplock.h
index 2802204..a156edf 100644
--- a/cpukit/score/include/rtems/score/smplock.h
+++ b/cpukit/score/include/rtems/score/smplock.h
@@ -98,7 +98,7 @@ typedef struct {
 } SMP_lock_Context;
 
 #if defined(RTEMS_DEBUG)
-#define SMP_LOCK_NO_OWNER 0xffffffff
+#define SMP_LOCK_NO_OWNER 0
 #endif
 
 /**
@@ -176,6 +176,17 @@ void _SMP_lock_Destroy( SMP_lock_Control *lock );
   _SMP_lock_Destroy_inline( lock )
 #endif
 
+#if defined(RTEMS_DEBUG)
+static inline uint32_t _SMP_lock_Who_am_I( void )
+{
+  /*
+   * The CPU index starts with zero.  Increment it by one, to allow global SMP
+   * locks to reside in the BSS section.
+   */
+  return _SMP_Get_current_processor() + 1;
+}
+#endif
+
 static inline void _SMP_lock_Acquire_inline(
   SMP_lock_Control *lock,
   SMP_lock_Context *context
@@ -192,7 +203,7 @@ static inline void _SMP_lock_Acquire_inline(
     &context->Stats_context
   );
 #if defined(RTEMS_DEBUG)
-  lock->owner = _SMP_Get_current_processor();
+  lock->owner = _SMP_lock_Who_am_I();
 #endif
 }
 
@@ -220,7 +231,7 @@ static inline void _SMP_lock_Release_inline(
 #if defined(RTEMS_DEBUG)
   _Assert( context->lock_used_for_acquire == lock );
   context->lock_used_for_acquire = NULL;
-  _Assert( lock->owner == _SMP_Get_current_processor() );
+  _Assert( lock->owner == _SMP_lock_Who_am_I() );
   lock->owner = SMP_LOCK_NO_OWNER;
 #else
   (void) context;
diff --git a/cpukit/score/include/rtems/score/threadqimpl.h b/cpukit/score/include/rtems/score/threadqimpl.h
index fc907d3..1558489 100644
--- a/cpukit/score/include/rtems/score/threadqimpl.h
+++ b/cpukit/score/include/rtems/score/threadqimpl.h
@@ -467,7 +467,7 @@ RTEMS_INLINE_ROUTINE bool _Thread_queue_Is_lock_owner(
 )
 {
 #if defined(RTEMS_SMP)
-  return the_thread_queue->owner == _SMP_Get_current_processor();
+  return the_thread_queue->owner == _SMP_lock_Who_am_I();
 #else
   return _ISR_Get_level() != 0;
 #endif
diff --git a/cpukit/score/src/smplock.c b/cpukit/score/src/smplock.c
index e921837..b9c7f6e 100644
--- a/cpukit/score/src/smplock.c
+++ b/cpukit/score/src/smplock.c
@@ -72,6 +72,6 @@ void _SMP_lock_Release_and_ISR_enable(
 #if defined(RTEMS_DEBUG)
 bool _SMP_lock_Is_owner( const SMP_lock_Control *lock )
 {
-  return lock->owner == _SMP_Get_current_processor();
+  return lock->owner == _SMP_lock_Who_am_I();
 }
 #endif
diff --git a/cpukit/score/src/threadq.c b/cpukit/score/src/threadq.c
index d427431..b12e3de 100644
--- a/cpukit/score/src/threadq.c
+++ b/cpukit/score/src/threadq.c
@@ -76,7 +76,7 @@ void _Thread_queue_Do_acquire_critical(
     lock_context
   );
 #if defined(RTEMS_DEBUG)
-  the_thread_queue->owner = _SMP_Get_current_processor();
+  the_thread_queue->owner = _SMP_lock_Who_am_I();
 #endif
 }
 
@@ -92,7 +92,7 @@ void _Thread_queue_Acquire(
     &queue_context->Lock_context.Lock_context
   );
 #if defined(RTEMS_DEBUG)
-  the_thread_queue->owner = _SMP_Get_current_processor();
+  the_thread_queue->owner = _SMP_lock_Who_am_I();
 #endif
 }
 



More information about the vc mailing list