FreeRTOS very low yield for simple port toggle

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

FreeRTOS very low yield for simple port toggle

464 Views
didierjeanjean
Contributor III

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

20161122-171800-002.jpg

0 Kudos
1 Reply

318 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Didier

vTaskDelay() is not used for acculturate delay. Because  vTaskDelay() does not  provide a good method of controlling the frequency, other task and interrupt activity  will affect it.  vTaskDelayuntil maybe better. 

I would say that just like C language cann’t beat the performance offered by assembly languages, RTOS based solution cannot offer quick response time as a bare metal code. The decision to use bare metal or RTOS based solution depends on lots of factors like target platform, device, complexity of requirement, lead time etc. Complexity is one of the key deciding factors. For simple task just like to toggle a LED, I think bare metal is better.  

Regards

Daniel

0 Kudos