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