CSE 237ACSE 237A Middleware and Operating Systems

42
CSE 237A CSE 237A Middleware and Operating Systems Tajana Simunic Rosing Department of Computer Science and Engineering University of California, San Diego. 1

Transcript of CSE 237ACSE 237A Middleware and Operating Systems

Page 1: CSE 237ACSE 237A Middleware and Operating Systems

CSE 237ACSE 237A Middleware and Operating Systems

Tajana Simunic RosingDepartment of Computer Science and EngineeringUniversity of California, San Diego.

1

Page 2: CSE 237ACSE 237A Middleware and Operating Systems

Soft are componentsSoftware componentsStandard softwareStandard software

e.g. MPEGx, databasesMiddlMiddlewareOperating systems

schedulers

2TSR

Page 3: CSE 237ACSE 237A Middleware and Operating Systems

Middle areMiddlewareBetween applications and OSBetween applications and OSProvides a set of higher-level capabilities and interfacesinterfacesCustomizable, composeable frameworksTypes of services:yp

component – independent of other servicesE.g. communication, information, computation

integrated setsintegrated setse.g. distributed computation environment

integration frameworks

3TSR

Tailor to specific domain: e.g. transaction processing

Page 4: CSE 237ACSE 237A Middleware and Operating Systems

Integrated setsIntegrated setsA t f i th t t k i ifi tA set of services that take significant advantage of each otherExample: Distributed Computing Environment (DCE)

Provides key distributed technologies – RPC, DNS, distributed file system, time synch,

t k it d th d inetwork security and threads serviceFrom Open SW Foundation, supported by

lti l hit t d j SW d4TSR

multiple architectures and major SW vendors

Page 5: CSE 237ACSE 237A Middleware and Operating Systems

DCEDCE

5TSR

Page 6: CSE 237ACSE 237A Middleware and Operating Systems

I t ti f k iddlIntegration frameworks middleware

I t ti i t t il d tIntegration environments tailored to specific domainExamples:

Workgroup frameworkTransaction processing frameworkNetwork management frameworkDistributed object computing (e.g. CORBA, E-SPEAK, JINI, message passing)

6TSR

Page 7: CSE 237ACSE 237A Middleware and Operating Systems

Distrib ted Object Comp tingDistributed Object ComputingAdvantages:Advantages:

SW reusability, more abstract programming, easier coordination among services

Issues:Issues:latency, partial failure, synchronization, complexity

Techniques:Message passing (object knows about network)Argument/Return Passing – like RPC

network data = args + return result + namesSerialzing and sending

network data = obj code + obj state + synch infoShared memory

7TSR

network data = data touched + synch info

Page 8: CSE 237ACSE 237A Middleware and Operating Systems

SW for access to remote objectsSW for access to remote objectsCORBA (Common Object Request Broker Architecture).Information sent to Object Request Broker (ORB) via local stubInformation sent to Object Request Broker (ORB) via local stub. ORB determines location to be accessed and sends information via the IIOP I/O protocol.

8TSRAccess times not predictable.OBJ management architecture

Page 9: CSE 237ACSE 237A Middleware and Operating Systems

Real time CORBAReal-time CORBAEnd-to-end predictability of timeliness in a

fixed priority system.respecting thread priorities between client p g p

and server for resolving resource contention,bounding the latencies of operationbounding the latencies of operation

invocations.RT CORBA includes provisions forRT-CORBA includes provisions for

bounding the time during which priority inversion due to competing resource access

9TSR

inversion due to competing resource access may occur.

Page 10: CSE 237ACSE 237A Middleware and Operating Systems

Message passing interfaceMessage passing interface

