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 /** Mutex */
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_mutex.h"
30 #ifdef TX_MUTEX_ENABLE_PERFORMANCE_INFO
31 #include "tx_trace.h"
32 #endif
33
34 /**************************************************************************/
35 /* */
36 /* FUNCTION RELEASE */
37 /* */
38 /* _tx_mutex_performance_info_get PORTABLE C */
39 /* 6.1 */
40 /* AUTHOR */
41 /* */
42 /* William E. Lamie, Microsoft Corporation */
43 /* */
44 /* DESCRIPTION */
45 /* */
46 /* This function retrieves performance information from the specified */
47 /* mutex. */
48 /* */
49 /* INPUT */
50 /* */
51 /* mutex_ptr Pointer to mutex control block */
52 /* puts Destination for the number of */
53 /* puts on to this mutex */
54 /* gets Destination for the number of */
55 /* gets on this mutex */
56 /* suspensions Destination for the number of */
57 /* suspensions on this mutex */
58 /* timeouts Destination for number of timeouts*/
59 /* on this mutex */
60 /* inversions Destination for number of priority*/
61 /* inversions on this mutex */
62 /* inheritances Destination for number of priority*/
63 /* inheritances on this mutex */
64 /* */
65 /* OUTPUT */
66 /* */
67 /* status Completion status */
68 /* */
69 /* CALLS */
70 /* */
71 /* None */
72 /* */
73 /* CALLED BY */
74 /* */
75 /* Application Code */
76 /* */
77 /* RELEASE HISTORY */
78 /* */
79 /* DATE NAME DESCRIPTION */
80 /* */
81 /* 05-19-2020 William E. Lamie Initial Version 6.0 */
82 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
83 /* resulting in version 6.1 */
84 /* */
85 /**************************************************************************/
_tx_mutex_performance_info_get(TX_MUTEX * mutex_ptr,ULONG * puts,ULONG * gets,ULONG * suspensions,ULONG * timeouts,ULONG * inversions,ULONG * inheritances)86 UINT _tx_mutex_performance_info_get(TX_MUTEX *mutex_ptr, ULONG *puts, ULONG *gets,
87 ULONG *suspensions, ULONG *timeouts, ULONG *inversions, ULONG *inheritances)
88 {
89
90 #ifdef TX_MUTEX_ENABLE_PERFORMANCE_INFO
91
92 TX_INTERRUPT_SAVE_AREA
93 UINT status;
94
95
96 /* Default status to success. */
97 status = TX_SUCCESS;
98
99 /* Determine if this is a legal request. */
100 if (mutex_ptr == TX_NULL)
101 {
102
103 /* Mutex pointer is illegal, return error. */
104 status = TX_PTR_ERROR;
105 }
106
107 /* Determine if the mutex ID is invalid. */
108 else if (mutex_ptr -> tx_mutex_id != TX_MUTEX_ID)
109 {
110
111 /* Mutex pointer is illegal, return error. */
112 status = TX_PTR_ERROR;
113 }
114 else
115 {
116
117 /* Disable interrupts. */
118 TX_DISABLE
119
120 /* If trace is enabled, insert this event into the trace buffer. */
121 TX_TRACE_IN_LINE_INSERT(TX_TRACE_MUTEX_PERFORMANCE_INFO_GET, mutex_ptr, 0, 0, 0, TX_TRACE_MUTEX_EVENTS)
122
123 /* Log this kernel call. */
124 TX_EL_MUTEX_PERFORMANCE_INFO_GET_INSERT
125
126 /* Retrieve all the pertinent information and return it in the supplied
127 destinations. */
128
129 /* Retrieve the number of puts on this mutex. */
130 if (puts != TX_NULL)
131 {
132
133 *puts = mutex_ptr -> tx_mutex_performance_put_count;
134 }
135
136 /* Retrieve the number of gets on this mutex. */
137 if (gets != TX_NULL)
138 {
139
140 *gets = mutex_ptr -> tx_mutex_performance_get_count;
141 }
142
143 /* Retrieve the number of suspensions on this mutex. */
144 if (suspensions != TX_NULL)
145 {
146
147 *suspensions = mutex_ptr -> tx_mutex_performance_suspension_count;
148 }
149
150 /* Retrieve the number of timeouts on this mutex. */
151 if (timeouts != TX_NULL)
152 {
153
154 *timeouts = mutex_ptr -> tx_mutex_performance_timeout_count;
155 }
156
157 /* Retrieve the number of priority inversions on this mutex. */
158 if (inversions != TX_NULL)
159 {
160
161 *inversions = mutex_ptr -> tx_mutex_performance_priority_inversion_count;
162 }
163
164 /* Retrieve the number of priority inheritances on this mutex. */
165 if (inheritances != TX_NULL)
166 {
167
168 *inheritances = mutex_ptr -> tx_mutex_performance__priority_inheritance_count;
169 }
170
171 /* Restore interrupts. */
172 TX_RESTORE
173 }
174 #else
175 UINT status;
176
177
178 /* Access input arguments just for the sake of lint, MISRA, etc. */
179 if (mutex_ptr != TX_NULL)
180 {
181
182 /* Not enabled, return error. */
183 status = TX_FEATURE_NOT_ENABLED;
184 }
185 else if (puts != TX_NULL)
186 {
187
188 /* Not enabled, return error. */
189 status = TX_FEATURE_NOT_ENABLED;
190 }
191 else if (gets != TX_NULL)
192 {
193
194 /* Not enabled, return error. */
195 status = TX_FEATURE_NOT_ENABLED;
196 }
197 else if (suspensions != TX_NULL)
198 {
199
200 /* Not enabled, return error. */
201 status = TX_FEATURE_NOT_ENABLED;
202 }
203 else if (timeouts != TX_NULL)
204 {
205
206 /* Not enabled, return error. */
207 status = TX_FEATURE_NOT_ENABLED;
208 }
209 else if (inversions != TX_NULL)
210 {
211
212 /* Not enabled, return error. */
213 status = TX_FEATURE_NOT_ENABLED;
214 }
215 else if (inheritances != TX_NULL)
216 {
217
218 /* Not enabled, return error. */
219 status = TX_FEATURE_NOT_ENABLED;
220 }
221 else
222 {
223
224 /* Not enabled, return error. */
225 status = TX_FEATURE_NOT_ENABLED;
226 }
227 #endif
228
229 /* Return completion status. */
230 return(status);
231 }
232
233