RTOS: real-time operating system

Rate-monotonic schedule of the first 30 ms of a model rocket flight computer: IMU every 5 ms, Kalman every 10 ms, baro every 20 ms and logging every 50 ms; shorter-period tasks always take the CPU first, the log task is cut into 4 pieces and finishes at 28 ms, before its 50 ms deadline
Download SVG
Embed

Copy this HTML to use the diagram on your site (CC BY 4.0, keep the credit line):

<figure><img src="https://cosmicaxis.space/img/rtos-la-gi-en.svg" alt="Rate-monotonic schedule of the first 30 ms of a model rocket flight computer: IMU every 5 ms, Kalman every 10 ms, baro every 20 ms and logging every 50 ms; shorter-period tasks always take the CPU first, the log task is cut into 4 pieces and finishes at 28 ms, before its 50 ms deadline" width="600" height="444"><figcaption>Source: <a href="https://cosmicaxis.space/en/rtos-real-time-operating-system/">CosmicAxis</a> · CC BY 4.0 · Based on: CosmicAxis own calculation after Liu and Layland (1973)</figcaption></figure>
Source

CosmicAxis own calculation after Liu and Layland (1973)

An RTOS (real-time operating system) guarantees that tasks finish by their deadlines, deterministically: the highest-priority ready task always gets the CPU first. Liu and Layland (1973) proved that rate-monotonic scheduling meets every periodic deadline when total CPU load stays at or below 75.7% for 4 tasks.

01Knowledge

What is an RTOS and how is it different from a normal operating system?

An RTOS (real-time operating system) is an operating system built for determinism: you know in advance which task runs when and the latest moment it can finish. An RTOS is not necessarily faster than Linux; it promises that results arrive on time, every time.

In an Arduino loop(), one slow SD-card write delays the next sensor read. An RTOS splits the program into prioritized tasks, and a scheduler decides which one uses the CPU. The ESP32’s ESP-IDF framework includes the FreeRTOS kernel.

Spacecraft need an RTOS because flight software is a fixed-period control loop (read sensors, estimate, command) at the core of avionics and flight software. In such a loop the worst-case response time matters more than the average.

A hard real-time system treats one missed deadline as a failure, as with an attitude control command or a parachute deployment. A soft real-time system tolerates occasional lateness, such as downlinking an image.

How does rate-monotonic scheduling work, and what is the Liu & Layland bound?

Common RTOS kernels use fixed-priority preemptive scheduling: when a higher-priority task becomes ready, the running task is interrupted at once. Rate-monotonic scheduling (RMS) assigns priority by period: the shorter the period, the higher the priority.

C. L. Liu (MIT) and James Layland (JPL) proved three results in 1973, in NASA-funded research:

  1. Optimal: no fixed-priority assignment can schedule a task set that rate-monotonic cannot.
  2. Critical instant: the worst response occurs when a task arrives together with every higher-priority task (theorem 1), so only that moment needs checking.
  3. Load bound: m tasks with utilization U = Σ Cᵢ/Tᵢ (C run time, T period) that does not exceed m · (2^(1/m) − 1) are guaranteed to meet their deadlines (theorem 5).
Number of tasks m Utilization bound U (%) Source, date
2 82.8 Liu & Layland, theorem 3; CosmicAxis own calculation, 2026-09-29
3 78.0 Liu & Layland, theorem 5; CosmicAxis own calculation, 2026-09-29
4 75.7 Liu & Layland, theorem 5; CosmicAxis own calculation, 2026-09-29
very large 69.3 (ln 2) Liu & Layland, theorem 5, 2026-09-29

The bound is sufficient, not necessary: above it, check directly at the critical instant. The paper assumes independent tasks, which fails when tasks share resources.

What are mutexes, semaphores and priority inversion?

A mutex is a lock protecting a shared resource such as an I2C bus, released only by the task that holds it; a semaphore is a synchronization signal, for example an interrupt announcing “new data”. The FreeRTOS documentation recommends binary semaphores for synchronization and mutexes for mutual exclusion.

Priority inversion happens when a high-priority task waits for a mutex held by a low-priority task, and a medium-priority task then takes the CPU away from the low-priority one. The high-priority task is blocked for an unbounded time. Sha, Rajkumar and Lehoczky (1990) called this uncontrolled priority inversion and proposed two protocols:

  • Priority inheritance: the task holding the lock temporarily takes the priority of the high-priority task waiting for it.
  • Priority ceiling: the worst-case blocking time is limited to one critical section of one lower-priority task, and deadlock is prevented.

