FreeRTOS run time stats.

hurza89 wrote on Tuesday, November 20, 2012:

Hi,
I would like to use vTaskGetRunTimeStats() function. I did 3 steps:
1. configGENERATE_RUN_TIME_STATS
2. portCONFIGURE_TIMER_FOR_RUN_TIME_STATS()
3. portGET_RUN_TIME_COUNTER_VALUE()
Then i wanted to use vTaskGetRunTimeStats() function. But compiler said me:

              [cc] Starting link
       [cc] arm-none-eabi-gcc -O0 -nostartfiles -Wl,-Map=SuperSystem.map -mcpu=cortex-m3 -mthumb -LC:\CooCox\CoIDE\workspace\SuperSystem -Wl,--gc-sections -Wl,-TC:\CooCox\CoIDE\workspace\SuperSystem/arm-gcc-link.ld -g -o SuperSystem.elf ..\obj\stm32f10x_tim.o ..\obj\startup_stm32f10x_md_vl.o ..\obj\core_cm3.o ..\obj\system_stm32f10x.o ..\obj\DisplayController.o ..\obj\stm32f10x_gpio.o ..\obj\main.o ..\obj\adsf.o ..\obj\requiredMethodsFromMain.o ..\obj\timers.o ..\obj\stm32f10x_rcc.o ..\obj\MotorsController.o ..\obj\stm32f10x_exti.o ..\obj\tasks.o ..\obj\stm32f10x_adc.o ..\obj\alfanumDisplay.o ..\obj\list.o ..\obj\stm32f10x_flash.o ..\obj\stm32f10x_it.o ..\obj\MeasurementsController.o ..\obj\queue.o ..\obj\port.o ..\obj\SSBootstrapper.o ..\obj\misc.o ..\obj\heap_1.o
       [cc] sbrkr.c:(.text._sbrk_r+0xc): undefined reference to `_sbrk'
       [cc] c:/program files (x86)/gnu tools arm embedded/4.6 2012q2/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/armv7-m\libg.a(lib_a-sbrkr.o): In function `_sbrk_r':
       [cc] c:/program files (x86)/gnu tools arm embedded/4.6 2012q2/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/armv7-m\libg.a(lib_a-abort.o): In function `abort':
       [cc] abort.c:(.text.abort+0xa): undefined reference to `_exit'
       [cc] c:/program files (x86)/gnu tools arm embedded/4.6 2012q2/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/armv7-m\libg.a(lib_a-signalr.o): In function `_kill_r':
       [cc] signalr.c:(.text._kill_r+0xe): undefined reference to `_kill'
       [cc] c:/program files (x86)/gnu tools arm embedded/4.6 2012q2/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/armv7-m\libg.a(lib_a-signalr.o): In function `_getpid_r':
       [cc] signalr.c:(.text._getpid_r+0x0): undefined reference to `_getpid'
       [cc] collect2: ld returned 1 exit status

What is: _sbrk  ? How to fix it ?
This problem is only when i add function vTaskGetRunTimeStats(). If i delete it, it’s all right.
I use CooCox.

Best Regards,
Horza.

rtel wrote on Tuesday, November 20, 2012:

It looks like your implementation has used a printf() type function (maybe sprintf()) that has resulted in library functions being linked into your application, and that the library function requires you to define some target specific functions.  I would guess, from your output, that CooCox is using GCC with Newlib - Newlib is not ideal for small embedded systems.

You have a few choices:

1) Provide stubs for the functions just to shut the linker up.  That is ok if the functions are never actually going to be used.  See the file newlib_stubs.c in one of the FreeRTOS/Demo subdirectories.

2) Provide real implementations for the functions.  See the syscalls.c files in a couple of sub-directories off of FreeRTOS/Demo for references.

3) Use a different library.  Try adding printf-stdarg.c to your project - you will find lots of copies in sub-directories off of FreeRTOS/Demo.  printf-stdarg.c implements a tiny sprintf() function that might prevent the Newlilb files being dragged into your build.  Be careful though, as snprintf() is not implemented properly in printf-stdarg.c.

Regards.

hurza89 wrote on Tuesday, November 20, 2012:

Aa so vTaskGetRunTimeStats function has sprintf. Can i remove this functions from tasks.c file ?, because i don’t need to print it on display, i want to send report about run time through SPI. I removed it, it’s compiled, but i don’t know if I have proper array with RunTimeStats.
I have additional question, how does this array looks after vTaskGetRunTimeStats() ? is that in each field is another data ? i mean: array is Task’s name, array is AbsTime and array is %Time ?

Regards.

hurza89 wrote on Wednesday, November 21, 2012:

I’ve added printf-stdarg.c and it works. But firstly in array from vTaskGetRunTimeStats() function percentage is ok i think, but in each next iteration i have studpid numbers. For example 2558% or more. Is that possible that my 16bit counter has overflow and then vTaskGetRunTimeStats() counts it wrong ? Or should I reset counter after vTaskGetRunTimeStats() ?

Regards.

rtel wrote on Wednesday, November 21, 2012:

The run time stats counter needs to have a resolution higher than the tick count, preferably at least 10 times higher.  Because of this, only 32 bit counters are practical.

Regards.

hurza89 wrote on Thursday, November 22, 2012:

It’s runs perfectly. Last problem was too small coutern, now with 32bit it’s OK.

Regards.

hurza89 wrote on Wednesday, November 28, 2012:

The last case which makes me trouble is that: What happens if 32bit counter overflow ? FreeRTOS detect it ? Or statistics are count again ?

Regards.

davedoors wrote on Wednesday, November 28, 2012:

Once the 32 bit counter overflows that is it. If you want to keep the run time stats going for ever then you could use a 64 bit counter but that is very inefficient. Or you could change the implementation. Normally the counter is only used for debugging and optimization though so not for more than a few hours at a time maximum.