• No results found

Real Time Kernels

N/A
N/A
Protected

Academic year: 2021

Share "Real Time Kernels"

Copied!
39
0
0

Loading.... (view fulltext now)

Full text

(1)

RTOS

RTOS

Lecture 9:

Lecture 9: Real-TReal-Time Kernelsime Kernels Reference: Real-T

Reference: Real-Time Systems ime Systems Design and Analysis byDesign and Analysis by Philip

(2)

Real-Time Kernel

Real-Time Kernel

● RRTOS must provide for three specific functions TOS must provide for three specific functions with respect towith respect to

tasks: tasks: ● ● SchedulingScheduling ● ● DispatchingDispatching ● ● IntercommunicationIntercommunication ● ● SynchronizationSynchronization ●

● The Kernel of the operating system is the smallest portion thatThe Kernel of the operating system is the smallest portion that

 provides for these functions.

 provides for these functions. ●

● A A scheduler determines which task will scheduler determines which task will run next in a mulrun next in a multi-taskingti-tasking

system.

system. ●

● Dispatcher performs book-keeping to start that task.Dispatcher performs book-keeping to start that task.

● Intertask communication & synchronization assures that the tasksIntertask communication & synchronization assures that the tasks

cooperate.

(3)

Real-Time Kernel

Real-Time Kernel

● RRTOS must provide for three specific functions TOS must provide for three specific functions with respect towith respect to

tasks: tasks: ● ● SchedulingScheduling ● ● DispatchingDispatching ● ● IntercommunicationIntercommunication ● ● SynchronizationSynchronization ●

● The Kernel of the operating system is the smallest portion thatThe Kernel of the operating system is the smallest portion that

 provides for these functions.

 provides for these functions. ●

● A A scheduler determines which task will scheduler determines which task will run next in a mulrun next in a multi-taskingti-tasking

system.

system. ●

● Dispatcher performs book-keeping to start that task.Dispatcher performs book-keeping to start that task.

● Intertask communication & synchronization assures that the tasksIntertask communication & synchronization assures that the tasks

cooperate.

(4)

Layers of an Operating System

(5)

Different types of Real-Time Kernels

● Pseudo-kernels

● Interrupt-Driven System

● Pre-emptive Priority System ● Hybrid Systems

(6)

Pseudokernels

● Real-Time multi-tasking can be achieved without interrupts and even without an operating system per se.

● When feasible, Following approaches may be utilized:

● Polled-loop

● Synchronized polled-loop ● Cyclic Executives

● State-driven code ● Coroutines

(7)

Polled-loops

● Used for fast response to single devices.

● a single and a repetitive instruction is used to test a flag that indicates

whether or not some event has occurred. If the event has not occurred, then the polling continues.

● Example: Software system to handle packets of data arriving at a rate

(8)

● Polled-loop schemes work well when a single

processor is dedicated to handling the I/O for 

some fast device and when overlapping of events is not allowed or minimized.

● They are ordinarily implemented as a background

task in an interrupt-driven system, or as a task in a cyclic executive.

● Polled-loops are excellent for handling high-speed

data channels, especially when the events occur at widely dispersed intervals.

● Polled-loops can not handle complex systems and

(9)

Synchronized Polled Loops

● A variation of polled-loop that uses a fixed clock interrupt to  pause between the time when the signaling event is triggered

and then reset.

● It is used for overcoming the false alarms generated due to switch bounce phenomenon.

● Example: suppose a polled-loop system is used to handle an event that occurs randomly, but no more than once per 

second. The event is known to exhibit a switch-bounce effect that disappears after 20 milliseconds. A 10-millisecond fixed-rate interrupt is available for synchronization. The event is signaled by an external device that sets a memory location via DMA.

(10)

for(;;) { /* do forever */ if(flag) /* check flag */ {

pause(20); /* wait 20 ms */ process_event(); /* process event */

flag=0; /* reset flag */ }

}

(11)

Cyclic Executives

● Cyclic executives are noninterrupt-driven systems that can

provide the illusion of simultaneity by taking advantage of 

relatively short processes on a fast processor in a continuous loop.

●  A de-facto cycle rate is established which is same for each

(12)

● Different rate structures

can be achieved by repeating a task in the list.

● Example: Space Invader 

 prog.

● Cyclic Executives are

used only for simplest of  real-time systems

 because of the

difficulties in uniformly dividing the processes and in the long response times that are created.

(13)

State-Driven Code

● Uses nested if–then statements, case statements, or finite state

automata to break up the processing of functions into code segments.

● The separation of processes allows each to be temporarily suspended

 before completion, without loss of critical data. This facilitates multi-tasking via scheme such coroutines.

● State-driven code works well in conjunction with cyclic executives

when the processes are too long or nonuniform in size.

● Finally, because mathematical techniques for reducing the number of 