A FreeRTOS mutex has priority inheritance, but the FreeRTOS documentation says it only reduces the effect; a hard real-time design should avoid priority inversion entirely.

02Practice

How do you check rate-monotonic schedulability for a flight computer?

Rate-monotonic schedulability is checked in two steps: compare the utilization U with the Liu & Layland bound, then simulate from the critical instant to get the worst-case response time R. The code below does both for a model rocket flight computer (the kind that only logs data and fires a parachute) running a Kalman filter to estimate altitude.

The task set is a CosmicAxis assumption, not a measurement: IMU read every 5 ms running 1 ms, Kalman every 10 ms running 2 ms, baro every 20 ms running 3 ms, SD-card logging every 50 ms running 10, 20, then 22 ms.

from math import lcm

def check(tasks):  # tasks: [(name, period T ms, run time C ms)]
    tasks = sorted(tasks, key=lambda x: x[1])  # shorter period = higher priority
    n = len(tasks)
    U = sum(C / T for _, T, C in tasks)
    bound = n * (2 ** (1 / n) - 1)  # Liu & Layland bound
    left, release, R = [0] * n, [0] * n, [0] * n
    for t in range(lcm(*(T for _, T, _ in tasks))):  # start at the critical instant
        for i, (_, T, C) in enumerate(tasks):
            if t % T == 0:
                if left[i]:
                    return U, bound, None  # previous job unfinished: deadline missed
                left[i], release[i] = C, t
        i = next((i for i in range(n) if left[i]), None)
        if i is not None:
            left[i] -= 1
            if left[i] == 0:
                R[i] = max(R[i], t + 1 - release[i])
    return U, bound, None if any(left) else dict(zip((x[0] for x in tasks), R))

for c_log in (10, 20, 22):
    U, bound, R = check([("imu", 5, 1), ("kalman", 10, 2), ("baro", 20, 3), ("log", 50, c_log)])
    print(f"log {c_log} ms: U = {U:.2f}, bound = {bound:.3f}, R = {R}")
# log 10 ms: U = 0.75, bound = 0.757, R = {'imu': 1, 'kalman': 3, 'baro': 7, 'log': 28}
# log 20 ms: U = 0.95, bound = 0.757, R = {'imu': 1, 'kalman': 3, 'baro': 7, 'log': 49}
# log 22 ms: U = 0.99, bound = 0.757, R = None

CosmicAxis ran this code on Python 3.14.6 and cross-checked it with a response-time analysis, with the same numbers. With a 10 ms log task, U = 0.75 is below the bound and the log finishes at 28 ms at the latest (cover image). With 20 ms the load exceeds the bound but the log still meets its deadline, with 1 ms to spare. With 22 ms the load is below 100% yet the deadline is missed. On real hardware, measure C in the worst case and add context-switch overhead.

How do you learn FreeRTOS on an STM32 or ESP32?

The effective way to learn an RTOS is to build a flight computer on FreeRTOS step by step, one concept per step (a CosmicAxis suggestion):

  1. Tasks and priorities: two tasks blink an LED at two periods; change the priorities and measure the jitter.
  2. Queues: the IMU task sends samples through a queue to the filter task, instead of a global variable.
  3. Interrupts and semaphores: a sensor interrupt wakes the reader task.
  4. Mutexes and time budgets: deliberately create priority inversion on a shared I2C bus; measure each task’s real C and feed it into the Python code above.

The same task architecture carries over to satellite computers such as a CubeSat.

03Reality

How did priority inversion reset Mars Pathfinder?

The Mars Pathfinder lander (landed at Ares Vallis on 4 July 1997, per NASA) rebooted itself on Mars because of priority inversion in the VxWorks operating system; after each reset, the rest of that day’s work slipped to the next day. Glenn Reeves, JPL’s flight software lead, described it in an email on 15 December 1997.

Two timelines: without priority inheritance the low task holds the mutex, the medium task takes the CPU, the high task misses its deadline and the computer resets; with priority inheritance the low task temporarily takes the high priority, releases the mutex early and the high task meets its deadline
Source

Glenn Reeves (JPL), What really happened on Mars?, 15 December 1997

According to Reeves, the 1553 data bus ran at 8 Hz: task bc_sched (highest priority) set up transactions, and task bc_dist (third priority) distributed the data. The low-priority ASI/MET weather task received data through pipe() and select(), which use an internal mutex. When ASI/MET held the mutex, medium-priority tasks took its CPU time; bc_dist waited for the mutex; bc_sched woke up, found bc_dist unfinished, treated it as a hard deadline miss and reset the computer.

