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 /**   Queue                                                               */
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_queue.h"
29 #ifdef TX_QUEUE_ENABLE_PERFORMANCE_INFO
30 #include "tx_trace.h"
31 #endif
32 
33 
34 /**************************************************************************/
35 /*                                                                        */
36 /*  FUNCTION                                               RELEASE        */
37 /*                                                                        */
38 /*    _tx_queue_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 queue system performance information.       */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    messages_sent                     Destination for total messages    */
51 /*                                        sent                            */
52 /*    messages_received                 Destination for total messages    */
53 /*                                        received                        */
54 /*    empty_suspensions                 Destination for total empty       */
55 /*                                        queue suspensions               */
56 /*    full_suspensions                  Destination for total full        */
57 /*                                        queue suspensions               */
58 /*    full_errors                       Destination for total queue full  */
59 /*                                        errors returned - no suspension */
60 /*    timeouts                          Destination for total number of   */
61 /*                                        timeouts                        */
62 /*                                                                        */
63 /*  OUTPUT                                                                */
64 /*                                                                        */
65 /*    status                            Completion status                 */
66 /*                                                                        */
67 /*  CALLS                                                                 */
68 /*                                                                        */
69 /*    None                                                                */
70 /*                                                                        */
71 /*  CALLED BY                                                             */
72 /*                                                                        */
73 /*    Application Code                                                    */
74 /*                                                                        */
75 /*  RELEASE HISTORY                                                       */
76 /*                                                                        */
77 /*    DATE              NAME                      DESCRIPTION             */
78 /*                                                                        */
79 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
80 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
81 /*                                            resulting in version 6.1    */
82 /*                                                                        */
83 /**************************************************************************/
_tx_queue_performance_system_info_get(ULONG * messages_sent,ULONG * messages_received,ULONG * empty_suspensions,ULONG * full_suspensions,ULONG * full_errors,ULONG * timeouts)84 UINT  _tx_queue_performance_system_info_get(ULONG *messages_sent, ULONG *messages_received,
85                     ULONG *empty_suspensions, ULONG *full_suspensions, ULONG *full_errors, ULONG *timeouts)
86 {
87 
88 #ifdef TX_QUEUE_ENABLE_PERFORMANCE_INFO
89 
90 TX_INTERRUPT_SAVE_AREA
91 
92 
93     /* Disable interrupts.  */
94     TX_DISABLE
95 
96     /* If trace is enabled, insert this event into the trace buffer.  */
97     TX_TRACE_IN_LINE_INSERT(TX_TRACE_QUEUE_PERFORMANCE_SYSTEM_INFO_GET, 0, 0, 0, 0, TX_TRACE_QUEUE_EVENTS)
98 
99     /* Log this kernel call.  */
100     TX_EL_QUEUE_PERFORMANCE_SYSTEM_INFO_GET_INSERT
101 
102     /* Retrieve all the pertinent information and return it in the supplied
103        destinations.  */
104 
105     /* Retrieve the total number of queue messages sent.  */
106     if (messages_sent != TX_NULL)
107     {
108 
109         *messages_sent =  _tx_queue_performance_messages_sent_count;
110     }
111 
112     /* Retrieve the total number of queue messages received.  */
113     if (messages_received != TX_NULL)
114     {
115 
116         *messages_received =  _tx_queue_performance__messages_received_count;
117     }
118 
119     /* Retrieve the total number of empty queue suspensions.  */
120     if (empty_suspensions != TX_NULL)
121     {
122 
123         *empty_suspensions =  _tx_queue_performance_empty_suspension_count;
124     }
125 
126     /* Retrieve the total number of full queue suspensions.  */
127     if (full_suspensions != TX_NULL)
128     {
129 
130         *full_suspensions =  _tx_queue_performance_full_suspension_count;
131     }
132 
133     /* Retrieve the total number of full errors.  */
134     if (full_errors != TX_NULL)
135     {
136 
137         *full_errors =  _tx_queue_performance_full_error_count;
138     }
139 
140     /* Retrieve the total number of queue timeouts.  */
141     if (timeouts != TX_NULL)
142     {
143 
144         *timeouts =  _tx_queue_performance_timeout_count;
145     }
146 
147     /* Restore interrupts.  */
148     TX_RESTORE
149 
150     /* Return completion status.  */
151     return(TX_SUCCESS);
152 
153 #else
154 
155 UINT        status;
156 
157 
158     /* Access input arguments just for the sake of lint, MISRA, etc.  */
159     if (messages_sent != TX_NULL)
160     {
161 
162         /* Not enabled, return error.  */
163         status =  TX_FEATURE_NOT_ENABLED;
164     }
165     else if (messages_received != TX_NULL)
166     {
167 
168         /* Not enabled, return error.  */
169         status =  TX_FEATURE_NOT_ENABLED;
170     }
171     else if (empty_suspensions != TX_NULL)
172     {
173 
174         /* Not enabled, return error.  */
175         status =  TX_FEATURE_NOT_ENABLED;
176     }
177     else if (full_suspensions != TX_NULL)
178     {
179 
180         /* Not enabled, return error.  */
181         status =  TX_FEATURE_NOT_ENABLED;
182     }
183     else if (full_errors != TX_NULL)
184     {
185 
186         /* Not enabled, return error.  */
187         status =  TX_FEATURE_NOT_ENABLED;
188     }
189     else if (timeouts != TX_NULL)
190     {
191 
192         /* Not enabled, return error.  */
193         status =  TX_FEATURE_NOT_ENABLED;
194     }
195     else
196     {
197 
198         /* Not enabled, return error.  */
199         status =  TX_FEATURE_NOT_ENABLED;
200     }
201 
202     /* Return completion status.  */
203     return(status);
204 #endif
205 }
206 
207