summaryrefslogtreecommitdiffstats
path: root/cpukit/score/include/rtems/score/smplockstats.h
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-05-18 16:54:12 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-05-19 11:50:37 +0200
commit26fafd5a2f707e5aac1cd92354d42b759996c789 (patch)
tree3a900c6b6fd6a34fe2946c18590de72ea34ec4b5 /cpukit/score/include/rtems/score/smplockstats.h
parentSMP: Move ticket lock to separate header file (diff)
downloadrtems-26fafd5a2f707e5aac1cd92354d42b759996c789.tar.bz2
SMP: Add and use lock statistics helper
Diffstat (limited to 'cpukit/score/include/rtems/score/smplockstats.h')
-rw-r--r--cpukit/score/include/rtems/score/smplockstats.h41
1 files changed, 41 insertions, 0 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.
*