[rtems commit] SMP: Add and use lock statistics helper

Sebastian Huber sebh at rtems.org
Thu May 19 09:51:19 UTC 2016


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed May 18 16:54:12 2016 +0200

SMP: Add and use lock statistics helper

---

 cpukit/score/include/rtems/score/smplockstats.h  | 41 ++++++++++++++++++++++++
 cpukit/score/include/rtems/score/smplockticket.h | 41 ++++++++----------------
 2 files changed, 54 insertions(+), 28 deletions(-)

diff --git a/cpukit/score/include/rtems/score/smplockstats.h b/cpukit/score/include/rtems/score/smplockstats.h
index 9785c1a..dd8e06c 100644
--- a/cpukit/score/include/rtems/score/smplockstats.h
+++ b/cpukit/score/include/rtems/score/smplockstats.h
@@ -171,6 +171,47 @@ void _SMP_lock_Stats_destroy( SMP_lock_Stats *stats );
 
 void _SMP_lock_Stats_register( SMP_lock_Stats *stats );
 
+typedef struct {
+  CPU_Counter_ticks first;
+} SMP_lock_Stats_acquire_context;
+
+static inline void _SMP_lock_Stats_acquire_begin(
+  SMP_lock_Stats_acquire_context *acquire_context
+)
+{
+  acquire_context->first = _CPU_Counter_read();
+}
+
+static inline void _SMP_lock_Stats_acquire_end(
+  const SMP_lock_Stats_acquire_context *acquire_context,
+  SMP_lock_Stats                       *stats,
+  SMP_lock_Stats_context               *stats_context,
+  unsigned int                          queue_length
+)
+{
+  CPU_Counter_ticks second;
+  CPU_Counter_ticks delta;
+
+  second = _CPU_Counter_read();
+  stats_context->acquire_instant = second;
+  delta = _CPU_Counter_difference( second, acquire_context->first );
+
+  ++stats->usage_count;
+
+  stats->total_acquire_time += delta;
+
+  if ( stats->max_acquire_time < delta ) {
+    stats->max_acquire_time = delta;
+  }
+
+  if ( queue_length >= SMP_LOCK_STATS_CONTENTION_COUNTS ) {
+    queue_length = SMP_LOCK_STATS_CONTENTION_COUNTS - 1;
+  }
+  ++stats->contention_counts[ queue_length ];
+
+  stats_context->stats = stats;
+}
+
 /**
  * @brief Updates an SMP lock statistics block during a lock release.
  *
diff --git a/cpukit/score/include/rtems/score/smplockticket.h b/cpukit/score/include/rtems/score/smplockticket.h
index 57d5411..e04c405 100644
--- a/cpukit/score/include/rtems/score/smplockticket.h
+++ b/cpukit/score/include/rtems/score/smplockticket.h
@@ -82,21 +82,18 @@ static inline void _SMP_ticket_lock_Do_acquire(
   SMP_ticket_lock_Control *lock
 #if defined(RTEMS_PROFILING)
   ,
-  SMP_lock_Stats *stats,
-  SMP_lock_Stats_context *stats_context
+  SMP_lock_Stats          *stats,
+  SMP_lock_Stats_context  *stats_context
 #endif
 )
 {
-  unsigned int my_ticket;
-  unsigned int now_serving;
-
+  unsigned int                   my_ticket;
+  unsigned int                   now_serving;
 #if defined(RTEMS_PROFILING)
-  CPU_Counter_ticks first;
-  CPU_Counter_ticks second;
-  CPU_Counter_ticks delta;
-  unsigned int initial_queue_length;
+  unsigned int                   initial_queue_length;
+  SMP_lock_Stats_acquire_context acquire_context;
 
-  first = _CPU_Counter_read();
+  _SMP_lock_Stats_acquire_begin( &acquire_context );
 #endif
 
   my_ticket =
@@ -118,24 +115,12 @@ static inline void _SMP_ticket_lock_Do_acquire(
 #if defined(RTEMS_PROFILING)
   }
 
-  second = _CPU_Counter_read();
-  stats_context->acquire_instant = second;
-  delta = _CPU_Counter_difference( second, first );
-
-  ++stats->usage_count;
-
-  stats->total_acquire_time += delta;
-
-  if ( stats->max_acquire_time < delta ) {
-    stats->max_acquire_time = delta;
-  }
-
-  if ( initial_queue_length >= SMP_LOCK_STATS_CONTENTION_COUNTS ) {
-    initial_queue_length = SMP_LOCK_STATS_CONTENTION_COUNTS - 1;
-  }
-  ++stats->contention_counts[initial_queue_length];
-
-  stats_context->stats = stats;
+  _SMP_lock_Stats_acquire_end(
+    &acquire_context,
+    stats,
+    stats_context,
+    initial_queue_length
+  );
 #endif
 }
 




More information about the vc mailing list