Chapter 19 Real-Time Systems

53
Chapter 19 Chapter 19 Real-Time Systems Real-Time Systems CS 540 Advanced Operating systems Instructor: Dr. Behzad Perviz Fall 2010 Presented By: Monali Bhavsar Amee

description

Chapter 19 Real-Time Systems. CS 540 Advanced Operating systems Instructor: Dr. Behzad Perviz Fall 2010 Presented By: Monali Bhavsar Amee Joshi. Real-Time Systems. System Characteristics - PowerPoint PPT Presentation

Transcript of Chapter 19 Real-Time Systems

Page 1: Chapter 19 Real-Time Systems

Chapter 19Chapter 19Real-Time SystemsReal-Time Systems

CS 540 Advanced Operating systems Instructor: Dr. Behzad Perviz

Fall 2010

Presented By: Monali Bhavsar Amee Joshi

Page 2: Chapter 19 Real-Time Systems

Real-Time SystemsReal-Time Systems

System CharacteristicsFeatures of Real-Time SystemsImplementing Real-Time

Operating SystemsReal-Time CPU SchedulingAn Example: VxWorks 5.x

Page 3: Chapter 19 Real-Time Systems

ObjectivesObjectivesTo explain the timing requirements of

real-time systemsTo distinguish between hard and soft

real-time systemsTo discuss the defining characteristics

of real-time systemsTo describe scheduling algorithms for

hard real-time systems

Page 4: Chapter 19 Real-Time Systems

Overview of Real-Time Overview of Real-Time SystemsSystems A Real-time system requires that results be

produced within a specified deadline period ◦ Example: Robot◦ Contrast: Desktop computer system, Batch

processing system.

An Embedded system is a computing device that is part of a larger system.(i.e. automobile, airliner)

◦ No timing requirements.◦ Embedded in specialized devices.◦ Presence of computing device is not obvious.◦ Examples: dishwashers, microwave ovens,

cameras, MP3 players.

Page 5: Chapter 19 Real-Time Systems

Continue…Continue… A Safety-critical system is a real-time system with

catastrophic results in case of failure.◦ Weapons systems, antilock brake system, flight

management system & health related systems.◦ System must respond to events by specific

deadline period.

A Hard real-time system guarantees that real-time tasks be completed within their required deadlines.◦ Critical real time tasks be completed within their

deadlines.◦ Safety critical systems are typically hard real time

systems.

A Soft real-time system provides priority of real-time tasks over non real-time tasks.◦ Priority retain until task completed.◦ Linux and many OS provide soft real time system.

Page 6: Chapter 19 Real-Time Systems

System CharacteristicsSystem Characteristics

Single purposeSmall sizeInexpensively mass-producedSpecific timing requirements

Page 7: Chapter 19 Real-Time Systems

System CharacteristicsSystem Characteristics Single purpose

◦ Unlike PC’s real time systems serves single purpose. Design of it reflects single purpose and its simple.

Small size◦ Existing environment is constrained in physical space

so CPU power and memory available is less then standard pc’s.

◦ Real time systems run on 8- or 16- bit processors and less then megabytes of memory.

◦ Footprint: amount of memory required to run the OS and its applications. Real time systems must have small footprints.

Specific timing requirements◦ Real time operating systems meet timing

requirements by using scheduling algorithms that gives real-time processes the highest scheduling priorities.

◦ Priority of scheduling tasks does not degrade over time.

◦ Technique for addressing timing requirements: minimize response time to events such as Interrupts.

Page 8: Chapter 19 Real-Time Systems

System CharacteristicsSystem Characteristics Inexpensively mass-

produced◦ Real time systems

are used in home appliances and consumer devices which are cost conscious environment, so microprocessors for real time systems must inexpensively mass produced.

◦ Example: SOC.

Bus Oriented System

Page 9: Chapter 19 Real-Time Systems

System-on-a-ChipSystem-on-a-Chip

Many real-time systems are designed using system-on-a-chip (SOC)strategy

SOC allows the CPU, memory, memory-management unit, and attached peripheral ports (I.e. USB) to be contained in a single integrated circuit.

