62643313d55c01a77af90c8f5475b3b6.ppt
- Количество слайдов: 52
Real Time System KUKUM Real Time System
Lecture Outline • Administrivia • • A few things about me Aims and Objective Intended Learning Outcomes Prerequisites Module Outline and Timetable Reading List Assessment • Introduction to Real Time System (RTS) KUKUM Real Time System
Lecturer Contact Details En. Zahereel Ishwar Abdul Khalib Email: zahereel@kukum. edu. my Off. Phone: 04 979 8641 Phone: 019 477 9177 Education: MSc. Real Time S. E. (UTM) 2005 BSc. Computer Engineering (Cal. USA) 2000 If u need to discuss/question on the materials covered, please do tell me and we can arrange as per when and where can we meet and discuss KUKUM Real Time System
Aims of the module • To introduce and explore the concept relying behind RTS. • To understand the challenges and grab the techniques necessary in developing RTS. KUKUM Real Time System
Intended Learning Outcomes • By digesting this course, the participants are expected to be able to: • Differentiate the different issues relating to designing real time system. • Explain the various concepts of time relating to RTS. • Comprehend the various static and dynamic scheduling mechanism in achieving a real time system. • Utilize the Unix system calls mechanism to write synchronize concurrent programs, which exhibits Real Time System KUKUM Real Time System
Prerequisite • You need to know C language, as we will dive deeper in it to perform Unix system level programming which exhibits Real Time System. KUKUM Real Time System
Module Outline Introduction to Real Time System • Defining RTS • OS and RTOS… what’s up • Issue in developing an RTS compared to non-RTS Real Time Programming and Concurrency • Concept of Concurrency • Abstraction of Concurrent programming • Writing Concurrent Programs Synchronization in RTS • The mutual exclusion problem & Solution • Semaphore KUKUM Real Time System
Module Outline …cont Scheduling in RTS • A Real Time Model • Types of Jobs & Dynamic vs Static • Clock driven scheduling algorithms • Priority driven scheduling algorithms • RMA, DMA, EDF, Round Robin POSIX programming • Multi process programming • Interprocess communication – – – Signal Pipe Shared memory Semaphore Msg Queue KUKUM Real Time System
Timetable • Lecture: 2+1 3 hours per week Monday: 3. 00 -5. 00 DKW 1 (Dewan Keikhlasan) KWSP • Lab: 2 hours per week TUESDAY: 4. 00 -6. 00 MKY 5 (Kg Wai) KUKUM Real Time System Jumaat: 11. 00 -12. 00 DKP 4 (Automart)
Assessment • • Final Exam: Course Work: • • 50% Assignment Test Mini Project 10% 20% - 2 test (10% each) 20% - 2 mini project ( 10% each) Bonus: Pop Quiz Max of 3% KUKUM Real Time System
Readings Introduction to Real Time System 1. Lecture Notes Real Time programming and Concurrency 1. Lecture Notes 2. M. Ben-Ari, Principles of Concurrent and Distributed Prog. , Prentice Hall, 1990 (chp: 1 -5) KUKUM Real Time System
…/Readings Synchronization in RTS 1. Lecture Notes Scheduling in RTS 1. Lecture Notes 2. Jane W. S. Liu, “Real-Time Systems”, Prentice Hall, 2000, ISBN 0130996513 POSIX programming 1. Lecture Notes 2. Graham Glass, Unix for Programmers and Users, Prentice Hall KUKUM Real Time System
Introducing Real Time System KUKUM Real Time System
Lecture Outline • What is real time system (RTS) • OS and RTOS KUKUM Real Time System
A System • Consists of a set of components that collaborate to achieve a common purpose. • A system comprises of hardware and software components which are put together through a well-defined interface. • Components include: • Hardware: sensors, keypads, display, communication chips • Software: concurrent processes, objects and etc. KUKUM Real Time System
Describing RTS • A system can be define as a collection of components that respond to inputs from the user or the environment or from itself. • Typically, there is an amount of time spent between receiving the input and responding to the input. • In any system it is quite natural to expect a response within a specific time interval. KUKUM Real Time System
. . / Describing RTS • But, out there exists systems which has very strict deadlines ( not necessarily short) to be met. These are the Real Time System. “ A late answer is wrong answer” KUKUM Real Time System
Overall Structure of RT Systems • Hardware (CPU, I/O device etc) – a clock! • A real time OS (function as standard OS, with predictable behavior and well-defined functionality) • A collection of RT tasks/processes (share resourses, communicate/synchronize with each other and the environment) KUKUM Real Time System
Types of RTS • Hard RTS: – A system where, a missing deadline could cause lost of life/ massive property destruction. • eg: Aircrafts, biomedical inst, nuclear reactor • Soft RTS: – A system where a few missed deadlines may not cause any significant inconvenience to the user. • eg: Internet streaming ( lost of some packets can be afforded) KUKUM Real Time System
What’s up with Fast & Slow RTS • Typically, any system that operates within subsecond response time can be classified as fast. • While systems that can take a second or more to respond is classified slow. KUKUM Real Time System
…/ Slow Fast RTS • Note: soft real time system can be “fast”. ie: a few packets can be lost across a high -speed router that works with nanosecond deadlines. • Similarly hard real time system can be “slow”. i. e: the cadmium rods inside a nuclear reactor need not be pulled out at a lighting speed. KUKUM Real Time System
Determinism in RTS • The concept of determinism differentiates real time programming from normal application programming. • The time interval between input occurrence and output occurrence must be “deterministic” or predictable. ie: the system always respond within a specified (known) period of time. KUKUM Real Time System
Which is RTS • • Mobile phones Cars, Trains, Aircrafts Washing machines Games. . . • All computers that do not look like a computer – Consumming 99% of processors produced in the world! KUKUM Real Time System
Digital control KUKUM Real Time System
Components of RTS KUKUM Real Time System
Characteristics of a RTS • Large and complex – vary from a few hundred lines of assembler or C to 20 million lines of Ada estimated for the Space Station Freedom • Concurrent control of separate system components – devices operate in parallel in the real-world; better to model this parallelism by concurrent entities in the program • Facilities to interact with special purpose hardware – need to be able to program devices in a reliable and abstract way KUKUM Real Time System
. . / Charac of RTS • Extreme reliability and safety – Embedded systems typically control the environment in which they operate; failure to control can result in loss of life, damage to environment or economic loss • Guaranteed response times – we need to be able to predict with confidence the worst case response times for systems; efficiency is important but predictability is essential KUKUM Real Time System
So what have I comprehend ? • A real-time system is any information processing system which has to respond to externally generated input stimuli within a finite and specified period – the correctness depends not only on the logical result – but also the time it was delivered – failure to respond is as bad as the wrong response! • A system is classified as an RTS if it is required to respond to the stimulus of real world events and complete its work & deliver its service on a timely basis – Not necessarily fast, but must meet some timing deadline KUKUM Real Time System
Remember • In RT systems, the correctness of computation depends not only on the results but also on the time when outputs are produced. – Real Time =/= Fast – Real Time =/= Time Sharing – Real Time = just in Time (predictable) KUKUM Real Time System
Example: A car controler • Activities of a car control system. Let • 1. C = worst case execution time • 2. T = (sampling) period • 3. D = deadline – – Speed measurement: C=4 ms, T=20 ms, D=5 ms ABS control: C=10 ms, T=40 ms, D=40 ms Fuel injection: C=40 ms, T=80 ms, D=80 ms Other software with soft deadlines e. g audio, air condition etc • Construct a controller meeting all the deadlines! KUKUM Real Time System
Programming the car controller (1) Process Speed: Loop read sensor, compute, display. . . sleep (0. 02) /*period*/ End loop Process ABS: Loop read sensor, compute, display. . . sleep (0. 04) /*period*/ End loop Process Fuel Loop read data, compute, inject. . . sleep(0. 08) End loop Soft RT Processes Loop read temperature el hiss, stereo. . End loop KUKUM Real Time System
Any problem? • We forgot the execution times ! • e. g. Process speed: • 20 ms = execution time + sleep(X) KUKUM Real Time System
Programming the car controller (2) Process Speed: Loop next : = get-time + 0. 02 read sensor, compute, display. . . sleep until next End loop Process Fuel Loop next: =get-time + 0. 08 read data, compute, inject. . . sleep until next End loop Process ABS Loop next: =get-time + 0. 04 Read sensor, compute, react sleep until next End loop Soft RT Processes Loop read temperature, el hiss, stereo. . End loop KUKUM Real Time System
What is the problem now? • We don’t know if the deadlines are met! – We need to know the execution times – We need to do schedulability analysis – We need to construct a schedule – We need to implement/buy an RT operating system – Run-time system (in programming language design) KUKUM Real Time System
Programming the car controller (3) KUKUM Real Time System
Main desirable properties of RT Systems(1) • Timeliness: not only outputs but also times they are produced • Robustness: must not collapse when subject to peak load, exception, manage all possible scenarios • Fault tolerance: hardware and software failures should not cause the system to crash • Predictability: able to predict the future consequences ( in relation to time) of current actions • Maintainability: modular structure to ease system modification • Testability: easy to test if the system can meet all the deadlines KUKUM Real Time System
How to achieve RTS ( the time factor) • How can u guarantee that your system fulfill the timing requirement? – A lot of things need to be considered, but here some of the most useful terms related to the answer • • Scheduling Concurrency Synchronization Re-entrant code KUKUM Real Time System
Those are expensive stuff ! • Answer: RTOS KUKUM Real Time System
Operating System KUKUM Real Time System
OS • A computer system composes of resources like CPU, memory, I/O devices and others • All this resources needed to be used by the programs which runs on the system • Thus, OS acts as manager which manages the system resources to all of the command issued by the programs running on the computer system. KUKUM Real Time System
OS • So, OS is a set of sw which manages the operation of computer system. • The central module of OS is called kernel • It is the part of the operating system that loads first, and it remains in main memory (RAM). • Because it stays in memory, it is important for the kernel to be as small as possible while still providing all the essential services required by other parts of the operating system and applications. KUKUM Real Time System
OS : basic task – Process management » Creation, Deletion, Synchronization, Comm, – Main memory management » » Which part of memory being used by whom Load new process when memory available Allocate and de-allocate memory space as needed Memory protection KUKUM Real Time System
. . / OS : basic task – 2 ndry storage management » File creation and deletion. » Directory creation and deletion. » Support of primitives for manipulating files and directories. » Mapping files onto secondary storage. » File backup on stable (nonvolatile) storage media. – I/O management – File management – Protection System KUKUM Real Time System
Process • A process is a program in some “state” of execution. A process needs certain resources, including CPU time, memory, files, and I/O devices, to accomplish its task. • process execution must progress in sequential fashion. • A process includes: – program counter – stack – data section • Two different processes from the same program have everything different but the text section, and may or may not share a copy of the text section KUKUM Real Time System
Process State • As a process executes, it changes state – new: The process is being created. – running: Instructions are being executed. – waiting: The process is waiting for some event to occur. – ready: The process is waiting to be assigned to a processor – not waiting for anything or resource. – terminated: The process has finished execution KUKUM Real Time System
Diagram of process state KUKUM Real Time System
Process State Transition Descp. • The job scheduler or long-term scheduler decides to admit a process from "new" into "ready". It uses the loader to do this. • The CPU scheduler or short-term scheduler decides to dispatch a process from "ready" into "running". This requires a context switch (more on that later. ) • The CPU scheduler also decides to remove a process from "running" to "ready". It does this on receiving a timer interrupt. An interrupt service routine handles the timer interrupt. KUKUM Real Time System
. . / Process State Transition Descp. • The process itself decides to go into a "wait" state. It does this by executing a system call to wait for I/O (or for an event). An interrupt service routine handles the system call. • Usually, a process in a "wait" state is waiting for I/O; thus an interrupt from the I/O device causes the process to move to the "ready" state, and the interrupt is processed by an interrupt service routine. • The process itself can decide to exit, by making a system call, or the process can be abnormally terminated in a number of ways. KUKUM Real Time System
Kernel ü Kernel contains a collection of primitives which are used to build the OS ü OS implements policy ü Kernel implements mechanisms Hardware kernel Operating system KUKUM Real Time System
The Unix Kernel • program that runs directly on the hardware • loaded at boot time and initializes system, – creates some initial system processes. – remains in memory and manages the system • Resource manager/mediator – – Time share (time-slice) the CPU, coordinate access to peripherals, manage virtual memory. Synchronization primitives. • Well defined entry points: – syscalls, exceptions or interrupts. • Performs privileged operations. KUKUM Real Time System
What makes an OS an RTOS? • A RTOS (Real-Time Operating System) has to be multitasking and pre-emptable. • The notion of process/thread priority has to exist. • The OS has to support predictable process synchronization mechanisms • A system of priority inheritance has to exist • OS behaviour should be known KUKUM Real Time System
The following figures should be good as well • The interrupt latency (i. e. time from interrupt to task run) : this has to be compatible with application requirements and has to be predictable. This value depends on the number of simultaneous pending interrupts. • For every system call, the maximum time it takes. It should be predictable and independent from the number of objects in the system; • The maximum time the OS and drivers mask the interrupts. • The following points should also be known by the developer: – System Interrupt Levels. – Device driver IRQ Levels, maximum time they take, etc. KUKUM Real Time System