Q: How to implement real-time constraints on embedded Linux with PREEMPT_RT?
Answer
The PREEMPT_RT patch makes the Linux kernel fully preemptible reducing worst-case interrupt latency from >100 us to <100 us on most platforms. Install: CONFIG_PREEMPT=y CONFIG_PREEMPT_RT=y. Boot with isolcpus= to reserve cores for real-time threads. Use SCHED_FIFO or SCHED_RR with pthread_attr_setschedpolicy() for real-time threads. Lock memory to prevent swap: mlockall(MCL_CURRENT|MCL_FUTURE). Avoid blocking operations in the real-time thread. Use lock-free data structures (kfifo seqlock) between real-time and non-real-time contexts. Use cyclictest to measure actual latency: cyclictest -l100000 -m -Sp99 –latency=100. Target: P99 latency <100 us for motor control <1 ms for general industrial control.
Filed under: FAQ