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