Less expensive then bus oriented organization.

Page 10: Chapter 19 Real-Time Systems

System-on-a-ChipSystem-on-a-Chip

Page 11: Chapter 19 Real-Time Systems

Features of Real-Time Features of Real-Time KernelsKernels Features provided by many operating systems are:

◦ Support variety of peripheral devices◦ Protection and security mechanism◦ Multiple usersSupporting these features results in large kernel.

Example, Windows XP. Most real-time systems do not provide the features

found in a standard desktop system as above. Reasons include

◦ Real-time systems are typically single-purpose◦ Real-time systems often do not require interfacing with

a user◦ Features found in a desktop PC require more substantial

hardware that what is typically unavailable in a real-time system due to lack of memory and fast processors. Both of these are unavailable in real time systems due to

space constraints. Addition to that many systems lack sufficient space to provide

graphical displays or disk drives, they support file systems using NVRAM(Non Volatile RAM).

◦ Features of desktop PC increase the cost of real time systems which makes systems economically impractical.

Page 12: Chapter 19 Real-Time Systems

Virtual Memory in Real-Virtual Memory in Real-Time SystemsTime Systems Providing virtual memory features requires that

the system include a Memory Management Unit(MMU).◦ MMUs increase the cost and power consumption.◦ Time required to translate logical address to

physical address especially in case of Translation Look aside Buffer(TLB) miss – may be prohibited in hard real time systems.

Address translation may occur via:1)Real-addressing mode where programs generate

actual addresses

2)Relocation register mode

3)Implementing full virtual memory

Page 13: Chapter 19 Real-Time Systems

Address TranslationAddress Translation

Page 14: Chapter 19 Real-Time Systems

Address TranslationAddress TranslationReal-addressing mode:

◦ CPU generates logical address L which must be mapped to physical address P.◦ Bypass the logical address and directly generate

physical address. ◦ Not employ virtual memory techniques so P

equals L.◦ Problem: no memory protection between

processes and programmers need to specify physical location of memory load.

◦ Benefits: fast, no time spent on address translation.

◦ Used in embedded systems with hard real time constraints.

Page 15: Chapter 19 Real-Time Systems

Address TranslationAddress TranslationRelocation register mode:◦ Same as Dynamic relocation register.◦ Relocation register R is set to memory

location where a program is loaded.◦ Physical address P is generated by adding

the contents of relocation register R to L.◦ Real time systems are configure the MMU

to perform this way because MMU can easily translate logical addresses to physical addresses using P=L+R.

◦ This system will also not provide memory protection between processes.

Page 16: Chapter 19 Real-Time Systems

Address TranslationAddress Translation Implementing full virtual memory:

◦ Address translation take place via page table and Translation Look aside buffer(TLB).◦ This strategy provides program to be

loaded at any memory location & memory protection between two processes.

◦ Without attaching disk drives not possible to provide all virtual memory features like Demand Paging and Swapping. Contrast to that some system provides that

using NVRAM. Examples: LynxOS and OnCore Systems.

Page 17: Chapter 19 Real-Time Systems

Implementing Real-Time Implementing Real-Time SystemsSystemsIn general, real-time operating

systems must provide:1)Preemptive, priority-based

scheduling2)Preemptive kernels3)Latency must be minimized

Page 18: Chapter 19 Real-Time Systems

Implementing Real-Time Implementing Real-Time SystemsSystems Preemptive, priority-based scheduling:

◦ Important feature: must respond immediately to a real time process so system must support Priority-based algorithm with Preemption.

Priority based scheduling algorithms assign priority based on their importance.

If scheduler supports preemption, a process currently running on CPU will be preempted if a higher priority process will available to run.

◦ Solaris, Windows XP & Linux systems assign highest scheduling priority to real time processes.

◦ This will provide only soft real time functionality. For hard real time functionalities we need additional scheduling features to meet timing requirements.

Page 19: Chapter 19 Real-Time Systems

Windows XP priorities:Windows XP priorities:Windows XP has 32 different priority levels, the

highest priority level values 16-31 are reserved for real time processes.

Page 20: Chapter 19 Real-Time Systems

