37#ifndef _RTEMS_SCORE_SMPLOCKSTATS_H
38#define _RTEMS_SCORE_SMPLOCKSTATS_H
40#include <rtems/score/cpu.h>
56#if defined(RTEMS_PROFILING)
61#define SMP_LOCK_STATS_CONTENTION_COUNTS 4
90 CPU_Counter_ticks max_acquire_time;
95 CPU_Counter_ticks max_section_time;
102 uint64_t usage_count;
113 uint64_t total_acquire_time;
125 uint64_t contention_counts[SMP_LOCK_STATS_CONTENTION_COUNTS];
135 uint64_t total_section_time;
152 CPU_Counter_ticks acquire_instant;
157 SMP_lock_Stats *stats;
158} SMP_lock_Stats_context;
163#define SMP_LOCK_STATS_INITIALIZER( name ) \
164 { { NULL, NULL }, 0, 0, 0, 0, { 0, 0, 0, 0 }, 0, name }
173static inline void _SMP_lock_Stats_initialize(
174 SMP_lock_Stats *stats,
178 SMP_lock_Stats init = SMP_LOCK_STATS_INITIALIZER( name );
188void _SMP_lock_Stats_destroy( SMP_lock_Stats *stats );
197void _SMP_lock_Stats_register_or_max_section_time(
198 SMP_lock_Stats *stats,
199 CPU_Counter_ticks max_section_time
203 CPU_Counter_ticks first;
204} SMP_lock_Stats_acquire_context;
211static inline void _SMP_lock_Stats_acquire_begin(
212 SMP_lock_Stats_acquire_context *acquire_context
226static inline void _SMP_lock_Stats_acquire_end(
227 const SMP_lock_Stats_acquire_context *acquire_context,
228 SMP_lock_Stats *stats,
229 SMP_lock_Stats_context *stats_context,
230 unsigned int queue_length
233 CPU_Counter_ticks second;
234 CPU_Counter_ticks delta;
237 stats_context->acquire_instant = second;
238 delta = second - acquire_context->first;
240 ++stats->usage_count;
242 stats->total_acquire_time += delta;
244 if ( stats->max_acquire_time < delta ) {
245 stats->max_acquire_time = delta;
248 if ( queue_length >= SMP_LOCK_STATS_CONTENTION_COUNTS ) {
249 queue_length = SMP_LOCK_STATS_CONTENTION_COUNTS - 1;
251 ++stats->contention_counts[ queue_length ];
253 stats_context->stats = stats;
261static inline void _SMP_lock_Stats_release_update(
262 const SMP_lock_Stats_context *stats_context
265 SMP_lock_Stats *stats;
266 CPU_Counter_ticks first;
267 CPU_Counter_ticks second;
268 CPU_Counter_ticks delta;
270 stats = stats_context->stats;
271 first = stats_context->acquire_instant;
273 delta = second - first;
275 stats->total_section_time += delta;
277 if ( stats->max_section_time < delta ) {
278 _SMP_lock_Stats_register_or_max_section_time( stats, delta );
284 SMP_lock_Stats *current;
285} SMP_lock_Stats_iteration_context;
292void _SMP_lock_Stats_iteration_start(
293 SMP_lock_Stats_iteration_context *iteration_context
307bool _SMP_lock_Stats_iteration_next(
308 SMP_lock_Stats_iteration_context *iteration_context,
309 SMP_lock_Stats *snapshot,
319void _SMP_lock_Stats_iteration_stop(
320 SMP_lock_Stats_iteration_context *iteration_context
325#define _SMP_lock_Stats_initialize( stats, name ) do { } while ( 0 )
327#define _SMP_lock_Stats_destroy( stats ) do { } while ( 0 )
CPU_Counter_ticks _CPU_Counter_read(void)
Gets the current CPU counter value.
Definition: system-clocks.c:130
This header file provides interfaces of the Chain Handler which are used by the implementation and th...
This structure represents a chain node.
Definition: chain.h:78