Using the built-in tracing tool, the team reproduced the bug in under 18 hours. The fix was to change one global configuration variable so the semaphore behind select() uses priority inheritance, an option Wind River had turned off by default for performance. Pre-launch testing covered only “best-case” data rates, while surface data rates were higher than expected: the kind of gap in verification and validation that systems engineering must close. Reeves’s lesson: when you fly commercial software, you must know how it runs.

What did the Apollo 11 1202 alarm show about priority scheduling?

The Apollo 11 1202 alarm showed that a priority scheduler saved the landing on 20 July 1969: when the computer was overloaded, it restarted and kept running only the important jobs.

According to Peter Adler, a lunar module software programmer at MIT, the Executive gave each job a scratch memory area called a core set, and the computer had only 7. Running out of core sets raised alarm 1202; running out of VAC areas raised 1201. Rendezvous radar processing was scheduled repeatedly because the radar switch was set wrongly, filling the queue. After each alarm the computer restarted, kept the engine guidance and display jobs, and dropped the unneeded radar work.

Fred Martin (MIT) wrote that the computer behaved as if running at about 80% speed because of cycle stealing while the radar switch was in AUTO. MIT had chosen a priority-driven Executive over round-robin or FIFO, so when time ran short the low-priority work fell first, the same principle as a modern RTOS.

Which RTOS and flight software frameworks do spacecraft use today?

Modern flight software is usually a framework running on an RTOS through an operating system abstraction layer, so the RTOS can be swapped without rewriting applications. NASA has two open-source frameworks:

  • NASA’s cFS (core Flight System, Goddard Space Flight Center) runs on Linux, RTEMS, VxWorks and QNX, and according to Goddard has flown on more than 40 NASA missions.
  • F´ (F Prime) from JPL is a C++ framework continuously tested on Linux, macOS, Zephyr, VxWorks 7 and FreeRTOS, and according to NASA (8 July 2021) it is the flight software foundation of the Ingenuity helicopter on Mars.

An abstraction layer cannot rescue a design flaw: Ariane 5 flight 501 was lost because two redundant inertial reference systems ran the same software and shut down together. For crewed spacecraft, each task’s worst-case response time must be calculated, measured and rechecked whenever the software changes. Code running on an RTOS must also follow a coding standard such as NASA’s Power of 10.

04Milestone

Milestone: check yourself

If you can do all of these, move on to the next article in this phase.

  • Can you explain why an RTOS is deterministic, not necessarily faster?
  • Can you compute the Liu & Layland bound for 4 tasks (0.757)?
  • Can you run the Python code and see the log task miss its deadline at 22 ms?
  • Can you redraw the chain of priority inversion on Mars Pathfinder?

Frequently asked questions

What is FreeRTOS?

FreeRTOS is an open-source RTOS kernel for microcontrollers with tasks, queues, semaphores and mutexes that support priority inheritance. The ESP-IDF framework for the ESP32 includes FreeRTOS.

How is an RTOS different from Linux?

An RTOS is designed so the worst-case response time of each task can be calculated; Linux favors throughput and fairness between processes. NASA's cFS framework runs on both kinds.

What is the difference between a mutex and a semaphore?

A mutex is a lock protecting a shared resource, released only by the task holding it; a semaphore is a synchronization signal. In FreeRTOS only the mutex has priority inheritance.

References

  1. Liu and Layland — Scheduling Algorithms for Multiprogramming in a Hard-Real-Time Environment, J. ACM 20(1), 1973 — accessed
  2. Sha, Rajkumar and Lehoczky — Priority Inheritance Protocols, IEEE Trans. Computers 39(9), 1990 — accessed
  3. Glenn Reeves (JPL) — What really happened on Mars?, 15 December 1997 — accessed
  4. NASA Science — Mars Pathfinder — accessed
  5. FreeRTOS — Mutexes — accessed
  6. Espressif — ESP-IDF: FreeRTOS Overview — accessed
  7. Peter Adler — Apollo 11 Program Alarms, ALSJ, 1998 — accessed
  8. Fred H. Martin — Apollo 11: 25 Years Later, ALSJ, 1994 — accessed
  9. NASA Goddard — core Flight System (cFS) — accessed
  10. NASA/JPL — F´ Supported Platforms — accessed
  11. NASA — Open-Source Software Powering Ingenuity, 8 July 2021 — accessed

Cite this article

CosmicAxis. (2026). RTOS: real-time operating system for flight software. https://cosmicaxis.space/en/rtos-real-time-operating-system/