Implementing Real-Time Implementing Real-Time SystemsSystems Preemptive kernels:

◦ Allows the Preemption of a task running in kernel mode.

◦ Designing preemptive kernel is difficult so if quick response is not require its not implemented. Ex. Windows XP is non-Preemptive.

◦ In Hard real time systems preemptive kernels are mandatory.

◦ There are two strategies to make kernel preemptible:

First: Insert Preemption points in long duration system calls.

Preemption points can be placed at safe locations in kernel that is where kernel data structure is not modified.

Second: Use of synchronization mechanisms. Any kernel data being updated are protected from

modification by the high priority process so kernel will always preemptible.

Page 21: Chapter 19 Real-Time Systems

Minimizing LatencyMinimizing LatencyEvent latency is the amount of time from

when an event occurs to when it is serviced.

Page 22: Chapter 19 Real-Time Systems

Interrupt LatencyInterrupt Latency Interrupt latency is the period of time

from when an interrupt arrives at the CPU to when it is serviced.

Page 23: Chapter 19 Real-Time Systems

Interrupt LatencyInterrupt Latency Important factor contributing to interrupt latency

is the amount of time interrupts may be disabled while kernel data structures are being updated.

Real time operating systems required that interrupts be disabled for very short period of time.

In hard real time systems it must not only be minimized, it must in fact bounded to guarantee the deterministic behavior of hard real time systems.

Page 24: Chapter 19 Real-Time Systems

Dispatch LatencyDispatch LatencyDispatch latency is the amount of time

required for the scheduler to stop one Process and start another

Page 25: Chapter 19 Real-Time Systems

Dispatch LatencyDispatch Latency If we want to provide real time tasks with

immediate access to CPU mandates that operating system should minimize Dispatch latency. To keep Dispatch latency low, provide Preemptive kernels.

The Conflict phase of dispatch latency has two components:◦ Preemption of any process running in the kernel◦ Release by low priority processes of resources needed

by a high-priority process. Ex. Solaris.

One issue that can affect the dispatch latency arises when a higher priority process needs to read or modify kernel data that are currently being accessed by a lower priority process. Or a chain of lower priority processes.

Problem: Priority inversion. Solved by: Priority-inheritance protocol.

Page 26: Chapter 19 Real-Time Systems

Priority InversionPriority Inversion

Page 27: Chapter 19 Real-Time Systems

Priority Inversion & Priority Inversion & Priority InheritancePriority Inheritance

Page 28: Chapter 19 Real-Time Systems

Real-Time Real-Time CPU CPU SchedulingScheduling Scheduling : Deciding how to allocate a single

resource

among multiple clients.◦ In what order and for how long.◦ Usually refers to CPU scheduling.

CPU Scheduling decisions may take place when a process:◦ Switches from running to waiting state◦ Switches from running to ready state◦ Switches from waiting to ready◦ Terminates.

Page 29: Chapter 19 Real-Time Systems

Real-Time CPU Real-Time CPU SchedulingSchedulingTwo types of Real Time

◦ Soft Real Time : Meet Deadline most of the time, but not mandatory.

Example : Live audio-video systems are usually soft real-time; violation of constraints results in degraded quality, but the system can continue to operate.

◦ Hard Real Time : Must meet deadline, otherwise can cause fatal error.Example : a car engine control system is a

hard real-time system because a delayed signal may cause engine failure or damage.

Page 30: Chapter 19 Real-Time Systems

Real-Time CPU Real-Time CPU SchedulingScheduling Periodic processes require the CPU at specified

intervals (periods) p is the duration of the period d is the deadline by when the process must

be serviced t is the processing time

Page 31: Chapter 19 Real-Time Systems

Real-Time CPU Real-Time CPU SchedulingScheduling Unusual about this scheduling is that a process

may have to announce its deadline requirements to the scheduler.

Using Technique an Admission Control algorithm the scheduler◦ either admits the process, guaranteeing that the

process will complete on time,◦ or rejects the request as impossible if it cannot

guarantee that task will be serviced by its deadline.

Page 32: Chapter 19 Real-Time Systems

Real Time CPU Real Time CPU Scheduling AlgorithmsScheduling Algorithms

