Trade‐offs of RTOS in Embedded Systems - 180D-FW-2023/Knowledge-Base-Wiki GitHub Wiki

Word count: 1061

Trade-offs of RTOS in Embedded Systems

I. What is an OS?

On modern computers, the scheduling of all running processes is virtually invisible: most users believe all their applications are running concurrently, yet what’s happening behind the scenes is more complicated and has been a historical problem since the inception of computers. Most devices only have a few cores that can each run only one application at time, but behind the scenes, an Operating Systems is rapidly switching between user applications as well as its own processes, giving the illusion of a concurrently running system by time-sharing the CPU and memory.

conceptual_view

Source: https://bournetocode.com/projects/AQA_AS_Theory/pages/3-6.html

Operating systems are software running on the lowest level of computers that use a variety of algorithms and techniques to determine how to schedule different processes and deal with sharing the limited amount of memory. They involve an algorithm, such as round-robin or shortest-remaining-time-left, to decide which task, or process, to run in a fixed time slot; when the time slot ends, a hardware timer interrupts the user task, resumes the OS’s own scheduling task, which then picks the next task to run. Because this happens rapidly, it gives the illusion that all tasks are running simultaneously. Modern operating systems also handle things such as memory management in order to give tasks the illusion that they have unlimited, contiguous memory: the OS organizes the memory, determines how much memory each process is allocated, and prevents tasks from accessing the memory of others.

II. RTOS vs OS

There are two main types of Operating Systems that embedded developers need to consider: RTOS, or real-time operating system, or general purpose operating systems, such as Windows or Linux, that run on personal computers.

rtos_types_of_os

Source: https://www.windriver.com/archive/202111?page=1

General purpose operating systems, like Windows, are designed to support as many applications and features as possible. The kernel, or space of OS tasks that run with more privilege than user tasks, of a GPOS is extremely large and complex, as it has to be able to support a variety of device drivers for any type of I/O. To name a few more features, it also uses virtual memory addressing for intra-application security, employs scheduling algorithms built on fairness, and has file-system features for protecting data in case of crashes. These features are extremely important for Operating Systems that are running on our computers and phones, as they provide maximum compatibility with any device or software, lots of security for protecting data, and scalability to support any workload.

Real time operating systems are designed to give developers more control over scheduling for time-critical tasks. For example, if an autopilot system on an autonomous vehicle is running Linux and suddenly decides, before colliding with an object ahead, to replace its body control process to hit the brakes and instead schedules a kernel task to clean up unused files and directories, this fatal system failure could result in a car crash. Though this example is exaggerated, it has truth to it since developers using general purpose operating systems can’t control every aspect of what the kernel is doing.

Real-time operating systems scheduling falls into two categories: hard real time and soft real time. Hard real time scheduling means that tasks are given time constraints that they have to meet with a certain period of time, e.g. a task has to run for at least ⅕ of the CPU time. Furthermore, high priority tasks are guaranteed to be executed before lower priority ones. This allows a deterministic operation of the device, since the time slots and run time for all tasks are pre-decided. This type of OS is used in time-critical applications like autonomous robots or medical devices. Soft real time scheduling has a more relaxed operation: tasks are still assigned priorities, and there is a level of predictability as to when tasks will be completed and which will be completed first, but there is no guarantee. This allows soft real time systems to be more dynamic, as they can still operate efficiently under different workloads and tasks priority situations.

121119_0515_Realtimeope1

Source: https://www.researchgate.net/publication/354586838_Article_noAJRCOS73758_Review_Article_Ismael_et_al

Another feature of RTOS is resource efficiency. The overall memory footprint of the OS software is smaller than that of general purpose operating systems, so it can run on less powerful, embedded devices; this is because an RTOS doesn’t need to come with, by default, a large variety of device drivers and applications. Furthermore, since the RTOS is more bare-bones than a general purpose OS, there are less tasks other than one that the developer defines that will be scheduled, maximizing CPU time for relevant tasks.

Though it may seem like RTOS is simply superior for embedded systems, there are pros and cons to each side. For example, debugging and developing embedded devices that are running Linux is much easier than those which run an RTOS; any existing Linux-supported tools can easily be used, and the UI is familiar and widely used. Furthermore, RTOS might need additional configuration, such as defining the file system layout and importing drivers to support external hardware to name a few.

III. Conclusion

The choice between running a general purpose operating system, such as Linux, or an RTOS on an embedded system is a trade off between precise and highly configurable performance and a feature-rich and extremely compatible environment. RTOS has advantages for scenarios when task deadlines and priorities are critical, as well as for devices that are resource constrained. General purpose operating systems provide an easy-to-develop and scalable platform that can help with quick and simple implementation. Overall, a developer should consider the constraints and requirements of their system and weigh the pros and cons of each operating system type to make a better decision.

Works Cited Hansen, Per Brinch. Classic Operating Systems: From Batch Processing to Distributed Systems. Springer New York, 2011. When it comes to helping companies meet their growing needs for real-time data processing with reliable and predictable real-time systems, Intel provides the solutions. “Real-Time Systems Overview and Examples.” Intel, www.intel.com/content/www/us/en/robotics/real-time-systems.html#:~:text=A%20hard%20real%2Dtime%2 0system,undesirable%20lower%20quality%20of%20output. Accessed 4 Nov. 2023.