Chapter 4 Introduction to Real-Time Operating Systems 4.pdf · Introduction A real-time operating...

34
Chapter 4 Introduction to Real-Time Operating Systems

Transcript of Chapter 4 Introduction to Real-Time Operating Systems 4.pdf · Introduction A real-time operating...

Chapter 4Introduction to Real-Time Operating Systems

OutlineIntroductionA Brief History of Operating SystemsDefining an RTOSThe SchedulerObjectsServicesKey Characteristics of an RTOS

IntroductionA real-time operating system (RTOS) is key to many embedded systems todayNot all embedded systems, however, are designed with an RTOS

A Brief History of Operating SystemsIn the early days, developers created software applications that included low-level machine code

To initialize and interact with the hardwareResult in no-portable, bug-prone application

Operating system thus provides the basic software foundation

Facilitate the abstraction of the underlying hardware

A Brief History of Operating Systems (Cont.)

General-purpose operating system (GPOS)UNIX

In the 60s and 70s, multi-user access to expensive mid-sized and mainframe computing systemEventually, ported to all types of machines

Microsoft WindowsDrive the personal-computing era

Real-time operating systemFor post-PC, embedded-computing era

VxWork, uClinux…

Similarities Between a RTOS and GPOS

Some level of multitaskingSoftware and hardware resource managementProvision of underlying OS services to applicationAbstracting the hardware from the software application

Difference Between a RTOS apart GPOS

Better reliability in embedded application contextsThe ability to scale up and down to meeting application needsFaster performanceReduced memory requirementsScheduling policies tailored for real-time embedded systemsSupport for diskless embedded systems by allowing executables to boot and run from ROM or RAMBetter portability to different hardware platforms

Defining an RTOSA program that

Schedules execution in a timely mannerManage system resourcesProvide a consistent foundation for developing application code

Besides, a good RTOS should be scalableTo meeting different requirements for different applications

Defining an RTOS (Cont.)For example, an RTOS is a combination of various modules

KernelProvide minimal logicSchedulingResource-management algorithms

File systemNetwork protocol stacks……

High-Level View of an RTOS

RTOS KernelScheduler

Determine which task executes when

ObjectsSpecial kernel construct that helps developer create applicationsTasks, semaphores, and message queues

ServicesOperations that the kernel performs on an objectTiming, interrupt handling, and resource management

Common Components in an RTOS kernel

The SchedulerAt the heart of every kernelRelated topics

Schedulable entitiesMultitaskingContext switchingDispatcherScheduling algorithms

Schedulable EntitiesA kernel object that can compete for execution time on a systemTask or processes

An independent thread of execution that contains a sequence of independently schedulable instructions

MultitaskingThe ability of the OS to handle multiple activities within set deadlinesMany thread of execution appear to be running concurrently

However, they are actually interleaved executions sequentially

The Context SwitchContext: the state of the CPU registers required for tasks’ running

Occurred when a scheduler switches from one task to anotherWhen a task running, its context is highly dynamic

TCB: Task Control BlockA data structure used by the kernel to maintain task-specific information

The contact of a task is stored in its TCB

Multitasking Using a Context Switch

The Context Switch (Cont.)Steps in context switches

The kernel save task 1’s context information in its TCBIt loads task 2’s context information from its TCB, which becomes the current thread of executionThe context of task 1 is frozen while task 2 executes

The DispatcherThe part of scheduler that performs context switching and changes the flow of executionThree areas that is passed through by the flow of execution (or flow of control)

Through an application taskThrough an ISRThrough the kernel

The Dispatcher (Cont.)A task or ISR makes a system call

Flow of control is passed the kernel to execute one of system routinesWhen leaving the kernel

Dispatch passes control to one of user applicationsNotably, not necessary the original one made the system callDepend on the scheduling algorithm

Scheduling AlgorithmsAlso called scheduling policyTwo common scheduling algorithms

Preemptive priority-based schedulingRound-robin scheduling

Developers can create and define their own scheduling algorithms

Preemptive Priority-Based SchedulingMost real-time kernels use preemptive priority-based scheduling by defaultReal-time kernel generally support 256 priority tasksPriority assignment

Static: assign priority to tasks when createdDynamic: priority can be changed dynamically

Preemptive Priority-Based Scheduling

Round-Robin SchedulingProvide each task an equal share of the CPU execution timePure RR (Round-Robin) scheduling cannot satisfy real-time system requirementsPriority-based scheduling can be augmented with round-robin scheduling

Equal allocation of CPU time for tasks of the same priority

Round-Robin and Preemptive Scheduling

ObjectsSpecial constructs that are the building blocks for application development

TasksSemaphoresMessage Queues

ServicesSets of API calls that can be used to

Perform operations on kernel objectsFacilitate

Timer managementInterrupt handlingDevice I/OMemory management

Key Characteristics of an RTOSReliabilityPredictabilityPerformanceCompactnessScalability

ReliabilityA reliable system

Be available (continue to provide service) and does not fail

Quantified by the download per yearNumber of 9s: the percent of the total time that a system must be available

To determine system reliabilityThe combination of all system elements determines the reliability of a system

Hardware, BSP, RTOS, and application-

Categorizing Highly Available Systems by Allowable Downtime

PredictabilityFor real-time systems, the RTOS needs to be predictable

The completion of operating system calls occurs within known timeframes

PerformanceProcessor’s performance

MIPS: million instructions per secondThrough may used to measure the overall performance of a systemCall-by-call method may be used to measure RTOS performance

Produce timestamps when a system call starts and when it completes

CompactnessTo determine how compact an embedded system be

Application design constraints Cost constraints

For example, a cell phone must be small, portable and low cost

Limit system memoryLimit the size of application and operating system

ScalabilityRTOSes can be used in a wide variety of embedded systems

Be able to scale up or down to meet application-specific requirements

For example, a RTOS may be used in both a cellular phone project and a base station project

Save time and money