Real-time Software


Real-time Tux

Tyler Veness

Definitions of Real-time

  • Hard
    • Can't miss deadlines
    • Aircraft control, pacemaker
  • Firm
    • Can miss deadlines, but late results are useless
    • Heads-up display, video stream
  • Soft
    • Usefulness of result degrades after deadline
    • Desktop application scheduling

Goals

  • Predictability
  • Determinism
    • malloc(), printf(), locks

Scheduling and Priority

  • Kernel can be preemptible
  • Real-time scheduling
    • SCHED_FIFO (queues) ∈ SCHED_RR
    • SCHED_DEADLINE (earliest first)
  • Non-RT
    • SCHED_OTHER, SCHED_BATCH and niceness ([-20..19])

Priority Inversion

  • Low priority task preempts high priority task for shared resource
  • High priority task waits on shared resource
  • Solutions
    • Disable interrupts
    • Priority inheritance
    • Lock-free and atomics

Disable Interrupts

  • Allow process with shared resource to complete
  • Doesn't scale well

Priority Inheritance

  • Elevate priority to that of highest priority waiting task

Lock-free and Atomics

  • No locks! (ideally)
  • Lock-free vs wait-free
  • Lock-free data structures
Roundabout

Lock-free Example

https://github.com/calcmogul/atomic_lib

Floating Point Unit (FPU)

roboRIO

Robot Code Example

Resources