Quality RTOS & Embedded Software

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


optimisation , discard unnecessary YIELD

Posted by Nobody/Anonymous on June 23, 2005
1. sometimes , one task want to yield to another task by calling taskYIELD(). But before the task do it, the ISRs maybe have taked place and yield to another in the end of the ISRs. So when control return to that task which will call taskYIELD(), it is unnecessary to yield again.

method to solve it : using context count
// how to use context count
..... do something else....
xSavedContextCount = xTaskContextCount(); // get the current Context change Count

//changed taskYIELD()
taskYIELD(portBASE_TYPE xSavedContextCount)
__if (xTaskContextCount() != xSavedContextCount)
____// go on yield

in vTaskDelayUntil , vTaskDelay
at line 308 in xQueueSend
at line 437 in xQueueReceive ,

there are some code like below

if( !xTaskResumeAll() )

but it's not completely appropriate to call taskYIELD() when xTaskResumeAll() return pdFALSE because before calling taskYIELD() ISRs maybe also put the current task in the Readylist. So its need not yield again and current task has meet it's requirement and can go on.
So these code can be

xTaskResumeAll() ;
if (current task is not in the readylist)

these method may be useful. :)

RE: optimisation , discard unnecessary YIELD

Posted by Richard on June 23, 2005
Thanks for the suggestions. They are both of coarse valid, but also both carry an overhead. Which is best is of coarse a matter of opinion, or even a matter of the type of system you are working on.

For example, the xSavedContextCount count method requires another function call (to get the xsavedContextCount) and interrupts to be disabled/enabled, but would save an unwanted switch. Which is best will be application or processor dependent, and also depend on how often the unwanted switch would actually occur.

In the second case the line:

if (current task is not in the readylist)

would required a pointer comparison. This is no problem on say an ARM, but can be costly on low en 8bit devices.

I would be interested in knowing a bit more about who you are and what your experiences are. Why not drop me an email to the address on the FreeRTOS.org site (r dot barry at freert ..... ). Your input has been very helpful.


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

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

Latest News

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