VijayNetwork.Com
RTOS Concepts

RTOS

RTOS is specifically designed for real time applications. It should respond the external events with in a short and predictable time frame. The following devices are using RTOS,
Mobiles
Set top box
Industrial robots
Spacecraft
Examples for RTOS,
  • RTLinux
  • VxWorks
  • ST Lite

Hard real-time

Realtime applications can be classified as either hard or soft realtime. Hard realtime applications require a response to events within a predetermined amount of time for the application to function properly. If a hard realtime application fails to meet specified deadlines, the application fails. While many hard realtime applications require high-speed responses, the granularity of the timing is not the central issue in a hard realtime application.

An example of a hard realtime application is Avionic control system where a late response will result fail in operation.

Soft real-time

Soft realtime applications do not fail if a deadline is missed. Some soft realtime applications can process large amounts of data or require a very fast response time, but the key issue is whether or not meeting timing constraints is a condition for success.

An example of a soft realtime application is an hotel reservation system where an occasional delay is tolerable, but unwanted.

Four main tasks of OS

  • Process Management
    • Process creation
    • Process execution control
    • Interaction of the process with signal events
    • Process monitoring
    • CPU allocation
    • Process termination
  • Interprocess Communication
    • Synchronization and coordination
    • Deadlock and Livelock detection
    • Process Protection
    • Data Exchange Mechanisms
  • Memory Management
    • Services for file creation, deletion, reposition and protection
  • Input/Output Management
    • Handles requests and release subroutines for a variety of peripherals and read, write and reposition programs

Three states of CPU to schedule

  • Ready - waiting to run (in ready list)
  • Running - process (thread or task) is utilizing the processor to execute instructions
  • Blocked - waiting for resources (I/O, memory, critical section, etc.)

The kernel scheduler

The kernel scheduler can be prevented from preempting or timeslicing the current task, by using the following pair of functions:
void task_lock (void);
void task_unlock (void);

Interrupts

Provide a away for external events to control the CPU.
CPU will stop executing the current task and start executing the interrupt handler for that interrupt.
Interrupts can be prevented from interrupting the task by using the interrupt_mask() or interrupt_mask_all() functions.

Timeslice Termination

A task needs to voluntarily give up control of the CPU so that another task at the same priority can execute, that is, terminate the current timeslice. This is achieved with the functions:
void task_reschedule (void);
void task_yield (void);

Message Queue

Tasks communicate with each other using message queues.

Semaphore and Mutex

Tasks synchronize their actions with each other using semaphores and mutexes.
Semaphore Services
  • Way to synchronize multiple tasks
  • to ensure mutual exclusion
  • Control access to a shared resource

What is preemption?

The act of suspending the execution of one thread and starting (or resuming) another. The suspended thread is said to have been "preempted" by the new thread.

preemptive scheduler

A scheduler that may switch between threads at any time.

What is priority inverse?

A situation where a low-priority task holds a resource which a higher-priority task is waiting for.