SlideShare ist ein Scribd-Unternehmen logo
1 von 43
Title: RT Linux
Seyed Navid Ashrafi
Telecommunication Networks Group
Technische Universität Berlin
Summer Semester 2018
35-minute presentation
NES SS2018 1
Over view
>> Introduction to RTOS
- Definitions and history
- Usages & requirements
NES SS2018 2
>> PREEMPT_RT patch
- Overview
- Features
>> Latency measurement test
>> Conclusion
>> Different approaches
- Xenomai
- PREEMPT_RT
- Cons & pros
What is real time?
• It is about fast operation time
• It is about performance
• Its about DETERMINISM
- You need to execute an operation in a specific time frame and you need a
guarantee for that.
- As fast as specified, not as fast as possible
- RT-Linux: Deterministic timing behavior in Linux.
- Depends on the system
NES SS2018 3
Usage and requirements of RT-Linux
• Usages:
- Industrial applications
- Multimedia systems
- Aerospace system
- Automative
- Financial services
• Requirements:
- Deterministic timing behavior
- Preemption
- priority inheritance
NES SS2018 4
Soft Realtime??
• It is in contrast with deterministic behavior
• We concentrate on 100% and 95% hard RT.
• 100% hard RT: Realtime requirements should be met 100% otherwise
it will lead to an error condition (industry)
• 95% hard RT: Realtime requirements should be met 95% (data
collection)
NES SS2018 5
Critical section
• Concurrent access to a shared resource can lead to
unexpected or error condition
• There are over 10,000 individual critical section in a
typical Linux 2.6 kernel
• In the non-preemptible design of Linux 2.6
kernel, any critical section can block preemption
• In the Preemptible design the effort was to reduce the total size and
number of non-preemptible critical sections.
NES SS2018 6
Approaches
Dual-kernel / Co-kernel
Single-kernel / In-kernel
NES SS2018 7
Dual-kernel approach
• First approaches which are still existing.
• Linux is running on top of a microkernel as a low priority real time task.
• The microkernel does the real time stuff.
• You need to maintain the microkernel and a hardware abstraction layer on Linux
to make it run on the microkernel:
- Big, time consuming effort.
- Reason why most of these approaches
are always one step behind
Linux fast development
NES SS2018 8
Single-kernel approach
• A way to make Linux it self real-time capable.
• You would have to touch every single file in the kernel.
• No microkernel or hardware abstraction layer (you can just work with
Linux standard tools).
NES SS2018 9
Xenomai
Xenomai 1.0
• Announced in 2001 – as portability framework for RTOS applications
• Required a real-time basis
• Development of ADEOS layer for Linux and RTAI
• Merged with RTAI
Xenomai 2.0
• Departed from RTAI in 2005 – incompatible design goals
• Evolved ADEOS to I-pipe layer (also used by RTAI)
• Ported to 6 architectures
Xenomai 3.0
• Released in 2015 after 5 years of development
• Rework of in-kernel core (now POSIX-centric)
• Support for native Linux
NES SS2018 10
Xenomai
NES SS2018 11
microkernel preempts Linux
Xenomai architecture
NES SS2018 12
Migration between schedulers
• creating realtime task in application, over a normal Linux task
• 2 threads for one task which share a lot of states
• only one of them can run at the same time
• Migration to RT: suspend Linux task, resume Cobalt thread
• Migration to Linux (on syscall, fault/trap, signal):
suspend Cobalt thread, resume Linux task
• Every things that we do not handle in Xenomai will be directed
to Linux
NES SS2018 13
Hardware abstraction layer
I-pipe Core
NES SS2018 14
Issues of dual-kernel approach
• Special API
• Special tools and libraries
• Microkernel needs to be ported for new HW and new Linux versions
• Bad scaling on big platforms
• Various number of not palatable patches
• Changes to critical subsystems regularly cause regressions
• Porting efforts consume core developer resources
-Most work done by Philippe and Gilles so far
-Time would be better spent on feature improvements...
NES SS2018 15
Xenomai application
• Machine control systems, PLCs
• Printing machines (manroland)
• Printers / copying machines
• Network switches (e.g. Ruggedcom)
• Magnetic resonance tomographs (Siemens Healthcare)
• OROCOS (OSS robotics framework)
• Robotic research projects
• … (many, many incognito applications)
NES SS2018 16
Preempt_RT
• Founded 14 years ago by: Thomas Gleixner & Ingo Molnar
• Huge community
• In-kernel approach
• Main idea: only code that, absolutely must be non-preemptible, is allowed
to be non-preemptible
• Most of the features already made it into the “mainline”
• Interrupt handlers run in a kernel thread which has two advantages:
- The kernel thread is interruptible
- It shows up in a process list with a PID
• First mainline integration 2006
NES SS2018 17
Preempt_RT Goals
• 100% Preemptible kernel
- not possible yet, but let’s try regardless
- Removal of interrupts and preemption disabling
- Fast “worst case” time.
• Quick reaction time
- Bring latencies down to a minimum
• Minimize non-Preemptible kernel code
- at the meantime Minimize code changing amount
NES SS2018 18
Evolution of RT-Linux
NES SS2018 19
PREEMPT_RT architecture
NES SS2018 20
Fully Preemptible kernel (the RT patch)
• Preemption almost everywhere
• Spinlocks turn into mutexes
• No hard interrupt context
• Preemptible critical section
• Preemptible interrupt handlers
• Preemptible “interrupt disable” code sequence
• Priority inheritance
• Deferred operation
• Latency reduction
NES SS2018 21
Mutex
• Critical sections are still protected without disabling preemption
• A Mutex guarantees data integrity while extending the operation of the
spinlock
- we have priority inheritance
- All locks are assumed to be preemptible
- This design eliminates the possibility that an inefficient locking
implementation in a driver can introduce un-detected latency into
the system.
- Only a small subset of locks stay unpreemptible which are manageable.
NES SS2018 22
Priority inversion
• When a high priority task wants to run but it can not because a lower
priority task is holding that lock
• It is bad but we can not get rid of it, what we can get rid of is
unbounded priority inversion
NES SS2018 23
Unbounded priority inversion
NES SS2018 24
A
B
C
Priority inheritance
NES SS2018 25
A
B
C
local_irq_disable
asmlinkage void
do_entInt(unsigned long type, unsigned long vector,
unsigned long la_ptr, struct pt_regs *regs)
{
struct pt_regs *old_regs;
local_irq_disable();
switch (type) {
case 0:
#ifdef CONFIG_SMP
NES SS2018 26
handle_ipi(regs);
return;
#else
irq_err_count++;
printk(KERN_CRIT "Interprocessor interrupt?
"You must be kidding!n");
#endif
break;
1 2
Preempt_disable
NES SS2018 27
• Local_irq_disable younger sibling
• Also does not give a hint to what does it do!
• Has the exact same problems of local_irq_disable
• Preempt_enable_no_resched
- only should be used within preempt_disable locations
Why do we still need Co-kernel?
Functional limitations of In-kernel
• Emulation of RTOS scheduling behavior limited
by Linux scheduler
• Not all kernel+libc code paths used by In-kernel approaches
are necessarily hard real-time under PREEMPT-RT
• No detection of non-RT behavior of your application
Performance limitations of In-kernel
• Co-kernel is usually more light-weight on low-end platforms
(limited caches vs. code path lengths)
• PREEMPT-RT can have unwanted impact
co-located non-RT workloads
Xenomai adds value to Linux
• it keeps the realtime stuff away from the complexities
of Linux kernel
• Co-kernel approach can be beneficial
for low latencies and real-time application architecture
NES SS2018 28
Latency measurement on xenomai & preempt_RT
• Made by Jan Altenberg from Linutronix GmbH
• On two ARM Cortex A9 SOC platforms
• IRQ test with 10KHz frequency with the latency box
• 100% CPU load with “hackbench”
• They did the test in usespace and kernelspace
• 12-hour duration
NES SS2018 29
Hackbench
• Starts n groups of 20 clients and 20 servers
• Each client sends 100 messages to each server via a socket
connection
NES SS2018 30
Latency box
NES SS2018 31
Xenomai latency userspace task
NES SS2018 32
PREEMPT_RT latency userspace task
NES SS2018 33
PREEMPT_RT latency userspace task (isolated CPU)
NES SS2018 34
Latency: userspac- Comparison
NES SS2018 35
Xenomai latency in kernelspace
NES SS2018 36
PREEMPT_RT latency in kernelspace
NES SS2018 37
PREEMPT_RT latency in kernelspace (isolated)
NES SS2018 38
PREEMPT_RT latency in kernelspace (using FIQ)
NES SS2018 39
Latency: Kernel - Comparison
NES SS2018 40
Test results
• Which approach to choose?
- If timing is vital, choose Xenomai, it separates the realtime interrupt
handling from complexities of Linux kernel
• You can go with PREEMPT_RT using FIQ
• Xenomai kernelspace is the best for 100% hard performance
• Xenomai userspace is slower than it’s kernelspace
• Tests only can help you in the field of latency which is dependent on
the hardware
• No guarantee for results repeatation
NES SS2018 41
Conclusion
• PREEMPT_RT is getting integrated in Linux mainline
- Download here: https://www.kernel.org/
• PREEMPT_RT Increases Linux stability and quality
• PREEMPT_RT is simple to use
• Xenomai has it’s own advantages over PREEMPT_RT
• Microkernels are hard to handle
• For the most use cases the latency of the both approaches is almost
the same
• FIQ offers very fast latency but brings limitations
NES SS2018 42
Thank you
NES SS2018 43

Weitere ähnliche Inhalte

Was ist angesagt?

P4, EPBF, and Linux TC Offload
P4, EPBF, and Linux TC OffloadP4, EPBF, and Linux TC Offload
P4, EPBF, and Linux TC Offload
Open-NFP
 

Was ist angesagt? (20)

Kdump and the kernel crash dump analysis
Kdump and the kernel crash dump analysisKdump and the kernel crash dump analysis
Kdump and the kernel crash dump analysis
 
ansible why ?
ansible why ?ansible why ?
ansible why ?
 
New Ways to Find Latency in Linux Using Tracing
New Ways to Find Latency in Linux Using TracingNew Ways to Find Latency in Linux Using Tracing
New Ways to Find Latency in Linux Using Tracing
 
eBPF Trace from Kernel to Userspace
eBPF Trace from Kernel to UserspaceeBPF Trace from Kernel to Userspace
eBPF Trace from Kernel to Userspace
 
Testing real-time Linux. What to test and how
Testing real-time Linux. What to test and how Testing real-time Linux. What to test and how
Testing real-time Linux. What to test and how
 
P4, EPBF, and Linux TC Offload
P4, EPBF, and Linux TC OffloadP4, EPBF, and Linux TC Offload
P4, EPBF, and Linux TC Offload
 
QEMU - Binary Translation
QEMU - Binary Translation QEMU - Binary Translation
QEMU - Binary Translation
 
Linux scheduler
Linux schedulerLinux scheduler
Linux scheduler
 
HKG15-505: Power Management interactions with OP-TEE and Trusted Firmware
HKG15-505: Power Management interactions with OP-TEE and Trusted FirmwareHKG15-505: Power Management interactions with OP-TEE and Trusted Firmware
HKG15-505: Power Management interactions with OP-TEE and Trusted Firmware
 
Module 4 Embedded Linux
Module 4 Embedded LinuxModule 4 Embedded Linux
Module 4 Embedded Linux
 
Function Level Analysis of Linux NVMe Driver
Function Level Analysis of Linux NVMe DriverFunction Level Analysis of Linux NVMe Driver
Function Level Analysis of Linux NVMe Driver
 
Page cache in Linux kernel
Page cache in Linux kernelPage cache in Linux kernel
Page cache in Linux kernel
 
The Linux Kernel Scheduler (For Beginners) - SFO17-421
The Linux Kernel Scheduler (For Beginners) - SFO17-421The Linux Kernel Scheduler (For Beginners) - SFO17-421
The Linux Kernel Scheduler (For Beginners) - SFO17-421
 
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven RostedtKernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
 
LCU14-410: How to build an Energy Model for your SoC
LCU14-410: How to build an Energy Model for your SoCLCU14-410: How to build an Energy Model for your SoC
LCU14-410: How to build an Energy Model for your SoC
 
Yet another introduction to Linux RCU
Yet another introduction to Linux RCUYet another introduction to Linux RCU
Yet another introduction to Linux RCU
 
Understanding of linux kernel memory model
Understanding of linux kernel memory modelUnderstanding of linux kernel memory model
Understanding of linux kernel memory model
 
SFO15-302: Energy Aware Scheduling: Progress Update
SFO15-302: Energy Aware Scheduling: Progress UpdateSFO15-302: Energy Aware Scheduling: Progress Update
SFO15-302: Energy Aware Scheduling: Progress Update
 
LISA2019 Linux Systems Performance
LISA2019 Linux Systems PerformanceLISA2019 Linux Systems Performance
LISA2019 Linux Systems Performance
 
SFO15-TR9: PSCI, ACPI (and UEFI to boot)
SFO15-TR9: PSCI, ACPI (and UEFI to boot)SFO15-TR9: PSCI, ACPI (and UEFI to boot)
SFO15-TR9: PSCI, ACPI (and UEFI to boot)
 

Ähnlich wie Real time Linux

Four Ways to Improve Linux Performance IEEE Webinar, R2.0
Four Ways to Improve Linux Performance IEEE Webinar, R2.0Four Ways to Improve Linux Performance IEEE Webinar, R2.0
Four Ways to Improve Linux Performance IEEE Webinar, R2.0
Michael Christofferson
 

Ähnlich wie Real time Linux (20)

Trends in Systems and How to Get Efficient Performance
Trends in Systems and How to Get Efficient PerformanceTrends in Systems and How to Get Efficient Performance
Trends in Systems and How to Get Efficient Performance
 
Værktøjer udviklet på AAU til analyse af SCJ programmer
Værktøjer udviklet på AAU til analyse af SCJ programmerVærktøjer udviklet på AAU til analyse af SCJ programmer
Værktøjer udviklet på AAU til analyse af SCJ programmer
 
淺談 Live patching technology
淺談 Live patching technology淺談 Live patching technology
淺談 Live patching technology
 
PuppetConf 2016: Why Network Automation Matters, and What You Can Do About It...
PuppetConf 2016: Why Network Automation Matters, and What You Can Do About It...PuppetConf 2016: Why Network Automation Matters, and What You Can Do About It...
PuppetConf 2016: Why Network Automation Matters, and What You Can Do About It...
 
Webinar: OpenEBS - Still Free and now FASTEST Kubernetes storage
Webinar: OpenEBS - Still Free and now FASTEST Kubernetes storageWebinar: OpenEBS - Still Free and now FASTEST Kubernetes storage
Webinar: OpenEBS - Still Free and now FASTEST Kubernetes storage
 
Four Ways to Improve Linux Performance IEEE Webinar, R2.0
Four Ways to Improve Linux Performance IEEE Webinar, R2.0Four Ways to Improve Linux Performance IEEE Webinar, R2.0
Four Ways to Improve Linux Performance IEEE Webinar, R2.0
 
Realtime
RealtimeRealtime
Realtime
 
운영체제론 Ch22
운영체제론 Ch22운영체제론 Ch22
운영체제론 Ch22
 
RISC V in Spacer
RISC V in SpacerRISC V in Spacer
RISC V in Spacer
 
Embedded systems introduction
Embedded systems introductionEmbedded systems introduction
Embedded systems introduction
 
Embedded Systems Introduction
Embedded Systems IntroductionEmbedded Systems Introduction
Embedded Systems Introduction
 
"Making Computer Vision Software Run Fast on Your Embedded Platform," a Prese...
"Making Computer Vision Software Run Fast on Your Embedded Platform," a Prese..."Making Computer Vision Software Run Fast on Your Embedded Platform," a Prese...
"Making Computer Vision Software Run Fast on Your Embedded Platform," a Prese...
 
Towards "write once - run whenever possible" with Safety Critical Java af Ben...
Towards "write once - run whenever possible" with Safety Critical Java af Ben...Towards "write once - run whenever possible" with Safety Critical Java af Ben...
Towards "write once - run whenever possible" with Safety Critical Java af Ben...
 
Intro to HPC
Intro to HPCIntro to HPC
Intro to HPC
 
Linux Kernel Security Overview - KCA 2009
Linux Kernel Security Overview - KCA 2009Linux Kernel Security Overview - KCA 2009
Linux Kernel Security Overview - KCA 2009
 
Update on Trinity System Procurement and Plans
Update on Trinity System Procurement and PlansUpdate on Trinity System Procurement and Plans
Update on Trinity System Procurement and Plans
 
Building the Internet of Things with Thingsquare and Contiki - day 2 part 1
Building the Internet of Things with Thingsquare and Contiki - day 2 part 1Building the Internet of Things with Thingsquare and Contiki - day 2 part 1
Building the Internet of Things with Thingsquare and Contiki - day 2 part 1
 
A Dataflow Processing Chip for Training Deep Neural Networks
A Dataflow Processing Chip for Training Deep Neural NetworksA Dataflow Processing Chip for Training Deep Neural Networks
A Dataflow Processing Chip for Training Deep Neural Networks
 
Introduction to netlink in linux kernel (english)
Introduction to netlink in linux kernel (english)Introduction to netlink in linux kernel (english)
Introduction to netlink in linux kernel (english)
 
Introduction to multicore .ppt
Introduction to multicore .pptIntroduction to multicore .ppt
Introduction to multicore .ppt
 

Kürzlich hochgeladen

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Kürzlich hochgeladen (20)

Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 

Real time Linux

  • 1. Title: RT Linux Seyed Navid Ashrafi Telecommunication Networks Group Technische Universität Berlin Summer Semester 2018 35-minute presentation NES SS2018 1
  • 2. Over view >> Introduction to RTOS - Definitions and history - Usages & requirements NES SS2018 2 >> PREEMPT_RT patch - Overview - Features >> Latency measurement test >> Conclusion >> Different approaches - Xenomai - PREEMPT_RT - Cons & pros
  • 3. What is real time? • It is about fast operation time • It is about performance • Its about DETERMINISM - You need to execute an operation in a specific time frame and you need a guarantee for that. - As fast as specified, not as fast as possible - RT-Linux: Deterministic timing behavior in Linux. - Depends on the system NES SS2018 3
  • 4. Usage and requirements of RT-Linux • Usages: - Industrial applications - Multimedia systems - Aerospace system - Automative - Financial services • Requirements: - Deterministic timing behavior - Preemption - priority inheritance NES SS2018 4
  • 5. Soft Realtime?? • It is in contrast with deterministic behavior • We concentrate on 100% and 95% hard RT. • 100% hard RT: Realtime requirements should be met 100% otherwise it will lead to an error condition (industry) • 95% hard RT: Realtime requirements should be met 95% (data collection) NES SS2018 5
  • 6. Critical section • Concurrent access to a shared resource can lead to unexpected or error condition • There are over 10,000 individual critical section in a typical Linux 2.6 kernel • In the non-preemptible design of Linux 2.6 kernel, any critical section can block preemption • In the Preemptible design the effort was to reduce the total size and number of non-preemptible critical sections. NES SS2018 6
  • 8. Dual-kernel approach • First approaches which are still existing. • Linux is running on top of a microkernel as a low priority real time task. • The microkernel does the real time stuff. • You need to maintain the microkernel and a hardware abstraction layer on Linux to make it run on the microkernel: - Big, time consuming effort. - Reason why most of these approaches are always one step behind Linux fast development NES SS2018 8
  • 9. Single-kernel approach • A way to make Linux it self real-time capable. • You would have to touch every single file in the kernel. • No microkernel or hardware abstraction layer (you can just work with Linux standard tools). NES SS2018 9
  • 10. Xenomai Xenomai 1.0 • Announced in 2001 – as portability framework for RTOS applications • Required a real-time basis • Development of ADEOS layer for Linux and RTAI • Merged with RTAI Xenomai 2.0 • Departed from RTAI in 2005 – incompatible design goals • Evolved ADEOS to I-pipe layer (also used by RTAI) • Ported to 6 architectures Xenomai 3.0 • Released in 2015 after 5 years of development • Rework of in-kernel core (now POSIX-centric) • Support for native Linux NES SS2018 10
  • 13. Migration between schedulers • creating realtime task in application, over a normal Linux task • 2 threads for one task which share a lot of states • only one of them can run at the same time • Migration to RT: suspend Linux task, resume Cobalt thread • Migration to Linux (on syscall, fault/trap, signal): suspend Cobalt thread, resume Linux task • Every things that we do not handle in Xenomai will be directed to Linux NES SS2018 13
  • 14. Hardware abstraction layer I-pipe Core NES SS2018 14
  • 15. Issues of dual-kernel approach • Special API • Special tools and libraries • Microkernel needs to be ported for new HW and new Linux versions • Bad scaling on big platforms • Various number of not palatable patches • Changes to critical subsystems regularly cause regressions • Porting efforts consume core developer resources -Most work done by Philippe and Gilles so far -Time would be better spent on feature improvements... NES SS2018 15
  • 16. Xenomai application • Machine control systems, PLCs • Printing machines (manroland) • Printers / copying machines • Network switches (e.g. Ruggedcom) • Magnetic resonance tomographs (Siemens Healthcare) • OROCOS (OSS robotics framework) • Robotic research projects • … (many, many incognito applications) NES SS2018 16
  • 17. Preempt_RT • Founded 14 years ago by: Thomas Gleixner & Ingo Molnar • Huge community • In-kernel approach • Main idea: only code that, absolutely must be non-preemptible, is allowed to be non-preemptible • Most of the features already made it into the “mainline” • Interrupt handlers run in a kernel thread which has two advantages: - The kernel thread is interruptible - It shows up in a process list with a PID • First mainline integration 2006 NES SS2018 17
  • 18. Preempt_RT Goals • 100% Preemptible kernel - not possible yet, but let’s try regardless - Removal of interrupts and preemption disabling - Fast “worst case” time. • Quick reaction time - Bring latencies down to a minimum • Minimize non-Preemptible kernel code - at the meantime Minimize code changing amount NES SS2018 18
  • 21. Fully Preemptible kernel (the RT patch) • Preemption almost everywhere • Spinlocks turn into mutexes • No hard interrupt context • Preemptible critical section • Preemptible interrupt handlers • Preemptible “interrupt disable” code sequence • Priority inheritance • Deferred operation • Latency reduction NES SS2018 21
  • 22. Mutex • Critical sections are still protected without disabling preemption • A Mutex guarantees data integrity while extending the operation of the spinlock - we have priority inheritance - All locks are assumed to be preemptible - This design eliminates the possibility that an inefficient locking implementation in a driver can introduce un-detected latency into the system. - Only a small subset of locks stay unpreemptible which are manageable. NES SS2018 22
  • 23. Priority inversion • When a high priority task wants to run but it can not because a lower priority task is holding that lock • It is bad but we can not get rid of it, what we can get rid of is unbounded priority inversion NES SS2018 23
  • 26. local_irq_disable asmlinkage void do_entInt(unsigned long type, unsigned long vector, unsigned long la_ptr, struct pt_regs *regs) { struct pt_regs *old_regs; local_irq_disable(); switch (type) { case 0: #ifdef CONFIG_SMP NES SS2018 26 handle_ipi(regs); return; #else irq_err_count++; printk(KERN_CRIT "Interprocessor interrupt? "You must be kidding!n"); #endif break; 1 2
  • 27. Preempt_disable NES SS2018 27 • Local_irq_disable younger sibling • Also does not give a hint to what does it do! • Has the exact same problems of local_irq_disable • Preempt_enable_no_resched - only should be used within preempt_disable locations
  • 28. Why do we still need Co-kernel? Functional limitations of In-kernel • Emulation of RTOS scheduling behavior limited by Linux scheduler • Not all kernel+libc code paths used by In-kernel approaches are necessarily hard real-time under PREEMPT-RT • No detection of non-RT behavior of your application Performance limitations of In-kernel • Co-kernel is usually more light-weight on low-end platforms (limited caches vs. code path lengths) • PREEMPT-RT can have unwanted impact co-located non-RT workloads Xenomai adds value to Linux • it keeps the realtime stuff away from the complexities of Linux kernel • Co-kernel approach can be beneficial for low latencies and real-time application architecture NES SS2018 28
  • 29. Latency measurement on xenomai & preempt_RT • Made by Jan Altenberg from Linutronix GmbH • On two ARM Cortex A9 SOC platforms • IRQ test with 10KHz frequency with the latency box • 100% CPU load with “hackbench” • They did the test in usespace and kernelspace • 12-hour duration NES SS2018 29
  • 30. Hackbench • Starts n groups of 20 clients and 20 servers • Each client sends 100 messages to each server via a socket connection NES SS2018 30
  • 32. Xenomai latency userspace task NES SS2018 32
  • 33. PREEMPT_RT latency userspace task NES SS2018 33
  • 34. PREEMPT_RT latency userspace task (isolated CPU) NES SS2018 34
  • 36. Xenomai latency in kernelspace NES SS2018 36
  • 37. PREEMPT_RT latency in kernelspace NES SS2018 37
  • 38. PREEMPT_RT latency in kernelspace (isolated) NES SS2018 38
  • 39. PREEMPT_RT latency in kernelspace (using FIQ) NES SS2018 39
  • 40. Latency: Kernel - Comparison NES SS2018 40
  • 41. Test results • Which approach to choose? - If timing is vital, choose Xenomai, it separates the realtime interrupt handling from complexities of Linux kernel • You can go with PREEMPT_RT using FIQ • Xenomai kernelspace is the best for 100% hard performance • Xenomai userspace is slower than it’s kernelspace • Tests only can help you in the field of latency which is dependent on the hardware • No guarantee for results repeatation NES SS2018 41
  • 42. Conclusion • PREEMPT_RT is getting integrated in Linux mainline - Download here: https://www.kernel.org/ • PREEMPT_RT Increases Linux stability and quality • PREEMPT_RT is simple to use • Xenomai has it’s own advantages over PREEMPT_RT • Microkernels are hard to handle • For the most use cases the latency of the both approaches is almost the same • FIQ offers very fast latency but brings limitations NES SS2018 42