Download presentation
Presentation is loading. Please wait.
Published byHarry Simon Modified over 9 years ago
1
Real Time System with MVL
2
© 2007 MontaVista Confidential | Overview of MontaVista Agenda Why Linux Real Time? Linux Kernel Scheduler Linux RT technology Making Real-Time systems MontaVista’s Solution for Real Time
3
© 2007 MontaVista Confidential | Overview of MontaVista Why Linux Real Time? Linux is good because It is open source It is robust It is feature rich And much more… However Real Time is also needed for some applications Requiring deterministic response time
4
© 2007 MontaVista Confidential | Overview of MontaVista Things to know H/W DelayVectoringDispatchISR / Driver Interrupt Latency Off-timeKernelSchedulerTaskInterrupt LatencyContext Switch Preemption or Task Response Latency
5
© 2007 MontaVista Confidential | Overview of MontaVista Linux Kernel Scheduler O(1) Scheduler Deterministic scheduler overhead regardless of # of tasks Supports task priority: 0 ~ 99 default Supports scheduling policy SCHED_OTHER, SCHED_RR and SCHED_FIFO The default scheduler for Linux 2.6.x kernels Reduces scheduling latency Completely Fair Scheduler (CFS)? It is not for Real Time applications Good for server and desktop
6
© 2007 MontaVista Confidential | Overview of MontaVista Priority based scheduling 99 98 … 50 … 1 0(-19) … 39(20) Real-time processes Normal processes SCHED_OTHER SCHED_FIFO SCHED_RR Dynamic priority Static priority SCHED_FIFO * Nice value is not a static priority
7
© 2007 MontaVista Confidential | Overview of MontaVista Preemptive Kernel Introduced by Rover Love (former MontaVista employee) Utilizes spin_lock / spin_unlock to protect kernel critical sections Supports kernel preemption Reduces preemption latency Preemption point At the end of interrupt handler At the end of system call At the end of spin_unlock But not in between spin_lock and spin_unlock
8
© 2007 MontaVista Confidential | Overview of MontaVista Voluntary Preemption By Ingor Molnar (RedHat) Adds more ‘explicit preemption points’ Minimize the maximum latency of rescheduling Reduces preemption latency might_sleep() is the key You can find many of this calls in the kernel source Normally in the loop code Valid only when CONFIG_PREEMPT_VOLUNTARY is set
9
© 2007 MontaVista Confidential | Overview of MontaVista Mutual Exclusion (MUTEX) Priority Inheritance Mutex – Kernel Converts spin_lock to priority inheritance mutex When CONFIG_PREEMPT_RT is set Transparent to kernel code: syntax is still same Enables preemption between spin_lock and spin_unlock New raw_spinlock_t Should be used where mutex can not be used Syntax is still same: spin_lock and spin_unlock Spin_lock appropriately handles it depending on the type Fast User Mutex (FUTEX) – Applications Utilizes kernel priority inheritance mutex No kernel call when there is no contention
10
© 2007 MontaVista Confidential | Overview of MontaVista Priority Inheritance Mutex Medium Prio Task (M) Low Prio Task (L) Kernel (scheduler) Medium Prio Task x High Priority Task (H) Locks Mutex Tries to get Mutex Unlocks Mutex Gets Mutex
11
© 2007 MontaVista Confidential | Overview of MontaVista Threaded Interrupt Handler Interupt handler is called by a kernel interrupt handler thread The interrupt handler thread is assigned a task priority Minimizes interrupt latency thus preemption latency as well Does not content with RT tasks Flexible system design Can assign a higher priority on an important task Default for PREEMPT_RT and optional for others IRQF_NODELAY is needed For timers and etc. Interrupt handler can not make use of spin_lock
12
© 2007 MontaVista Confidential | Overview of MontaVista Threaded Interrupt Handler (2) IRQ Thread H/W Interrupt Kernel (scheduler) Running Task (L) High Priority Task (H) Minimized Latency IRQ Thread wake-up
13
© 2007 MontaVista Confidential | Overview of MontaVista Voluntary Preemption Preemptible Kernel Preemption mode comparison PreemptibleNon-Preemptible No Preemption Realtime Preemption
14
© 2007 MontaVista Confidential | Overview of MontaVista Improved latency
15
© 2007 MontaVista Confidential | Overview of MontaVista System Design Theory You should only have one highest priority process* IO-bound control algorithms are IO-bound: they start and end with IO Finite time running guarantee on your process Definitely NO infinite loops! sum(total running time + 2 x scheduler run) < latency req. Scheduler Highest Priority Other tasks
16
© 2007 MontaVista Confidential | Overview of MontaVista Mistake: priority design Be careful! Ksoftirqd manages: High-res timers NAPI (network!) Some blockdevice stuff IRQs might have wrong prio Does your RT apps need something from (soft)IRQs? 0 99 regular apps threaded IRQs ksoftirqd watchdog thread migration Your RT app here??? non-RT app here???
17
© 2007 MontaVista Confidential | Overview of MontaVista 17 Mistake: “running at prio 99 froze my system” testrt.c: #include int main(void) { set_my_priority_to_highest(); while (true) {;} return 0; } or: while (someVolatile != -1) { sched_yield(); }
18
© 2007 MontaVista Confidential | Overview of MontaVista 18 Throughput High responsiveness Real-Time Response vs. Throughput Efficiency and Responsiveness are Inversely Related Overhead for Real-Time Preemption Mutex Operations more complex than Spinlock Operations Priority Inheritance on Mutex increases Task Switching Priority Inheritance increases Worst-Case Execution Time Design flexibility allows much better worst case scenarios Real-time tasks are designed to use kernel resources in managed ways then delays can be eliminated or reduced
19
© 2007 MontaVista Confidential | Overview of MontaVista MontaVista Linux 5.0 Real-Time Kernel features for Real-Time All previous features plus more… Kernel 2.6.18 (+2.6.19 & 20 backports) Real-Time for Linux native applications Default Thread model : NPTL Priority Queueing for Mutex/Semaphore Priority Inheritance Mutex Robust Mutex
20
Questions and Answers
21
Thank You
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.