17 #ifndef _RTEMS_SCORE_SMPLOCKSTATS_H 18 #define _RTEMS_SCORE_SMPLOCKSTATS_H 20 #include <rtems/score/cpu.h> 22 #if defined(RTEMS_SMP) 36 #if defined(RTEMS_PROFILING) 41 #define SMP_LOCK_STATS_CONTENTION_COUNTS 4 70 CPU_Counter_ticks max_acquire_time;
75 CPU_Counter_ticks max_section_time;
93 uint64_t total_acquire_time;
105 uint64_t contention_counts[SMP_LOCK_STATS_CONTENTION_COUNTS];
115 uint64_t total_section_time;
132 CPU_Counter_ticks acquire_instant;
137 SMP_lock_Stats *stats;
138 } SMP_lock_Stats_context;
143 #define SMP_LOCK_STATS_INITIALIZER( name ) \ 144 { { NULL, NULL }, 0, 0, 0, 0, { 0, 0, 0, 0 }, 0, name } 153 static inline void _SMP_lock_Stats_initialize(
154 SMP_lock_Stats *stats,
158 SMP_lock_Stats init = SMP_LOCK_STATS_INITIALIZER( name );
168 void _SMP_lock_Stats_destroy( SMP_lock_Stats *stats );
170 void _SMP_lock_Stats_register_or_max_section_time(
171 SMP_lock_Stats *stats,
172 CPU_Counter_ticks max_section_time
176 CPU_Counter_ticks first;
177 } SMP_lock_Stats_acquire_context;
179 static inline void _SMP_lock_Stats_acquire_begin(
180 SMP_lock_Stats_acquire_context *acquire_context
186 static inline void _SMP_lock_Stats_acquire_end(
187 const SMP_lock_Stats_acquire_context *acquire_context,
188 SMP_lock_Stats *stats,
189 SMP_lock_Stats_context *stats_context,
190 unsigned int queue_length
193 CPU_Counter_ticks second;
194 CPU_Counter_ticks delta;
197 stats_context->acquire_instant = second;
198 delta = _CPU_Counter_difference( second, acquire_context->first );
200 ++stats->usage_count;
202 stats->total_acquire_time += delta;
204 if ( stats->max_acquire_time < delta ) {
205 stats->max_acquire_time = delta;
208 if ( queue_length >= SMP_LOCK_STATS_CONTENTION_COUNTS ) {
209 queue_length = SMP_LOCK_STATS_CONTENTION_COUNTS - 1;
211 ++stats->contention_counts[ queue_length ];
213 stats_context->stats = stats;
221 static inline void _SMP_lock_Stats_release_update(
222 const SMP_lock_Stats_context *stats_context
225 SMP_lock_Stats *stats;
226 CPU_Counter_ticks first;
227 CPU_Counter_ticks second;
228 CPU_Counter_ticks delta;
230 stats = stats_context->stats;
231 first = stats_context->acquire_instant;
233 delta = _CPU_Counter_difference( second, first );
235 stats->total_section_time += delta;
237 if ( stats->max_section_time < delta ) {
238 _SMP_lock_Stats_register_or_max_section_time( stats, delta );
244 SMP_lock_Stats *current;
245 } SMP_lock_Stats_iteration_context;
247 void _SMP_lock_Stats_iteration_start(
248 SMP_lock_Stats_iteration_context *iteration_context
252 bool _SMP_lock_Stats_iteration_next(
253 SMP_lock_Stats_iteration_context *iteration_context,
254 SMP_lock_Stats *snapshot,
259 void _SMP_lock_Stats_iteration_stop(
260 SMP_lock_Stats_iteration_context *iteration_context
265 #define _SMP_lock_Stats_initialize( stats, name ) do { } while ( 0 ) 267 #define _SMP_lock_Stats_destroy( stats ) do { } while ( 0 )
CPU_Counter_ticks _CPU_Counter_read(void)
Returns the current CPU counter value.
Definition: system-clocks.c:117