source: rtems/cpukit/include/rtems/profiling.h @ 255fe43

Last change on this file since 255fe43 was 255fe43, checked in by Joel Sherrill <joel@…>, on 03/01/22 at 20:40:44

cpukit/: Scripted embedded brains header file clean up

Updates #4625.

  • Property mode set to 100644
File size: 9.0 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup RTEMSAPIProfiling
5 *
6 * @brief This header file provides the Profiling Support API.
7 */
8
9/*
10 * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
11 *
12 * The license and distribution terms for this file may be
13 * found in the file LICENSE in this distribution or at
14 * http://www.rtems.org/license/LICENSE.
15 */
16
17#ifndef _RTEMS_PROFILING_H
18#define _RTEMS_PROFILING_H
19
20#include <stdint.h>
21
22#include <rtems/print.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif /* __cplusplus */
27
28/**
29 * @defgroup RTEMSAPIProfiling Profiling Support
30 *
31 * @ingroup RTEMSAPI
32 *
33 * @brief The profiling support offers functions to report profiling
34 * information available in the system.
35 *
36 * Profiling support is by default disabled.  It must be enabled via the
37 * configure command line with the <tt>--enable-profiling</tt> option.  In this
38 * case the RTEMS_PROFILING pre-processor symbol is defined and profiling
39 * statistics will be gathered during system run-time.  The profiling support
40 * increases the time of critical sections and has some memory overhead.  The
41 * overhead should be acceptable for most applications.  The aim of the
42 * profiling implementation is to be available even for production systems so
43 * that verification is simplified.
44 *
45 * Profiling information includes critical timing values such as the maximum
46 * time of disabled thread dispatching which is a measure for the thread
47 * dispatch latency.  On SMP configurations statistics of all SMP locks in the
48 * system are available.
49 *
50 * Profiling information can be retrieved via rtems_profiling_iterate() and
51 * reported as an XML dump via rtems_profiling_report_xml().  These functions
52 * are always available, but actual profiling data is only available if enabled
53 * at build configuration time.
54 *
55 * @{
56 */
57
58/**
59 * @brief Type of profiling data.
60 */
61typedef enum {
62  /**
63   * @brief Type of per-CPU profiling data.
64   *
65   * @see rtems_profiling_per_cpu.
66   */
67  RTEMS_PROFILING_PER_CPU,
68
69  /**
70   * @brief Type of SMP lock profiling data.
71   *
72   * @see rtems_profiling_smp_lock.
73   */
74  RTEMS_PROFILING_SMP_LOCK
75} rtems_profiling_type;
76
77/**
78 * @brief The profiling data header.
79 */
80typedef struct {
81  /**
82   * @brief The profiling data type.
83   */
84  rtems_profiling_type type;
85} rtems_profiling_header;
86
87/**
88 * @brief Per-CPU profiling data.
89 *
90 * Theoretically all values in this structure can overflow, but the integer
91 * types are chosen so that they cannot overflow in practice.  On systems with
92 * a 1GHz CPU counter, the 64-bit integers can overflow in about 58 years.
93 * Since the system should not spend most of the time in critical sections the
94 * actual system run-time is much longer.  Several other counters in the system
95 * will overflow before we get a problem in the profiling area.
96 */
97typedef struct {
98  /**
99   * @brief The profiling data header.
100   */
101  rtems_profiling_header header;
102
103  /**
104   * @brief The processor index of this profiling data.
105   */
106  uint32_t processor_index;
107
108  /**
109   * @brief The maximum time of disabled thread dispatching in nanoseconds.
110   */
111  uint32_t max_thread_dispatch_disabled_time;
112
113  /**
114   * @brief Count of times when the thread dispatch disable level changes from
115   * zero to one in thread context.
116   *
117   * This value may overflow.
118   */
119  uint64_t thread_dispatch_disabled_count;
120
121  /**
122   * @brief Total time of disabled thread dispatching in nanoseconds.
123   *
124   * The average time of disabled thread dispatching is the total time of
125   * disabled thread dispatching divided by the thread dispatch disabled
126   * count.
127   *
128   * This value may overflow.
129   */
130  uint64_t total_thread_dispatch_disabled_time;
131
132  /**
133   * @brief The maximum interrupt delay in nanoseconds if supported by the
134   * hardware.
135   *
136   * The interrupt delay is the time interval from the recognition of an
137   * interrupt signal by the hardware up to the execution start of the
138   * corresponding high-level handler.  The interrupt delay is the main
139   * contributor to the interrupt latency.  To measure this time hardware
140   * support is required.  A time stamp unit must capture the interrupt signal
141   * recognition time.  If no hardware support is available, then this field
142   * will have a constant value of zero.
143   */
144  uint32_t max_interrupt_delay;
145
146  /**
147   * @brief The maximum time spent to process a single sequence of nested
148   * interrupts in nanoseconds.
149   *
150   * This is the time interval between the change of the interrupt nest level
151   * from zero to one and the change back from one to zero.  It is the measured
152   * worst-case execution time of interrupt service routines.  Please note that
153   * in case of nested interrupts this time includes the combined execution
154   * time and not the maximum time of an individual interrupt service routine.
155   */
156  uint32_t max_interrupt_time;
157
158  /**
159   * @brief Count of times when the interrupt nest level changes from zero to
160   * one.
161   *
162   * This value may overflow.
163   */
164  uint64_t interrupt_count;
165
166  /**
167   * @brief Total time of interrupt processing in nanoseconds.
168   *
169   * The average time of interrupt processing is the total time of interrupt
170   * processing divided by the interrupt count.
171   *
172   * This value may overflow.
173   */
174  uint64_t total_interrupt_time;
175} rtems_profiling_per_cpu;
176
177/**
178 * @brief Count of lock contention counters for SMP lock profiling.
179 */
180#define RTEMS_PROFILING_SMP_LOCK_CONTENTION_COUNTS 4
181
182/**
183 * @brief SMP lock profiling data.
184 *
185 * The lock acquire attempt instant is the point in time right after the
186 * interrupt disable action in the lock acquire sequence.
187 *
188 * The lock acquire instant is the point in time right after the lock
189 * acquisition.  This is the begin of the critical section code execution.
190 *
191 * The lock acquire time is the time elapsed between the lock acquire attempt
192 * instant and the lock acquire instant.
193 *
194 * The lock release instant is the point in time right before the interrupt
195 * enable action in the lock release sequence.
196 *
197 * The lock section time is the time elapsed between the lock acquire instant
198 * and the lock release instant.
199 */
200typedef struct {
201  /**
202   * @brief The profiling data header.
203   */
204  rtems_profiling_header header;
205
206  /**
207   * @brief The lock name.
208   */
209  const char *name;
210
211  /**
212   * @brief The maximum lock acquire time in nanoseconds.
213   */
214  uint32_t max_acquire_time;
215
216  /**
217   * @brief The maximum lock section time in nanoseconds.
218   */
219  uint32_t max_section_time;
220
221  /**
222   * @brief The count of lock uses.
223   *
224   * This value may overflow.
225   */
226  uint64_t usage_count;
227
228  /**
229   * @brief Total lock acquire time in nanoseconds.
230   *
231   * The average lock acquire time is the total acquire time divided by the
232   * lock usage count.  The ration of the total section and total acquire times
233   * gives a measure for the lock contention.
234   *
235   * This value may overflow.
236   */
237  uint64_t total_acquire_time;
238
239  /**
240   * @brief Total lock section time in nanoseconds.
241   *
242   * The average lock section time is the total section time divided by the
243   * lock usage count.
244   *
245   * This value may overflow.
246   */
247  uint64_t total_section_time;
248
249  /**
250   * @brief The counts of lock acquire operations by contention.
251   *
252   * The contention count for index N corresponds to a lock acquire attempt
253   * with an initial queue length of N.  The last index corresponds to all
254   * lock acquire attempts with an initial queue length greater than or equal
255   * to RTEMS_PROFILING_SMP_LOCK_CONTENTION_COUNTS minus one.
256   *
257   * The values may overflow.
258   */
259  uint64_t contention_counts[RTEMS_PROFILING_SMP_LOCK_CONTENTION_COUNTS];
260} rtems_profiling_smp_lock;
261
262/**
263 * @brief Collection of profiling data.
264 */
265typedef union {
266  /**
267   * @brief Header to specify the actual profiling data.
268   */
269  rtems_profiling_header header;
270
271  /**
272   * @brief Per-CPU profiling data if indicated by the header.
273   */
274  rtems_profiling_per_cpu per_cpu;
275
276  /**
277   * @brief SMP lock profiling data if indicated by the header.
278   */
279  rtems_profiling_smp_lock smp_lock;
280} rtems_profiling_data;
281
282/**
283 * @brief Visitor function for the profiling iteration.
284 *
285 * @param[in, out] arg The visitor argument.
286 * @param[in] data The current profiling data.
287 *
288 * @see rtems_profiling_iterate().
289 */
290typedef void (*rtems_profiling_visitor)(
291  void *arg,
292  const rtems_profiling_data *data
293);
294
295/**
296 * @brief Iterates through all profiling data of the system.
297 *
298 * @param[in] visitor The visitor.
299 * @param[in, out] visitor_arg The visitor argument.
300 */
301void rtems_profiling_iterate(
302  rtems_profiling_visitor visitor,
303  void *visitor_arg
304);
305
306/**
307 * @brief Reports profiling data as XML.
308 *
309 * @param[in] name The name of the profiling report.
310 * @param[in] printer The RTEMS printer to send the output too.
311 * @param[in] indentation_level The current indentation level.
312 * @param[in] indentation The string used for indentation.
313 *
314 * @returns As specified by printf().
315 */
316int rtems_profiling_report_xml(
317  const char *name,
318  const rtems_printer *printer,
319  uint32_t indentation_level,
320  const char *indentation
321);
322
323/** @} */
324
325#ifdef __cplusplus
326}
327#endif /* __cplusplus */
328
329#endif /* _RTEMS_PROFILING_H */
Note: See TracBrowser for help on using the repository browser.