Skip to content

Commit

Permalink
Fix run time stats for SMP (#76)
Browse files Browse the repository at this point in the history
* Update get idle tasks stats

* Fix get task stats

* Fix missing configNUM_CORES
  • Loading branch information
chinglee-iot authored Apr 21, 2023
1 parent 2d281c7 commit e35fd38
Showing 1 changed file with 42 additions and 25 deletions.
67 changes: 42 additions & 25 deletions tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -7388,40 +7388,27 @@ 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 )

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;

/* 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
{
Expand All @@ -7434,24 +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 )
{
return ulTaskGetRunTimeCounter( xIdleTaskHandle );
configRUN_TIME_COUNTER_TYPE ulReturn = 0;

for( BaseType_t i = 0; i < configNUMBER_OF_CORES; i++ )
{
ulReturn += xIdleTaskHandles[ i ]->ulRunTimeCounter;
}

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 )
{
return ulTaskGetRunTimePercent( xIdleTaskHandle );
configRUN_TIME_COUNTER_TYPE ulTotalTime, ulReturn;
configRUN_TIME_COUNTER_TYPE ulRunTimeCounter = 0;

ulTotalTime = portGET_RUN_TIME_COUNTER_VALUE() * configNUMBER_OF_CORES;

/* For percentage calculations. */
ulTotalTime /= ( configRUN_TIME_COUNTER_TYPE ) 100;

/* 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;
}
else
{
ulReturn = 0;
}

return ulReturn;
}

#endif
#endif /* if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) ) */
/*-----------------------------------------------------------*/

static void prvAddCurrentTaskToDelayedList( TickType_t xTicksToWait,
Expand Down

0 comments on commit e35fd38

Please sign in to comment.