Fall 2013 SILICON VALLEY UNIVERSITY CONFIDENTIAL 1 Introduction to Embedded Systems Dr. Jerry Shiao, Silicon Valley University.

Slides:



Advertisements
Similar presentations
Copyright © 2000, Daniel W. Lewis. All Rights Reserved. CHAPTER 8 SCHEDULING.
Advertisements

Tutorial 3 - Linux Interrupt Handling -
Operating Systems Process Scheduling (Ch 3.2, )
CPU Scheduling Questions answered in this lecture: What is scheduling vs. allocation? What is preemptive vs. non-preemptive scheduling? What are FCFS,
Sogang University Advanced Operating Systems (Process Scheduling - Linux) Advanced Operating Systems (Process Scheduling - Linux) Sang Gue Oh, Ph.D. .
CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.
Architectural Support for Operating Systems. Announcements Most office hours are finalized Assignments up every Wednesday, due next week CS 415 section.
5: CPU-Scheduling1 Jerry Breecher OPERATING SYSTEMS SCHEDULING.
Wk 2 – Scheduling 1 CS502 Spring 2006 Scheduling The art and science of allocating the CPU and other resources to processes.
OS and the Computer System  Some OS programs exist permanently in the system area of the memory to monitor and control activities in the computer system.
Comparative Operating Systems Fall 2001 An Examination of Embedded Linux as a Real Time Operating System Mark Mahoney.
The Design of Robust and Efficient Microkernel ManRiX, The Design of Robust and Efficient Microkernel Presented by: Manish Regmi
1Chapter 05, Fall 2008 CPU Scheduling The CPU scheduler (sometimes called the dispatcher or short-term scheduler): Selects a process from the ready queue.
Performance Evaluation of Real-Time Operating Systems
Process Scheduling in Windows XP, Linux, and UNIX By Sarah G. Levinson CSC 4320.
Exception and Interrupt Handling
Introduction to Embedded Systems
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 5 Operating Systems.
OPERATING SYSTEMS CPU SCHEDULING.  Introduction to CPU scheduling Introduction to CPU scheduling  Dispatcher Dispatcher  Terms used in CPU scheduling.
Fair Resource Access & Allocation  OS Scheduling
1 Previous lecture review n Out of basic scheduling techniques none is a clear winner: u FCFS - simple but unfair u RR - more overhead than FCFS may not.
Linux and Real Time Real-time systems are characterized by deadlines. When a missed deadline results in inconvenience or a diminished customer experience,
Introduction to Embedded Systems Rabie A. Ramadan 6.
CS 153 Design of Operating Systems Spring 2015 Lecture 11: Scheduling & Deadlock.
Chapter 6 Scheduling. Basic concepts Goal is maximum utilization –what does this mean? –cpu pegged at 100% ?? Most programs are I/O bound Thus some other.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
CPU Scheduling CSCI 444/544 Operating Systems Fall 2008.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Mutual Exclusion.
Operating Systems CSE 411 Multi-processor Operating Systems Multi-processor Operating Systems Dec Lecture 30 Instructor: Bhuvan Urgaonkar.
Unit - VI. Linux and Real Time: Real Time Tasks Hard and Soft Real Time Tasks Linux Scheduling Latency Kernel Preemption Challenges in Kernel Preemption.
What Every Developer Should Know about the Kernel Dr. Michael L. Collard 1.
Scheduling Lecture 6. What is Scheduling? An O/S often has many pending tasks. –Threads, async callbacks, device input. The order may matter. –Policy,
CSE 451: Operating Systems Section 5 Midterm review.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
1 Review of Process Mechanisms. 2 Scheduling: Policy and Mechanism Scheduling policy answers the question: Which process/thread, among all those ready.
4300 Lines Added 1800 Lines Removed 1500 Lines Modified PER DAY DURING SUSE Lab.
Preemptive Context Switching
1 VxWorks 5.4 Group A3: Wafa’ Jaffal Kathryn Bean.
CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015.
Real Time System with MVL. © 2007 MontaVista Confidential | Overview of MontaVista Agenda Why Linux Real Time? Linux Kernel Scheduler Linux RT technology.
Windows CE Portable Modular Real-time Small footprint Embedded market.
Lecture 12 Page 1 CS 111 Online Using Devices and Their Drivers Practical use issues Achieving good performance in driver use.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 2: The Linux System Part 3.
CHAPTER 7 CONCURRENT SOFTWARE Copyright © 2000, Daniel W. Lewis. All Rights Reserved.
1.  System Characteristics  Features of Real-Time Systems  Implementing Real-Time Operating Systems  Real-Time CPU Scheduling  An Example: VxWorks5.x.
1 CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
Low Overhead Real-Time Computing General Purpose OS’s can be highly unpredictable Linux response times seen in the 100’s of milliseconds Work around this.
Chapter 3 RTOS Concepts And Definitions Department of Computer Science Hsu Hao Chen Professor Hsung-Pin Chang.
Where Testing Fails …. Problem Areas Stack Overflow Race Conditions Deadlock Timing Reentrancy.
Interrupts and Interrupt Handling David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Scheduling.
Copyright © 2010 K Computing Use of RT-Preempt Kevin Dankwardt, Ph.D. K Computing
Inside The RT Patch Steven Rostedt (Red Hat) Darren V Hart (IBM) Talk: Benchmarks :
CPU Scheduling Scheduling processes (or kernel-level threads) onto the cpu is one of the most important OS functions. The cpu is an expensive resource.
REAL-TIME OPERATING SYSTEMS
Interfacing with Hardware
Process Management Process Concept Why only the global variables?
Topics Covered What is Real Time Operating System (RTOS)
Realtime Linux Clark Williams Tech Lead
Chapter 6: CPU Scheduling
Real-Time Operating Systems
Chapter 2: The Linux System Part 3
CSCI1600: Embedded and Real Time Software
CPU SCHEDULING.
CPU scheduling decisions may take place when a process:
Top Half / Bottom Half Processing
EE 472 – Embedded Systems Dr. Shwetak Patel.
CSCI1600: Embedded and Real Time Software
Linux Scheduling CSE 2431: Introduction to Operating Systems
Presentation transcript:

Fall 2013 SILICON VALLEY UNIVERSITY CONFIDENTIAL 1 Introduction to Embedded Systems Dr. Jerry Shiao, Silicon Valley University

SILICON VALLEY UNIVERSITY CONFIDENTIAL 2 Spring 2014 Section 14 Real-Time Patch Linux 2.6 Real-Time Modifications  Linux Community wants to convert the Linux Kernel into true Real-Time Operation System (RTOS) without a microkernel.  Linux RTOS Needs: Interrupt Service Routines must NOT unconditionally preempt any process running on the CPU. Critical Sections as needed by processes. Unbounded Priority Inversion not allowed.  Ingo Molnar, approached the Linux RTOS problem by changing the Linux system with Real-Time features that would improve user’s experience. High-Resolution timers. Kernel lock validation. Generic interrupts for all architectures. Robust futexes. Priority Inheritance.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 3 Spring 2014 Section 14 Real-Time Patch Linux 2.6 Real-Time Modifications  Interrupt as Threads  Interrupt Service Routine (ISR) has highest priority events in the Operating System and only another ISR can interrupt an ISR, but only if interrupts are enable.  ISR pushes work to Kernel Thread, Tasklet, or Softirq. Kernel Thread: Work Queue, queues up work from ISR that will be executed by worker kernel thread, keventd. Works in a FIFO order. Softirq: Service routine performed after ISR returns and before interrupted process is resumed. Kernel Thread, ksoftirqd, executes queued softirqs.  Same softirq run simultaneously on different CPUs.  Reentrant: Need to use locks to protect against concurrent accesses. Tasklet: Similar to softirq, performed after ISR returns and before resuming interrupted process.  Same tasklet cannot run simultaneously on different CPUs.  Not reentrant.  Implemented as a softirq

SILICON VALLEY UNIVERSITY CONFIDENTIAL 4 Spring 2014 Section 14 Real-Time Patch Linux 2.6 Real-Time Modifications  Interrupt Signal Will Always Preempts CPU and executes the ISR.  Interrupt Inversion: ISR takes time away from higher priority process to handle lower priority process.  Lower Interrupt Latency and Interrupt Inversion: Transform all ISRs, softirqs, and tasklets into Kernel Threads.  Converts Interrupt Handlers into Kernel Threads. Masking of the Interrupt Line. Wake Interrupt Service Thread (one for each type of interrupt). Interrupt Service Thread registered by the Device Driver.  Original Process Higher Priority, than Interrupt Service Thread will not Preempt.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 5 Spring 2014 Section 14 Real-Time Patch Linux 2.6 Real-Time Modifications Interrupt Inversion: Interrupt Service Routine takes time away from a high priority process in order to perform work that is of lower priority. The ISR is lower priority than the process that is currently running. Interrupt Latency: Time before the high priority process gets the CPU back.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 6 Spring 2014 Section 14 Real-Time Patch Linux 2.6 Real-Time Modifications Real Time Patch: ISR wakes up a Kernel Thread that will run the function registered by the Device Driver. Interrupt Latency: Shortens the time of Interrupt Inversion to a bare minimum.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 7 Spring 2014 Section 14 Real-Time Patch Linux 2.6 Real-Time Modifications Real Time Patch: The Threads that are created to service the interrupts are named “IRQ_n”, where “n” is the number of the Interrupt Vector. Interrupt Thread for Interrupt Vector 14, the IDE disk driver.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 8 Spring 2014 Section 14 Real-Time Patch Linux 2.6 Real-Time Modifications ps command shows the pid = 1722 has priority set to 80. chrt command sets the Real- Time scheduling attributes of the process ( pid ). -p: Existing pid = 1722, set the priority = 80. -f: Set scheduling policy to SCHED_FIFO.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 9 Spring 2014 Section 14 Real-Time Patch Linux 2.6 Real-Time Modifications  Interrupts and CPU Affinities. Each thread kept on the CPU where the thread started execution in order to prevent expensive cache flushes.  IRQ Thread determined by CPU Affinity of Interrupt. # cat /proc/interrupts | grep ide0 14: IO-APIC-edge ide0 # ps ax | grep IRQ ? S< 0:00 [IRQ-14] # cat /proc/irq/14/smp_affinity 1 # echo 2 > /proc/irq/14/smp_affinity # cat /proc/irq/14/smp_affinity 2 Get the Interrupt Vector for the IDE 0 Controller ( 14 ). Get the Process ID of ISR Thread 14. Get the CPU Affinity of IRQ Interrupt Vector 14 ( CPU 0 ). Set the CPU Affinity of IRQ Interrupt Vector 14 ( CPU 1 ).

SILICON VALLEY UNIVERSITY CONFIDENTIAL 10 Spring 2014 Section 14 Real-Time Patch Linux 2.6 Real-Time Modifications  IRQ Thread determined by CPU Affinity of Interrupt. # taskset -p 790 pid 790's current affinity mask: 2 # echo 1 > /proc/irq/14/smp_affinity # taskset -p 790 pid 790's current affinity mask: 2 # ls -lR / > /dev/null # taskset -p 790 pid 790's current affinity mask: 1 Get IRQ Thread’s CPU Affinity. The IRQ Thread’s CPU Affinity does not change until the interrupt is triggered. Trigger some IDE interrupts. After the interrupts, the IRQ Thread’s Affinity follows the IRQ Affinity. Set the CPU Affinity of IRQ Interrupt Vector 14 ( CPU 0 ).

SILICON VALLEY UNIVERSITY CONFIDENTIAL 11 Spring 2014 Section 14 Real-Time Patch Linux 2.6 Real-Time Modifications Softirqs As Threads. Softirq runs with interrupts enabled. Possible Preempt higher priority Kernel Threads. Make ALL softirqs run under ksoftirqd Thread.  Problem: ALL softirqs grouped into one priority (the ksoftirqd Thread).  Solution: Softirq Thread is created for each softirq routine. Softirq Thread bound to a CPU. Softirq Thread has name: softirq-name/n “n” is the CPU where Softirq Thread is set to run.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 12 Spring 2014 Section 14 Real-Time Patch Linux 2.6 Real-Time Modifications Softirqs As Threads. $ ps -e -o pid,rtprio,comm | grep sirq 5 50 sirq-high/ sirq-timer/ sirq-net-tx/ 8 50 sirq-net-rx/ 9 50 sirq-block/ sirq-tasklet sirq-sched/ sirq-hrtimer sirq-rcu/ sirq-high/ sirq-timer/ sirq-net-tx/ sirq-net-rx/ sirq-block/ sirq-tasklet sirq-sched/ sirq-hrtimer sirq-rcu/1 Softirq Thread has name: softirq-name/n “n” is the CPU where Softirq Thread is set to run. Priority of the softirqs are set at 50 by default.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 13 Spring 2014 Section 14 Real-Time Patch Linux 2.6 Real-Time Modifications Softirq Timer Thread (softirq-hrtimer) Control Timing Events:  Crucial to be executed on time. timer_create POSIX System Call:  Registers function to be called by hrtimer subsystem. High-priority process MUST be lower priority than softirq-hrtimer thread.  If not, high-priority process will NOT release CPU and softirq-hrtimer thread will starve. Dynamic softirq-hrtimer thread: Automatically change its priority to the high-priority process that requested the timer.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 14 Spring 2014 Section 14 Real-Time Patch Linux 2.6 Real-Time Modifications  Priority Inheritance: Low-priority task has priority raised until completes critical section (releases shared resource). Nested resource locks can lead to deadlock.  Avoid deadlock by allowing each task to own one shared resource.  Do not allow nested locks. Overhead raising priority and then lowering priority. Task M Task L Normal Execution Critical Section Execution -Task M request resource. -Task L priority raised. Executes critical section. -Task L Completes critical section. Priority lowered. -Task M receives resource. Executes critical section.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 15 Spring 2014 Section 14 Real-Time Patch Linux 2.6 Real-Time Modifications Linux Configuration  make menuconfig  Preemption Mode  No Forced Preemption (Server)  Linux Kernel runs in 2.4 Kernel Mode. No Preemption of the Kernel when CPU is in Kernel Mode. High-Priority Process MUST wait until current process context switch back to User Mode or blocks on I/O.  Low Overhead: Low Context Switching Less scheduling, more time for process to run on CPU. Cache is valid. Translation Lookaside Buffer (TLB) is valid. Large batch processes, need throughput, and run serially.  Disadvantages: Low reaction time. Negative affect on application requiring low latencies and user interaction.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 16 Spring 2014 Section 14 Real-Time Patch Linux 2.6 Real-Time Modifications Linux Configuration  Kernel code has points of voluntary preemption, where preemption is safe.  make menuconfig  Preemption Mode  Voluntary Kernel Preemption Kernel cannot call schedule( ) when interrupts are disabled. “might_sleep” function checks for interrupts are disabled or spin lock is held. Place “might_sleep” function in Kernel process handling system call. The Kernel process will call schedule( ) when condition is valid and allow higher priority process to get the CPU.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 17 Spring 2014 Section 14 Real-Time Patch Linux 2.6 Real-Time Modifications  Linux originally designed around fairness, sharing resources among its uses and to perform under sustained load conditions. General purpose complexity too unpredictable for real-time.  Preemption Linux 2.6 system call was preemptable. A process forced to release CPU.  Real Time Scheduler Linux 2.6 scheduler determined time slice for each process and which process to run based on runqueue per priority level. Active and Expired priority arrays.  High Resolution POSIX Timers. Timer hardware removed timer update dependency on Jiffies.  Minimize execution of interrupt critical sections (interrupt latency).

SILICON VALLEY UNIVERSITY CONFIDENTIAL Spring 2014 Section 14 Real-Time Patch Real-Time Patch To Native Linux Kernel  Linux Kernel in Real-Time Environment: Preemption Improvements.  Reduce time in non-preemptible code (interrupt context) to minimize interrupt latency and scheduling latency.  Low latency patches in Kernel, add points where Kernel thread relinquishes non-preemption. Unbounded Priority Inversion avoided Normal Execution Critical Section Execution Unbounded Priority Inversion Task H Task M Task L Priority

SILICON VALLEY UNIVERSITY CONFIDENTIAL 19 Spring 2014 Section 14 Real-Time Patch Real-Time Patch To Native Linux Kernel  Priority Ceiling: Shared resource has predefined priority ceiling. Task acquires shared resource, task priority temporarily raised to priority ceiling. Prevents deadlocks by stopping nested locks. Static analysis to determine priority ceiling of each shared resource. Every task must be known. Task H Task M Task L Normal Execution Critical Section Execution -Task L priority raised to priority ceiling. -Executes critical section. -Task H request resource. Priority raised to priority ceiling. -Executes critical section.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 20 Spring 2014 Section 14 Real-Time Patch Real-Time Patch To Native Linux Kernel  Linux Kernel in Real-Time Environment: Handle IRQs as Threads.  Lowers latency caused by softirqs and tasklets.  Softirqs preempts all threads, including kernel.  Default priority IRQ threads (PID = IRQ_n, n is interrupt vector) is 50.  chrt utility used to modify the priority of the ISR thread.  Interrupts can be prioritized, even though hardware does not support prioritized interrupts.  User process can be prioritized higher than IRQ thread.  CPU affinity of IRQ thread based on CPU affinity of the interrupt. Prevents expensive cache flushes.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 21 Spring 2014 Section 14 Real-Time Patch Real-Time Patch To Native Linux Kernel  Linux Kernel in Real-Time Environment: Real-Time Patch has infrastructure for most hard real-time.  Size of the code is too large and general purpose design makes it difficult to meet all RT Patch needs. Only necessary drivers are loaded (bulk of Linux are drivers).  Drivers must be audited to not disable interrupts for long periods. Kernel configuration options must be optimized. Only enable options that are needed.