0% found this document useful (0 votes)
7 views10 pages

RTOS Study Notes

The document provides a comprehensive overview of Real-Time Operating Systems (RTOS), detailing their structure, task management, scheduling algorithms, and key features. It distinguishes between hard, soft, and firm real-time systems, and explains the importance of timing in critical applications. Additionally, it covers various scheduling algorithms and popular RTOS used in the industry.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views10 pages

RTOS Study Notes

The document provides a comprehensive overview of Real-Time Operating Systems (RTOS), detailing their structure, task management, scheduling algorithms, and key features. It distinguishes between hard, soft, and firm real-time systems, and explains the importance of timing in critical applications. Additionally, it covers various scheduling algorithms and popular RTOS used in the industry.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Real-Time Operating System (RTOS)

Complete Study Notes — Simple & Concise

Based on lecture slides by Dr. Subir Das, IIEST Shibpur

Topics covered: Real-Time Systems · Hard vs Soft RT · RTOS Structure · Kernel · Task Management ·
Scheduling Algorithms (Clock-Driven, EDF, RMA, Round-Robin) · Popular RTOS
1. What is a Real-Time System?
A real-time system is a computer system where tasks must be completed within a strict time limit. Missing
the deadline can cause serious problems — or even disaster.

Key idea: It's not just about getting the correct answer — the answer must arrive on time.

Example: A car's airbag must deploy within milliseconds of a crash. A correct but delayed response is
useless and dangerous.

Types of Real-Time Systems

Type What happens if deadline is missed? Example

Hard Real-Time System fails — catastrophic result Missile tracking, ABS brakes, airbags

Soft Real-Time Performance degrades — not catastrophic Online stock trading, video streaming

Firm Real-Time Late result is discarded — system continues Assembly line sensors

Basic Model of a Real-Time System


A real-time system follows this flow:

• Sensor → detects physical events (temperature, speed, pressure)


• Input Conditioning Unit → filters/amplifies raw sensor data
• Input Interface → converts signal to digital form for the computer
• Real-Time Computer → processes data and makes decisions
• Output Interface → sends decision to actuator
• Output Conditioning Unit → converts digital signal back to physical
• Actuator → performs the physical action (apply brake, open valve)
• Human-Computer Interface → allows operators to monitor/control

2. Real-Time Programming
Real-time programming means writing software that must respond within strict time limits. Three key
constraints:

• Latency — the delay between an event and the system's response


• Deadlines — the latest time by which a task must finish
• Response time — how quickly the system reacts to inputs

Languages used: C (procedure-oriented) and C++ or Java (object-oriented) are most common. Code
must also be optimized for limited memory.

For simple systems: programming can be done directly in C without an RTOS. For complex systems with
many hardware components: an RTOS is needed.
3. Real-Time Operating System (RTOS)
An RTOS is a special operating system built for systems where timing is critical. Unlike a general-purpose
OS (like Windows), an RTOS guarantees that tasks run at exactly the right time, every time.

Feature General-Purpose OS (GPOS) RTOS

Focus User convenience, multitasking Timing correctness

Example Windows, Linux, macOS VxWorks, RTLinux, FreeRTOS

Memory size Hundreds of MB 10 KB – 100 KB (very small)

Use case Office work, browsing Missiles, medical devices, cars

Timing Best-effort (no guarantees) Deterministic (guaranteed)

When is RTOS NOT needed?


• Small embedded systems with simple tasks
• Functions like memory allocation can use standard C (malloc/free)
• When there are few tasks and no strict timing requirements

When is RTOS needed?


• Multiple hardware devices need to be managed simultaneously
• Many tasks need to run and share CPU time fairly
• Interrupt handling from hardware must be reliable
• File and device I/O management is complex

4. Structure of an RTOS — The Kernel


The most important part of any RTOS is its Kernel — the core program that controls everything else.

What does the Kernel do?


• It is the first program loaded when the system starts (after the bootloader)
• It stays in memory as long as the system is running
• It manages: disk, memory, tasks, and hardware devices
• It provides a bridge between software applications and hardware
• When a program asks the kernel for help, it's called a System Call

Two Types of Kernels


