|
In this article:
- What is a real-time operating system
- RTOS Design
What is a Real-time Operating System
A real-time operating system (RTOS) is a type of operating system that is intended to be used with real-time applications or software. Embedded applications, industrial robots and scientific research equipment are all examples of a real-time operating system. A RTOS helps produce real-time systems. However, the end product or the finished product so produced may or may not be real-time. To achieve this, a careful development process for the product would have to be followed. However, by using a RTOS, it is possible to meet system deadlines in an efficient manner either generally (called ‘soft real-time’) or deterministically (called ‘hard real-time’). RTOSes make use of scheduling algorithms that are specifically designed to suit the needs of a real-time developer and provides him or her with the required tools to produce such systems. A RTOS is usually aimed at responding in as less amount of time as possible to the even in question rather than reducing the time it takes to complete a given task or tasks.
RTOS Design
RTOSes maybe implemented in two basic ways:
- An event-driven operating system which alters the tasks when an event of higher priority that requires service takes place. This is called as preemptive priority.
- A time-sharing operating system that switches tasks based on a clock interrupt giving a certain amount of time to each of the events. This is also called round robin method.
An advantage of implementing a RTOS as a time-sharing operating system is that though it switches the tasks many times more than actually required, it does so smoothly, making it possible to achieve deterministic multitasking.
Today, CPUs tend to implement both of the above methods at the same time as necessary. However, certain key points need to be understood:
- Scheduling
Scheduling is an important aspect of RTOSes. At a time, a task maybe either running, ready (to run) or blocked since only a single task can run on a CPU at a time. These states are assigned by a scheduler and it is this component that is difficult to design. The scheduler maintains a list of tasks to be performed. These tasks are arranged in their order of priority starting with the one having the highest priority over others. The list is constantly being changed as tasks move in and out of the list based on their priority and completion. An important term here is flyback time which is the time taken to add a new task to the list or queue while restoring the priorities of all the other tasks.
- Resource sharing
Since resources on a computer system are limited, it is important that the operating system (especially a multitasking one) addresses the problem of resource sharing. This is so because if two tasks access the same resources (whether software or hardware), it is said to be an unsafe condition since the results of outcome would be unpredictable. Certain techniques maybe used to deal with these problems. For example, embedded system software runs in a kernel mode which provides an efficient manner to execute system calls. Another example of such a technique is inter-task communication where tasks that share a resource have only a single ‘manger’ task for the resource. The tasks that want to use the same resources have to send a message to this task about their intention to do so.
- Memory allocation
Memory allocation is an important aspect of RTOSes. There are various considerations, the first one being the time taken to allocate the memory. Another thing to be considered is the fragmentation of the memory as used regions come in between the free regions in the memory. This can render a program unable to find any free memory though it is available. RTOSes have to take care that such situations do no arise since embedded systems cannot afford to allow them (since they run continuously without rebooting for years together as against desktop PCs which maybe rebooted frequently).
|