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 /**   Block 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_block_pool.h"
30 #ifdef TX_BLOCK_POOL_ENABLE_PERFORMANCE_INFO
31 #include "tx_trace.h"
32 #endif
33 
34 
35 /**************************************************************************/
36 /*                                                                        */
37 /*  FUNCTION                                               RELEASE        */
38 /*                                                                        */
39 /*    _tx_block_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 /*    block pool.                                                         */
49 /*                                                                        */
50 /*  INPUT                                                                 */
51 /*                                                                        */
52 /*    pool_ptr                          Pointer to block pool control blk */
53 /*    allocates                         Destination for the number of     */
54 /*                                        allocations from this pool      */
55 /*    releases                          Destination for the number of     */
56 /*                                        blocks released back to pool    */
57 /*    suspensions                       Destination for number of         */
58 /*                                        suspensions on this pool        */
59 /*    timeouts                          Destination for number of timeouts*/
60 /*                                        on this pool                    */
61 /*                                                                        */
62 /*  OUTPUT                                                                */
63 /*                                                                        */
64 /*    status                            Completion status                 */
65 /*                                                                        */
66 /*  CALLS                                                                 */
67 /*                                                                        */
68 /*    None                                                                */
69 /*                                                                        */
70 /*  CALLED BY                                                             */
71 /*                                                                        */
72 /*    Application Code                                                    */
73 /*                                                                        */
74 /*  RELEASE HISTORY                                                       */
75 /*                                                                        */
76 /*    DATE              NAME                      DESCRIPTION             */
77 /*                                                                        */
78 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
79 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
80 /*                                            resulting in version 6.1    */
81 /*                                                                        */
82 /**************************************************************************/
_tx_block_pool_performance_info_get(TX_BLOCK_POOL * pool_ptr,ULONG * allocates,ULONG * releases,ULONG * suspensions,ULONG * timeouts)83 UINT  _tx_block_pool_performance_info_get(TX_BLOCK_POOL *pool_ptr, ULONG *allocates, ULONG *releases,
84                     ULONG *suspensions, ULONG *timeouts)
85 {
86 
87 #ifdef TX_BLOCK_POOL_ENABLE_PERFORMANCE_INFO
88 
89 TX_INTERRUPT_SAVE_AREA
90 UINT                    status;
91 
92 
93     /* Determine if this is a legal request.  */
94     if (pool_ptr == TX_NULL)
95     {
96 
97         /* Block pool pointer is illegal, return error.  */
98         status =  TX_PTR_ERROR;
99     }
100 
101     /* Determine if the pool ID is invalid.  */
102     else if (pool_ptr -> tx_block_pool_id != TX_BLOCK_POOL_ID)
103     {
104 
105         /* Block pool pointer is illegal, return error.  */
106         status =  TX_PTR_ERROR;
107     }
108     else
109     {
110 
111         /* Disable interrupts.  */
112         TX_DISABLE
113 
114         /* If trace is enabled, insert this event into the trace buffer.  */
115         TX_TRACE_IN_LINE_INSERT(TX_TRACE_BLOCK_POOL_PERFORMANCE_INFO_GET, pool_ptr, 0, 0, 0, TX_TRACE_BLOCK_POOL_EVENTS)
116 
117         /* Log this kernel call.  */
118         TX_EL_BLOCK_POOL_PERFORMANCE_INFO_GET_INSERT
119 
120         /* Retrieve all the pertinent information and return it in the supplied
121            destinations.  */
122 
123         /* Retrieve the number of allocations from this block pool.  */
124         if (allocates != TX_NULL)
125         {
126 
127             *allocates =  pool_ptr -> tx_block_pool_performance_allocate_count;
128         }
129 
130         /* Retrieve the number of blocks released to this block pool.  */
131         if (releases != TX_NULL)
132         {
133 
134             *releases =  pool_ptr -> tx_block_pool_performance_release_count;
135         }
136 
137         /* Retrieve the number of thread suspensions on this block pool.  */
138         if (suspensions != TX_NULL)
139         {
140 
141             *suspensions =  pool_ptr -> tx_block_pool_performance_suspension_count;
142         }
143 
144         /* Retrieve the number of thread timeouts on this block pool.  */
145         if (timeouts != TX_NULL)
146         {
147 
148             *timeouts =  pool_ptr -> tx_block_pool_performance_timeout_count;
149         }
150 
151         /* Restore interrupts.  */
152         TX_RESTORE
153 
154         /* Return successful completion.  */
155         status =  TX_SUCCESS;
156     }
157 #else
158 UINT                    status;
159 
160 
161     /* Access input arguments just for the sake of lint, MISRA, etc.  */
162     if (pool_ptr != TX_NULL)
163     {
164 
165         /* Not enabled, return error.  */
166         status =  TX_FEATURE_NOT_ENABLED;
167     }
168     else if (allocates != TX_NULL)
169     {
170 
171         /* Not enabled, return error.  */
172         status =  TX_FEATURE_NOT_ENABLED;
173     }
174     else if (releases != TX_NULL)
175     {
176 
177         /* Not enabled, return error.  */
178         status =  TX_FEATURE_NOT_ENABLED;
179     }
180     else if (suspensions != TX_NULL)
181     {
182 
183         /* Not enabled, return error.  */
184         status =  TX_FEATURE_NOT_ENABLED;
185     }
186     else if (timeouts != TX_NULL)
187     {
188 
189         /* Not enabled, return error.  */
190         status =  TX_FEATURE_NOT_ENABLED;
191     }
192     else
193     {
194 
195         /* Not enabled, return error.  */
196         status =  TX_FEATURE_NOT_ENABLED;
197     }
198 #endif
199 
200     /* Return completion status.  */
201     return(status);
202 }
203 
204