Quality RTOS & Embedded Software

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




Loading

an optimization in vPortYield()

Posted by ares.qi on June 22, 2005
when call vPortYield(), what they do is below;

portSAVE_CONTEXT();
vTaskSwitchContext();
portRESTORE_CONTEXT();

but if scheduler is locked or there is no higher or the other same priority task in readylist , we have to return to the current task again. In these cases, portSAVE_CONTEXT() and portRESTORE_CONTEXT() waste much system resources.

so i think we should let vTaskSwitchContext() return a value to solve this problem like this:

signed portBASE_TYPE vTaskSwitchContext()
{
................
................
if we have switched to another task
return pdTRUE;
else
return pdFALSE
}

thus vPortYield() maybe change to
void vPortYield( void )
{
signed portBASE_TYPE xReturn;
.....
portENTER_CRITICAL();
xReturn = vTaskSwitchContext();
portEXIT_CRITICAL();
if (xReturn == pdFALSE) return;
portSAVE_CONTEXT();
portRESTORE_CONTEXT();
.....
}

And this change doesn't afffect vPortYieldFromTick or other ISRs.

RE: an optimization in vPortYield()

Posted by ares.qi on June 22, 2005
sorry vPortYield() should be

void vPortYield( void )
{
__signed portBASE_TYPE xReturn;
.....
__portENTER_CRITICAL();

__xReturn = vTaskSwitchContext();

__if (xReturn == pdFALSE)
__{
____portEXIT_CRITICAL();
____return;
__}

__portSAVE_CONTEXT();
__portRESTORE_CONTEXT();

__portEXIT_CRITICAL();
.....
}

RE: an optimization in vPortYield()

Posted by Nobody/Anonymous on June 22, 2005
this definately will not work. SwitchContext must come between save_context and restore_context otherwise you save the context of one task into the tcb of another.

as

1\ task a is running.

2\ tick happens

3\ SwitchContext decides another task (b) should run and switches the current tcb.

4\ as your code SwitchContext returns true and save_context is called.

5\ save_context saves task a context into task b stack.

6\ restore_context then immediately removes task a context from task b stack.

now task a is running but the current tcb is pointing to task b.

RE: an optimization in vPortYield()

Posted by ares.qi on June 22, 2005
yes, you are right.

But i think it's better we need a method to avoid portSAVE_CONTEXT() and portRESTORE_CONTEXT() when scheduler is locked or there is no higher or the other same priority task in readylist.

of course , my method will not work , i know now. But it will has another way to do this.

RE: an optimization in vPortYield()

Posted by Nobody/Anonymous on June 22, 2005
which port do you use. there is very little overhead in hc12 port, but more in say pic port.

RE: an optimization in vPortYield()

Posted by ares.qi on June 22, 2005
sorry , now i have not run it acctually.

I am reading the source and try to understand all ot it and post my problems here


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




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

Latest News

FreeRTOS kernel V10 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