P

RTOS Emulator

A real-time kernel, simulated in C

Six schedulers, priority-inversion protocols, deadlock recovery and power management, with a live terminal UI.

A portable, deterministic emulator of a real-time operating system kernel, written to study how real-time embedded systems schedule and synchronise work. Scheduling, synchronisation, memory management, deadlock handling, interrupts and power management live in one C codebase. It runs on Windows, Linux and macOS with a multi-panel, colour-coded ANSI dashboard.

What it does

  • Six hot-swappable schedulers: Round-Robin, FCFS, SRTF, Priority Preemptive, Earliest Deadline First and Rate Monotonic.
  • Deadlock detection by three-colour DFS on a Resource Allocation Graph, Banker's safety algorithm, and recovery by preempting the lowest-priority victim.
  • Priority Inheritance and Priority Ceiling protocols on mutexes, plus highest-priority handoff, to prevent priority inversion.
  • Custom first-fit heap over an 8 KB block with splitting, coalescing, 8-byte alignment and 0xDEADBEEF canaries to catch overflows and double-frees.
  • Power management across 4 virtual cores: C-states and DVFS scaling from 100 to 800 MHz by deadline urgency.
  • Simulated IRQs, message queues, software timers, a stack-overflow guard and a starvation watchdog.
  • Headless benchmark runs a reproducible 500-tick workload on a deterministic PRNG and compares all six schedulers; a Python suite checks the metrics.

Architecture

The kernel engine, platform shims, terminal UI and entry point are separate modules sharing one header. Platform shims hide keyboard input and timers for Windows and POSIX, so the same code builds with GCC, Clang or MSVC. While it runs, keys hot-swap schedulers, inject interrupts or deadlocks, force stack overflows and export the trace to CSV.