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 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _tx_block_pool_performance_system_info_get          PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    William E. Lamie, Microsoft Corporation                             */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function retrieves block pool performance information.         */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    allocates                         Destination for the total number  */
50 /*                                        of block allocations            */
51 /*    releases                          Destination for the total number  */
52 /*                                        of blocks released              */
53 /*    suspensions                       Destination for the total number  */
54 /*                                        of suspensions                  */
55 /*    timeouts                          Destination for total number of   */
56 /*                                        timeouts                        */
57 /*                                                                        */
58 /*  OUTPUT                                                                */
59 /*                                                                        */
60 /*    status                            Completion status                 */
61 /*                                                                        */
62 /*  CALLS                                                                 */
63 /*                                                                        */
64 /*    None                                                                */
65 /*                                                                        */
66 /*  CALLED BY                                                             */
67 /*                                                                        */
68 /*    Application Code                                                    */
69 /*                                                                        */
70 /*  RELEASE HISTORY                                                       */
71 /*                                                                        */
72 /*    DATE              NAME                      DESCRIPTION             */
73 /*                                                                        */
74 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
75 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
76 /*                                            resulting in version 6.1    */
77 /*                                                                        */
78 /**************************************************************************/
_tx_block_pool_performance_system_info_get(ULONG * allocates,ULONG * releases,ULONG * suspensions,ULONG * timeouts)79 UINT  _tx_block_pool_performance_system_info_get(ULONG *allocates, ULONG *releases, ULONG *suspensions, ULONG *timeouts)
80 {
81 
82 #ifdef TX_BLOCK_POOL_ENABLE_PERFORMANCE_INFO
83 
84 TX_INTERRUPT_SAVE_AREA
85 
86 
87     /* Disable interrupts.  */
88     TX_DISABLE
89 
90     /* If trace is enabled, insert this event into the trace buffer.  */
91     TX_TRACE_IN_LINE_INSERT(TX_TRACE_BLOCK_POOL__PERFORMANCE_SYSTEM_INFO_GET, 0, 0, 0, 0, TX_TRACE_BLOCK_POOL_EVENTS)
92 
93     /* Log this kernel call.  */
94     TX_EL_BLOCK_POOL_PERFORMANCE_SYSTEM_INFO_GET_INSERT
95 
96     /* Retrieve all the pertinent information and return it in the supplied
97        destinations.  */
98 
99     /* Retrieve the total number of block allocations.  */
100     if (allocates != TX_NULL)
101     {
102 
103         *allocates =  _tx_block_pool_performance_allocate_count;
104     }
105 
106     /* Retrieve the total number of blocks released.  */
107     if (releases != TX_NULL)
108     {
109 
110         *releases =  _tx_block_pool_performance_release_count;
111     }
112 
113     /* Retrieve the total number of block pool thread suspensions.  */
114     if (suspensions != TX_NULL)
115     {
116 
117         *suspensions =  _tx_block_pool_performance_suspension_count;
118     }
119 
120     /* Retrieve the total number of block pool thread timeouts.  */
121     if (timeouts != TX_NULL)
122     {
123 
124         *timeouts =  _tx_block_pool_performance_timeout_count;
125     }
126 
127     /* Restore interrupts.  */
128     TX_RESTORE
129 
130     /* Return completion status.  */
131     return(TX_SUCCESS);
132 
133 #else
134 
135 UINT        status;
136 
137 
138     /* Access input arguments just for the sake of lint, MISRA, etc.  */
139     if (allocates != TX_NULL)
140     {
141 
142         /* Not enabled, return error.  */
143         status =  TX_FEATURE_NOT_ENABLED;
144     }
145     else if (releases != TX_NULL)
146     {
147 
148         /* Not enabled, return error.  */
149         status =  TX_FEATURE_NOT_ENABLED;
150     }
151     else if (suspensions != TX_NULL)
152     {
153 
154         /* Not enabled, return error.  */
155         status =  TX_FEATURE_NOT_ENABLED;
156     }
157     else if (timeouts != TX_NULL)
158     {
159 
160         /* Not enabled, return error.  */
161         status =  TX_FEATURE_NOT_ENABLED;
162     }
163     else
164     {
165 
166         /* Not enabled, return error.  */
167         status =  TX_FEATURE_NOT_ENABLED;
168     }
169 
170     /* Return completion status.  */
171     return(status);
172 #endif
173 }
174 
175