AnsweredAssumed Answered

FreeRTOS very low yield for simple port toggle

Question asked by Didier JEANJEAN on Nov 23, 2016
Latest reply on Mar 12, 2017 by Daniel Chen

I use KDS with FreeRTOS on MK22FN512 at 80Mhz.
When i toggle a simple I/O port using FreeRTOS, i find the time very long , as you see in the picture at the end, i find 11.47µsec (=> 918 cycles at 80MHz) only for the  task where there is only the following C instructions.  

while(1)
{
   vTaskDelay(1000);
   LED_GREEN_TOGGLE();
}

 

Where LED_GREEN_TOGGLE() is a simple macro that use one assembler instruction that use max 4 cycles for just making the mask word and writing it to "base->PTOR = mask;"

All the other instruction are using by the vTaskDelay function.
And FreeRTOS in black in the SYSTEMVIEW graphic add approx 13µsec that is 1040 cycle.

The total time is 918+1040= 1958 cycle = 24µsec only for toggle a simple LED that with no RTOS will take a maximum of 30 instruction that will use 50 cycle = 0.625µsec to make the same work.

 

The conclusion is that RTOS simplify the work but the cost in CPU time Consumption is very important, in this case the CPU power reduction is 1958/50= 40.  I understand that it is a special case where the action is very simple but event the power reduction seem not negligeable. Is it du to FreeRTOS ? But i found for "embOS" RTOS on SEGGER SYSTEMVIEW site the same 840 cycles with time for 7µs at 120MHz clock.

For more complex functions, the drop in RTOS yield will necessarily be greater, but in view of these results, it should not exceed 20% = 1/5 of what will be possible without RTOS whereas here it is at best 2.5 % = 1/40.

 

Be awareness of take care not using RTOS when you need to use all the power of a CPU.

 

Can somedoby have concrete result for more complex  software ?

 

Best regards

Didier JEANJEAN

 

SYSTEMVIEW timing for I/O port toggle

Outcomes