From d8d2454421a110f36b331cf1b8986d5f909289cc Mon Sep 17 00:00:00 2001 From: Ching-Hsin Lee Date: Thu, 20 Apr 2023 22:01:42 +0800 Subject: [PATCH 1/3] Update get idle tasks stats --- tasks.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/tasks.c b/tasks.c index d082b60b21b..15e1960ad06 100644 --- a/tasks.c +++ b/tasks.c @@ -460,8 +460,8 @@ PRIVILEGED_DATA static volatile UBaseType_t uxSchedulerSuspended = ( UBaseType_t /* Do not move these variables to function scope as doing so prevents the * code working with debuggers that need to remove the static qualifier. */ - PRIVILEGED_DATA static configRUN_TIME_COUNTER_TYPE ulTaskSwitchedInTime[ configNUM_CORES ] = { 0UL }; /**< Holds the value of a timer/counter the last time a task was switched in. */ - PRIVILEGED_DATA static volatile configRUN_TIME_COUNTER_TYPE ulTotalRunTime[ configNUM_CORES ] = { 0UL }; /**< Holds the total amount of execution time as defined by the run time counter clock. */ + PRIVILEGED_DATA static configRUN_TIME_COUNTER_TYPE ulTaskSwitchedInTime[ configNUMBER_OF_CORES ] = { 0UL }; /**< Holds the value of a timer/counter the last time a task was switched in. */ + PRIVILEGED_DATA static volatile configRUN_TIME_COUNTER_TYPE ulTotalRunTime[ configNUMBER_OF_CORES ] = { 0UL }; /**< Holds the total amount of execution time as defined by the run time counter clock. */ #endif @@ -7438,7 +7438,15 @@ TickType_t uxTaskResetEventItemValue( void ) configRUN_TIME_COUNTER_TYPE ulTaskGetIdleRunTimeCounter( void ) { - return ulTaskGetRunTimeCounter( xIdleTaskHandle ); + configRUN_TIME_COUNTER_TYPE ulIdleRunTimeCounter = 0; + BaseType_t i; + + for( i = 0; i < configNUMBER_OF_CORES; i++ ) + { + ulIdleRunTimeCounter += ulTaskGetRunTimeCounter( xIdleTaskHandles[ i ] ); + } + + return ulIdleRunTimeCounter; } #endif @@ -7448,7 +7456,16 @@ TickType_t uxTaskResetEventItemValue( void ) configRUN_TIME_COUNTER_TYPE ulTaskGetIdleRunTimePercent( void ) { - return ulTaskGetRunTimePercent( xIdleTaskHandle ); + + configRUN_TIME_COUNTER_TYPE ulIdleRunTimePercent = 0; + BaseType_t i; + + for( i = 0; i < configNUMBER_OF_CORES; i++ ) + { + ulIdleRunTimePercent += ulTaskGetRunTimePercent( xIdleTaskHandles[ i ] ); + } + + return ulIdleRunTimePercent; } #endif From a5f109450887e29cdca1f74ab66f1a63cc548782 Mon Sep 17 00:00:00 2001 From: Ching-Hsin Lee Date: Fri, 21 Apr 2023 13:10:50 +0800 Subject: [PATCH 2/3] Fix get task stats --- tasks.c | 62 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/tasks.c b/tasks.c index 15e1960ad06..0c1538543c1 100644 --- a/tasks.c +++ b/tasks.c @@ -7388,17 +7388,10 @@ TickType_t uxTaskResetEventItemValue( void ) configRUN_TIME_COUNTER_TYPE ulTaskGetRunTimeCounter( const TaskHandle_t xTask ) { - configRUN_TIME_COUNTER_TYPE ulReturn = 0; - - for( BaseType_t i = 0; i < configNUMBER_OF_CORES; i++ ) - { - ulReturn += xIdleTaskHandles[ i ]->ulRunTimeCounter; - } - - return ulReturn; + return xTask->ulRunTimeCounter; } -#endif /* if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) ) */ +#endif /*-----------------------------------------------------------*/ #if ( configGENERATE_RUN_TIME_STATS == 1 ) @@ -7406,9 +7399,8 @@ TickType_t uxTaskResetEventItemValue( void ) configRUN_TIME_COUNTER_TYPE ulTaskGetRunTimePercent( const TaskHandle_t xTask ) { configRUN_TIME_COUNTER_TYPE ulTotalTime, ulReturn; - configRUN_TIME_COUNTER_TYPE ulRunTimeCounter = 0; - ulTotalTime = ( configRUN_TIME_COUNTER_TYPE ) ( portGET_RUN_TIME_COUNTER_VALUE() * configNUMBER_OF_CORES ); + ulTotalTime = ( configRUN_TIME_COUNTER_TYPE ) portGET_RUN_TIME_COUNTER_VALUE(); /* For percentage calculations. */ ulTotalTime /= ( configRUN_TIME_COUNTER_TYPE ) 100; @@ -7416,12 +7408,7 @@ TickType_t uxTaskResetEventItemValue( void ) /* Avoid divide by zero errors. */ if( ulTotalTime > ( configRUN_TIME_COUNTER_TYPE ) 0 ) { - for( BaseType_t i = 0; i < configNUMBER_OF_CORES; i++ ) - { - ulRunTimeCounter += xIdleTaskHandles[ i ]->ulRunTimeCounter; - } - - ulReturn = ulRunTimeCounter / ulTotalTime; + ulReturn = xTask->ulRunTimeCounter / ulTotalTime; } else { @@ -7434,41 +7421,54 @@ TickType_t uxTaskResetEventItemValue( void ) #endif /* if ( configGENERATE_RUN_TIME_STATS == 1 ) */ /*-----------------------------------------------------------*/ -#if ( configGENERATE_RUN_TIME_STATS == 1 ) +#if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) ) configRUN_TIME_COUNTER_TYPE ulTaskGetIdleRunTimeCounter( void ) { - configRUN_TIME_COUNTER_TYPE ulIdleRunTimeCounter = 0; - BaseType_t i; + configRUN_TIME_COUNTER_TYPE ulReturn = 0; - for( i = 0; i < configNUMBER_OF_CORES; i++ ) + for( BaseType_t i = 0; i < configNUM_CORES; i++ ) { - ulIdleRunTimeCounter += ulTaskGetRunTimeCounter( xIdleTaskHandles[ i ] ); + ulReturn += xIdleTaskHandles[ i ]->ulRunTimeCounter; } - return ulIdleRunTimeCounter; + return ulReturn; } -#endif +#endif /* if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) ) */ /*-----------------------------------------------------------*/ -#if ( configGENERATE_RUN_TIME_STATS == 1 ) +#if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) ) configRUN_TIME_COUNTER_TYPE ulTaskGetIdleRunTimePercent( void ) { + configRUN_TIME_COUNTER_TYPE ulTotalTime, ulReturn; + configRUN_TIME_COUNTER_TYPE ulRunTimeCounter = 0; - configRUN_TIME_COUNTER_TYPE ulIdleRunTimePercent = 0; - BaseType_t i; + ulTotalTime = portGET_RUN_TIME_COUNTER_VALUE() * configNUMBER_OF_CORES; + + /* For percentage calculations. */ + ulTotalTime /= ( configRUN_TIME_COUNTER_TYPE ) 100; - for( i = 0; i < configNUMBER_OF_CORES; i++ ) + /* Avoid divide by zero errors. */ + if( ulTotalTime > ( configRUN_TIME_COUNTER_TYPE ) 0 ) { - ulIdleRunTimePercent += ulTaskGetRunTimePercent( xIdleTaskHandles[ i ] ); + for( BaseType_t i = 0; i < configNUMBER_OF_CORES; i++ ) + { + ulRunTimeCounter += xIdleTaskHandles[ i ]->ulRunTimeCounter; + } + + ulReturn = ulRunTimeCounter / ulTotalTime; + } + else + { + ulReturn = 0; } - return ulIdleRunTimePercent; + return ulReturn; } -#endif +#endif /* if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) ) */ /*-----------------------------------------------------------*/ static void prvAddCurrentTaskToDelayedList( TickType_t xTicksToWait, From 39b3beafda16bb8b352cbae01ba9bcd58c474d0e Mon Sep 17 00:00:00 2001 From: Ching-Hsin Lee Date: Fri, 21 Apr 2023 13:23:30 +0800 Subject: [PATCH 3/3] Fix missing configNUM_CORES --- tasks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks.c b/tasks.c index 0c1538543c1..d54975086d7 100644 --- a/tasks.c +++ b/tasks.c @@ -7427,7 +7427,7 @@ TickType_t uxTaskResetEventItemValue( void ) { configRUN_TIME_COUNTER_TYPE ulReturn = 0; - for( BaseType_t i = 0; i < configNUM_CORES; i++ ) + for( BaseType_t i = 0; i < configNUMBER_OF_CORES; i++ ) { ulReturn += xIdleTaskHandles[ i ]->ulRunTimeCounter; }