states exist, programs based on finite state machines (FSMs) can be formally optimized.

●  Not all processes lend themselves naturally to division into states; some

 processes are therefore unsuitable for this technique.

● In addition, the tables needed to implement the code can become quite

large and the manual translation process from the finite state automaton to tabular form is error-prone.

(14)

Co-routines

● These types of kernels are employed in conjunction with

code-driven by finite state automata.

● In this scheme, two or more processes are coded in the

state-driven fashion and after each phase is complete, a call is made to a central dispatcher.

● The dispatcher holds the program counter for a list of 

 processes that are executed in round-robin fashion; that is, it

selects the next process to execute.

●  Note that if there is only one coroutine, then it will be

repeated cyclically. Such a system is called a cycle executive.

(15)

● Communication between the processes is achieved

via global variables.

● Example: Consider a system in which two processes

are executing “in parallel” and in isolation.

● After executing phase_a1, process_a returns control to

the central dispatcher by executing break.

● The dispatcher initiates process_b, which executes

 phase_b1 to completion before returning control to the dispatcher.

● The dispatcher then starts process_a, which begins

 phase_a2, and so on.

●  state_a and state_b are state counters that are global

(16)
(17)

Interrupt-Driven System

● The main program is a single jump-to-self instruction.

● The various tasks in the system are scheduled via either hardware or 

software interrupts, whereas dispatching is performed by the interrupt-handling routines.

● Hardware Scheduling

● Clock or external devices issues interrupt signals that are directed

to interrupt controller.

● The interrupt controller issues interrupt signals, depending on

the order of arrival and priority of the interrupts involved.

● If the computer architecture supports multiple interrupts, then the

hardware handles dispatching as well. If only a single interrupt level is available, then the interrupt-handling routine will have to read the interrupt vector on the interrupt controller, determine which interrupts occurred, and dispatch the appropriate tasks.

(18)

Interrupt Service Routines

● When an interrupt occurs, a particular ISR is

executed by the CPU.

● Regardless of the type of ISR to be written, a

snapshot of the machine – called the context – must be preserved upon switching tasks so that it can be restoredupon resuming the interrupted process.

● Reentrant code can execute simultaneously in

(19)

Context-Switching

● Context switching is the process of saving and restoring sufficient

information for a real-time task so that it can be resumed after being interrupted.

● Context-switching time is a major contributor to response time.

Therefore, it must be minimized.

● The stack model for context switching is used mostly in embedded

systems where the number of real-time or interrupt-driven tasks is fixed.

● In the stack model, each interrupt handler is associated with a

hardware interrupt and is invoked by the CPU, which vectors to the instruction stored at the appropriate interrupt-handler location.

● The context is then saved to a specially designated memory area that

can be static, in the case of a single-interrupt system, or a stack, in the case of a multiple-interrupt system.

(20)
(21)

Preemptive-Priority Systems

●  A higher-priority task is said to preempt a

lower-priority task if it interrupts the lower-lower-priority task.

● Systems that use preemption schemes instead of 

round-robin or first-come-first-served scheduling are called preemptive-priority systems.

● Prioritized interrupts can be either fixed priority or 

dynamic priority.

● Fixed priority systems are less flexible, since the task

priorities cannot be changed. Dynamic-priority

systems can allow the priority of tasks to be adjusted at runtime to meet changing process demands.

(22)

● Preemptive-priority schemes can suffer from resource

hogging by higher priority tasks. This can lead to a lack of available resources for lower-priority tasks. In this case, the lower-priority tasks are said to be facing a problem called starvation.

●  A special class of fixed-rate preemptive-priority

interrupt-driven systems, called rate-monotonic

systems, comprises those real-time systems where the priorities are assigned so that the higher the

(23)

Hybrid Systems

● Hybrid systems include interrupts that occur at both fixed

rates and sporadically.

● The sporadic interrupts can be used to handle a critical error 

that requires immediate attention, and thus have highest priority.

●  Another type of hybrid system found in commercial

operating systems is a combination of round-robin and preemptive systems.

● In these systems, tasks of higher priority can always preempt

those of lower priority. However, if two or more tasks of the same priority are ready to run simultaneously, then they run in round-robin fashion

(24)

Hybrid-Systems

● Foreground/Background Systems ● Background Processing ● Initialization ● Real-Time Operation ●

(25)

Interrupt-Only System

● Interrupt-only systems are easy to write and typically have fast

response times because process scheduling can be done via hardware.

● Interrupt-only systems are a special case of 

foreground/background systems, which are widely used in embedded systems.

● One weakness of interrupt-only systems, however, is the time

wasted in the jump-to-self loop and the difficulty in providing advanced services. These services include device drivers and interfaces to multiple layered networks.

● Another weakness is vulnerability to malfunctions owing to timing

variations, unanticipated race conditions, hardware failure, and so on.

(26)