Message passing interface (MPI): alternative to CORBAMPI/RT l ti i f MPI [MPI/RTMPI/RT: a real-time version of MPI [MPI/RT forum, 2001].MPI RT does not cover issues such as threadMPI-RT does not cover issues such as thread creation and termination.MPI/RT is conceived as a layer between theMPI/RT is conceived as a layer between the operating system and non real-time MPI.

10TSR

Page 11: CSE 237ACSE 237A Middleware and Operating Systems

Soft are componentsSoftware componentsStandard softwareStandard software

e.g. MPEGx, databasesMiddlMiddlewareOperating systems

Focus on RTOS

11TSR

Page 12: CSE 237ACSE 237A Middleware and Operating Systems

Real-time operating systemsReal-time operating systems

Th k i tThree key requirements1. Predictable OS timing behavior

upper bound on the execution time of OS servicesupper bound on the execution time of OS servicesshort times during which interrupts are disabled,contiguous files to avoid unpredictable head movementsmovements

2. OS must be fast 3. OS must manage the timing and scheduling

OS possibly has to be aware of task deadlines;OS possibly has to be aware of task deadlines;(unless scheduling is done off-line).OS must provide precise time services with high resolution

12TSR

resolution.

Page 13: CSE 237ACSE 237A Middleware and Operating Systems

RTOS-KernelsRTOS-KernelsDistinction between real-time kernels and modified kernels of standard OSeskernels of standard OSes.

Distinction betweenl d RTOS f ifi d igeneral and RTOSes for specific domains,

standard APIs (e.g. POSIX RT-Extension of Unix) or proprietary APIs

13TSR

or proprietary APIs.

Page 14: CSE 237ACSE 237A Middleware and Operating Systems

Ho to organi e m ltiple tasks?How to organize multiple tasks?C clic e ec ti e (Static table dri en sched ling)Cyclic executive (Static table driven scheduling)

static schedulability analysisresulting schedule or table used at run timeg

Event-driven non-preemptivetasks are represented by functions that are handlers for eventsnext event processed after function for previous event finishes

Static and dynamic priority preemptive schedulingstatic schedulability analysisstatic schedulability analysisat run time tasks are executed “highest priority first”Rate monotonic, deadline monotonic, earliest deadline first, least l k

14TSR

slack

Page 15: CSE 237ACSE 237A Middleware and Operating Systems

RTOS Organization: gCyclic Executive

Application Application Application

I/O S i

pp pp pp

Kernel Mode

Device Drivers

Network Drivers

I/O Services

TCP/IPTCP/IP Stack

15TSR

Hardware

Page 16: CSE 237ACSE 237A Middleware and Operating Systems

RTOS Organization: gMonolithic Kernel

Application Application Application

User Mode(protected)

Kernel ModeFilesystems I/O Managers Graphics

SubsystemDevice Drivers

Network Drivers

SubsystemGraphics Drivers Other….

16TSR HardwareHardware Interface Layer

Page 17: CSE 237ACSE 237A Middleware and Operating Systems

RTOS Organization: gMicrokernel

Network Drivers H

a

Network Manager

ard

Graphics Drivers

Application

ApplicationPhoton

Device Drivers

war

Fil t

Application

Fil t

Device Manager

User Mode(protected)

eFilesystem Manager

Filesystem Drivers

17TSRKernel Mode Kernel (tiny)

Page 18: CSE 237ACSE 237A Middleware and Operating Systems

Types of RTOS Kernelsyp1. Fast proprietary kernels

designed to be fast, rather than predictableInadequate for complex systemsInadequate for complex systemsExamples include

QNX, PDOS, VCOS, VTRX32, VxWORKS.

18TSR

Page 19: CSE 237ACSE 237A Middleware and Operating Systems

E ample V WorksExample: VxWorks

19TSR© Windriver

Page 20: CSE 237ACSE 237A Middleware and Operating Systems

V Works Config rationVxWorks Configuration

_ds.

pdf

rnad

o2/to

rnad

o_2_

men

t_to

ols/

ide/

tor

/pro

duct

s/de

velo

pmw

w.w

indr

iver

.com

/

20TSR © Windriver

http

://w

w

Page 21: CSE 237ACSE 237A Middleware and Operating Systems

Types of RTOS KernelsTypes of RTOS Kernels2. Standard OS with real-time extensions

RT k l i ll RT t kRT-kernel running all RT-tasks.Standard-OS executed as one task.

+ Crash of standard-OS does not affect RT-tasks;- RT-tasks cannot use Standard-OS services;

21TSR

less comfortable than expected

Page 22: CSE 237ACSE 237A Middleware and Operating Systems

E ample RT LinExample: RT-LinuxInit Bash Mozilla

scheduler

RT-Task RT-TaskLinux-Kernel

driver

RT-Linux RT-Schedulerinterrupts

interrupts

Hardware

RT Linuxinterrupts

interruptsI/O

22TSR

Hardware

Page 23: CSE 237ACSE 237A Middleware and Operating Systems

E ample Posi 1 b RTExample: Posix 1.b RTStandard scheduler can be replaced by POSIXStandard scheduler can be replaced by POSIX scheduler implementing priorities for RT tasks

S i l RT &Init Bash MozillaRT-Task RT-Task

Special RT & standard OS calls available

Linux KernelPOSIX 1.b scheduler

calls available.Easy programmingLinux-Kernel

driver

/O

programming, no guarantee for meeting

23TSRHardware

I/O, interrupts g

deadline

Page 24: CSE 237ACSE 237A Middleware and Operating Systems

Types of RTOS KernelsTypes of RTOS Kernels3. Research systems

Research issueslow overhead memory protection,low overhead memory protection,temporal protection of computing resources RTOSes for on-chip multiprocessorssupport for continuous mediaquality of service (QoS) control.

24TSR

Page 25: CSE 237ACSE 237A Middleware and Operating Systems

Kernel e amplesKernel examplesS ll k lSmall kernels

PALOS, TinyOSMedium size

uCos II, eCosLarger

RT Linux, WinCERT Linux, WinCE

25TSR

Page 26: CSE 237ACSE 237A Middleware and Operating Systems

E ample I PALOSExample I: PALOSStructure – PALOS Core, Drivers, Managers, and user defined TasksPALOS Core

Task control: slowing, stopping, resumingPeriodic and aperiodic handling and schedulingInter-task Communication via event queuesEvent-driven tasks: task routine processes events stored in event queues p q

DriversProcessor-specific: UART, SPI, Timers.. Platform-specific: Radio, LEDs, Sensors

Small FootprintSmall Footprint Core (compiled for ATMega128L) Code Size: 956 Bytes , Mem Size: 548 BytesTypical( 3 drivers, 3 user tasks) Code Size: 8 Kbytes, Mem Size: 1.3 Kbytes

Task 1

PALOSCore TA

SK 1

K 2

TASK

5

TASK

N

K 3

TASK 4 Task 2 Task 3

PALOS

26TSR Drivers (Hardware Abstraction Layer)

Manager

T

TAS

TAS

Task 3 Event Q

PALOSCore

Page 27: CSE 237ACSE 237A Middleware and Operating Systems

Execution control in PALOSExecution control in PALOSEach task has a task counterCounters initialized to:

0: normal>>:0 slowdown-1: stop>=0: restart

D t d

TASK 1

TASK 2

Task Routine

Event Q

Task Routine

Event QMain

Control Decremented 1) every iteration

