FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [June 2005 Threads] 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
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|