Slow context switching in FreeRTOS?

Heard that FreeRTOS context switching time is usually longer than other commercially available RTOSs. There were suggestions that I heard from professionals that it might be due to the working of memory management. What is your take on this? How to optimize the memory management in FreeRTOS to improve the context switching time?
3 Replies
Umesh Lokhande
Umesh Lokhande8mo ago
Hi, @Yash Naidu , Great point, I think in any RTOS irrespective of free or commercial. The slower context switching could be due to a variety of reasons such as hardware limitation, resource contention, RTOS configuration, scheduling algorithm, interrupt handling, etc.. Many of these issues can be fixed with the help of tools like Seggers SystemView. It's a free software. We can analyze the task and timings while programming
I agree with the second part. Memory management sometimes slows down context switching. So for mission critical/health care product, I suggest choosing the microcontroller who have hardware support for context switching which will make context switching faster. I mean avoid relying on software based context switching. Usually, it slows down context switching
I prefer commercial RTOS for 2-reasons: * Security - Certification Otherwise, I still prefer FreeRTOS (Amazon) Finally, I suggest all serious developers use SEGGER J-Trace PRO (h/w). It helps a lot in debugging and fixing memory-related issues while working with complex RTOS projects.
Let me know your thoughts, thank you!
Yash Naidu
Yash Naidu8mo ago
Thanks for your input Umesh. Really valuable.
Luc Paquin Teacher
Most operating systems appear to allow multiple programs to execute at the same time. This is called multi-tasking. In reality, each processor core can only be running a single thread of execution at any given point in time. A part of the operating system called the scheduler is responsible for deciding which program to run when, and provides the illusion of simultaneous execution by rapidly switching between each program. The scheduler in a RTOS is designed to provide a predictable execution pattern. This is particularly of interest to embedded systems as embedded systems often have real time requirements. A real time requirements is one that specifies that the embedded system must respond to a certain event within a strictly defined time. A guarantee to meet real time requirements can only be made if the behaviour of the operating system's scheduler can be predicted. RTOS and FreeRTOS that is designed to be small enough to run on a microcontroller. -Health care -Robotic -Mission critical -IoT -Etc...