TDDB47 Real Time Systems Lecture 1: Introduction & cyclic scheduling Real-time systems Mikael Asplund Real-Time Systems Laboratory Department of Computer and Information Science Linköping University, Sweden The lecture notes are partly based on lecture notes by Calin Curescu, Simin NadjmTehrani, Jörgen Hansson, Anders Törne. They also loosely follow Burns’ and Welling book “Real-Time Systems and Programming Languages”. These lecture notes should only be used for internal teaching purposes at Linköping University. Lecture 1: Introduction & cyclic scheduling Mikael Asplund 42 pages Lecture 1: Introduction & cyclic scheduling Mikael Asplund What is a real-time system? 2 of 42 Computer systems • Correctness depends on time! • Predictability • Usually a component in a larger engineering system - embedded • Usually a critical system – Safety-critical – Dependable – Fault-tolerant Lecture 1: Introduction & cyclic scheduling Mikael Asplund 3 of 42 Lecture 1: Introduction & cyclic scheduling Mikael Asplund 4 of 42 Really good example Why should you care? • For the fun... • For the money • To save the world Lecture 1: Introduction & cyclic scheduling Mikael Asplund 5 of 42 Lecture 1: Introduction & cyclic scheduling Mikael Asplund 6 of 42 Course Information • Website: www.ida.liu.se/~TDDB47 • Examiner Course – Mikael Asplund, mikas@ida.liu.se • Course assistant – Jonas Elmqvist, jonel@ida.liu.se • Course secretary – Gunilla Mellheden, gunme@ida.liu.se Lecture 1: Introduction & cyclic scheduling Mikael Asplund 7 of 42 Lecture 1: Introduction & cyclic scheduling Mikael Asplund 8 of 42 Aim and Prerequisites • Aims • Course Book – To understand the methods and structuring mechanisms involved in the design and implementation of real-time systems. – A. Burns and A. Wellings: Real-Time Systems and Programming Languages, Addison-Wesley, – NOT covered/followed chapter by chapter • Prerequisites • Additional material posted on the web – Process Programming and Operating Systems (TDDB68/72) – Some Java knowledge for the labs • Introductory lesson Lecture 1: Introduction & cyclic scheduling Mikael Asplund Reading – Get copies from assistant on material that is not available on the course Literature page 9 of 42 Lecture 1: Introduction & cyclic scheduling Mikael Asplund Laboratory 10 of 42 Lectures and Lessons • Apply your knowledge! • Lectures vs. reading • Real-time system • Slides • Please make sure that you • Lessons: – Read the compendium – Introduction to labs – Observe the instructions – Possibility to ask questions before exam – Keep the deadline (6th December) Lecture 1: Introduction & cyclic scheduling Mikael Asplund 11 of 42 Lecture 1: Introduction & cyclic scheduling Mikael Asplund 12 of 42 Examination • Written exam – December 13th 14.00-18.00 – Old exams available on the web Real-time systems • Labs – Practical part – Theoretical part Lecture 1: Introduction & cyclic scheduling Mikael Asplund 13 of 42 Lecture 1: Introduction & cyclic scheduling Mikael Asplund Definitions of an RT System 14 of 42 What is an embedded system? • Oxford Computing Dictionary – ”Any system in which the time at which output is produced is significant. This is usually because the input corresponds to some movement in the physical world, and the output has to relate to that same movement. The lag from input time to output time must be sufficiently small for acceptable timeliness.” • Timeliness: milliseconds, seconds, hours • A computer system that – – – – is part of a larger system is tailor-made for a specific application is characterised by restricted programmability by the user has tight interaction with a physical environment • Real-time vs. embedded • Randell et. al 1995 – Usually an rt-system is embedded – RT and not embedded? – Embedded and not RT? – ”A real-time system is a system that is required to react to stimuli from the environment (including the passage of physical time) within time intervals dictated by the environment.” Lecture 1: Introduction & cyclic scheduling Mikael Asplund 15 of 42 Lecture 1: Introduction & cyclic scheduling Mikael Asplund 16 of 42 Application areas Hard real-time Utility • Manufacturing and process control • Command and control and communication • Generalised embedded system r Fly-by-wire, brake-by wire Atomic power plant control Garden sprinkle system Computer games Robot vision processing Communication equipment Lecture 1: Introduction & cyclic scheduling Mikael Asplund time −∞ • Examples – – – – – – d • Missed deadline = failure • Predictability crucial • Critical applications 17 of 42 Lecture 1: Introduction & cyclic scheduling Mikael Asplund 18 of 42 Soft real-time Utility Firm real-time Utility r d r time d time • A late response is worth nothing • Deadlines should be met... • Deadlines can be missed occasionally • but a miss is just a miss. • Performance! Lecture 1: Introduction & cyclic scheduling Mikael Asplund 19 of 42 Characteristics of a RTS • Large and complex 20 of 42 Misconceptions about RT systems • Real-time computing is equivalent to fast computing. • Concurrent control of separate system components • Advances in hardware will solve real-time problem. • Facilities to interact with special purpose hardware • There is no science in real-time system design. • Extreme reliability and safety • Real-time systems research is about performance tuning. • Guaranteed response times Lecture 1: Introduction & cyclic scheduling Mikael Asplund Lecture 1: Introduction & cyclic scheduling Mikael Asplund 21 of 42 Lecture 1: Introduction & cyclic scheduling Mikael Asplund Part II 22 of 42 Scheduling • Allocating resources, especially the CPU time, among all computational processes such that the timeliness requirements are met. Scheduling Lecture 1: Introduction & cyclic scheduling Mikael Asplund • The scheduler decides which process is to be executed next. 23 of 42 Lecture 1: Introduction & cyclic scheduling Mikael Asplund 24 of 42 Process as an abstraction Non Real-Time Scheduling 1. Interactive performance • For different computational processes in the OS 2. Fairness • For parallel developments within the physical environment and in the control system • Typical metrics and goals: – Minimize response time – Maximize throughput • For nodes in a network, with interaction and communication • Examples – FCFS (First-Come-First-Served) – RR (Round-Robin) – CFS (Completely Fair Scheduler) Lecture 1: Introduction & cyclic scheduling Mikael Asplund 25 of 42 Lecture 1: Introduction & cyclic scheduling Mikael Asplund Real-Time Scheduling • Scheduling, resource management 2. The rest • Dependability Typical metrics and goals: – Guarantee ratio (hard real-time) – Maximize completion ratio / minimize miss ratio (hard / firm) – Minimize overall lateness (soft real-time) • Content • Introduction to Real-time Systems 1. Predictability • 26 of 42 • Distributed real-time systems • Real-time operating systems • Real-time applications Examples – Cyclic Scheduling – EDF (Earliest Deadline First) – LS (Least Slack) – RM (Rate-Monotonic) Lecture 1: Introduction & cyclic scheduling Mikael Asplund 27 of 42 Some parameters R r Lecture 1: Introduction & cyclic scheduling Mikael Asplund 28 of 42 Scheduling: Problem Space • Uniprocessor / multiprocessor / distributed system d • Periodic / sporadic / aperiodic • Independent / interdependent C • • • • • • • • Preemptive / non-preemptive Release time: r f Computation time: C Absolute deadline: d Finish time: f Response time: R = f-r Relative deadline D = d-r Task period: T (Usually D=T) Lecture 1: Introduction & cyclic scheduling Mikael Asplund • Handle transient overloads • Support fault tolerance 29 of 42 Lecture 1: Introduction & cyclic scheduling Mikael Asplund 30 of 42 Simple Process Model • Fixed set of processes, uniprocessor system Performance Metrics • Completion ratio / miss ratio • Periodic • Maximize total value (weighted sum) • Independent • Context switch is for free • Maximize value of task • D=T • Minimize lateness • Worst-case execution time is known • Minimize error (imprecise tasks) Lecture 1: Introduction & cyclic scheduling Mikael Asplund 31 of 42 Lecture 1: Introduction & cyclic scheduling Mikael Asplund 32 of 42 Static vs dynamic scheduling Variants • Static (off-line) • Preemptive vs. non-preemptive – complete a priori knowledge of the task set and its constraints is available – hard/safety-critical system • Off-line vs. on-line scheduling analysis • off-line analysis can be used with dynamic scheduling • Dynamic (on-line) – partial taskset knowledge, runtime predictions – firm/soft/best-effort systems, hybrid systems Lecture 1: Introduction & cyclic scheduling Mikael Asplund • off-line analysis very important for hard-rt systems 33 of 42 Scheduling Approaches Lecture 1: Introduction & cyclic scheduling Mikael Asplund 34 of 42 Cyclic Executive • Cyclic executives • Fixed priority scheduling – RM - Rate Monotonic – DM - Deadline Monotonic Scheduling • Dynamic priority scheduling – EDF - Earliest Deadline First – LSF - Least Slack First • OBS! – Don’t confuse dynamic scheduling with dynamic priority Lecture 1: Introduction & cyclic scheduling Mikael Asplund 35 of 42 1: Introduction & cyclic scheduling •Lecture What happens if the periods are not harmonic? Mikael Asplund 36 of 42 General Procedure Calculate major cycle = lcm T 1 ,T 2 , ,T n • Calculate minor cycle = gcd T 1 ,T 2 , ,T n • Schedulability analysis? – See if a taskset is schedulable. • Scheduling analysis? • Populate all the minor cycles of a first major cycle with tasks – If a task cannot fit (its WCET) in a minor cycle it needs to be split • Over several minor cycles • If the programming technique allows it – Every task should run to completion once per period • Period might span several minor cycles • A new task instance cannot be scheduled before its natural release Lecture 1: Introduction & cyclic scheduling Mikael Asplund Schedulability analysis – Analyse the particular scheduling. • Is a taskset schedulable using cyclic scheduling? – Construct the schedule and find out. • ∑ Ci /T i ≤ 1 ? – YES: If we assume a simple task model, and that tasks can be split in arbitrarily small pieces, then the taskset is schedulable using cyclic scheduling. – NO: The taskset is not schedulable using cyclic scheduling. 37 of 42 Task dependencies & cyclic Lecture 1: Introduction & cyclic scheduling Mikael Asplund 38 of 42 Cyclic executives observations • No actual processes exist at run-time • Dependences due to • Sharing resources • Computation precedence requirements • The procedures share a common address space • Make sure the running order of the tasks is respected • Data does not need to be protected • A taskset that is schedulable if tasks are independent might not be schedulable if dependencies are introduced Lecture 1: Introduction & cyclic scheduling Mikael Asplund 39 of 42 Lecture 1: Introduction & cyclic scheduling Mikael Asplund Problems with Cyclic 40 of 42 Reading • Sporadic processes • Burns & Wellings, Ch 1. and Ch. 13 • Processes with long periods • Tasks with dependencies • Adding new tasks • Processes with sizeable computation times. – How do you split them? – Can you split them? Lecture 1: Introduction & cyclic scheduling Mikael Asplund 41 of 42 Lecture 1: Introduction & cyclic scheduling Mikael Asplund 42 of 42