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