EDF Scheduler and SRP Implementation

Github Repository

Project Overview

This project extends FreeRTOS by implementing two major features: an Earliest Deadline First (EDF) scheduling algorithm and Stack Resource Policy (SRP) mechanisms and provides an API for user access that follows FreeRTOS conventions. FreeRTOS is a popular open-source real-time operating system (RTOS) designed for embedded systems, enabling precise task scheduling and resource management. These enhancements improve task prioritization and resource management in real-time systems. The project was developed on a Raspberry Pi Pico using the C programming language. I completed this project as part of CPSC 538G Real-Time Systems at UBC.

What is EDF and SRP?

EDF (Earliest Deadline First): A dynamic scheduling algorithm that prioritizes tasks based on their deadlines. The task with the earliest deadline is executed first, ensuring time-critical operations are performed within their constraints.

SRP (Stack Resource Policy): A protocol to manage resource access in priority-driven systems. It prevents priority inversion and deadlocks by assigning a system ceiling to resources and ensuring tasks adhere to these ceilings.

EDF Scheduler Implementation Details

  • Task Control Block Modifications: Introduced fields like TaskDeadline, TaskPeriod, and ActivationTime.
  • EDF Task Creation: A dedicated method to initialize tasks with EDF-specific parameters.
  • Admission Control: Ensures system utilization does not exceed 1 at task creation.
  • Deadline Monitoring: Detects and handles missed deadlines with customizable options.
  • Demo Tasks: Included to validate EDF functionality with busy loops simulating workloads.

With my implementation, users can call the xTaskCreateEDF function to create tasks with periodic execution. It calculates activation times and absolute deadlines dynamically for each task. Admission control ensures that tasks are only admitted if system utilization allows.

SRP Implementation

The project integrates Stack Resource Policy (SRP) mechanisms into FreeRTOS to manage resource access in systems with priority inheritance requirements. This ensures efficient and deterministic resource sharing.

  • System Ceiling Management: Tracks active system ceilings to enforce resource access rules.
  • SRP Binary Semaphores: Custom semaphores with SRP properties like priority ceiling and maximum task priority.
  • Functions:
    • SRP_GetCurrentCeiling: Retrieves the current system ceiling.
    • xSRPCreateBinary: Creates semaphores with SRP properties.
    • xSRPSemaphoreTake: Acquires an SRP semaphore.
    • xSRPSemaphoreGive: Releases an SRP semaphore.

The SRP mechanisms prevent priority inversion by enforcing system ceilings and simplify real-time system design.

Testing the Scheduler and SRP

The enhancements were validated using demo workloads with the pico connected to various LEDs to visually demonstrate different tasks running. Tests verified the EDF scheduler's task execution order, deadline enforcement, and system utilization. For SRP, tasks were tested for deterministic resource sharing and priority inversion prevention. Initial testing involved simply stepping through the code to ensure correctness.

Challenges and Lessons Learned

Challenges:

  • Integrating EDF with the existing FreeRTOS scheduler required a deep understanding of its architecture.
  • Debugging timing issues on the Raspberry Pi Pico due to its limited debugging tools.
  • Ensuring resource ceilings were correctly enforced under SRP in all edge cases.

Lessons Learned:

  • Gained proficiency in FreeRTOS internals and task scheduling concepts.
  • Developed a systematic approach to debugging real-time systems.
  • Improved understanding of real-time scheduling algorithms and resource management protocols.

Other Projects

Inverted Pendulum

Designed a real-time control system to evaluate the performance of a Byzantine Fault Tolerant key-value store.

Learn more

2nd Place - Autonomous Driving Competition

Trained a rover to drive on a simulated road, detecting license plates and avoiding obstacles.

Learn more