Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix run time stats for SMP #76

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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