Basic concepts of RTOS

Atomic an operation is said to be atomic if it can be completed without interruption.

Context Switch the process of changing execution from one process to the next. The time required to perform a context switch will have a significant impact on performance. So, knowing how much information is stored as part of a task's context may be important to you. The minimum amount of information required to perform a context switch is largely processor dependent, however, the RTOS vendor may have chosen to include some extra information that will slow down the context switch.

Cooperative multitasking in a cooperative multitasking environment, generally the current running task will be allowed to run until it completes or until it chooses to yield to another task. Yielding to another task may be explicit through a call to a yield function or it may be implied through a call to a function that may cause it to wait for an event or resource.

Counting Semaphore a mechanism for synchronizing processes and their access to resources.

Critical Section a section of code in a program that must be executed while no other piece of code is running. Typically, this means that all interrupts must be disabled. So, critical sections should be kept as small as possible.

Deadlock: Deadlock is a condition where multiple processes may be waiting for a resource to be made available which will never become available. Generally, the programmer must design the system to prevent deadlock from occurring. The typical approach to preventing deadlock in an embedded system is for tasks to always request needed resources in a predefined order.

Deferred interrupt processing Deferred interrupt processing is an approach used to minimize interrupt latency by reducing the amount of time spent inside interrupt service routines. Typically, the interrupt handler sends a message to the operating system indicating that the interrupt has occurred allowing the operating system to invoke a task to handle the external event. The improved interrupt latency due to this approach should result in more deterministic behavior of the system.

Event: An event is generally a mechanism provided by the RTOS to permit communications between processes.

Interprocess communications: Processes or tasks generally need a synchronized method of communications. The relationship between the tasks could be various, including one-to-one, one-to-many, or many-to-many. An RTOS needs to provide mechanisms to permit all of these kinds of communications. Common mechanisms include mailboxes, queues, and events.

Memory management Real-time operating systems frequently provide specialized memory management routines to help solve common embedded system problems. An RTOS may provide the ability to allocate memory in fixed sized blocks or from distinct memory pools, each of which may have special purposes. For example, distinct server processes may have unique memory pools for allocation. Typically the goal is to help avoid memory fragmentation that could lead to a system failure.

Mailbox a mechanism provided by an RTOS for interprocess communications. A process may have a mailbox that other processes can send messages to.

Multitasking/Time slicing A CPU typically can only have a single state or context. Essentially, the CPU can only do one thing at a time. Multitasking the process of frequently changing context to make it appear as if the CPU were performing multiple tasks simultaneously. This task switching may occur on either a cooperative or preemptive multitasking basis.

Mutual Exclusion Refers to ensuring that a shared resource cannot be accessed simultaneously to prevent unwanted interaction. One example of the need for mutual exclusion would be keyboard I/O. Generally; an operating system must ensure that only one process can have access to the keyboard at a time

Preemptive multitasking in a preemptive multitasking system, a supervisor or scheduling task can change which task is currently executing without the permission of the current task. In a preemptive system, the scheduler will generally switch tasks at a periodic interval known as the time slice.

Priority In a real-time operating system, tasks can be assigned a priority. Usually, the scheduler will allow higher priority tasks to run before lower priority tasks are allowed to run. However, there may be a lot of variations between different real-time operating systems and how they treat tasks varying priorities. Some systems will not allow lower priority tasks to execute at all until the higher priority tasks have completed. Other systems may assign larger time slices to higher priority task; yet still allow low priority tasks to execute with a smaller time slice.

Priority Inheritance Priority inheritance, an approach to dealing with the problem of priority inversion, allows a low-priority task to become high priority if it owns a resource that a high-priority task is waiting for. The goal of priority inheritance is to minimize the amount of time high-priority tasks are required to wait for needed resources.

Priority Inversion In a system where a high- and a low-priority task may both need access to the same resource, it is possible that the high-priority task may have to wait for the low-priority task to complete. This is called priority inversion. In such a situation, the low-priority task may not get its time slice until other high-priority tasks complete.

Process/Thread/Task A process, thread, or task is a unit of execution. The use of these terms may be somewhat indistinguishable at times, especially from one RTOS to the next. However, some environments actually define more than one of these. For example, under Windows NT, a process is usually an executable program. And that process may have multiple smaller threads associated with it. Sometimes, as is the case with Windows NT, the terminology in part describes how much context information is associated with it.

Queue a mechanism provided by an RTOS for interprocess communications. Usually, one process acts as a consumer, removing messages from the queue. And, one or many processes may act as producers adding messages to the queue.

Reentrant/Non-Reentrant Reentrant code is code, which does not rely on being executed without interruption before completion. Reentrant code can be used by multiple, simultaneous tasks. Reentrant code generally does not access global data. Variables within a reentrant function are allocated on the stack, so each instance of the function has its own private data. Non-reentrant code, to be used safely by multiple processes, should have access controlled via some synchronization method such as a semaphore.

Resource a resource is usually a mechanism provided by the RTOS to synchronize access to an object within the system, which requires mutually exclusive access. The object within the system, also frequently called a resource, may be a physical device such as a keyboard or an EEPROM, or just a system variable.
Scheduler The scheduler is the portion of the RTOS responsible for determining which task will run next. Real-time operating systems use a wide variety of algorithms for making this selection. Sometimes it is as simple as just allowing the next available process with the highest priority to run. Other systems may have a hybrid prioritized round-robin system where tasks are only allowed to run for a specific time slice before the next task is run.

Semaphore a mechanism for ensuring mutual exclusion or synchronizing processing related to a resource. Time slice The largest amount of time that a task will be allowed to run in a preemptive multitasking system before the scheduler may invoke a new task.

Scheduler scheduling policies are as follows

  • First-Come-First-Served (FCFS)
  • Shortest-Job-First (SJF)
  • Priority Scheduling (PS)
  • Round-Robin Scheduling (RR)
  • Multi-level feedback queues (MLF)
  • Real-time scheduling