kukum real time system. kukum real time system lecture outline administrivia a few things about me...
TRANSCRIPT
Real Time System
KUKUM
Real Time System
Real Time System
KUKUM
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)
Real Time System
KUKUM
Lecturer Contact Details
En. Zahereel Ishwar Abdul Khalib Email: [email protected]. Phone: 04 979 8641Phone: 019 477 9177Education: 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
Real Time System
KUKUM
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.
Real Time System
KUKUM
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
Real Time System
KUKUM
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.
Real Time System
KUKUM
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
Real Time System
KUKUM
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
Real Time System
KUKUM
Timetable
• Lecture: 2+1 3 hours per week
• Lab: 2 hours per week
Monday: 3.00 -5.00DKW1 (Dewan Keikhlasan)
KWSP
Jumaat: 11.00 -12.00DKP 4 (Automart)
TUESDAY: 4.00-6.00MKY 5 (Kg Wai)
Real Time System
KUKUM
Assessment
• Final Exam: 50%• Course Work: 50%
• Assignment 10%• Test 20% - 2 test (10% each)• Mini Project 20% - 2 mini project
( 10% each)
• Bonus: Pop Quiz Max of 3%
Real Time System
KUKUM
Readings
Introduction to Real Time System1. Lecture Notes
Real Time programming and Concurrency1. Lecture Notes2. M. Ben-Ari, Principles of Concurrent and
Distributed Prog., Prentice Hall, 1990(chp: 1-5)
Real Time System
KUKUM
…/ReadingsSynchronization in RTS1. Lecture Notes
Scheduling in RTS1. Lecture Notes2. Jane W. S. Liu, “Real-Time Systems”,
Prentice Hall, 2000, ISBN 0130996513
POSIX programming1. Lecture Notes 2. Graham Glass, Unix for Programmers and
Users, Prentice Hall
Real Time System
KUKUM
IntroducingReal Time System
Real Time System
KUKUM
Lecture Outline
• What is real time system (RTS)
• OS and RTOS
Real Time System
KUKUM
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.
Real Time System
KUKUM
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.
Real Time System
KUKUM
../ 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”
Real Time System
KUKUM
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)
Real Time System
KUKUM
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)
Real Time System
KUKUM
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.
Real Time System
KUKUM
…/ 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.
Real Time System
KUKUM
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.
Real Time System
KUKUM
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!
Real Time System
KUKUM
Digital control
Real Time System
KUKUM
Components of RTS
Real Time System
KUKUM
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
Real Time System
KUKUM
../ 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
Real Time System
KUKUM
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
Real Time System
KUKUM
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)
Real Time System
KUKUM
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=4ms, T=20ms, D=5ms– ABS control: C=10ms,T=40ms, D=40ms– Fuel injection: C=40ms,
T=80ms,D=80ms– Other software with soft deadlines e.g audio, air
condition etc
• Construct a controller meeting all the deadlines!
Real Time System
KUKUM
Programming the car controller (1)
Process Speed:Loopread sensor,compute,display...sleep (0.02) /*period*/End loop
Process ABS:Loopread sensor,compute,display...sleep (0.04) /*period*/End loop
Soft RT ProcessesLoopread temperatureel hiss, stereo....End loop
Process FuelLoopread data, compute, inject ...sleep(0.08)End loop
Real Time System
KUKUM
Any problem?
• We forgot the execution times !
• e.g. Process speed:
• 20ms = execution time + sleep(X)
Real Time System
KUKUM
Programming the car controller (2)
Process Speed:Loopnext := get-time + 0.02read sensor,compute,display...sleep until nextEnd loop
Process ABSLoopnext:=get-time + 0.04Read sensor, compute, reactsleep until nextEnd loop
Soft RT ProcessesLoopread temperature,el hiss, stereo....End loop
Process FuelLoopnext:=get-time + 0.08read data, compute, inject ...sleep until nextEnd loop
Real Time System
KUKUM
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)
Real Time System
KUKUM
Programming the car controller (3)
Real Time System
KUKUM
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
Real Time System
KUKUM
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
Real Time System
KUKUM
Those are expensive stuff !
• Answer: RTOS
Real Time System
KUKUM
Operating System
Real Time System
KUKUM
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.
Real Time System
KUKUM
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.
Real Time System
KUKUM
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
Real Time System
KUKUM
../ OS : basic task
– 2ndry 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
Real Time System
KUKUM
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
Real Time System
KUKUM
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
Real Time System
KUKUM
Diagram of process state
Real Time System
KUKUM
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.
Real Time System
KUKUM
../ 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.
Real Time System
KUKUM
Kernel
Kernel contains a collection of primitives which are used to build the OS
OS implements policyKernel implements mechanisms
Hardware
kernel
Operating system
Real Time System
KUKUM
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.
Real Time System
KUKUM
What makes an OS an RTOS?
• A RTOS (Real-Time Operating System) has to be multi-tasking 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
Real Time System
KUKUM
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.