Run Time Statistics Overrun

Hi All,

I am using STM32L4+ microcontroller and FreeRTOS V10.0.1 kernel.

My STM32 is working with 118,784 MHz and the freertos with 1KHz (configTICK_RATE_HZ = 100)

I have to use the vTaskGetRunTimeStats() function in order to print rum time statistics, So I have configured and started the DWT counter, and get the CYCCNT value of the DWT register in the portGET_RUN_TIME_COUNTER_VALUE() function.

Note that the CYCCNT counter overruns every 36,15 seconds.
So at the 36 first seconds, vTaskGetRunTimeStats() function return correct statistic, but next, data are wrong (percentage time is more than 100%) .

In this ticket case, I noticed that I can add functions in order to clear runTimeStat usage :

But, I think that when I use this function to clear counter, statistic come wrong.

So my questions are :

  1. Should I use the vTaskClearUsage() API ?
  • if yes, this API should be called every time I called the vTaskGetRunTimeStats() function ? Or only when data come wrong.

  • In the vTaskClearUsage() function, the user have to re-configure the timer (DWT) by using vConfigureTimerForRunTimeStats();, So should I reconfigure the DWT ? Is it correct ?

  1. If not, What should I do when the percentage time come wrong ? Note that If I use a timer at a frequency of 10KHz (minimum recommended) I will also have the same problem, but later.

Best regards,
Ghada

The head revision in Github introduces configRUN_TIME_COUNTER_TYPE, which lets the application writer set the type used to hold the run time stats counter - so you can set it to uint64_t if that helps with the overrun time. Do that by adding the following to FreeRTOSConfig.h:

#define configRUN_TIME_COUNTER_TYPE uint64_t

Hi Richard,

Thank you very much for your suggestion, it was very helpful.
I am now able to get Run time stats.

What I understood using this API, is to calculate how much time each task is executed since the scheduler is started.

Not that I modified the code source in order to get stats in an Interrupt context (interrupt of a timer executed each 2s)

So, In addition to this API, is there another way to get statistic of a windowed period?
I.e.: to calculate how much time each task is executed since the last call of the previous get a statistic API ( not since the scheduler is started)

Regards,
Ghada

Hi Ghada,

you are probably already aware of this option, but I recommend to look into percepio’s tracealyzer or a compatible tool.

Can you just subtract the second reading form the first reading to find the time the task has been executing between the two?

1 Like

Hi Richard,

Yes, that is what I am doing now.
But, I asked if there is already a solution proposed by FreeRTOS.

Thank you.
Ghada

No. There are some feature requests to be able to clear the run time counter values but to do so would be a slow operation as it requires traversing the task lists to clear each counter individually.