diff options
Diffstat (limited to 'utility')
| -rw-r--r-- | utility/execution_profile_kit/tx_execution_profile.c | 127 | ||||
| -rw-r--r-- | utility/execution_profile_kit/tx_execution_profile.h | 5 |
2 files changed, 97 insertions, 35 deletions
diff --git a/utility/execution_profile_kit/tx_execution_profile.c b/utility/execution_profile_kit/tx_execution_profile.c index 5ec6dd5e..7928a237 100644 --- a/utility/execution_profile_kit/tx_execution_profile.c +++ b/utility/execution_profile_kit/tx_execution_profile.c @@ -28,27 +28,27 @@ #include "tx_api.h" #include "tx_execution_profile.h" -/* Note to developers upgrading from ThreadX version 5: In ThreadX 5, the instruction was to +/* Note to developers upgrading from ThreadX version 5: In ThreadX 5, the instruction was to modify TX_THREAD_EXTENSION_3, and to define the symbol TX_ENABLE_EXECUTION_CHANGE_NOTIFY. For ThreadX 6, user no long need to modify TX_THREAD_EXTENSION_3, and shall use the symbol - TX_EXECUTION_PROFILE_ENABLE instead of TX_ENABLE_EXECUTION_CHANGE_NOTIFY. + TX_EXECUTION_PROFILE_ENABLE instead of TX_ENABLE_EXECUTION_CHANGE_NOTIFY. For backward compatibiliy reasons, project upgraded from ThreadX 5 may still be able to use - Execution Profile without changes to existing project, users are strongly recommended to + Execution Profile without changes to existing project, users are strongly recommended to make the change. */ #if defined(TX_ENABLE_EXECUTION_CHANGE_NOTIFY) || defined(TX_EXECUTION_PROFILE_ENABLE) -/* The thread execution profile kit is designed to track thread execution time - based on the hardware timer defined by TX_EXECUTION_TIME_SOURCE and - TX_EXECUTION_MAX_TIME_SOURCE below. When the thread's total time reaches +/* The thread execution profile kit is designed to track thread execution time + based on the hardware timer defined by TX_EXECUTION_TIME_SOURCE and + TX_EXECUTION_MAX_TIME_SOURCE below. When the thread's total time reaches the maximum value, it remains there until the time is reset to 0 via a call - to tx_thread_execution_time_reset. There are several assumptions to the + to tx_thread_execution_time_reset. There are several assumptions to the operation of this kit, as follows: - 1. The TX_EXECUTION_TIME_SOURCE and TX_EXECUTION_MAX_TIME_SOURCE macros are + 1. The TX_EXECUTION_TIME_SOURCE and TX_EXECUTION_MAX_TIME_SOURCE macros are defined to utilize a local hardware time source. 2. ThreadX 5.4 (or later) is being used, with the assembly code enabled to @@ -59,9 +59,9 @@ VOID _tx_execution_isr_enter(void); VOID _tx_execution_isr_exit(void); - 3. The ThreadX library assembly code must be rebuilt with TX_EXECUTION_PROFILE_ENABLE so - that these macros are expanded in the TX_THREAD structure and so the assembly code macros - are enabled to call the execution profile routines. + 3. The ThreadX library assembly code must be rebuilt with TX_EXECUTION_PROFILE_ENABLE so + that these macros are expanded in the TX_THREAD structure and so the assembly code macros + are enabled to call the execution profile routines. 4. Add tx_execution_profile.c to the application build. */ @@ -86,7 +86,7 @@ EXECUTION_TIME _tx_execution_thread_time_total; and _tx_thread_context_restore are tracked by this utility. */ EXECUTION_TIME _tx_execution_isr_time_total; -EXECUTION_TIME_SOURCE_TYPE _tx_execution_isr_time_last_start; +EXECUTION_TIME_SOURCE_TYPE _tx_execution_isr_time_last_start; /* Define the system idle time gathering information. For idle time that exceeds the range of the timer @@ -95,19 +95,67 @@ EXECUTION_TIME_SOURCE_TYPE _tx_execution_isr_time_last_start; EXECUTION_TIME _tx_execution_idle_time_total; EXECUTION_TIME_SOURCE_TYPE _tx_execution_idle_time_last_start; - +UINT _tx_execution_idle_active; /* For Cortex-M targets, we need to keep track of nested interrupts internally. */ #ifdef TX_CORTEX_M_EPK ULONG _tx_execution_isr_nest_counter = 0; #endif + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _tx_execution_initialize PORTABLE C */ +/* 6.1.11 */ +/* AUTHOR */ +/* */ +/* Scott Larson, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function is called at initialization. */ +/* */ +/* INPUT */ +/* */ +/* None */ +/* */ +/* OUTPUT */ +/* */ +/* None */ +/* */ +/* CALLS */ +/* */ +/* None */ +/* */ +/* CALLED BY */ +/* */ +/* xxx xxx */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 04-25-2022 Scott Larson Initial Version 6.1.11 */ +/* */ +/**************************************************************************/ +VOID _tx_execution_initialize(void) +{ + /* In idle mode until a thread is scheduled or ISR occurs. */ + _tx_execution_idle_active = TX_TRUE; + + /* Pickup the start of idle time. */ + _tx_execution_idle_time_last_start = TX_EXECUTION_TIME_SOURCE; +} + + /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _tx_execution_thread_enter PORTABLE C */ -/* 6.1.7 */ +/* 6.1.11 */ /* AUTHOR */ /* */ /* William E. Lamie, Microsoft Corporation */ @@ -137,6 +185,9 @@ ULONG _tx_execution_isr_nest_counter = 0; /* DATE NAME DESCRIPTION */ /* */ /* 06-02-2021 William E. Lamie Initial Version 6.1.7 */ +/* 04-25-2022 Scott Larson Modified comments and fixed */ +/* wrap-around calculation, */ +/* resulting in version 6.1.11 */ /* */ /**************************************************************************/ VOID _tx_execution_thread_enter(void) @@ -164,7 +215,7 @@ EXECUTION_TIME new_total_time; last_start_time = _tx_execution_idle_time_last_start; /* Determine if idle time is being measured. */ - if (last_start_time) + if (_tx_execution_idle_active) { /* Determine how to calculate the difference. */ @@ -173,12 +224,12 @@ EXECUTION_TIME new_total_time; /* Simply subtract. */ delta_time = (EXECUTION_TIME) (current_time - last_start_time); - } + } else { /* Timer wrapped, compute the delta assuming incrementing time counter. */ - delta_time = (EXECUTION_TIME) (current_time + (((EXECUTION_TIME_SOURCE_TYPE) TX_EXECUTION_MAX_TIME_SOURCE) - last_start_time)); + delta_time = (EXECUTION_TIME) (current_time + ((((EXECUTION_TIME_SOURCE_TYPE) TX_EXECUTION_MAX_TIME_SOURCE) + 1) - last_start_time)); } /* Pickup the total time. */ @@ -196,10 +247,10 @@ EXECUTION_TIME new_total_time; } /* Now store back the total idle time. */ - _tx_execution_idle_time_total = new_total_time; + _tx_execution_idle_time_total = new_total_time; /* Disable the idle time measurement. */ - _tx_execution_idle_time_last_start = 0; + _tx_execution_idle_active = TX_FALSE; } } @@ -209,7 +260,7 @@ EXECUTION_TIME new_total_time; /* FUNCTION RELEASE */ /* */ /* _tx_execution_thread_exit PORTABLE C */ -/* 6.1.7 */ +/* 6.1.11 */ /* AUTHOR */ /* */ /* William E. Lamie, Microsoft Corporation */ @@ -239,6 +290,9 @@ EXECUTION_TIME new_total_time; /* DATE NAME DESCRIPTION */ /* */ /* 06-02-2021 William E. Lamie Initial Version 6.1.7 */ +/* 04-25-2022 Scott Larson Modified comments and fixed */ +/* wrap-around calculation, */ +/* resulting in version 6.1.11 */ /* */ /**************************************************************************/ VOID _tx_execution_thread_exit(void) @@ -283,7 +337,7 @@ EXECUTION_TIME delta_time; { /* Timer wrapped, compute the delta assuming incrementing time counter. */ - delta_time = (EXECUTION_TIME) (current_time + (((EXECUTION_TIME_SOURCE_TYPE) TX_EXECUTION_MAX_TIME_SOURCE) - last_start_time)); + delta_time = (EXECUTION_TIME) (current_time + ((((EXECUTION_TIME_SOURCE_TYPE) TX_EXECUTION_MAX_TIME_SOURCE) + 1) - last_start_time)); } /* Pickup the total time. */ @@ -303,7 +357,7 @@ EXECUTION_TIME delta_time; /* Store back the new total time. */ thread_ptr -> tx_thread_execution_time_total = new_total_time; - /* Now accumulate this thread's execution time into the total thread execution time. */ + /* Now accumulate this thread's execution time into the total thread execution time. */ new_total_time = _tx_execution_thread_time_total + delta_time; /* Determine if a rollover on the total time is present. */ @@ -312,18 +366,18 @@ EXECUTION_TIME delta_time; /* Rollover. Set the total time to max value. */ new_total_time = (EXECUTION_TIME) TX_EXECUTION_MAX_TIME_SOURCE; - } + } /* Store back the new total time. */ _tx_execution_thread_time_total = new_total_time; } - + /* Is the system now idle? */ if (_tx_thread_execute_ptr == TX_NULL) { - /* Yes, idle system. Pickup the start of idle time. */ _tx_execution_idle_time_last_start = TX_EXECUTION_TIME_SOURCE; + _tx_execution_idle_active = TX_TRUE; } } } @@ -334,7 +388,7 @@ EXECUTION_TIME delta_time; /* FUNCTION RELEASE */ /* */ /* _tx_execution_isr_enter PORTABLE C */ -/* 6.1.7 */ +/* 6.1.11 */ /* AUTHOR */ /* */ /* William E. Lamie, Microsoft Corporation */ @@ -364,6 +418,9 @@ EXECUTION_TIME delta_time; /* DATE NAME DESCRIPTION */ /* */ /* 06-02-2021 William E. Lamie Initial Version 6.1.7 */ +/* 04-25-2022 Scott Larson Modified comments and fixed */ +/* wrap-around calculation, */ +/* resulting in version 6.1.11 */ /* */ /**************************************************************************/ VOID _tx_execution_isr_enter(void) @@ -381,7 +438,7 @@ EXECUTION_TIME delta_time; _tx_execution_isr_nest_counter++; #endif - /* Determine if this is the first interrupt. Nested interrupts are all treated as + /* Determine if this is the first interrupt. Nested interrupts are all treated as general interrupt processing. */ #ifdef TX_CORTEX_M_EPK if ((TX_THREAD_GET_SYSTEM_STATE()) && (_tx_execution_isr_nest_counter == 1)) @@ -420,7 +477,7 @@ EXECUTION_TIME delta_time; { /* Timer wrapped, compute the delta assuming incrementing time counter. */ - delta_time = (EXECUTION_TIME) (current_time + (((EXECUTION_TIME_SOURCE_TYPE) TX_EXECUTION_MAX_TIME_SOURCE) - last_start_time)); + delta_time = (EXECUTION_TIME) (current_time + ((((EXECUTION_TIME_SOURCE_TYPE) TX_EXECUTION_MAX_TIME_SOURCE) + 1) - last_start_time)); } /* Pickup the total time. */ @@ -440,7 +497,7 @@ EXECUTION_TIME delta_time; /* Store back the new total time. */ thread_ptr -> tx_thread_execution_time_total = new_total_time; - /* Now accumulate this thread's execution time into the total thread execution time. */ + /* Now accumulate this thread's execution time into the total thread execution time. */ new_total_time = _tx_execution_thread_time_total + delta_time; /* Determine if a rollover on the total time is present. */ @@ -457,7 +514,7 @@ EXECUTION_TIME delta_time; } /* Has idle time started? */ - else if (_tx_execution_idle_time_last_start) + else if (_tx_execution_idle_active) { /* Pickup the last idle start time. */ @@ -474,7 +531,7 @@ EXECUTION_TIME delta_time; { /* Timer wrapped, compute the delta assuming incrementing time counter. */ - delta_time = (EXECUTION_TIME) (current_time + (((EXECUTION_TIME_SOURCE_TYPE) TX_EXECUTION_MAX_TIME_SOURCE) - last_start_time)); + delta_time = (EXECUTION_TIME) (current_time + ((((EXECUTION_TIME_SOURCE_TYPE) TX_EXECUTION_MAX_TIME_SOURCE) + 1) - last_start_time)); } /* Pickup the total time. */ @@ -495,7 +552,7 @@ EXECUTION_TIME delta_time; _tx_execution_idle_time_total = new_total_time; /* Disable the idle time measurement. */ - _tx_execution_idle_time_last_start = 0; + _tx_execution_idle_active = TX_FALSE; } /* Save the ISR start time. */ @@ -509,7 +566,7 @@ EXECUTION_TIME delta_time; /* FUNCTION RELEASE */ /* */ /* _tx_execution_isr_exit PORTABLE C */ -/* 6.1.7 */ +/* 6.1.11 */ /* AUTHOR */ /* */ /* William E. Lamie, Microsoft Corporation */ @@ -539,6 +596,9 @@ EXECUTION_TIME delta_time; /* DATE NAME DESCRIPTION */ /* */ /* 06-02-2021 William E. Lamie Initial Version 6.1.7 */ +/* 04-25-2022 Scott Larson Modified comments and fixed */ +/* wrap-around calculation, */ +/* resulting in version 6.1.11 */ /* */ /**************************************************************************/ VOID _tx_execution_isr_exit(void) @@ -620,6 +680,7 @@ EXECUTION_TIME delta_time; /* Yes, idle system. Pickup the start of idle time. */ _tx_execution_idle_time_last_start = TX_EXECUTION_TIME_SOURCE; + _tx_execution_idle_active = TX_TRUE; } } diff --git a/utility/execution_profile_kit/tx_execution_profile.h b/utility/execution_profile_kit/tx_execution_profile.h index 09ca91a9..9973c22d 100644 --- a/utility/execution_profile_kit/tx_execution_profile.h +++ b/utility/execution_profile_kit/tx_execution_profile.h @@ -58,20 +58,21 @@ typedef unsigned long EXECUTION_TIME_SOURCE_TYPE; /* Example for Cortex-M targets: */ #ifndef TX_EXECUTION_TIME_SOURCE -#define TX_EXECUTION_TIME_SOURCE (EXECUTION_TIME_SOURCE_TYPE) *((ULONG *) 0xE0001004) +#define TX_EXECUTION_TIME_SOURCE (EXECUTION_TIME_SOURCE_TYPE) *((volatile ULONG *) 0xE0001004) #endif #ifndef TX_EXECUTION_MAX_TIME_SOURCE #define TX_EXECUTION_MAX_TIME_SOURCE 0xFFFFFFFF #endif /* For 64-bit time source, the constant would be: */ -/*#define TX_EXECUTION_TIME_SOURCE (EXECUTION_TIME_SOURCE_TYPE) *((unsigned long long *) 0xE0001004) */ +/*#define TX_EXECUTION_TIME_SOURCE (EXECUTION_TIME_SOURCE_TYPE) *((volatile unsigned long long *) 0xE0001004) */ /*#define TX_EXECUTION_MAX_TIME_SOURCE 0xFFFFFFFFFFFFFFFF */ /* Define APIs of the execution profile kit. */ struct TX_THREAD_STRUCT; +VOID _tx_execution_initialize(void); VOID _tx_execution_thread_enter(void); VOID _tx_execution_thread_exit(void); VOID _tx_execution_isr_enter(void); |
