ulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE();\r
#endif\r
\r
- /* Add the amount of time the task has been running to the accumulated\r
- time so far. The time the task started running was stored in\r
- ulTaskSwitchedInTime. Note that there is no overflow protection here\r
- so count values are only valid until the timer overflows. Generally\r
- this will be about 1 hour assuming a 1uS timer increment. */\r
- pxCurrentTCB->ulRunTimeCounter += ( ulTotalRunTime - ulTaskSwitchedInTime );\r
+ /* Add the amount of time the task has been running to the \r
+ accumulated time so far. The time the task started running was \r
+ stored in ulTaskSwitchedInTime. Note that there is no overflow \r
+ protection here so count values are only valid until the timer \r
+ overflows. The guard against negative values is to protect\r
+ against suspect run time stat counter implementations - which\r
+ are provided by the application, not the kernel. */\r
+ if( ulTotalRunTime > ulTaskSwitchedInTime )\r
+ {\r
+ pxCurrentTCB->ulRunTimeCounter += ( ulTotalRunTime - ulTaskSwitchedInTime );\r
+ }\r
ulTaskSwitchedInTime = ulTotalRunTime;\r
}\r
#endif /* configGENERATE_RUN_TIME_STATS */\r