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