Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Remaining time after call taskYield

Posted by juankike11 on September 23, 2016

Hello everyone,

I have a doubt using taskYIELD() in FreeRTOS, after calling this function what happend with the execution time, I mean if the tick doesn't finish yet. Maybe I don't have very clear how the FreeRTOS works, but I assume some things:

-The remaining time is used in the Idlehook until the tick ends and then the next task ready is executed -Imediatley the next task ready is executed

Also I have the doubt if every task is executed just during one tick or if can be executed more than one tick. I say this because in my aplication I can't waste too much time, although I'm not very sure of how much time my critical task takes in make a calculation I think it would take some considerable time.

Regards, Juan.

Remaining time after call taskYield

Posted by richard_damon on September 23, 2016

When a task calls taskYIELD(), the current task is moved to the back of the ready queue of its current priority, and then the schedule finds the highest priority task that is ready and starts it. That might be the task that called taskYIELD() if there are no other ready task of the same (or possible higher) priority available.

When you have FreeRTOS running with Preemption turned on (which I would think is normal) then every timer tick, the system effectively does a taskYIELD() for the currently running task (unless the scheduler has been disabled) which says that if another ready task exists of the same prioirty, they will trade execution back and forth each timer tick. A lower priority task will only get a chance to execute if all the higher priority tasks are blocked waiting on something (time, a queue, a semaphore, etc). If a higher priority task becomes ready, and preemption is on, then the current task will be suspended and the higher task will procceed.

With preemption turned on, the fundamental rule is that the running task will always be the highest priority task that is ready, and multiple ready tasks of the same priority will execute round robin, switching every timer tick.

With preemption off, a higher priority task or same priority task will need to wait for the current task to yield, letting the scheduler find the new highest priority task.

One key thing to remember, is that, except for priority 0 tasks (IDLE priority) all tasks should be blocking for something at times or the lower priority tasks will get starved for time. And prioriry 0 tasks should either yield at times or you need to have preemption turned on.

Remaining time after call taskYield

Posted by juankike11 on October 20, 2016

Thanks Richard

Your explanation is pretty clear and you have solved another doubt I had

[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

Meet us at Embedded World. Hall 3A-525.

Hear from Richard Barry at Embedded World. Feb 28, 16:00, Hall 4-428.

Video: Watch James Gosling & Richard Barry at re:Invent, Las Vegas 2017.

FreeRTOS kernel V10.0.1 is available for immediate download. Now MIT licensed.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS