[rtems commit] score: Add _ISR_lock_Is_owner()

Sebastian Huber sebh at rtems.org
Thu May 12 11:33:13 UTC 2016


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon May  9 06:49:53 2016 +0200

score: Add _ISR_lock_Is_owner()

---

 cpukit/score/include/rtems/score/isrlock.h | 19 ++++++++++++
 cpukit/score/include/rtems/score/percpu.h  |  2 ++
 cpukit/score/include/rtems/score/smplock.h | 48 ++++++++++++++++++++++++++++--
 cpukit/score/src/smplock.c                 | 25 +++++++++++++++-
 4 files changed, 90 insertions(+), 4 deletions(-)

diff --git a/cpukit/score/include/rtems/score/isrlock.h b/cpukit/score/include/rtems/score/isrlock.h
index 12afd08..f87f555 100644
--- a/cpukit/score/include/rtems/score/isrlock.h
+++ b/cpukit/score/include/rtems/score/isrlock.h
@@ -281,6 +281,25 @@ typedef struct {
     (void) _context;
 #endif
 
+#if defined( RTEMS_DEBUG )
+  /**
+   * @brief Returns true, if the ISR lock is owned by the current processor,
+   * otherwise false.
+   *
+   * On uni-processor configurations, this function returns true, if interrupts
+   * are disabled, otherwise false.
+   *
+   * @param[in] _lock The ISR lock control.
+   */
+  #if defined( RTEMS_SMP )
+    #define _ISR_lock_Is_owner( _lock ) \
+      _SMP_lock_Is_owner( &( _lock )->Lock )
+  #else
+    #define _ISR_lock_Is_owner( _lock ) \
+      ( _ISR_Get_level() != 0 )
+  #endif
+#endif
+
 /**
  * @brief Flashes an ISR lock.
  *
diff --git a/cpukit/score/include/rtems/score/percpu.h b/cpukit/score/include/rtems/score/percpu.h
index 6b60858..a4a8ffb 100644
--- a/cpukit/score/include/rtems/score/percpu.h
+++ b/cpukit/score/include/rtems/score/percpu.h
@@ -43,6 +43,8 @@ extern "C" {
    */
   #if defined( RTEMS_PROFILING )
     #define PER_CPU_CONTROL_SIZE_LOG2 9
+  #elif defined( RTEMS_DEBUG )
+    #define PER_CPU_CONTROL_SIZE_LOG2 8
   #else
     #define PER_CPU_CONTROL_SIZE_LOG2 7
   #endif
diff --git a/cpukit/score/include/rtems/score/smplock.h b/cpukit/score/include/rtems/score/smplock.h
index f98f38a..0cefe38 100644
--- a/cpukit/score/include/rtems/score/smplock.h
+++ b/cpukit/score/include/rtems/score/smplock.h
@@ -10,7 +10,7 @@
  * COPYRIGHT (c) 1989-2011.
  * On-Line Applications Research Corporation (OAR).
  *
- * Copyright (c) 2013-2015 embedded brains GmbH
+ * Copyright (c) 2013, 2016 embedded brains GmbH
  *
  * The license and distribution terms for this file may be
  * found in the file LICENSE in this distribution or at
@@ -32,7 +32,7 @@
 #include <string.h>
 #endif
 
-#if defined( RTEMS_PROFILING )
+#if defined( RTEMS_PROFILING ) || defined( RTEMS_DEBUG )
 #define RTEMS_SMP_LOCK_DO_NOT_INLINE
 #endif
 
@@ -373,6 +373,21 @@ static inline void _SMP_ticket_lock_Do_release(
  */
 typedef struct {
   SMP_ticket_lock_Control Ticket_lock;
+#if defined( RTEMS_DEBUG )
+  /**
+   * @brief The index of the owning processor of this lock.
+   *
+   * The processor index is used instead of the executing thread, so that this
+   * works in interrupt and system initialization context.  It is assumed that
+   * thread dispatching is disabled in SMP lock critical sections.
+   *
+   * In case the lock is free, then the value of this field is
+   * SMP_LOCK_NO_OWNER.
+   *
+   * @see _SMP_lock_Is_owner().
+   */
+  uint32_t owner;
+#endif
 #if defined( RTEMS_PROFILING )
   SMP_lock_Stats Stats;
 #endif
@@ -388,10 +403,24 @@ typedef struct {
 #endif
 } SMP_lock_Context;
 
+#if defined( RTEMS_DEBUG )
+#define SMP_LOCK_NO_OWNER 0xffffffff
+#endif
+
 /**
  * @brief SMP lock control initializer for static initialization.
  */
-#if defined( RTEMS_PROFILING )
+#if defined( RTEMS_DEBUG ) && defined( RTEMS_PROFILING )
+  #define SMP_LOCK_INITIALIZER( name ) \
+    { \
+      SMP_TICKET_LOCK_INITIALIZER, \
+      SMP_LOCK_NO_OWNER, \
+      SMP_LOCK_STATS_INITIALIZER( name ) \
+    }
+#elif defined( RTEMS_DEBUG )
+  #define SMP_LOCK_INITIALIZER( name ) \
+    { SMP_TICKET_LOCK_INITIALIZER, SMP_LOCK_NO_OWNER }
+#elif defined( RTEMS_PROFILING )
   #define SMP_LOCK_INITIALIZER( name ) \
     { SMP_TICKET_LOCK_INITIALIZER, SMP_LOCK_STATS_INITIALIZER( name ) }
 #else
@@ -422,6 +451,9 @@ static inline void _SMP_lock_Initialize(
 )
 {
   _SMP_ticket_lock_Initialize( &lock->Ticket_lock );
+#if defined( RTEMS_DEBUG )
+  lock->owner = SMP_LOCK_NO_OWNER;
+#endif
 #if defined( RTEMS_PROFILING )
   _SMP_lock_Stats_initialize( &lock->Stats, name );
 #else
@@ -559,6 +591,16 @@ static inline void _SMP_lock_Release_and_ISR_enable(
   _ISR_Enable_without_giant( context->isr_level );
 }
 
+#if defined( RTEMS_DEBUG )
+/**
+ * @brief Returns true, if the SMP lock is owned by the current processor,
+ * otherwise false.
+ *
+ * @param[in] lock The SMP lock control.
+ */
+bool _SMP_lock_Is_owner( const SMP_lock_Control *lock );
+#endif
+
 #if defined( RTEMS_PROFILING )
 
 typedef struct {
diff --git a/cpukit/score/src/smplock.c b/cpukit/score/src/smplock.c
index 1440091..35b1930 100644
--- a/cpukit/score/src/smplock.c
+++ b/cpukit/score/src/smplock.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 embedded brains GmbH.  All rights reserved.
+ * Copyright (c) 2015, 2016 embedded brains GmbH.  All rights reserved.
  *
  *  embedded brains GmbH
  *  Dornierstr. 4
@@ -17,6 +17,8 @@
 #endif
 
 #include <rtems/score/smplock.h>
+#include <rtems/score/assert.h>
+#include <rtems/score/smp.h>
 
 #if defined(RTEMS_SMP_LOCK_DO_NOT_INLINE)
 
@@ -39,6 +41,9 @@ void _SMP_lock_Acquire(
 )
 {
   _SMP_lock_Acquire_body( lock, context );
+#if defined(RTEMS_DEBUG)
+  lock->owner = _SMP_Get_current_processor();
+#endif
 }
 
 void _SMP_lock_Release(
@@ -46,6 +51,10 @@ void _SMP_lock_Release(
   SMP_lock_Context *context
 )
 {
+#if defined(RTEMS_DEBUG)
+  _Assert( lock->owner == _SMP_Get_current_processor() );
+  lock->owner = SMP_LOCK_NO_OWNER;
+#endif
   _SMP_lock_Release_body( lock, context );
 }
 
@@ -55,6 +64,9 @@ void _SMP_lock_ISR_disable_and_acquire(
 )
 {
   _SMP_lock_ISR_disable_and_acquire_body( lock, context );
+#if defined(RTEMS_DEBUG)
+  lock->owner = _SMP_Get_current_processor();
+#endif
 }
 
 void _SMP_lock_Release_and_ISR_enable(
@@ -62,7 +74,18 @@ void _SMP_lock_Release_and_ISR_enable(
   SMP_lock_Context *context
 )
 {
+#if defined(RTEMS_DEBUG)
+  _Assert( lock->owner == _SMP_Get_current_processor() );
+  lock->owner = SMP_LOCK_NO_OWNER;
+#endif
   _SMP_lock_Release_and_ISR_enable_body( lock, context );
 }
 
+#if defined(RTEMS_DEBUG)
+bool _SMP_lock_Is_owner( const SMP_lock_Control *lock )
+{
+  return lock->owner == _SMP_Get_current_processor();
+}
+#endif
+
 #endif /* defined(RTEMS_SMP_LOCK_DO_NOT_INLINE) */



More information about the vc mailing list