ulRunTimeCounter in task status structure represents which of the following
- Ticks for which a task has run or
- milli seconds for which a task has run
ulRunTimeCounter in task status structure represents which of the following
Hi @kartike61
Welcome to the FreeRTOS Community Forums !
The ulRunTimeCounter
in a task status structure typically represents the number of ticks or clock cycles for which the task has run.
Ticks or clock cycles are a more precise unit of measurement compared to milliseconds, as they account for the actual processor cycles used by the task. This provides a more accurate representation of the task’s runtime. Milliseconds would be a less granular measurement that could potentially miss shorter task execution times.
Its neither ticks nor miliseconds - but a time base you provide yourself. See Run Time Statistics - FreeRTOS™
Hi @rtel & @karahulx
My configTICK_RATE_HZ has been set to 100hz.
As an example if my ulRunTimeCounter value is 1000. What does it imply?
The run time would be 1000/100 seconds or something else?
As @rtel mentioned
It does not depend on the configTICK_RATE_HZ
, but how you have implemented the time base for run time statistics.
portCONFIGURE_TIMER_FOR_RUN_TIME_STATS is not a variable, but a macro that you have to provide yourself.
As per the documentation page for run time stats (Run Time Statistics - FreeRTOS™), to use the facility you need to provide three macros. You have to provide portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() which must configure the clock used as the run time stats time base, and portGET_RUN_TIME_COUNTER_VALUE() which much return the current value of whichever clock you are using.
You will find lots of examples by grep-ing portCONFIGURE_TIMER_FOR_RUN_TIME_STATS in the FreeRTOSConfig.h files found in the many sub-directories of FreeRTOS/Demo repository . Here is one example:
Where you will find that portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() calls vInitialiseTimerForRunTimeStats()
(which is a function implemented in
the project’s main.c
source file), and portGET_RUN_TIME_COUNTER_VALUE()
is implemented to directly access a timer counter register (with some bit manipulation as it is a down counter).
Hi, so let suppose I want to use this ulRunTimeCounter value to initialize a software timer with period = ulRunTimeCounter. The value of ulRunTimeCounter can be used as it is or do I need to pass this value to pdMS_TO_TICKS() macro?
Hi,
If you are using xTimerCreate
API to create a software timer, you need the timer period in ticks as its parameter.
xTimer = xTimerCreate(
"MyTimer", /* Timer name (for debugging purposes) */
pdMS_TO_TICKS(1000), /* Timer period in ticks (1000 ms) */
pdTRUE, /* Periodic timer (will auto-reload) */
(void *)0, /* Timer ID (optional) */
TimerCallback /* Timer callback function */
);
If your ulRunTimeCounter calculates the time in milliseconds, you will need to use the pdMS_TO_TICKS() macro for initializing the software timer.
It depends on the time unit of the ulRunTimeCounter.
FreeRTOS kernel measures time in ticks. A timer interrupt (the tick interrupt) increments the tick count. All the FreeRTOS APIs expect time period to be specified in ticks. pdMS_TO_TICKS() macro helps you to convert milliseconds to ticks.
Run time statistics use a application provided completely separate time base (usually a hardware timer) that has no relation to the tick count. Since the application configures this time base, the kernel cannot know its frequency (i.e. how it relates to tick).