Real Time Operating Systems

35
Real-Time Systems Introduction to Real-Time Systems 1

description

y

Transcript of Real Time Operating Systems

Slide 1

Real-Time Systems Introduction to Real-Time Systems1Real-time Systems -- IntroductionReal-time systems are defined as those systems in which the correctness of the system depends not only on the logical result of computation, but also on the time at which the results are produced.

Hard real-time systems (e.g., Avionic control).

Firm real-time systems (e.g., Banking).

Soft real-time systems (e.g., Video on demand). 2Real-time Systems -- IntroductionHard Deadline: Penalty due to missing deadline is a higher order of magnitude than the reward in meeting the deadlineFirm Deadline: Penalty and reward are in the same order of magnitudeSoft Deadline: Penalty often lesser magnitude than reward3A typical REAL-TIME System

45Example Car driverMission: Reaching the destination safely.

Controlled System: Car.

Operating environment: Road conditions.

Controlling System - Human driver: Sensors - Eyes and Ears of the driver. - Computer: Sensors - Cameras, Infrared receiver, and Laser telemeter.

Controls: Accelerator, Steering wheel, Break-pedal.

Actuators: Wheels, Engines, and Brakes.

6Example Car driver (contd)Critical tasks: Steering and breaking.

Non-critical tasks: Turning on radio.

Performance is not an absolute one. It measures the goodness of the outcome relative to the best outcome possible under a given circumstance.

Cost of fulfilling the mission Efficient solution.

Reliability of the driver Fault-tolerance is a must.

7Real-Time Systems - IssuesResource Management (RM) IssuesScheduling, Fault-tolerance, Resource reclaiming, Communication

Architectural IssuesComputing subsystem, Communication subsystem, I/O subsystem

Software IssuesRequirements, specification, and verification, Real-time languages, Real-time databases

8Preemptive vs Non-preemptive schedulingPreemptive SchedulingTask execution is preempted and resumed later Preemption occurs to execute higher priority task. Offers higher schedulability Involves higher scheduling overhead due to context switching

Non-preemptive Scheduling Once a task starts executing, it completes its full executionOffers lower schedulabilityLess overhead due to less context switching9Architectural IssuesPredictability in Instruction execution time, Memory access, Context switching, Interrupt handling.

RT systems usually avoid caches and superscalar features.

Support for error handling (self-checking circuitry, voters, system monitors).

Support for fast and reliable communication (routing, priority handling, buffer and timer management).10Introduction: SummaryReal-time systems require logical correctness and timeliness.

Real-time system consists of a controlling system, controlled system, and the environment.

Real-time systems are classified as: hard, firm, and soft RT systems.

Workload (tasks) are periodic, aperiodic.

The notion of predictability is very important in real-time systems.

Important issues include: scheduling, resource reclaiming, fault-tolerance, communication, architectural issues, system specification and verification, programming languages, and databases.

Role of an OS in Real Time SystemsStandalone ApplicationsOften no OS involvedMicro controller based Embedded Systems Some Real Time Applications are huge & complexMultiple threadsComplicated Synchronization RequirementsFilesystem / Network / Windowing supportOS primitives reduce the software design time

Real-Time Operating System An RTOS is an OS for response time-controlled and event-controlled processes. It is very essential for large scale embedded systems.

RTOS occupy little space from 10 KB to 100KB

The main task of a RTOS is to manage theresources of the computer such that a particular operation executes in precisely the same amount of time every time it occur.

Renesas automotive dashboard platform.Features of RTOSsScheduling.

Resource Allocation.

Interrupt Handling.

Other issues like kernel size.Scheduling in RTOSMore information about the tasks are knownNo of tasksResource RequirementsRelease TimeExecution timeDeadlinesBeing a more deterministic system better scheduling algorithms can be devised.Scheduling Algorithms in RTOSClock Driven Scheduling

Weighted Round Robin Scheduling

Priority Scheduling (Greedy / List / Event Driven)

Scheduling Algorithms in RTOS (contd)Clock DrivenAll parameters about jobs (release time/ execution time/deadline) known in advance.Schedule can be computed offline or at some regular time instances.Minimal runtime overhead.Not suitable for many applications.Scheduling Algorithms in RTOS (contd)Weighted Round RobinJobs scheduled in FIFO mannerTime quantum given to jobs is proportional to its weightExample use : High speed switching networkQOS guarantee.Not suitable for precedence constrained jobs.Job A can run only after Job B. No point in giving time quantum to Job B before Job A. Job1 = Total time to complete 250 ms (quantum 100 ms).First allocation = 100 ms.Second allocation = 100 ms.Third allocation = 100 ms butjob1self-terminates after 50 ms.Total CPU time ofjob1= 250 ms

