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 /**   Queue                                                               */
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_queue.h"
30 #ifdef TX_QUEUE_ENABLE_PERFORMANCE_INFO
31 #include "tx_trace.h"
32 #endif
33 
34 
35 /**************************************************************************/
36 /*                                                                        */
37 /*  FUNCTION                                               RELEASE        */
38 /*                                                                        */
39 /*    _tx_queue_performance_info_get                      PORTABLE C      */
40 /*                                                           6.1          */
41 /*  AUTHOR                                                                */
42 /*                                                                        */
43 /*    William E. Lamie, Microsoft Corporation                             */
44 /*                                                                        */
45 /*  DESCRIPTION                                                           */
46 /*                                                                        */
47 /*    This function retrieves performance information from the specified  */
48 /*    queue.                                                              */
49 /*                                                                        */
50 /*  INPUT                                                                 */
51 /*                                                                        */
52 /*    queue_ptr                         Pointer to queue control block    */
53 /*    messages_sent                     Destination for messages sent     */
54 /*    messages_received                 Destination for messages received */
55 /*    empty_suspensions                 Destination for number of empty   */
56 /*                                        queue suspensions               */
57 /*    full_suspensions                  Destination for number of full    */
58 /*                                        queue suspensions               */
59 /*    full_errors                       Destination for queue full errors */
60 /*                                        returned - no suspension        */
61 /*    timeouts                          Destination for number of timeouts*/
62 /*                                        on this queue                   */
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_queue_performance_info_get(TX_QUEUE * queue_ptr,ULONG * messages_sent,ULONG * messages_received,ULONG * empty_suspensions,ULONG * full_suspensions,ULONG * full_errors,ULONG * timeouts)85 UINT  _tx_queue_performance_info_get(TX_QUEUE *queue_ptr, ULONG *messages_sent, ULONG *messages_received,
86                     ULONG *empty_suspensions, ULONG *full_suspensions, ULONG *full_errors, ULONG *timeouts)
87 {
88 
89 #ifdef TX_QUEUE_ENABLE_PERFORMANCE_INFO
90 
91 TX_INTERRUPT_SAVE_AREA
92 UINT                    status;
93 
94 
95     /* Determine if this is a legal request.  */
96     if (queue_ptr == TX_NULL)
97     {
98 
99         /* Queue pointer is illegal, return error.  */
100         status =  TX_PTR_ERROR;
101     }
102 
103     /* Determine if the queue ID is invalid.  */
104     else if (queue_ptr -> tx_queue_id != TX_QUEUE_ID)
105     {
106 
107         /* Queue pointer is illegal, return error.  */
108         status =  TX_PTR_ERROR;
109     }
110     else
111     {
112 
113         /* Disable interrupts.  */
114         TX_DISABLE
115 
116         /* If trace is enabled, insert this event into the trace buffer.  */
117         TX_TRACE_IN_LINE_INSERT(TX_TRACE_QUEUE_PERFORMANCE_INFO_GET, queue_ptr, 0, 0, 0, TX_TRACE_QUEUE_EVENTS)
118 
119         /* Log this kernel call.  */
120         TX_EL_QUEUE_PERFORMANCE_INFO_GET_INSERT
121 
122         /* Retrieve all the pertinent information and return it in the supplied
123            destinations.  */
124 
125         /* Retrieve the number of messages sent to this queue.  */
126         if (messages_sent != TX_NULL)
127         {
128 
129             *messages_sent =  queue_ptr -> tx_queue_performance_messages_sent_count;
130         }
131 
132         /* Retrieve the number of messages received from this queue.  */
133         if (messages_received != TX_NULL)
134         {
135 
136             *messages_received =  queue_ptr -> tx_queue_performance_messages_received_count;
137         }
138 
139         /* Retrieve the number of empty queue suspensions on this queue.  */
140         if (empty_suspensions != TX_NULL)
141         {
142 
143             *empty_suspensions =  queue_ptr -> tx_queue_performance_empty_suspension_count;
144         }
145 
146         /* Retrieve the number of full queue suspensions on this queue.  */
147         if (full_suspensions != TX_NULL)
148         {
149 
150             *full_suspensions =  queue_ptr -> tx_queue_performance_full_suspension_count;
151         }
152 
153         /* Retrieve the number of full errors (no suspension!) on this queue.  */
154         if (full_errors != TX_NULL)
155         {
156 
157             *full_errors =  queue_ptr -> tx_queue_performance_full_error_count;
158         }
159 
160         /* Retrieve the number of timeouts on this queue.  */
161         if (timeouts != TX_NULL)
162         {
163 
164             *timeouts =  queue_ptr -> tx_queue_performance_timeout_count;
165         }
166 
167         /* Restore interrupts.  */
168         TX_RESTORE
169 
170         /* Return completion status.  */
171         status =  TX_SUCCESS;
172     }
173 #else
174 UINT                    status;
175 
176 
177     /* Access input arguments just for the sake of lint, MISRA, etc.  */
178     if (queue_ptr != TX_NULL)
179     {
180 
181         /* Not enabled, return error.  */
182         status =  TX_FEATURE_NOT_ENABLED;
183     }
184     else if (messages_sent != TX_NULL)
185     {
186 
187         /* Not enabled, return error.  */
188         status =  TX_FEATURE_NOT_ENABLED;
189     }
190     else if (messages_received != TX_NULL)
191     {
192 
193         /* Not enabled, return error.  */
194         status =  TX_FEATURE_NOT_ENABLED;
195     }
196     else if (empty_suspensions != TX_NULL)
197     {
198 
199         /* Not enabled, return error.  */
200         status =  TX_FEATURE_NOT_ENABLED;
201     }
202     else if (full_suspensions != TX_NULL)
203     {
204 
205         /* Not enabled, return error.  */
206         status =  TX_FEATURE_NOT_ENABLED;
207     }
208     else if (full_errors != TX_NULL)
209     {
210 
211         /* Not enabled, return error.  */
212         status =  TX_FEATURE_NOT_ENABLED;
213     }
214     else if (timeouts != 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