(relative timing) 2) by timer interrupts

PALOSTaskTable

TASK 3

Event Q

Task Routine

Event Q

ControlLoop

2) by timer interrupts (exact timing)

If counter = 0, call taks; reset counter to

TASK NTask Routine

Event Q

27TSR

reset counter to initialization value

Page 28: CSE 237ACSE 237A Middleware and Operating Systems

E ent Handlers in PALOSEvent Handlers in PALOS

Periodic or Handler 1

Handler 2

Handler 3

aperiodic events can be scheduled using Delta Q andTask 2

Task 1

TimerTask using Delta Q and

Timer InterruptWhen event expires Expired Event Q

Task

appropriate event handler is called

Delta Q

Timer PALOS

28TSR

TimerInterrupt

PALOSCore

Page 29: CSE 237ACSE 237A Middleware and Operating Systems

Example II: TinyOSExample II: TinyOSSystem composed of

scheduler, graph of components, execution contextComponent modelComponent model

Basically FSMsFour interrelated parts of implementation

Encapsulated fixed-size frame (storage)A set of command & event handlersA b dl f i l t k ( t ti )A bundle of simple tasks (computation)

Modular interfaceCommands it uses and acceptsEvents it signals and handles

Tasks, commands, and event handlersExecute in context of the frame & operate on its stateCommands are non-blocking requests to lower level componentsEvent handlers deal with hardware eventsTasks perform primary work, but can be preempted by p p y p p yevents

Scheduling and storage modelShared stack, static framesEvents prempt tasks, tasks do notEvents can signal events or call commands

Messaging Component

Internal StateInternal Tasks

29TSR

Events can signal events or call commandsCommands don’t signal eventsEither can post tasks

Commands Events

Page 30: CSE 237ACSE 237A Middleware and Operating Systems

Tin OS O er ieTinyOS OverviewStylized programming model with extensive static informationy p g g

Compile time memory allocationEasy migration across h/w -s/w boundarySmall Software Footprint - 3.4 KB T l l h d li t tTwo level scheduling structure

Preemptive scheduling of event handlersNon-preemptive FIFO scheduling of tasksBounded size scheduling data structureBounded size scheduling data structure

Rich and Efficient Concurrency SupportEvents propagate across many componentsTasks provide internal concurrency

C fPower Consumption on Rene PlatformTransmission Cost: 1 µJ/bitInactive State: 5 µAPeak Load: 20 mA

30TSR

Peak Load: 20 mAEfficient Modularity - events propagate through stack <40 µS

Page 31: CSE 237ACSE 237A Middleware and Operating Systems

Complete Tin OS ApplicationComplete TinyOS Application

31TSR Ref: from Hill, Szewczyk et. al., ASPLOS 2000

Page 32: CSE 237ACSE 237A Middleware and Operating Systems

E ample III COS IIExample III: µCOS-IIPortable ROMable scalable preemptivePortable, ROMable, scalable, preemptive, multitasking RTOSServicesServices

Semaphores, event flags, mailboxes, message queues, task management, fixed-size memory block management time managementmanagement, time management

Source freely available for academic non-commercial usage for many platformsg y p