For example, if the time slot is 100 milliseconds, andjob1takes a total time of 250 ms to complete, the round-robin scheduler will suspend the job after 100 ms and give other jobs their time on the CPU. Once the other jobs have had their equal share (100 ms each),job1will get another allocation ofCPUtime and the cycle will repeat. This process continues until the job finishes and needs no more time on the CPU.Job1 = Total time to complete 250 ms (quantum 100 ms).First allocation = 100 ms.Second allocation = 100 ms.Third allocation = 100 ms butjob1self-terminates after 50 ms.Total CPU time ofjob1= 250 msScheduling Algorithms in RTOS (contd)Priority Scheduling (Greedy/List/Event Driven)Processor never left idle when there are ready tasksProcessor allocated to processes according to prioritiesPriorities static - at design timeDynamic - at runtimeBurstWaitingTurnaroundProcessTimePriorityTimeTime10361611012416181518195216Average--8.212Nested Preemption Priority Scheduling

Timeline for Priority-based Preemptive SchedulingResource Allocation in RTOS Resource AllocationThe issues with scheduling applicable here.Resources can be allocated inWeighted Round Robin Priority BasedSome resources are non preemptibleDynamic Memory Allocation in RTOSDevice I/O and Time Management

Solutions to Priority Inversion Non Blocking Critical SectionHigher priority Thread may get blocked by unrelated low priority threadPriority CeilingEach resource has an assigned priorityPriority of thread is the highest of all priorities of the resources its holdingPriority InheritanceThe thread holding a resource inherits the priority of the thread blocked on that resourceOther RTOS issuesInterrupt Latency should be very smallKernel has to respond to real time eventsInterrupts should be disabled for minimum possible timeFor embedded applications Kernel Size should be smallShould fit in ROMSophisticated features can be removedNo Virtual MemoryNo Protection

Peripheral devices and protocols Interfacing Serial/parallel ports, USB, I2C, PCMCIA, IDE Communication Serial, Ethernet, Low bandwidth radio, IrDA, 802.11b based devices User Interface LCD, Keyboard, Touch sensors, Sound, Digital pads, Webcams Sensors A variety of sensors using fire, temperature, pressure, water level, seismic, sound, visionExample of RtosWind River SystemsVxWorkspSOSQNX Software SystemsQNXMentor Graphics VRTXPalm ComputingPalmOSMobile OSSymbianOS

Linux basedEmbedded Debian Projectconvert Debian to an embedded OSETLinuxfor PC104 SBCsuCLinuxfor microprocessors that dont have MMuLinux (muLinux)distro fits on a single floppy

25RT-Linux Introduction

26ContentsReal-Time Operating System (RTOS) Vs. General Purpose OS (GPOS)

Can Linux provide real-time guarantees?

Commercial RTOSs

RTLinux Vs. Linux: Architectural comparison

RTLinux Vs. Linux: Code perspective

27RTOS Vs. GPOS

RTOSneeds deterministic timing behaviorWorks under worst case assumptions

GPOShigh throughput and fairnessOptimizes for the average case

Hence, the design objectives of the OSs are different

28Can Linux provide real-time guarantees?-- No!!Linuxnon-preemptible kernelA system call might take long time to completeTasks can be released only with 10ms precisionVirtual memoryIntroduces unpredictable amount of delaysVariable priorityEach task is assigned a priority which varies over the time; this is to achieve fairness29Can Linux provide real-time guarantees?-- No!! (contd..)LinuxLinux will batch several operations for efficient use of H/W delaying all tasks

Linux also reorders requests from multiple processes for H/W efficiency

Linux does not preempt low priority task in a system call, instead queues the high priority task

Linux makes high priority tasks to wait for low priority tasks to release resources

Therefore, Linux cannot provide real-time guarantees30Commercial RTOSRTLinux Monolithic kernel with loadable modules

QNX Microkernel approach

VxWorks Monolithic kernel

LynxOS Microkernel

ARTS, Spring, KURT, RTAI, etc.

31Open source Linux project

Supports x86, PowerPC, Alpha

Available as a patch to the regular Linux kernel

Provides an RT API for developers

Runs Linux kernel as lowest priority process

RTLinux: Overview32Linux KernelSystem librariesDevice driversLinux kernelHardwareI/OHardware InterruptsUser Processes33RTLinux KernelHardwareSystem librariesDevice driversLinux kernelI/OSoftware InterruptsUser ProcessesRTLinux Plug-inReal Time TasksRT-SchedulerI/OHardware InterruptsLinux is executed in the backgroundDirect h/w access34Linux Kernel: code perspectiveLinux Monolithic kernel coreM1M2M3M4Kernel Loadable ModulesRAMDISKModule M2 service (system call)User ProcessM2THE controller

35RTLinux Kernel: code perspectiveLinux Monolithic kernel coreRTM2RTM3M1M2Kernel Loadable ModulesRAMDISKLoad RT coreRT Load command

RT-Core ModuleRT coreM3THE controller