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