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