summaryrefslogtreecommitdiffstats
path: root/cpukit/include/rtems/score/profiling.h
blob: 20e6a4a027c6cf6bd63dc35b1b384cc60bd59219 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/**
 * @file
 *
 * @ingroup RTEMSScoreProfiling
 *
 * @brief This header file provides the interfaces of the
 *   @ref RTEMSScoreProfiling.
 */

/*
 * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
 *
 *  embedded brains GmbH
 *  Dornierstr. 4
 *  82178 Puchheim
 *  Germany
 *  <rtems@embedded-brains.de>
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rtems.org/license/LICENSE.
 */

#ifndef _RTEMS_SCORE_PROFILING
#define _RTEMS_SCORE_PROFILING

#include <rtems/score/percpu.h>
#include <rtems/score/isrlock.h>

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/**
 * @defgroup RTEMSScoreProfiling Profiling Support
 * 
 * @ingroup RTEMSScore
 *
 * @brief This group contains the implementation to support profiling.
 *
 * @{
 */

/**
 * @brief Disables the thread dispatch if the previous thread dispatch
 *      disable level is zero.
 *
 * @param[out] cpu The cpu control.
 * @param previous_thread_dispatch_disable_level The dispatch disable
 *      level of the previous thread.
 */
static inline void _Profiling_Thread_dispatch_disable(
  Per_CPU_Control *cpu,
  uint32_t previous_thread_dispatch_disable_level
)
{
#if defined( RTEMS_PROFILING )
  if ( previous_thread_dispatch_disable_level == 0 ) {
    Per_CPU_Stats *stats = &cpu->Stats;

    stats->thread_dispatch_disabled_instant = _CPU_Counter_read();
    ++stats->thread_dispatch_disabled_count;
  }
#else
  (void) cpu;
  (void) previous_thread_dispatch_disable_level;
#endif
}

/**
 * @brief Disables the thread dispatch.
 *
 * Only if the previous thread dispatch disable level is zero.  This
 * method also takes into account the lock_context.
 *
 * @param[out] cpu The cpu control.
 * @param previous_thread_dispatch_disable_level The dispatch disable
 *      level of the previous thread.
 * @param lock_context The lock context.
 */
static inline void _Profiling_Thread_dispatch_disable_critical(
  Per_CPU_Control        *cpu,
  uint32_t                previous_thread_dispatch_disable_level,
  const ISR_lock_Context *lock_context
)
{
#if defined( RTEMS_PROFILING )
  if ( previous_thread_dispatch_disable_level == 0 ) {
    Per_CPU_Stats *stats = &cpu->Stats;

    stats->thread_dispatch_disabled_instant = lock_context->ISR_disable_instant;
    ++stats->thread_dispatch_disabled_count;
  }
#else
  (void) cpu;
  (void) previous_thread_dispatch_disable_level;
  (void) lock_context;
#endif
}

/**
 * @brief Enables the thread dispatch.
 *
 * Only if the @a new_thread_dispatch_disable_level is 0.
 *
 * @param[out] cpu The cpu control.
 * @param new_thread_dispatch_disable_level The dispatch disable level
 *      of the new thread.
 */
static inline void _Profiling_Thread_dispatch_enable(
  Per_CPU_Control *cpu,
  uint32_t new_thread_dispatch_disable_level
)
{
#if defined( RTEMS_PROFILING )
  if ( new_thread_dispatch_disable_level == 0 ) {
    Per_CPU_Stats *stats = &cpu->Stats;
    CPU_Counter_ticks now = _CPU_Counter_read();
    CPU_Counter_ticks delta = _CPU_Counter_difference(
      now,
      stats->thread_dispatch_disabled_instant
    );

    stats->total_thread_dispatch_disabled_time += delta;

    if ( stats->max_thread_dispatch_disabled_time < delta ) {
      stats->max_thread_dispatch_disabled_time = delta;
    }
  }
#else
  (void) cpu;
  (void) new_thread_dispatch_disable_level;
#endif
}

/**
 * @brief Updates the maximum interrupt delay.
 *
 * @param[out] cpu The cpu control.
 * @param interrupt_delay The new interrupt delay.
 */
static inline void _Profiling_Update_max_interrupt_delay(
  Per_CPU_Control *cpu,
  CPU_Counter_ticks interrupt_delay
)
{
#if defined( RTEMS_PROFILING )
  Per_CPU_Stats *stats = &cpu->Stats;

  if ( stats->max_interrupt_delay < interrupt_delay ) {
    stats->max_interrupt_delay = interrupt_delay;
  }
#else
  (void) cpu;
  (void) interrupt_delay;
#endif
}

/**
 * @brief Updates the interrupt profiling statistics.
 *
 * Must be called with the interrupt stack and before the thread dispatch
 * disable level is decremented.
 *
 * @param cpu The cpu control.
 * @param interrupt_entry_instant The instant that the interrupt occured.
 * @param interrupt_exit_instant The instant in which the interrupt was exited.
 */
void _Profiling_Outer_most_interrupt_entry_and_exit(
  Per_CPU_Control *cpu,
  CPU_Counter_ticks interrupt_entry_instant,
  CPU_Counter_ticks interrupt_exit_instant
);

/** @} */

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* _RTEMS_SCORE_PROFILING */