Enea® Linux Real-Time Guide
Total Page:16
File Type:pdf, Size:1020Kb
Enea® Linux Real-Time Guide 4.0-docupdate1 Enea® Linux Real-Time Guide Enea® Linux Real-Time Guide Copyright Copyright © Enea Software AB 2014. This User Documentation consists of confidential information and is protected by Trade Secret Law. This notice of copyright does not indicate any actual or intended publication of this information. Except to the extent expressly stipulated in any software license agreement covering this User Documentation and/or corresponding software, no part of this User Documentation may be reproduced, transmitted, stored in a retrieval system, or translated, in any form or by any means, without the prior written permission of Enea Software AB. However, permission to print copies for personal use is hereby granted. Disclaimer The information in this User Documentation is subject to change without notice, and unless stipulated in any software license agreement covering this User Documentation and/or corresponding software, should not be construed as a commitment of Enea Software AB. Trademarks Enea®, Enea OSE®, and Polyhedra® are the registered trademarks of Enea AB and its subsidiaries. Enea OSE®ck, Enea OSE® Epsilon, Enea® Element, Enea® Optima, Enea® Linux, Enea® LINX, Enea® LWRT, Enea® Accelerator, Polyhedra® Flash DBMS, Polyhedra® Lite, Enea® dSPEED, Accelerating Network Convergence™, Device Software Optimized™, and Embedded for Leaders™ are unregistered trademarks of Enea AB or its subsidiaries. Any other company, product or service names mentioned in this document are the registered or unregistered trade- marks of their respective owner. Acknowledgements and Open Source License Conditions Information is found in the Release Information manual. © Enea Software AB 2014 4.0-docupdate1 ii Enea® Linux Real-Time Guide Table of Contents 1 - Introduction ................................................................................................................ 5 1.1 - How to read this document ................................................................................... 5 1.2 - Terminology ...................................................................................................... 5 2 - Basic Linux from a Real-Time Perspective ...................................................................... 9 2.1 - Kernel Preemption Model ..................................................................................... 9 2.2 - Scheduling ....................................................................................................... 10 2.2.1 - SCHED_FIFO and SCHED_RR ................................................................ 11 2.2.2 - SCHED_OTHER .................................................................................... 11 2.2.3 - SCHED_BATCH .................................................................................... 11 2.2.4 - SCHED_IDLE ........................................................................................ 12 2.3 - Real-Time Throttling ......................................................................................... 12 2.4 - The PREEMPT_RT Patch ................................................................................... 12 2.5 - CPU Load Balancing ......................................................................................... 14 2.6 - CPU Isolation ................................................................................................... 14 2.7 - Dynamic Ticks (NO_HZ) ................................................................................... 15 2.8 - Power Save ...................................................................................................... 16 2.8.1 - Dynamic Freqency Scaling ....................................................................... 16 2.8.2 - CPU Power States ................................................................................... 16 2.8.3 - CPU Hotplug ......................................................................................... 16 2.9 - I/O Scheduling .................................................................................................. 17 2.10 - System calls ................................................................................................... 17 2.11 - Interrupts ........................................................................................................ 18 2.12 - Soft IRQs and Tasklets ..................................................................................... 18 2.13 - Work Queues .................................................................................................. 18 2.14 - Threaded Interrupts .......................................................................................... 19 2.15 - Ticks ............................................................................................................. 19 2.16 - Memory Overcommit ....................................................................................... 19 2.17 - RCU- Read, Copy and Update ........................................................................... 20 3 - Improving the Real-Time Properties ............................................................................ 21 3.1 - Evaluating Real-Time Properties .......................................................................... 21 3.2 - First Attempt .................................................................................................... 21 3.2.1 - Configure the Proper Kernel Preemption Model ............................................ 21 3.2.2 - Optimize Power Save .............................................................................. 22 3.2.3 - Use Threaded Interrupts ........................................................................... 22 3.2.4 - Optimize Real-Time Throttling .................................................................. 23 3.3 - Isolate the Application ....................................................................................... 24 3.3.1 - CPU Isolation ........................................................................................ 24 3.3.2 - Full Dynamic Ticks ................................................................................. 26 3.3.3 - Optimizing a Partitioned System ................................................................ 29 3.3.4 - Benchmarks for CPU isolation .................................................................. 31 3.3.5 - Further reading about CPU isolation ........................................................... 32 3.3.6 - The CPU Partitioning Tool - partrt ............................................................. 32 3.4 - Further Actions if Needed ................................................................................... 33 3.4.1 - User Space Runtime ................................................................................ 33 3.4.2 - Use an RTOS ......................................................................................... 34 4 - Designing Real-Time Applications ................................................................................ 35 4.1 - Application Memory Handling ............................................................................. 35 4.2 - Multi-Threaded Applications ............................................................................... 38 4.3 - Application I/O ................................................................................................. 39 5 - Hardware Aspects ...................................................................................................... 40 5.1 - CPU ................................................................................................................ 40 5.2 - Shared Resources .............................................................................................. 40 © Enea Software AB 2014 4.0-docupdate1 iii Enea® Linux Real-Time Guide 5.2.1 - Shared Memory and Memory Congestion .................................................... 40 5.2.2 - Hyper-Threading ..................................................................................... 41 5.2.3 - NUMA ................................................................................................. 41 5.2.4 - Decrease Impact of Shared Resource Congestion .......................................... 41 5.3 - The System Management Mode (x86) ................................................................... 42 Appendix A - Optimizing Example - P2041 ........................................................................ 43 A.1 - In reality, "real-time" is not only about interrupt latency ........................................... 43 A.2 - Performance and latency tuning strategy ............................................................... 43 A.3 - Configuring and building the Enea Linux PowerPC p2041rdb kernel(s) ....................... 44 A.4 - Benchmark description ...................................................................................... 44 A.5 - The "default" LLD kernel targeting demo/debug ..................................................... 44 A.6 - The performance-optimized RELEASE kernel ........................................................ 45 A.7 - The "rt-optimized" mainstream Low-Latency Desktop kernel .................................... 45 A.8 - The "rt-optimized" PREEMPT_RT kernel ............................................................. 47 A.9 - Summary and Conclusion ................................................................................... 47 Appendix B - Benchmark Details .....................................................................................