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 /**   Timer                                                               */
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_timer.h"
29 #ifdef TX_TIMER_ENABLE_PERFORMANCE_INFO
30 #include "tx_trace.h"
31 #endif
32 
33 
34 /**************************************************************************/
35 /*                                                                        */
36 /*  FUNCTION                                               RELEASE        */
37 /*                                                                        */
38 /*    _tx_timer_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 timer performance information.              */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    activates                         Destination for total number of   */
51 /*                                        activations                     */
52 /*    reactivates                       Destination for total number of   */
53 /*                                        reactivations                   */
54 /*    deactivates                       Destination for total number of   */
55 /*                                        deactivations                   */
56 /*    expirations                       Destination for total number of   */
57 /*                                        expirations                     */
58 /*    expiration_adjusts                Destination for total number of   */
59 /*                                        expiration adjustments          */
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_timer_performance_system_info_get(ULONG * activates,ULONG * reactivates,ULONG * deactivates,ULONG * expirations,ULONG * expiration_adjusts)82 UINT  _tx_timer_performance_system_info_get(ULONG *activates, ULONG *reactivates,
83                     ULONG *deactivates, ULONG *expirations, ULONG *expiration_adjusts)
84 {
85 
86 #ifdef TX_TIMER_ENABLE_PERFORMANCE_INFO
87 
88 TX_INTERRUPT_SAVE_AREA
89 
90 
91     /* Disable interrupts.  */
92     TX_DISABLE
93 
94     /* If trace is enabled, insert this event into the trace buffer.  */
95     TX_TRACE_IN_LINE_INSERT(TX_TRACE_TIMER_PERFORMANCE_SYSTEM_INFO_GET, 0, 0, 0, 0, TX_TRACE_TIMER_EVENTS)
96 
97     /* Log this kernel call.  */
98     TX_EL_TIMER_PERFORMANCE_SYSTEM_INFO_GET_INSERT
99 
100     /* Retrieve the total number of timer activations.  */
101     if (activates != TX_NULL)
102     {
103 
104         *activates =  _tx_timer_performance_activate_count;
105     }
106 
107     /* Retrieve the total number of timer reactivations.  */
108     if (reactivates != TX_NULL)
109     {
110 
111         *reactivates =  _tx_timer_performance_reactivate_count;
112     }
113 
114     /* Retrieve the total number of timer deactivations.  */
115     if (deactivates != TX_NULL)
116     {
117 
118         *deactivates =  _tx_timer_performance_deactivate_count;
119     }
120 
121     /* Retrieve the total number of timer expirations.  */
122     if (expirations != TX_NULL)
123     {
124 
125         *expirations =  _tx_timer_performance_expiration_count;
126     }
127 
128     /* Retrieve the total number of timer expiration adjustments.  */
129     if (expiration_adjusts != TX_NULL)
130     {
131 
132         *expiration_adjusts =  _tx_timer_performance__expiration_adjust_count;
133     }
134 
135     /* Restore interrupts.  */
136     TX_RESTORE
137 
138     /* Return completion status.  */
139     return(TX_SUCCESS);
140 
141 #else
142 
143 UINT        status;
144 
145 
146     /* Access input arguments just for the sake of lint, MISRA, etc.  */
147     if (activates != TX_NULL)
148     {
149 
150         /* Not enabled, return error.  */
151         status =  TX_FEATURE_NOT_ENABLED;
152     }
153     else if (reactivates != TX_NULL)
154     {
155 
156         /* Not enabled, return error.  */
157         status =  TX_FEATURE_NOT_ENABLED;
158     }
159     else if (deactivates != TX_NULL)
160     {
161 
162         /* Not enabled, return error.  */
163         status =  TX_FEATURE_NOT_ENABLED;
164     }
165     else if (expirations != TX_NULL)
166     {
167 
168         /* Not enabled, return error.  */
169         status =  TX_FEATURE_NOT_ENABLED;
170     }
171     else if (expiration_adjusts != TX_NULL)
172     {
173 
174         /* Not enabled, return error.  */
175         status =  TX_FEATURE_NOT_ENABLED;
176     }
177     else
178     {
179 
180         /* Not enabled, return error.  */
181         status =  TX_FEATURE_NOT_ENABLED;
182     }
183 
184     /* Return completion status.  */
185     return(status);
186 #endif
187 }
188 
189