Skip to content

leopoldch/kernel-mutex-prio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mi11-rtos-priority-inheritance

Implementation of the Priority Inheritance Protocol (PIP) in a Preemptive Real-Time Kernel

Project Overview

This project, developed for a course miniproject (Spring 2025), focuses on converting an existing fixed-priority preemptive Real-Time Operating System (RTOS) kernel into a dynamic-priority system to solve the critical Priority Inversion Problem.

We implemented the Priority Inheritance Protocol (PIP) by modifying the Mutex API and the core kernel scheduler to support dynamic priority promotion/demotion.

Setup and Requirements (VS Code)

The project is configured for command-line compilation and debugging using VS Code, providing an alternative to the Eclipse IDE environment.

1. Software Prerequisites

The following tools are required (on OSX arm) for development, compilation, and emulation:

  • Visual Studio Code (VS Code)
  • Extensions: C/C++ Extension Pack, Cortex-Debug
  • ARM Toolchain: GCC and GDB (arm-none-eabi-gcc)
  • QEMU: ARM system emulator
  • Console Client: Netcat (nc) or telnet (for serial output)

2. Installation (macOS via Homebrew)

brew install --cask gcc-arm-embedded

brew install qemu

3. Compilation

The project uses a standard Makefile to manage the build process. This includes the correct linker script (kernel/ld.x) and compiler flags specifically for the Cortex-M7 target.

From the project root (mi11_ntr_full_p25_emu/), run:

make clean
make all

4. VS Code Debugging Setup

The debugging setup is designed to bypass the restrictive Cortex-Debug internal server. Instead, it connects GDB directly to QEMU via TCP, mirroring the "OpenOCD (via pipe)" method often used in Eclipse.

  • tasks.json: Contains a background task named launch-qemu. This task executes the necessary QEMU command to emulate the target, opening the GDB port (3333) and the Serial port (1234).
  • launch.json: Defines a cppdbg configuration named Debug QEMU via GDB. This configuration uses arm-none-eabi-gdb and connects to localhost:3333. It ensures that the launch-qemu task runs first via the preLaunchTask setting.

To Start the Debug Session:

  1. Select the Debug QEMU via GDB configuration in VS Code's Run and Debug tab.

  2. After QEMU starts, open a separate terminal and connect to the serial port to view the kernel's chronogram output:

nc localhost 1234

Priority Inheritance Protocol (PIP) Demonstration

The test program (noyau_test_mutex.c) is designed to use three tasks to simulate priority inversion, thereby demonstrating the effectiveness of the PIP implementation.

  • Prio 16 (Prio 2): High Priority Task
  • Prio 32 (Prio 4): Medium Priority Task
  • Prio 48 (Prio 6): Low Priority Task

1. Scenario: Priority Inversion (Without PIP)

In this scenario, the low-priority task (Prio 48) holds the mutex. When the high-priority task (Prio 16) attempts to acquire the mutex and waits, the medium-priority task (Prio 32) preempts the low-priority task. This effectively extends the delay for the high-priority task indefinitely, showcasing the priority inversion problem.

Chronogram (Execution without inheritance):

Execution without inheritance

2. Scenario: Priority Inheritance (With PIP)

With PIP enabled, when Task 16 blocks while waiting for the mutex, Task 48 immediately inherits priority 16. This ensures that Task 48 runs ahead of Task 32, allowing it to quickly release the critical resource and resolve the priority inversion.

Chronogram (Execution with inheritance):

Execution with inheritance

Contributors

Leopold C. (@leopoldch) Alexandre Eberhardt (@alexandreeberhardt)

About

Bare metal minimalist real time kernel (RTOS)

Resources

Stars

Watchers

Forks