ROBOTIC.INDUSTRIES

Robot Software

Real-Time Robot Control on Linux: What PREEMPT_RT Buys You

PREEMPT_RT turns Linux into a usable real-time platform with worst-case latency in the tens of microseconds, but only after the userspace mistakes that dominate jitter are removed.

Engineering workstation in a robot cell with monitors showing motion data
Engineering workstation in a robot cell with monitors showing motion data

A tuned Linux system with the real-time preemption patches, mainlined into the kernel in 2024, reaches worst-case scheduling latency in the region of 20 to 100 microseconds on suitable hardware. That is enough for a 1 kHz joint control loop with margin. It is not enough to save code that allocates memory, takes page faults or logs to disk inside the loop, and in practice userspace mistakes cause more jitter than the kernel ever does.

20 to 100 ustypical worst-case latency, tuned system
1 kHzcommon joint control loop rate
1,000 usbudget available at 1 kHz
2024year the preemption patches were mainlined

What real-time actually means here

Real-time is about bounded worst case, not about speed. A loop that usually completes in 50 microseconds and occasionally takes 4 milliseconds is not real-time, even though its average is excellent. For robot control the question is whether the deadline is met every cycle, because a missed cycle on a torque controller is a visible motion artefact and, at worst, an instability.

Latency classes on Linux
ConfigurationTypical worst caseSuitable for
Standard kernel, no tuning1 to 20 msPlanning, perception, user interface
Standard kernel, tuned200 to 1,000 us100 Hz to 250 Hz loops
Preemptible kernel, tuned20 to 100 us1 kHz joint control
Isolated core, preemptible, tuned10 to 40 us4 kHz to 10 kHz current loops
Dedicated microcontroller1 to 5 usCommutation, safety functions

The userspace mistakes that dominate

Every one of these has been measured causing millisecond-scale spikes on systems whose kernel latency was already excellent.

  • Dynamic memory allocation in the loop. Any allocation can trigger a system call and a page fault. Preallocate everything, then lock memory so it cannot be paged out.
  • Page faults on first touch. Memory that is allocated but never written is not resident. Touch every page during initialisation.
  • Logging and file I/O. A write to disk in the control path is a blocking operation of unbounded duration. Log to a preallocated ring buffer and drain it from a non-real-time thread.
  • Priority inversion. A high-priority thread waiting on a lock held by a low-priority one. Use priority-inheriting mutexes, and prefer lock-free structures at the boundary.
  • Frequency scaling and idle states. Deep processor sleep states cost tens of microseconds to exit. Disable them on the control core.
  • Interrupt affinity. A network interrupt landing on the control core steals time. Pin interrupts elsewhere and isolate the core.
Measure worst case over hours, not seconds. Latency spikes cluster around rare events: garbage collection somewhere in the system, a network burst, a filesystem flush, a thermal throttle. A 60 second test that shows 30 microseconds proves nothing about the 4 millisecond spike that arrives twice a day.

Building a loop budget

At 1 kHz the period is 1,000 microseconds and the budget breaks down roughly as follows for a joint controller on a mid-size arm.

Illustrative 1 kHz control loop budget
ItemTypicalNote
Scheduling latency20 to 100 usKernel contribution
Fieldbus receive50 to 150 usDepends on cycle alignment
State estimation30 to 120 usFiltering, kinematics
Control computation50 to 300 usRises sharply with whole-body optimisation
Safety and limit checks10 to 40 usNever skip under load
Fieldbus transmit30 to 100 us
Total worst case190 to 810 usAgainst a 1,000 us deadline

The margin looks comfortable until the control computation grows. Whole-body optimisation at 1 kHz is where budgets break, which is why many systems run balance and whole-body control at 200 Hz to 500 Hz and only the joint loop at 1 kHz or above.

The architecture most robots end up with

A split, and it is worth designing deliberately rather than discovering.

  1. Microcontroller or FPGA for commutation, current control and hard safety functions, at microsecond scale.
  2. Preemptible Linux with isolated cores for joint and whole-body control at 200 Hz to 2 kHz.
  3. Standard Linux for perception, planning, logging and communication, with no deadline guarantee.

Keeping the boundary explicit is what prevents a perception update from delaying a torque command, and it is the single most useful structural decision in a robot software stack.

Frequently asked questions

Can Linux do hard real-time control?

With the real-time preemption support, isolated cores and careful userspace, worst-case latency reaches roughly 20 to 100 microseconds, which is sufficient for 1 kHz joint control. Microsecond-scale commutation and safety functions still belong on dedicated hardware.

What causes latency spikes if the kernel is tuned?

Almost always userspace: memory allocation in the loop, page faults, file logging, priority inversion on a mutex, or processor idle states and frequency scaling on the control core.

How long should a latency test run?

Hours, under realistic system load. Spikes cluster around rare events such as network bursts, filesystem flushes and thermal throttling, so a short test systematically underestimates the worst case.

What loop rate does a robot actually need?

Joint position and torque control typically runs at 1 kHz, current control at 4 kHz to 20 kHz on dedicated hardware, and whole-body or balance control at 200 Hz to 1 kHz. Planning and perception run far slower without deadline guarantees.

Is a real-time kernel enough on its own?

No. It removes the kernel as a source of unbounded delay, which is necessary but not sufficient. Preallocated and locked memory, priority-inheriting locks, interrupt affinity and core isolation are all required to realise the benefit.

Sources

  1. Linux kernel documentation, real-time schedulingKernel documentation on real-time scheduling classes and throttling
  2. Real-time Linux projectLinux Foundation, status of the preemption work and tuning guidance
  3. Real-time programming backgroundROS 2 design article on real-time requirements in robot software