Rate Monotonic SchedulingEarliest Deadline First SchedulingProportional Share SchedulingPthread Scheduling

Page 33: Chapter 19 Real-Time Systems

Rate Monotonic Rate Monotonic SchedulingScheduling It schedules periodic tasks using a static priority

policy with preemption.◦ If a lower priority process is running and a higher

priority process becomes available to run, it will preempt the lower priority process.

Each periodic task is assigned a priority inversely based on its period:◦ The shorter the period , the higher the priority.◦ The longer the period, the lower the priority.

Rate monotonic scheduling assumes that the processing time of a periodic process is the same for each CPU burst.◦ Every time a process acquires the CPU, the duration

of its CPU burst is the same.

Page 34: Chapter 19 Real-Time Systems

ExampleExample Two Processes P1 and P2. The periods for p1 = 50 and p2 = 100. The Processing times are t1 = 20 for P1 and t2 = 35 for

P2. The deadline for each process requires that it complete

its CPU burst by the start of its next period. The CPU utilization of a process Pi as the ratio of its burst

to its period – ti/pi so, for P1 it is 20/50 = 0.40 and for P2 it is 35/100 = 0.35. so total CPU utilization of 75 percent.

First, suppose we assign P2 a higher priority than P1.

Page 35: Chapter 19 Real-Time Systems

Example - continueExample - continue

Now suppose we use rate monotonic scheduling, in which we assign P1 a higher priority than P2.

Page 36: Chapter 19 Real-Time Systems

Missing Deadline with Missing Deadline with rate monotonic rate monotonic schedulingscheduling

Assume that Process P1 has a period of p1 = 50 and CPU burst of t1 = 25.

For P2, the corresponding values are p2 = 80 and t2 = 35.

The total CPU utilization of the two processes is (25/50) + (35/80) = 0.94.

Page 37: Chapter 19 Real-Time Systems

LimitationLimitation CPU utilization is bounded.

The worst case CPU utilization for scheduling N processes is 2(2^(1/n)-1).

◦ With one process in the system, CPU utilization is 100 percent, but it falls to approximately 69 percent as the number of processes approaches infinity.

◦ With two processes, CPU utilization is bounded at about 83 percent.

Page 38: Chapter 19 Real-Time Systems

Earliest Deadline Earliest Deadline First SchedulingFirst Scheduling

It dynamically assigns priorities according to deadline.◦ The earlier the deadline, the higher the priority.◦ The later the deadline, the lower the priority.◦ If two tasks have the same absolute deadlines,

chose one of the two at random (ties can be broken arbitrarily).

Page 39: Chapter 19 Real-Time Systems

ExampleExample

Suppose we have two Process P1 and P2. P1 has values of p1 = 50 and t1 = 25. P2 has values of p2 = 80 and t2 = 35.

Page 40: Chapter 19 Real-Time Systems

Unlike the rate monotonic algorithm, EDF scheduling does not require that processes be periodic, nor must a process require a constant amount of CPU time per burst..◦ The only requirement is that a process announce its

deadline to the scheduler when it becomes runnable.

The appeal of EDF scheduling is that, theoretically it can schedule processes so that each process can meet its deadline requirements and CPU utilization will be 100 percent.◦ It’s impossible due to the cost of context switching

between processes and interrupt handling.

Page 41: Chapter 19 Real-Time Systems

Proportional Proportional Share Share SchedulingScheduling

Associate a weight with each application and allocate CPU bandwidth proportional to weight

T shares are allocated among all processes in the system

An application receives N shares where N < T This ensures each application will receive N / T

of the total processor time

Wt=2

2/3 1/3

Wt=1 Applications

CPU bandwidth

Page 42: Chapter 19 Real-Time Systems

ExampleExample

Assume that a total of T = 100 shares is to be divided among three processes, A, B and C.

A is assigned 50 shares, B is assigned 15 shares, and C is assigned 20 shares.

This scheme ensures that A will have 50 percent of total processor time, B will have 15 percent, and C will have 20 percent.

Page 43: Chapter 19 Real-Time Systems

Proportional Share Proportional Share Scheduling Scheduling