Kernel Type Description Pros / Cons

Monolithic Kernel All OS services (memory, I/O, tasks) run in one bigFast,
blockbut
of acode
bug can crash the whole system

Microkernel Only essential services in kernel; others run as separate


Safer and
server
modular,
programs
but slightly slower due to message p
Board Support Package (BSP)
The BSP is processor-specific code that makes an RTOS work on particular hardware. Think of it as a
'translator' between the RTOS and the physical chip.

5 Key RTOS Kernel Functions


# Function What it does

1 Task Management Creates, schedules, deletes, and tracks all tasks

2 Inter-task Communication Lets tasks share data and synchronize with each other

3 Dynamic Memory Allocation Gives memory to tasks when needed and frees it when done

4 Timers Provides precise time tracking and delays

5 Device I/O Supervisor Manages access to hardware devices (sensors, displays)


5. Task Management
In an RTOS, a Task (also called a Process) is any job that:

• Takes a known amount of time to execute (execution time)


• Uses a fixed amount of memory

Task Management is the process of controlling tasks through their entire life cycle — from creation to
termination.

Task State Lifecycle


State Description

Start Task is created and initialized

Ready Task is waiting to use the CPU (all resources available except CPU)

Running Task is currently executing on the CPU

Wait Task is blocked — waiting for a resource, signal, or timer

Terminated Task has completed its work and is removed from the system

■ Key rule: Each task belongs to exactly ONE state at any given time. The Scheduler only works with
tasks in the Ready state.

Types of Real-Time Tasks


Task Type Deadline Importance What happens if missed?

Hard Real-Time Absolute — must not miss System fails completely

Firm Real-Time Important but not fatal Late result discarded; system continues

Soft Real-Time Best-effort (average basis) Performance degrades gradually

Non-Real-Time None No consequence for timing

6. Real-Time Task Scheduling — Key Concepts

Term Simple Explanation

Task Instance Each time a task runs, it is one 'instance'

Relative Deadline Time allowed from task start to finish (e.g. 10 ms)

Absolute Deadline Exact clock time by which task must finish

Response Time Time from task arrival to task completion

Task Precedence Task A must finish before Task B can start

Periodic Task Runs at fixed regular intervals (e.g. every 5 ms)

Sporadic Task Runs randomly but with a minimum gap between runs
Term Simple Explanation

Aperiodic Task Runs randomly with NO minimum gap between runs

Utilization (u) u = execution_time / period. Fraction of CPU a task uses

Jitter Variation in when a periodic task actually arrives

Preemption Stopping a low-priority task to run a higher-priority one

Performance Metrics
• CPU Utilization: % of time CPU is busy. 40% = light load; 90% = heavy load
• Throughput: Number of tasks completed per unit time
• Turnaround Time: Time from task submission to completion
• Waiting Time: Turnaround time minus actual execution time
7. Scheduling Algorithms
Scheduling decides which task runs on the CPU and when. Three main categories:

Category Algorithms

Clock-Driven (Static / Offline) Table-Driven, Cyclic

Event-Driven (Dynamic / Online) Simple Priority-Based, Rate Monotonic (RMA), Earliest Deadline First (EDF)

Hybrid Round-Robin

7a. Clock-Driven Scheduling


The schedule is pre-computed before the system starts and stored in a table. At runtime, the system just
follows the table.

• ■ Advantages: No runtime overhead, simple, predictable


• ■ Disadvantages: Cannot handle sporadic or aperiodic tasks (unpredictable tasks)

Table-Driven Scheduling: Stores exactly which task runs in which time slot. The table repeats every LCM
(Least Common Multiple) of all task periods.

■ Formula: Major Cycle M = LCM(p1, p2, ..., pn) where p = period of each task

Cyclic Scheduling: Divides the major cycle into smaller frames (minor cycles). Tasks are assigned to
frames. A timer interrupt marks each frame boundary.

Frame size F must satisfy 3 rules:

Rule Condition Purpose

1 — Min Context Switching F ≥ max(execution times) A task must fit in one frame

2 — Min Table Size M must be divisible by F Fewer frames = smaller table

3 — Meet All Deadlines 2F − gcd(F, p) ≤ d for every task No task misses its deadline

