17 #ifndef _RTEMS_SCORE_SMPLOCKSTATS_H 18 #define _RTEMS_SCORE_SMPLOCKSTATS_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 );
177 void _SMP_lock_Stats_register_or_max_section_time(
178 SMP_lock_Stats *stats,
179 CPU_Counter_ticks max_section_time
183 CPU_Counter_ticks first;
184 } SMP_lock_Stats_acquire_context;
191 static inline void _SMP_lock_Stats_acquire_begin(
192 SMP_lock_Stats_acquire_context *acquire_context
195 acquire_context->first = _CPU_Counter_read();
206 static inline void _SMP_lock_Stats_acquire_end(
207 const SMP_lock_Stats_acquire_context *acquire_context,
208 SMP_lock_Stats *stats,
209 SMP_lock_Stats_context *stats_context,
210 unsigned int queue_length
213 CPU_Counter_ticks second;
214 CPU_Counter_ticks delta;
216 second = _CPU_Counter_read();
217 stats_context->acquire_instant = second;
218 delta = _CPU_Counter_difference( second, acquire_context->first );
220 ++stats->usage_count;
222 stats->total_acquire_time += delta;
224 if ( stats->max_acquire_time < delta ) {
225 stats->max_acquire_time = delta;
228 if ( queue_length >= SMP_LOCK_STATS_CONTENTION_COUNTS ) {
229 queue_length = SMP_LOCK_STATS_CONTENTION_COUNTS - 1;
231 ++stats->contention_counts[ queue_length ];
233 stats_context->stats = stats;
241 static inline void _SMP_lock_Stats_release_update(
242 const SMP_lock_Stats_context *stats_context
245 SMP_lock_Stats *stats;
246 CPU_Counter_ticks first;
247 CPU_Counter_ticks second;
248 CPU_Counter_ticks delta;
250 stats = stats_context->stats;
251 first = stats_context->acquire_instant;
252 second = _CPU_Counter_read();
253 delta = _CPU_Counter_difference( second, first );
255 stats->total_section_time += delta;
257 if ( stats->max_section_time < delta ) {
258 _SMP_lock_Stats_register_or_max_section_time( stats, delta );
264 SMP_lock_Stats *current;
265 } SMP_lock_Stats_iteration_context;
272 void _SMP_lock_Stats_iteration_start(
273 SMP_lock_Stats_iteration_context *iteration_context
287 bool _SMP_lock_Stats_iteration_next(
288 SMP_lock_Stats_iteration_context *iteration_context,
289 SMP_lock_Stats *snapshot,
299 void _SMP_lock_Stats_iteration_stop(
300 SMP_lock_Stats_iteration_context *iteration_context
305 #define _SMP_lock_Stats_initialize( stats, name ) do { } while ( 0 ) 307 #define _SMP_lock_Stats_destroy( stats ) do { } while ( 0 )
SPARC CPU Department Source.