Value added products such as GUI, TCP/IP stack etc.

32TSR

Page 33: CSE 237ACSE 237A Middleware and Operating Systems

E ample IV eCosExample IV: eCosEmbedded, Configurable OS, Open-sourceSeveral scheduling options

bit-map scheduler, lottery scheduler, multi-level schedulerThree-level processingThree-level processing

Hardware interrupt (ISR), software interrupt (DSR), threadsInter-thread communication

Mutex, semaphores, condition variables, flags, message boxPortable - Hardware Abstraction Layer (HAL)Based on configurable componentsBased on configurable components

Package based configuration toolKernel size from 32 KB to 32 MB

33TSR

Implements ITRON standard for embedded systemsOS-neutral POSIX compliant EL/IX API

Page 34: CSE 237ACSE 237A Middleware and Operating Systems

E ample V Real time LinExample V: Real-time LinuxMicrocontroller (no MMU) OSes:( )

uClinux - small-footprint Linux (< 512KB kernel) with full TCP/IP

Q S t i f d ktQoS extensions for desktop:Linux-SRT and QLinux

soft real-time kernel extensiontarget: media applications

Embedded PCRTLi RTAIRTLinux, RTAI

hard real time OSE.g. RTLinux has Linux kernel as the lowest priority task in a RTOS

34TSR

fully compatible with GNU/LinuxHardHat Linux

Page 35: CSE 237ACSE 237A Middleware and Operating Systems

E ample VI WinCEExample VI: WinCEApplications

Embedded shellRemote connectivity

Applications

Win32 APIs

WinCE shell servicesy

Kernellibrary GWES Device

managerFile

manager IrDA TCP/IP

OEM h d

OALbootload drivers Device

driversFile

driversNetworkdrivers

35TSR

OEM hardware

Page 36: CSE 237ACSE 237A Middleware and Operating Systems

Virt al memorVirtual memoryWinCE ses irt al memorWinCE uses virtual memory.Code can be paged from ROM, etc.Wi CE t fl t 32 bit i t l ddWinCE suports a flat 32-bit virtual address space.Vi t l dd bVirtual address may be:

Statically mapped (kernel-mode code).Dynamically mapped (user mode and some kernelDynamically mapped (user-mode and some kernel-mode code).

Address space: bottom half user, top kernel

36TSR

p , p

Page 37: CSE 237ACSE 237A Middleware and Operating Systems

Dri er str ct reDriver structureDriver = DLL with particular interface pointsDriver = DLL with particular interface points.Hosted by a device manager process space H dl i t t b d di t d IST th dHandle interrupts by dedicated IST thread.Synchronize driver and application via critical

ti d MUTEXsections and MUTEXes.

37TSR

Page 38: CSE 237ACSE 237A Middleware and Operating Systems

De ice managerDevice managerAlways running user level processAlways-running user-level process.Contains the I/O Resource Manager.Loads the registry enumerator DLL which in turnLoads the registry enumerator DLL which in turn loads drivers.

RegEnum scans registry, loads bus drivers.Bus driver scans bus, locates devices.Searches registry for device information.Loads appropriate driversLoads appropriate drivers.Sends notification that interface is available.

Provides power notification callbacks.

38TSR

Provides power notification callbacks.

Page 39: CSE 237ACSE 237A Middleware and Operating Systems

Interr pt handlingInterrupt handlingInterrupt service routine (ISR):Interrupt service routine (ISR):

Kernel mode service.May be static or installable.

Interrupt service thread (IST):Interrupt service thread (IST):User mode thread.

IST processing

ISR ISR

ISR ISR

ISH Set event Enable ID

39TSR

All higherenabled

All enabledExcept ID All enableddevice

Page 40: CSE 237ACSE 237A Middleware and Operating Systems

Kernel sched lerKernel schedulerTwo styles of preemptive multitaskingTwo styles of preemptive multitasking.

Thread runs until end of quantum.Thread runs until higher priority thread is ready to run.g p y y

Round-robin within priority level.Quantum is defined by OEM and application.yPriority inheritance to control priority inversion.256 total priorities.

Top 248 can be protected by the OEM.

40TSR

Page 41: CSE 237ACSE 237A Middleware and Operating Systems

S mmarSummarySWSW

MPEG decode etc.Middleweare

E.g DCE, CORBARTOS

E.g TinyOS, eCos, RT-Linux, WinCEE.g TinyOS, eCos, RT Linux, WinCE

41TSR

Page 42: CSE 237ACSE 237A Middleware and Operating Systems

Sources and References

Peter Marwedel, “Embedded Systems D i ” 2004Design,” 2004.Wayne Wolf, “Computers as Components,” Morgan Kaufmann, 2001. Nikil Dutt @ UCI@Mani Srivastava @ UCLA

42TSR