diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-05-18 16:54:12 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-05-19 11:50:37 +0200 |
commit | 26fafd5a2f707e5aac1cd92354d42b759996c789 (patch) | |
tree | 3a900c6b6fd6a34fe2946c18590de72ea34ec4b5 /cpukit/score/include | |
parent | SMP: Move ticket lock to separate header file (diff) | |
download | rtems-26fafd5a2f707e5aac1cd92354d42b759996c789.tar.bz2 |
SMP: Add and use lock statistics helper
Diffstat (limited to '')
-rw-r--r-- | cpukit/score/include/rtems/score/smplockstats.h | 41 | ||||
-rw-r--r-- | 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 9785c1a7f0..dd8e06c81d 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 57d541161e..e04c4056a5 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 } |