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 /**   Byte Memory                                                         */
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_byte_pool.h"
30 #ifdef TX_BYTE_POOL_ENABLE_PERFORMANCE_INFO
31 #include "tx_trace.h"
32 #endif
33 
34 
35 /**************************************************************************/
36 /*                                                                        */
37 /*  FUNCTION                                               RELEASE        */
38 /*                                                                        */
39 /*    _tx_byte_pool_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 /*    byte pool.                                                          */
49 /*                                                                        */
50 /*  INPUT                                                                 */
51 /*                                                                        */
52 /*    pool_ptr                          Pointer to byte pool control block*/
53 /*    allocates                         Destination for number of         */
54 /*                                        allocates on this pool          */
55 /*    releases                          Destination for number of         */
56 /*                                        releases on this pool           */
57 /*    fragments_searched                Destination for number of         */
58 /*                                        fragments searched during       */
59 /*                                        allocation                      */
60 /*    merges                            Destination for number of adjacent*/
61 /*                                        free fragments merged           */
62 /*    splits                            Destination for number of         */
63 /*                                        fragments split during          */
64 /*                                        allocation                      */
65 /*    suspensions                       Destination for number of         */
66 /*                                        suspensions on this pool        */
67 /*    timeouts                          Destination for number of timeouts*/
68 /*                                        on this byte pool               */
69 /*                                                                        */
70 /*  OUTPUT                                                                */
71 /*                                                                        */
72 /*    status                            Completion status                 */
73 /*                                                                        */
74 /*  CALLS                                                                 */
75 /*                                                                        */
76 /*    None                                                                */
77 /*                                                                        */
78 /*  CALLED BY                                                             */
79 /*                                                                        */
80 /*    Application Code                                                    */
81 /*                                                                        */
82 /*  RELEASE HISTORY                                                       */
83 /*                                                                        */
84 /*    DATE              NAME                      DESCRIPTION             */
85 /*                                                                        */
86 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
87 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
88 /*                                            resulting in version 6.1    */
89 /*                                                                        */
90 /**************************************************************************/
_tx_byte_pool_performance_info_get(TX_BYTE_POOL * pool_ptr,ULONG * allocates,ULONG * releases,ULONG * fragments_searched,ULONG * merges,ULONG * splits,ULONG * suspensions,ULONG * timeouts)91 UINT  _tx_byte_pool_performance_info_get(TX_BYTE_POOL *pool_ptr, ULONG *allocates, ULONG *releases,
92                     ULONG *fragments_searched, ULONG *merges, ULONG *splits, ULONG *suspensions, ULONG *timeouts)
93 {
94 
95 #ifdef TX_BYTE_POOL_ENABLE_PERFORMANCE_INFO
96 
97 TX_INTERRUPT_SAVE_AREA
98 
99 UINT        status;
100 
101 
102     /* Determine if this is a legal request.  */
103     if (pool_ptr == TX_NULL)
104     {
105 
106         /* Byte pool pointer is illegal, return error.  */
107         status =  TX_PTR_ERROR;
108     }
109 
110     /* Determine if the pool ID is invalid.  */
111     else if (pool_ptr -> tx_byte_pool_id != TX_BYTE_POOL_ID)
112     {
113 
114         /* Byte pool pointer is illegal, return error.  */
115         status =  TX_PTR_ERROR;
116     }
117     else
118     {
119 
120         /* Disable interrupts.  */
121         TX_DISABLE
122 
123         /* If trace is enabled, insert this event into the trace buffer.  */
124         TX_TRACE_IN_LINE_INSERT(TX_TRACE_BYTE_POOL_PERFORMANCE_INFO_GET, pool_ptr, 0, 0, 0, TX_TRACE_BYTE_POOL_EVENTS)
125 
126         /* Log this kernel call.  */
127         TX_EL_BYTE_POOL_PERFORMANCE_INFO_GET_INSERT
128 
129         /* Retrieve all the pertinent information and return it in the supplied
130            destinations.  */
131 
132         /* Retrieve the number of allocates on this byte pool.  */
133         if (allocates != TX_NULL)
134         {
135 
136             *allocates =  pool_ptr -> tx_byte_pool_performance_allocate_count;
137         }
138 
139         /* Retrieve the number of releases on this byte pool.  */
140         if (releases != TX_NULL)
141         {
142 
143             *releases =  pool_ptr -> tx_byte_pool_performance_release_count;
144         }
145 
146         /* Retrieve the number of fragments searched in this byte pool.  */
147         if (fragments_searched != TX_NULL)
148         {
149 
150             *fragments_searched =  pool_ptr -> tx_byte_pool_performance_search_count;
151         }
152 
153         /* Retrieve the number of fragments merged on this byte pool.  */
154         if (merges != TX_NULL)
155         {
156 
157             *merges =  pool_ptr -> tx_byte_pool_performance_merge_count;
158         }
159 
160         /* Retrieve the number of fragment splits on this byte pool.  */
161         if (splits != TX_NULL)
162         {
163 
164             *splits =  pool_ptr -> tx_byte_pool_performance_split_count;
165         }
166 
167         /* Retrieve the number of suspensions on this byte pool.  */
168         if (suspensions != TX_NULL)
169         {
170 
171             *suspensions =  pool_ptr -> tx_byte_pool_performance_suspension_count;
172         }
173 
174         /* Retrieve the number of timeouts on this byte pool.  */
175         if (timeouts != TX_NULL)
176         {
177 
178             *timeouts =  pool_ptr -> tx_byte_pool_performance_timeout_count;
179         }
180 
181         /* Restore interrupts.  */
182         TX_RESTORE
183 
184         /* Return completion status.  */
185         status =  TX_SUCCESS;
186     }
187 
188     /* Return completion status.  */
189     return(status);
190 #else
191 
192 UINT        status;
193 
194 
195     /* Access input arguments just for the sake of lint, MISRA, etc.  */
196     if (pool_ptr != TX_NULL)
197     {
198 
199         /* Not enabled, return error.  */
200         status =  TX_FEATURE_NOT_ENABLED;
201     }
202     else if (allocates != TX_NULL)
203     {
204 
205         /* Not enabled, return error.  */
206         status =  TX_FEATURE_NOT_ENABLED;
207     }
208     else if (releases != TX_NULL)
209     {
210 
211         /* Not enabled, return error.  */
212         status =  TX_FEATURE_NOT_ENABLED;
213     }
214     else if (fragments_searched != TX_NULL)
215     {
216 
217         /* Not enabled, return error.  */
218         status =  TX_FEATURE_NOT_ENABLED;
219     }
220     else if (merges != TX_NULL)
221     {
222 
223         /* Not enabled, return error.  */
224         status =  TX_FEATURE_NOT_ENABLED;
225     }
226     else if (splits != TX_NULL)
227     {
228 
229         /* Not enabled, return error.  */
230         status =  TX_FEATURE_NOT_ENABLED;
231     }
232     else if (suspensions != TX_NULL)
233     {
234 
235         /* Not enabled, return error.  */
236         status =  TX_FEATURE_NOT_ENABLED;
237     }
238     else if (timeouts != TX_NULL)
239     {
240 
241         /* Not enabled, return error.  */
242         status =  TX_FEATURE_NOT_ENABLED;
243     }
244     else
245     {
246 
247         /* Not enabled, return error.  */
248         status =  TX_FEATURE_NOT_ENABLED;
249     }
250 
251     /* Return completion status.  */
252     return(status);
253 #endif
254 }
255 
256