1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** ThreadX Component                                                     */
17 /**                                                                       */
18 /**   Execution Profile Kit                                               */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 
24 #ifndef TX_EXECUTION_PROFILE_H
25 #define TX_EXECUTION_PROFILE_H
26 
27 
28 /*  The thread execution profile kit is designed to track thread execution time
29     based on the hardware timer defined by TX_EXECUTION_TIME_SOURCE and
30     TX_EXECUTION_MAX_TIME_SOURCE below. When the thread's total time reaches
31     the maximum value, it remains there until the time is reset to 0 via a call
32     to tx_thread_execution_time_reset. There are several assumptions to the
33     operation of this kit, as follows:
34 
35     1. In tx_port.h replace:
36         #define TX_THREAD_EXTENSION_3"
37       with:
38         #define TX_THREAD_EXTENSION_3           unsigned long long  tx_thread_execution_time_total; \
39                                                 unsigned long       tx_thread_execution_time_last_start;
40 
41     2.  The TX_EXECUTION_TIME_SOURCE and TX_EXECUTION_MAX_TIME_SOURCE macros are
42         defined to utilize a local hardware time source.
43 
44     3.  The following routines are called from assembly code:
45             VOID  _tx_execution_thread_enter(void);
46             VOID  _tx_execution_thread_exit(void);
47             VOID  _tx_execution_isr_enter(void);
48             VOID  _tx_execution_isr_exit(void);
49 
50     4.  The ThreadX library must be rebuilt with TX_ENABLE_EXECUTION_CHANGE_NOTIFY so
51         that these macros are expanded in the TX_THREAD structure and so the assembly code macros
52         are enabled to call the execution profile routines.
53 
54     5.  Add tx_execution_profile.c to the application build.  */
55 
56 /* Define the basic time typedefs for 64-bit accumulation and a 32-bit timer source, which is the
57    most common configuration.  */
58 
59 typedef unsigned long long              EXECUTION_TIME;
60 typedef unsigned long                   EXECUTION_TIME_SOURCE_TYPE;
61 /* For 64-bit time source, the typedef would be:  */
62 /* typedef unsigned long long              EXECUTION_TIME_SOURCE_TYPE;  */
63 
64 /* Define basic constants for the execution profile kit.  */
65 
66 ULONG _tx_thread_smp_time_get(void);
67 
68 #define TX_EXECUTION_TIME_SOURCE        (EXECUTION_TIME_SOURCE_TYPE) _tx_thread_smp_time_get();
69 #define TX_EXECUTION_MAX_TIME_SOURCE     0xFFFFFFFF
70 /* For 64-bit time source, the constant would be:  */
71 /* #define TX_EXECUTION_MAX_TIME_SOURCE     0xFFFFFFFFFFFFFFFF  */
72 
73 
74 /* Define APIs of the execution profile kit.  */
75 
76 struct TX_THREAD_STRUCT;
77 VOID  _tx_execution_thread_enter(void);
78 VOID  _tx_execution_thread_exit(void);
79 VOID  _tx_execution_isr_enter(void);
80 VOID  _tx_execution_isr_exit(void);
81 UINT  _tx_execution_thread_time_reset(struct TX_THREAD_STRUCT *thread_ptr);
82 UINT  _tx_execution_thread_total_time_reset(void);
83 UINT  _tx_execution_isr_time_reset(void);
84 UINT  _tx_execution_idle_time_reset(void);
85 UINT  _tx_execution_thread_time_get(struct TX_THREAD_STRUCT *thread_ptr, EXECUTION_TIME *total_time);
86 UINT  _tx_execution_thread_total_time_get(EXECUTION_TIME *total_time);
87 UINT  _tx_execution_isr_time_get(EXECUTION_TIME *total_time);
88 UINT  _tx_execution_idle_time_get(EXECUTION_TIME *total_time);
89 UINT  _tx_execution_core_thread_total_time_get(UINT core, EXECUTION_TIME *total_time);
90 UINT  _tx_execution_core_isr_time_get(UINT core, EXECUTION_TIME *total_time);
91 UINT  _tx_execution_core_idle_time_get(UINT core, EXECUTION_TIME *total_time);
92 
93 #endif
94