7b. Earliest Deadline First (EDF)


At every scheduling point, the task with the nearest upcoming deadline gets the CPU. Dynamic —
priorities change as deadlines change.

• A task set is schedulable under EDF if total CPU utilization ≤ 1

■ EDF condition: Σ (ei / pi) ≤ 1 If p > d: use min(p, d) instead of p

• ■ Optimal — can schedule any task set that is theoretically schedulable


• ■ Priority of every task changes dynamically — more complex to implement

7c. Rate Monotonic Algorithm (RMA)


A static priority algorithm: priorities are assigned based on task frequency.

• Higher frequency (shorter period) → Higher priority


• Lower frequency (longer period) → Lower priority
• Priorities are fixed at design time (static)

■ RMA schedulability condition: Σ ui ≤ n × (21/n − 1) where n = number of tasks. As n→∞, the bound
approaches ln(2) ≈ 0.693

• ■ Simple, predictable, easy to implement


• ■ Not optimal — some schedulable task sets may fail this test
• ■ Cannot exceed ~69% CPU utilization for guaranteed scheduling

7d. Simple Priority-Based (Foreground-Background)


Tasks are divided into two groups:

Group Task Type Priority Runs when?

Foreground Real-time periodic tasks HIGH Always preempts background

Background Aperiodic, sporadic, non-real-time tasks LOW Only when foreground is idle

■ Background CPU time available = 1 − Σ(ei/pi)


8. Round-Robin Scheduling
Each task gets a fixed slice of CPU time called a Time Quantum (Q). Tasks are served in circular order —
like taking turns.

Rule Detail

Queue type FIFO (First-In, First-Out) circular queue

Priority No priority — all tasks are equal

If task finishes early Voluntarily releases CPU; next task runs

If task runs out of Q Timer interrupt; task goes to end of queue

Effect of Quantum Size


Quantum Size Behavior

Very Large Behaves like FCFS (First Come First Served) — poor for interactive tasks

Very Small Too many context switches — CPU wastes time switching instead of working

Ideal (10–100 ms) Good balance; aim for 80–90% of tasks to finish in one quantum

Key Formulas
Metric Formula

Response Time Time CPU is first given to task − Arrival time

Turnaround Time Exit time − Arrival time

Waiting Time Turnaround time − Burst time

Avg Waiting Time Sum of all waiting times ÷ Number of processes

Worked Example (Q = 5 ms)


Process Arrival Burst Response Time Waiting Time Turnaround Time

P1 0 ms 8 ms 0 ms 10 ms 18 ms

P2 1 ms 7 ms 4 ms 12 ms 19 ms

P3 2 ms 10 ms 8 ms 13 ms 23 ms

Ready Queue order: P1 → P2 → P3 → P1 → P2 → P3

• ■ Fair — every task gets equal CPU time


• ■ Good response time for interactive tasks
• ■ Higher turnaround time than priority-based methods
• ■ Not suitable for tasks with precedence constraints
9. Quick Comparison of Scheduling Algorithms

Algorithm Type Priority Optimal? Best For

Table-Driven Static Pre-set No Simple periodic systems

Cyclic Static Frame No Small embedded apps

Priority-Based Dynamic Fixed No Foreground/background tasks

RMA Static Rate No Periodic tasks, ≤69% load

EDF Dynamic Deadline Yes Maximum CPU utilization

Round-Robin Hybrid Equal No Fair time-sharing

10. Popular RTOS in Industry

RTOS Key Feature / Usage

VxWorks Most widely used industrial RTOS — aerospace, defense, networking

LynxOS Hard real-time, POSIX-compatible — military and avionics

RTLinux Real-time extension for Linux — research and industrial automation

Windows CE Microsoft's embedded OS — consumer electronics, handheld devices

FreeRTOS Free, open-source — popular for microcontrollers (Arduino, ESP32)

Summary in one line: An RTOS is a small, fast, predictable operating system that ensures every task
runs at exactly the right time — making it essential for safety-critical embedded systems.

Prepared from: Dr. Subir Das, IIEST Shibpur — Real-Time Operating System Lectures

You might also like