1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** ThreadX Component */
16 /** */
17 /** Thread */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22 #define TX_SOURCE_CODE
23
24
25 /* Include necessary system files. */
26
27 #include "tx_api.h"
28 #include "tx_thread.h"
29 #ifdef TX_THREAD_ENABLE_PERFORMANCE_INFO
30 #include "tx_trace.h"
31 #endif
32
33
34 /**************************************************************************/
35 /* */
36 /* FUNCTION RELEASE */
37 /* */
38 /* _tx_thread_performance_system_info_get PORTABLE C */
39 /* 6.1 */
40 /* AUTHOR */
41 /* */
42 /* William E. Lamie, Microsoft Corporation */
43 /* */
44 /* DESCRIPTION */
45 /* */
46 /* This function retrieves thread system performance information. */
47 /* */
48 /* INPUT */
49 /* */
50 /* resumptions Destination for total number of */
51 /* thread resumptions */
52 /* suspensions Destination for total number of */
53 /* thread suspensions */
54 /* solicited_preemptions Destination for total number of */
55 /* thread preemption from thread */
56 /* API calls */
57 /* interrupt_preemptions Destination for total number of */
58 /* thread preemptions as a result */
59 /* of threads made ready inside of */
60 /* Interrupt Service Routines */
61 /* priority_inversions Destination for total number of */
62 /* priority inversions */
63 /* time_slices Destination for total number of */
64 /* time-slices */
65 /* relinquishes Destination for total number of */
66 /* relinquishes */
67 /* timeouts Destination for total number of */
68 /* timeouts */
69 /* wait_aborts Destination for total number of */
70 /* wait aborts */
71 /* non_idle_returns Destination for total number of */
72 /* times threads return when */
73 /* another thread is ready */
74 /* idle_returns Destination for total number of */
75 /* times threads return when no */
76 /* other thread is ready */
77 /* */
78 /* OUTPUT */
79 /* */
80 /* status Completion status */
81 /* */
82 /* CALLS */
83 /* */
84 /* None */
85 /* */
86 /* CALLED BY */
87 /* */
88 /* Application Code */
89 /* */
90 /* RELEASE HISTORY */
91 /* */
92 /* DATE NAME DESCRIPTION */
93 /* */
94 /* 05-19-2020 William E. Lamie Initial Version 6.0 */
95 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
96 /* resulting in version 6.1 */
97 /* */
98 /**************************************************************************/
_tx_thread_performance_system_info_get(ULONG * resumptions,ULONG * suspensions,ULONG * solicited_preemptions,ULONG * interrupt_preemptions,ULONG * priority_inversions,ULONG * time_slices,ULONG * relinquishes,ULONG * timeouts,ULONG * wait_aborts,ULONG * non_idle_returns,ULONG * idle_returns)99 UINT _tx_thread_performance_system_info_get(ULONG *resumptions, ULONG *suspensions,
100 ULONG *solicited_preemptions, ULONG *interrupt_preemptions, ULONG *priority_inversions,
101 ULONG *time_slices, ULONG *relinquishes, ULONG *timeouts, ULONG *wait_aborts,
102 ULONG *non_idle_returns, ULONG *idle_returns)
103 {
104
105 #ifdef TX_THREAD_ENABLE_PERFORMANCE_INFO
106
107 TX_INTERRUPT_SAVE_AREA
108
109
110 /* Disable interrupts. */
111 TX_DISABLE
112
113 /* If trace is enabled, insert this event into the trace buffer. */
114 TX_TRACE_IN_LINE_INSERT(TX_TRACE_THREAD_PERFORMANCE_SYSTEM_INFO_GET, 0, 0, 0, 0, TX_TRACE_THREAD_EVENTS)
115
116 /* Log this kernel call. */
117 TX_EL_THREAD_PERFORMANCE_SYSTEM_INFO_GET_INSERT
118
119 /* Retrieve all the pertinent information and return it in the supplied
120 destinations. */
121
122 /* Retrieve total number of thread resumptions. */
123 if (resumptions != TX_NULL)
124 {
125
126 *resumptions = _tx_thread_performance_resume_count;
127 }
128
129 /* Retrieve total number of thread suspensions. */
130 if (suspensions != TX_NULL)
131 {
132
133 *suspensions = _tx_thread_performance_suspend_count;
134 }
135
136 /* Retrieve total number of solicited thread preemptions. */
137 if (solicited_preemptions != TX_NULL)
138 {
139
140 *solicited_preemptions = _tx_thread_performance_solicited_preemption_count;
141 }
142
143 /* Retrieve total number of interrupt thread preemptions. */
144 if (interrupt_preemptions != TX_NULL)
145 {
146
147 *interrupt_preemptions = _tx_thread_performance_interrupt_preemption_count;
148 }
149
150 /* Retrieve total number of thread priority inversions. */
151 if (priority_inversions != TX_NULL)
152 {
153
154 *priority_inversions = _tx_thread_performance_priority_inversion_count;
155 }
156
157 /* Retrieve total number of thread time-slices. */
158 if (time_slices != TX_NULL)
159 {
160
161 *time_slices = _tx_thread_performance_time_slice_count;
162 }
163
164 /* Retrieve total number of thread relinquishes. */
165 if (relinquishes != TX_NULL)
166 {
167
168 *relinquishes = _tx_thread_performance_relinquish_count;
169 }
170
171 /* Retrieve total number of thread timeouts. */
172 if (timeouts != TX_NULL)
173 {
174
175 *timeouts = _tx_thread_performance_timeout_count;
176 }
177
178 /* Retrieve total number of thread wait aborts. */
179 if (wait_aborts != TX_NULL)
180 {
181
182 *wait_aborts = _tx_thread_performance_wait_abort_count;
183 }
184
185 /* Retrieve total number of thread non-idle system returns. */
186 if (non_idle_returns != TX_NULL)
187 {
188
189 *non_idle_returns = _tx_thread_performance_non_idle_return_count;
190 }
191
192 /* Retrieve total number of thread idle system returns. */
193 if (idle_returns != TX_NULL)
194 {
195
196 *idle_returns = _tx_thread_performance_idle_return_count;
197 }
198
199 /* Restore interrupts. */
200 TX_RESTORE
201
202 /* Return completion status. */
203 return(TX_SUCCESS);
204
205 #else
206
207 UINT status;
208
209
210 /* Access input arguments just for the sake of lint, MISRA, etc. */
211 if (resumptions != TX_NULL)
212 {
213
214 /* Not enabled, return error. */
215 status = TX_FEATURE_NOT_ENABLED;
216 }
217 else if (suspensions != TX_NULL)
218 {
219
220 /* Not enabled, return error. */
221 status = TX_FEATURE_NOT_ENABLED;
222 }
223 else if (solicited_preemptions != TX_NULL)
224 {
225
226 /* Not enabled, return error. */
227 status = TX_FEATURE_NOT_ENABLED;
228 }
229 else if (interrupt_preemptions != TX_NULL)
230 {
231
232 /* Not enabled, return error. */
233 status = TX_FEATURE_NOT_ENABLED;
234 }
235 else if (priority_inversions != TX_NULL)
236 {
237
238 /* Not enabled, return error. */
239 status = TX_FEATURE_NOT_ENABLED;
240 }
241 else if (time_slices != TX_NULL)
242 {
243
244 /* Not enabled, return error. */
245 status = TX_FEATURE_NOT_ENABLED;
246 }
247 else if (relinquishes != TX_NULL)
248 {
249
250 /* Not enabled, return error. */
251 status = TX_FEATURE_NOT_ENABLED;
252 }
253 else if (timeouts != TX_NULL)
254 {
255
256 /* Not enabled, return error. */
257 status = TX_FEATURE_NOT_ENABLED;
258 }
259 else if (wait_aborts != TX_NULL)
260 {
261
262 /* Not enabled, return error. */
263 status = TX_FEATURE_NOT_ENABLED;
264 }
265 else if (non_idle_returns != TX_NULL)
266 {
267
268 /* Not enabled, return error. */
269 status = TX_FEATURE_NOT_ENABLED;
270 }
271 else if (idle_returns != TX_NULL)
272 {
273
274 /* Not enabled, return error. */
275 status = TX_FEATURE_NOT_ENABLED;
276 }
277 else
278 {
279
280 /* Not enabled, return error. */
281 status = TX_FEATURE_NOT_ENABLED;
282 }
283
284 /* Return completion status. */
285 return(status);
286 #endif
287 }
288
289