Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

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
taskENTER_CRITICAL();
..... do something else....
xSavedContextCount = xTaskContextCount(); // get the current Context change Count
taskEXIT_CRITICAL();
taskYIELD(xSavedContextCount);

//changed taskYIELD()
taskYIELD(portBASE_TYPE xSavedContextCount)
{
__taskENTER_CRITICAL();
__if (xTaskContextCount() != xSavedContextCount)
__{
____// go on yield
__}
__ taskEXIT_CRITICAL();
}


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

there are some code like below

vTaskSuspendAll();
......
if( !xTaskResumeAll() )
{
__taskYIELD();
}

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

vTaskSuspendAll();
......
xTaskResumeAll() ;
if (current task is not in the readylist)
{
__taskYIELD();
}

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.

Regards.


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




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists