Copyright © 2001 Stephen A. Edwards All rights reserved Real-Time Operating Systems Prof. Stephen A. Edwards.

Slides:



Advertisements
Similar presentations
Introduction to Embedded Systems Resource Management - III Lecture 19.
Advertisements

Copyright © 2000, Daniel W. Lewis. All Rights Reserved. CHAPTER 8 SCHEDULING.
CPU Scheduling Questions answered in this lecture: What is scheduling vs. allocation? What is preemptive vs. non-preemptive scheduling? What are FCFS,
Task Allocation and Scheduling n Problem: How to assign tasks to processors and to schedule them in such a way that deadlines are met n Our initial focus:
Real-Time Kernels and Operating Systems Basic Issue - Purchase commercial “off-the- shelf” system or custom build one Basic Functions –Task scheduling.
CS444/CS544 Operating Systems Scheduling 1/31/2007 Prof. Searleman
Project 2 – solution code
CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.
Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.
5: CPU-Scheduling1 Jerry Breecher OPERATING SYSTEMS SCHEDULING.
Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the RTSJ  Memory Management.
Wk 2 – Scheduling 1 CS502 Spring 2006 Scheduling The art and science of allocating the CPU and other resources to processes.
By Group: Ghassan Abdo Rayyashi Anas to’meh Supervised by Dr. Lo’ai Tawalbeh.
Spring 2002Real-Time Systems (Shin) Rate Monotonic Analysis Assumptions – A1. No nonpreemptible parts in a task, and negligible preemption cost –
Java How to Program, 9/e CET 3640 Professor: Dr. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Advanced Embedded Systems Design Pre-emptive scheduler BAE 5030 Fall 2004 Roshani Jayasekara Biosystems and Agricultural Engineering Oklahoma State University.
 Scheduling  Linux Scheduling  Linux Scheduling Policy  Classification Of Processes In Linux  Linux Scheduling Classes  Process States In Linux.
Chapter 6: CPU Scheduling
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 5 Operating Systems.
Chapter 4 Processor Management
OPERATING SYSTEMS CPU SCHEDULING.  Introduction to CPU scheduling Introduction to CPU scheduling  Dispatcher Dispatcher  Terms used in CPU scheduling.
Advanced Operating Systems CIS 720 Lecture 1. Instructor Dr. Gurdip Singh – 234 Nichols Hall –
Chapter 6 CPU SCHEDULING.
MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)
1 Computer System Overview Chapter 1. 2 n An Operating System makes the computing power available to users by controlling the hardware n Let us review.
Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.
Scheduling policies for real- time embedded systems.
Real-Time Systems Mark Stanovich. Introduction System with timing constraints (e.g., deadlines) What makes a real-time system different? – Meeting timing.
CPU Scheduling CSCI 444/544 Operating Systems Fall 2008.
Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.
Real-Time Scheduling CS 3204 – Operating Systems Lecture 20 3/3/2006 Shahrooz Feizabadi.
What Every Developer Should Know about the Kernel Dr. Michael L. Collard 1.
CompSci 143A1 5. Process and thread scheduling 5.1 Organization of Schedulers – Embedded and Autonomous Schedulers – Priority Scheduling 5.2 Scheduling.
Lecture 7: Scheduling preemptive/non-preemptive scheduler CPU bursts
Chapter 5: Process Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Basic Concepts Maximum CPU utilization can be obtained.
RTOS task scheduling models
Cpr E 308 Spring 2005 Process Scheduling Basic Question: Which process goes next? Personal Computers –Few processes, interactive, low response time Batch.
Process Program (Passive Entity) is a sequence of instructions, written to perform a specified task on a computer. A computer requires programs to function,
CSE 522 Real-Time Scheduling (2)
Real-Time Scheduling CS 3204 – Operating Systems Lecture 13 10/3/2006 Shahrooz Feizabadi.
1 Real-Time Scheduling. 2Today Operating System task scheduling –Traditional (non-real-time) scheduling –Real-time scheduling.
CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015.
Introduction to Embedded Systems Rabie A. Ramadan 5.
CSCI1600: Embedded and Real Time Software Lecture 23: Real Time Scheduling I Steven Reiss, Fall 2015.
CS Spring 2009 CS 414 – Multimedia Systems Design Lecture 31 – Process Management (Part 1) Klara Nahrstedt Spring 2009.
Lecture Topics: 11/15 CPU scheduling: –Scheduling goals and algorithms.
CS333 Intro to Operating Systems Jonathan Walpole.
For a good summary, visit:
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 2: The Linux System Part 3.
Embedded Computer - Definition When a microcomputer is part of a larger product, it is said to be an embedded computer. The embedded computer retrieves.
1.  System Characteristics  Features of Real-Time Systems  Implementing Real-Time Operating Systems  Real-Time CPU Scheduling  An Example: VxWorks5.x.
Undergraduate course on Real-time Systems Linköping University TDDD07 Real-time Systems Lecture 2: Scheduling II Simin Nadjm-Tehrani Real-time Systems.
Real Time Operating Systems Lecture 4 1MHA,2015,AAiT.
Unit - I Real Time Operating System. Content : Operating System Concepts Real-Time Tasks Real-Time Systems Types of Real-Time Tasks Real-Time Operating.
Chapter 3 RTOS Concepts And Definitions Department of Computer Science Hsu Hao Chen Professor Hsung-Pin Chang.
Operating Systems Scheduling. Scheduling Short term scheduler (CPU Scheduler) –Whenever the CPU becomes idle, a process must be selected for execution.
Chapter 4 CPU Scheduling. 2 Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling Algorithm Evaluation.
Lecturer 5: Process Scheduling Process Scheduling  Criteria & Objectives Types of Scheduling  Long term  Medium term  Short term CPU Scheduling Algorithms.
Scheduling.
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.
EMERALDS Landon Cox March 22, 2017.
EEE 6494 Embedded Systems Design
Chapter 8 – Processor Scheduling
Chapter 2.2 : Process Scheduling
Chapter 6: CPU Scheduling
CPU SCHEDULING.
Processes and operating systems
Real-Time Process Scheduling Concepts, Design and Implementations
Real-Time Process Scheduling Concepts, Design and Implementations
Real-Time Operating Systems
Presentation transcript:

Copyright © 2001 Stephen A. Edwards All rights reserved Real-Time Operating Systems Prof. Stephen A. Edwards

Copyright © 2001 Stephen A. Edwards All rights reserved What’s an Operating System?  Provides environment for executing programs  Process abstraction for multitasking/concurrency Scheduling  Hardware abstraction layer (device drivers)  Filesystems  Communication  We will focus on concurrent, real-time issues

Copyright © 2001 Stephen A. Edwards All rights reserved Do I Need One?  Not always  Simplest approach: cyclic executive loop do part of task 1 do part of task 2 do part of task 3 end loop

Copyright © 2001 Stephen A. Edwards All rights reserved Cyclic Executive  Advantages Simple implementation Low overhead Very predictable  Disadvantages Can’t handle sporadic events Everything must operate in lockstep Code must be scheduled manually

Copyright © 2001 Stephen A. Edwards All rights reserved Interrupts  Some events can’t wait for next loop iteration Communication channels Transient events  A solution: Cyclic executive plus interrupt routines  Interrupt: environmental event that demands attention Example: “byte arrived” interrupt on serial channel  Interrupt routine: piece of code executed in response to an interrupt

Copyright © 2001 Stephen A. Edwards All rights reserved Handling an Interrupt 1. Normal program execution 2. Interrupt occurs 3. Processor state saved 4. Interrupt routine runs 5. Interrupt routine terminates 6. Processor state restored 7. Normal program execution resumes

Copyright © 2001 Stephen A. Edwards All rights reserved Interrupt Service Routines  Most interrupt routines:  Copy peripheral data into a buffer  Indicate to other code that data has arrived  Acknowledge the interrupt (tell hardware)  Longer reaction to interrupt performed outside interrupt routine  E.g., causes a process to start or resume running

Copyright © 2001 Stephen A. Edwards All rights reserved Cyclic Executive Plus Interrupts  Works fine for many signal processing applications  has direct hardware support for this style  Insanely cheap, predictable interrupt handler: When interrupt occurs, execute a single user-specified instruction This typically copies peripheral data into a circular buffer No context switch, no environment save, no delay

Copyright © 2001 Stephen A. Edwards All rights reserved Drawbacks of CE + Interrupts  Main loop still running in lockstep  Programmer responsible for scheduling  Scheduling static  Sporadic events handled slowly

Copyright © 2001 Stephen A. Edwards All rights reserved Cooperative Multitasking  A cheap alternative  Non-preemptive  Processes responsible for relinquishing control  Examples: Original Windows, Macintosh  A process had to periodically call get_next_event() to let other processes proceed  Drawbacks: Programmer had to ensure this was called frequently An errant program would lock up the whole system  Alternative: preemptive multitasking

Copyright © 2001 Stephen A. Edwards All rights reserved Concurrency Provided by OS  Basic philosophy:  Scheduling and function usually orthogonal  Changing the algorithm would require a change in scheduling  First, a little history Let the operating system handle scheduling, and let the programmer handle function

Copyright © 2001 Stephen A. Edwards All rights reserved Batch Operating Systems  Original computers ran in batch mode: Submit job & its input Job runs to completion Collect output Submit next job  Processor cycles very expensive at the time  Jobs involved reading, writing data to/from tapes  Cycles were being spent waiting for the tape!

Copyright © 2001 Stephen A. Edwards All rights reserved Timesharing Operating Systems  Solution Store multiple batch jobs in memory at once When one is waiting for the tape, run the other one  Basic idea of timesharing systems  Fairness primary goal of timesharing schedulers Let no one process consume all the resources Make sure every process gets “equal” running time

Copyright © 2001 Stephen A. Edwards All rights reserved Real-Time Is Not Fair  Main goal of an RTOS scheduler: meeting deadlines  If you have five homework assignments and only one is due in an hour, you work on that one  Fairness does not help you meet deadlines

Copyright © 2001 Stephen A. Edwards All rights reserved Priority-based Scheduling  Typical RTOS based on fixed-priority preemptive scheduler  Assign each process a priority  At any time, scheduler runs highest priority process ready to run  Process runs to completion unless preempted

Copyright © 2001 Stephen A. Edwards All rights reserved Typical RTOS Task Model  Each task a triplet: (execution time, period, deadline)  Usually, deadline = period  Can be initiated any time during the period Execution time Period Deadline Time Initiation

Copyright © 2001 Stephen A. Edwards All rights reserved Example: Fly-by-wire Avionics  Hard real-time system with multirate behavior INU 1kHz GPS 20 Hz Air data 1 kHz Joystick 500 Hz Pitch control 500 Hz Lateral Control 250 Hz Throttle Control 250 Hz Aileron 1 1 kHz Aileron 2 1 kHz Elevator 1 kHz Rudder 1 kHz gyros, accel. GPS Sensor Stick Aileron Elevator Rudder Sensors Signal Conditioning Control lawsActuating Actuators

Copyright © 2001 Stephen A. Edwards All rights reserved Priority-based Preemptive Scheduling  Always run the highest-priority runnable process 1 2 3

Copyright © 2001 Stephen A. Edwards All rights reserved Priority-Based Preempting Scheduling  Multiple processes at the same priority level?  A few solutions Simply prohibit: Each process has unique priority Time-slice processes at the same priority  Extra context-switch overhead  No starvation dangers at that level Processes at the same priority never preempt the other  More efficient  Still meets deadlines if possible

Copyright © 2001 Stephen A. Edwards All rights reserved Rate-Monotonic Scheduling  Common way to assign priorities  Result from Liu & Layland, 1973 (JACM)  Simple to understand and implement:  E.g., Processes with shorter period given higher priority PeriodPriority 101(highest) (lowest)

Copyright © 2001 Stephen A. Edwards All rights reserved Key RMS Result  Rate-monotonic scheduling is optimal:  Task sets do not always have a schedule  Simple example: P1 = (10, 20, 20) P2 = (5, 9, 9) Requires more than 100% processor utilization If there is fixed-priority schedule that meets all deadlines, then RMS will produce a feasible schedule

Copyright © 2001 Stephen A. Edwards All rights reserved RMS Missing a Deadline  p1 = (10,20,20) p2 = (15,30,30) utilization is 100% 1 2 P2 misses first deadline Would have met the deadline if p2 = (10,30,30), utilization reduced 83%

Copyright © 2001 Stephen A. Edwards All rights reserved When Is There an RMS Schedule?  Key metric is processor utilization: sum of compute time divided by period for each process: U =  c i / p i  No schedule can possibly exist if U > 1 No processor can be running 110% of the time  Fundamental result: RMS schedule always exists if U < n (2 1/n – 1) Proof based on case analysis (P1 finishes before P2)

Copyright © 2001 Stephen A. Edwards All rights reserved When Is There an RMS Schedule? nBound for U 1100%Trivial: one process 283%Two process case 378% 476%  69%Asymptotic bound

Copyright © 2001 Stephen A. Edwards All rights reserved When Is There an RMS Schedule?  Asymptotic result:  Converse is not true. Instead: If the required processor utilization is under 69%, RMS will give a valid schedule If the required processor utilization is over 69%, RMS might still give a valid schedule, but there is no guarantee

Copyright © 2001 Stephen A. Edwards All rights reserved EDF Scheduling  RMS assumes fixed priorities  Can you do better with dynamically-chosen priorities?  Earliest deadline first: Processes with soonest deadline given highest priority

Copyright © 2001 Stephen A. Edwards All rights reserved EDF Meeting a Deadline  p1 = (10,20,20) p2 = (15,30,30) utilization is 100% 1 2 P2 takes priority because its deadline is sooner

Copyright © 2001 Stephen A. Edwards All rights reserved Key EDF Result  Earliest deadline first scheduling is optimal:  Earliest deadline first scheduling is efficient: If a dynamic priority schedule exists, EDF will produce a feasible schedule A dynamic priority schedule exists if and only if utilization is no greater than 100%

Copyright © 2001 Stephen A. Edwards All rights reserved Static Scheduling More Prevalent  RMA only guarantees feasibility at 69% utilization, EDF guarantees it at 100%  EDF is complicated enough to have unacceptable overhead  More complicated than RMA: harder to analyze  Less predictable: can’t guarantee which process runs when

Copyright © 2001 Stephen A. Edwards All rights reserved Priority Inversion  RMS and EDF assume no process interaction  Often a gross oversimplification  Consider the following scenario: 1 2 Process 2 begins running Process 2 acquires lock on resource Process 1 preempts Process 2 Process 1 tries to acquire lock for resource

Copyright © 2001 Stephen A. Edwards All rights reserved Priority Inversion  Lower-priority process effectively blocks a higher- priority one  Lower-priority process’s ownership of lock prevents higher-priority process from running  Nasty: makes high-priority process runtime unpredictable

Copyright © 2001 Stephen A. Edwards All rights reserved Nastier Example  Higher priority process blocked indefinitely 1 Process 3 begins running Process 3 acquires lock on resource Process 2 preempts Process 3 Process 1 tries to acquire lock and is blocked 3 2 Process 1 preempts Process 2 Process 2 delays process 3’s release of lock

Copyright © 2001 Stephen A. Edwards All rights reserved Priority Inheritance  Solution to priority inversion  Temporarily increase process’s priority when it acquires a lock  Level to increase: highest priority of any process that might want to acquire same lock I.e., high enough to prevent it from being preempted  Danger: Low-priority process acquires lock, gets high priority and hogs the processor So much for RMS

Copyright © 2001 Stephen A. Edwards All rights reserved Priority Inheritance  Basic rule: low-priority processes should acquire high-priority locks only briefly  An example of why concurrent systems are so hard to analyze  RMS gives a strong result  No equivalent result when locks and priority inheritance is used

Copyright © 2001 Stephen A. Edwards All rights reserved Summary  Cyclic executive Way to avoid an RTOS Adding interrupts helps somewhat  Interrupt handlers Gather data, acknowledge interrupt as quickly as possible  Cooperative multitasking But programs don’t like to cooperate

Copyright © 2001 Stephen A. Edwards All rights reserved Summary  Preemptive Priority-Based Multitasking Deadlines, not fairness, the goal of RTOSes  Rate-monotonic analysis Shorter periods get higher priorities Guaranteed at 69% utilization, may work higher  Earliest deadline first scheduling Dynamic priority scheme Optimal, guaranteed when utilization 100% or less

Copyright © 2001 Stephen A. Edwards All rights reserved Summary  Priority Inversion Low-priority process acquires lock, blocks higher- priority process Priority inheritance temporarily raises process priority Difficult to analyze