Proportional Share Schedulers must work in conjunction with an admission control policy to guarantee that an application receives its allocated shares of time.◦ An admission control policy will only admit a client

requesting a particular number of shares if there are sufficient shares available.

Page 44: Chapter 19 Real-Time Systems

Pthread Pthread SchedulingScheduling The Pthread (POSIX Thread) Library is set of

functions that enable C/C++ code to spawn multiple “threads” of execution to do multiple tasks simultaneously.

The Pthread API provides functions for managing real-time threads.

Pthreads defines two scheduling classes for real-time threads:

(1) SCHED_FIFO - threads are scheduled using a FCFS strategy with a FIFO queue. There is no time-slicing for threads of equal priority

(2) SCHED_RR - similar to SCHED_FIFO except time-slicing occurs for threads of equal priority

Page 45: Chapter 19 Real-Time Systems

Pthread Scheduling APIPthread Scheduling API#include <pthread.h>#include <stdio.h>#define NUM THREADS 5int main(int argc, char *argv[]){

int i, policy;pthread_t tid[NUM THREADS];pthread_attr_t attr;

/* get the default attributes */pthread _attr_ init(&attr);

/* get the current scheduling policy */if (pthread_attr_getschedulepolicy (&attr, &policy) != 0)

fprintf (stderr, “Unable to get policy.\n”);

Page 46: Chapter 19 Real-Time Systems

Pthread Scheduling APIPthread Scheduling APIelse {

if (policy == SCHED_OTHER)printf(“SCHED_OTHER\n”);

elase if (policy == SCHED_RR)printf(“SCHED_RR\n”);

else if (policy == SCHED_FIFO)printf(“SCHED_FIFO\n”);

}

/* set the scheduling policy - FIFO, RT, or OTHER */if (pthread_attr_setschedpolicy (&attr, SCHED_OTHER) != 0)

/* create the threads */for (i = 0; i < NUM _THREADS; i++)

pthread _create (&tid[i], &attr, runner, NULL);

Page 47: Chapter 19 Real-Time Systems

Pthread Scheduling APIPthread Scheduling API/* now join on each thread */

for (i = 0; i < NUM _THREADS; i++)

pthread _join (tid[i], NULL);

}

/* Each thread will begin control in this function */

void *runner(void *param)

{

/* do some work … */

pthread _exit(0);

}

Page 48: Chapter 19 Real-Time Systems

An Example: An Example: VxWorks 5.xVxWorks 5.x A popular real-time operating system providing

hard real-time support. Commercially developed by Wind River Systems. It is widely used in automobiles, consumer and

industrial devices, and networking equipment such as switches and routers.

It is also used to control the two rovers – Spirit and Opportunity – that began exploring the planet Mars in 2004.

Page 49: Chapter 19 Real-Time Systems

The Organization The Organization of VxWorksof VxWorks

Page 50: Chapter 19 Real-Time Systems

Wind MicrokernelWind Microkernel The Wind microkernel provides support for the

following:

(1) Processes and threads using Pthread API;

(2) preemptive and non-preemptive round-robin scheduling;

(3) manages interrupts (with bounded interrupt and dispatch latency times);

(4) shared memory and message passing as communication between separate tasks. Also allows tasks to communicate using a technique known as pipes. Also provides semaphores and mutex locks with a priority inheritance protocol to prevent priority inversion.

Page 51: Chapter 19 Real-Time Systems

Interesting approach to Interesting approach to memory managementmemory management Supports two levels of virtual memory.

First Level: ◦ Quite simple, allows for control of the cache on a

per-page basis.◦ Enables and application to specify certain pages as

non-cacheable. Second Level:

◦ Virtual memory requires the optional virtual memory component VxVMI along with processor support for a memory management unit(MMU).

◦ VxWorks allows pages containing kernel code along with the interrupt vector to be declared as read-only.

Page 52: Chapter 19 Real-Time Systems

ReferencesReferences

Operating System Concepts, 8th edition by Silberschatz, Galvin and Gange.

www.wikipedia.com

Page 53: Chapter 19 Real-Time Systems

Thank youThank you