Skip to content

Commit e35fd38

Browse files
authored
Fix run time stats for SMP (#76)
* Update get idle tasks stats * Fix get task stats * Fix missing configNUM_CORES
1 parent 2d281c7 commit e35fd38

File tree

1 file changed

+42
-25
lines changed

1 file changed

+42
-25
lines changed

tasks.c

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,8 @@ PRIVILEGED_DATA static volatile UBaseType_t uxSchedulerSuspended = ( UBaseType_t
460460

461461
/* Do not move these variables to function scope as doing so prevents the
462462
* code working with debuggers that need to remove the static qualifier. */
463-
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. */
464-
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. */
463+
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. */
464+
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. */
465465

466466
#endif
467467

@@ -7388,40 +7388,27 @@ TickType_t uxTaskResetEventItemValue( void )
73887388

73897389
configRUN_TIME_COUNTER_TYPE ulTaskGetRunTimeCounter( const TaskHandle_t xTask )
73907390
{
7391-
configRUN_TIME_COUNTER_TYPE ulReturn = 0;
7392-
7393-
for( BaseType_t i = 0; i < configNUMBER_OF_CORES; i++ )
7394-
{
7395-
ulReturn += xIdleTaskHandles[ i ]->ulRunTimeCounter;
7396-
}
7397-
7398-
return ulReturn;
7391+
return xTask->ulRunTimeCounter;
73997392
}
74007393

7401-
#endif /* if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) ) */
7394+
#endif
74027395
/*-----------------------------------------------------------*/
74037396

74047397
#if ( configGENERATE_RUN_TIME_STATS == 1 )
74057398

74067399
configRUN_TIME_COUNTER_TYPE ulTaskGetRunTimePercent( const TaskHandle_t xTask )
74077400
{
74087401
configRUN_TIME_COUNTER_TYPE ulTotalTime, ulReturn;
7409-
configRUN_TIME_COUNTER_TYPE ulRunTimeCounter = 0;
74107402

7411-
ulTotalTime = ( configRUN_TIME_COUNTER_TYPE ) ( portGET_RUN_TIME_COUNTER_VALUE() * configNUMBER_OF_CORES );
7403+
ulTotalTime = ( configRUN_TIME_COUNTER_TYPE ) portGET_RUN_TIME_COUNTER_VALUE();
74127404

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

74167408
/* Avoid divide by zero errors. */
74177409
if( ulTotalTime > ( configRUN_TIME_COUNTER_TYPE ) 0 )
74187410
{
7419-
for( BaseType_t i = 0; i < configNUMBER_OF_CORES; i++ )
7420-
{
7421-
ulRunTimeCounter += xIdleTaskHandles[ i ]->ulRunTimeCounter;
7422-
}
7423-
7424-
ulReturn = ulRunTimeCounter / ulTotalTime;
7411+
ulReturn = xTask->ulRunTimeCounter / ulTotalTime;
74257412
}
74267413
else
74277414
{
@@ -7434,24 +7421,54 @@ TickType_t uxTaskResetEventItemValue( void )
74347421
#endif /* if ( configGENERATE_RUN_TIME_STATS == 1 ) */
74357422
/*-----------------------------------------------------------*/
74367423

7437-
#if ( configGENERATE_RUN_TIME_STATS == 1 )
7424+
#if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) )
74387425

74397426
configRUN_TIME_COUNTER_TYPE ulTaskGetIdleRunTimeCounter( void )
74407427
{
7441-
return ulTaskGetRunTimeCounter( xIdleTaskHandle );
7428+
configRUN_TIME_COUNTER_TYPE ulReturn = 0;
7429+
7430+
for( BaseType_t i = 0; i < configNUMBER_OF_CORES; i++ )
7431+
{
7432+
ulReturn += xIdleTaskHandles[ i ]->ulRunTimeCounter;
7433+
}
7434+
7435+
return ulReturn;
74427436
}
74437437

7444-
#endif
7438+
#endif /* if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) ) */
74457439
/*-----------------------------------------------------------*/
74467440

7447-
#if ( configGENERATE_RUN_TIME_STATS == 1 )
7441+
#if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) )
74487442

74497443
configRUN_TIME_COUNTER_TYPE ulTaskGetIdleRunTimePercent( void )
74507444
{
7451-
return ulTaskGetRunTimePercent( xIdleTaskHandle );
7445+
configRUN_TIME_COUNTER_TYPE ulTotalTime, ulReturn;
7446+
configRUN_TIME_COUNTER_TYPE ulRunTimeCounter = 0;
7447+
7448+
ulTotalTime = portGET_RUN_TIME_COUNTER_VALUE() * configNUMBER_OF_CORES;
7449+
7450+
/* For percentage calculations. */
7451+
ulTotalTime /= ( configRUN_TIME_COUNTER_TYPE ) 100;
7452+
7453+
/* Avoid divide by zero errors. */
7454+
if( ulTotalTime > ( configRUN_TIME_COUNTER_TYPE ) 0 )
7455+
{
7456+
for( BaseType_t i = 0; i < configNUMBER_OF_CORES; i++ )
7457+
{
7458+
ulRunTimeCounter += xIdleTaskHandles[ i ]->ulRunTimeCounter;
7459+
}
7460+
7461+
ulReturn = ulRunTimeCounter / ulTotalTime;
7462+
}
7463+
else
7464+
{
7465+
ulReturn = 0;
7466+
}
7467+
7468+
return ulReturn;
74527469
}
74537470

7454-
#endif
7471+
#endif /* if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) ) */
74557472
/*-----------------------------------------------------------*/
74567473

74577474
static void prvAddCurrentTaskToDelayedList( TickType_t xTicksToWait,

0 commit comments

Comments
 (0)