cooperative vs preemptive
Posted by Nobody/Anonymous on January 15, 2005
Hi, is ther a configuration maro for cooperative/ preemptive compilation? If I need only coperative OS, will it take less ram and rom?
RE: cooperative vs preemptive
Posted by Richard
on January 15, 2005
See the page:
Also, most ports have a macro portUSE_PREEMPTION. This can be found near the top of the portmacro.h file for the port you are using (described on the port documentation page). It is best to set portUSE_PREEMPTION to either 1 or 0 (to use preemptive or cooperative respectively), and then pass this macro to vTaskStartScheduler(). For example:
#define portUSE_PREEMPTION 1
[in your application source code]
vTaskStartScheduler( portUSE_PREEMPTION );
The amount of RAM and ROM used depends on how many tasks you create, not which scheduler is used. However, the scheduler processing overhead is less with the cooperative scheduler.
If RAM usage is important then consider how you create tasks. Each task requires its own stack so the fewer tasks the less RAM is required.
For example, if your application has one periodic function that must run with very regular frequency, and a few other functions that can be considered 'background' then:
You can create one task for each function and use preemptive scheduling. The periodic task has the highest priority to ensure it meets its timing requirements. This gives the simplest design but uses the most RAM.
You can create a high priority task for the periodic function, and a single low priority task for the other functions and use the preemptive scheduler. The low priority task would contain some kind of loop that loops through all the background functions. Whenever the periodic function needed to execute the background function task would be preempted. This option uses less RAM as there are less tasks, but still maintains the timing requirements of the periodic task. Provided your background functions never block you could even add them to the Idle task - saving even more RAM.
This is a hybrid option. It is the same as option 2, but using the cooperative scheduler. If the periodic task can be signalled by an interrupt then you can perform a context switch to the periodic task from the interrupt handler even though the cooperative scheduler is being used.
There will be some more WEB documentation on this very subject appearing in the next week or so.
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.