Foreground/Background Systems

● Most common architecture for embedded applications. ● Mixture of interrupt-driven or real-time processes

(foreground) + Non-interrupt driven processes (background) ● The foreground tasks run in round-robin, preemptive priority,

or hybrid fashion.

● The background task is fully preemptable by any foreground task 

● All real-time solutions are just special cases of the foreground/background systems.

(27)

● Polled-loop: F/B System

with No FG

● Synchronized loops: Full

F/B system ● State-driven systems: No FG ● Coroutines: Complicated Background process ● Interrupt-only System:  No BG

(28)

Background Processing

●  Not time critical

●  Non-interrupt driven lowest priority tasks ● Should complete to execution whenever cpu

utilization is less than 100% & no deadlocking occurs.

● Example: software watchdog timer, self-testing

 programs, low priority display updates, logging to  printers etc.

(29)

Initialization of F/B System

● Disable interrupts

● Set up interrupt vectors and stacks ● Perform self-test

● Perform system initialization ● Enable interrupts

Initialization is actually the first part of the background  process.

(30)

Real-Time Operation

● Foreground processes are real-time in nature and they

operate as in Interrupt-only System.

● Assume a two address computer system ● Only one interrupt

● EPI and DPI instructions can be used to enable and

disable the interrupt explicitly

● For context-switching purposes, it is necessary to save

the eight general registers, R0-R7, on the stack.

● The address of the interrupt-handler routine (the interrupt

(31)

● Initialization:

(32)

● Background program:

● Context is saved for background process, but not for 

(33)

Pros & Cons of F/B Systems

● F/B Systems have good response time as they rely on

h/w to perform scheduling.

● Drawback: complicated interface to devices and

networks must be written.

● This procedure can be tedious and error-prone.

● these types of systems are best implemented when the

number of foreground tasks is fixed and known a priori.

● Vulnerable to timing variation, unanticipated race

(34)

Task-Control Block Model

● Most popular method for implementing commercial,

full-featured, real-time operating system where the number of real-time tasks may vary.

● Interactive on-line system where tasks associated

with users come and go.

● Drawback: significant overhead when a large

number of tasks are created

(35)

● In this model, each task is associated with a data

structure, called a task control block.

● This data structure contains at least

● a PC,

● register contents,

● an identification string or number, ● a status,

● and a priority if applicable.

● The system stores these TCBs in one or more data

(36)

Task States

● A task typically can be in any one of the four following

states:

● Executing – task that is running

● Ready – ready to run but not running

● Suspended (or blocked) : that are waiting on a particular 

resource

● Dormant (or sleeping) – it exists but unavailable to

operating system.

● Once a task has been created, it can become dormant by

(37)

Task Management

● The operating system is responsible for maintaining

● a linked list containing the TCBs of all the ready tasks, ● and a second linked list of those in the suspended state. ● a table of resources and a table of resource requests.

● When invoked, the OS

● checks the ready list to see if the next task is eligible for  execution.

● If it is eligible, then the TCB of the currently executing task is moved to the end of the ready list

● and the eligible task is removed from the ready list and its execution begins.

(38)

● Each TCB contains the

essential information

normally tracked by the interrupt service routine

● Task management can

be achieved simply by manipulating the

status word.

● This approach reduces

(39)

TCB Vs ISR Model

● TCB model

● tasks track their own resources.

● Useful when no. Of tasks is indeterminate at design time and

can change during operation

● More flexible

● Smaller overheads due to the absence of dynamic memory

management

● Deterministic performance because the TCB list is of constant

size.

● ISR model - the resources are managed by the operating

References

Related documents

Enhancing GPM Passive and Combined Microwave Algorithms with Dynamic Surface Information for Drizzle Retrieval and Improved Precipitation Detection Over Land.. Sarah Ringerud,

Analyzing the management of the disaster at the local level (in Cape Town), and the various discourses and mobilizations involved in it, this article shows how widespread violence

Members Conference on ‘ BAS 39: Salient Features and Implications’ was held in the evening of Monday, 18 June 2012 at ICAB Auditorium, CA Bhaban, Dhaka. Ghulam Muhammed Quader,

However, the results of this study and the process of integrating participatory maps and GIS maps used here are relevant in a wide variety of proj- ects where the goal is to

Glion Institute of Higher Education and Les Roches International School of Hotel Management , both in Switzerland, are accredited by the New England Association of Schools

For non-adopters we find support for several of our hypotheses and three key factors consistently affecting intended adoption: 1) attitudes and belief (H1); 2) local perceived

Solar Generation Solar Generation Water Treatment Plant Sewage Co-Generation System Industrial Area Substation (66kV) Grid Power Supply Plant g Treatment Plant Energy

In recent years DIMAR has become interested in incorporating a marine mammal component in its cruises: since 2004 it has regularly invited marine mammal observers on