rtos concepts and defn from pseudokernels to operating systems miscellaneous pseudokernels...

23
RTOS Concepts and Defn From Pseudokernels to Operating Systems Miscellaneous Pseudokernels Interrupt-Only Systems Preemptive Priority Systems Hybrid Scheduling Systems The Task Control Block Model Theoretical Foundations of Scheduling Scheduling Framework Round-Robin Scheduling Cyclic Code Scheduling Fixed-Priority Scheduling: Rate-Monotonic Approach Dynamic Priority Scheduling: Earliest Deadline First Approach System Services for Application Programs Linear Buffers Ring Buffers Mailboxes Semaphores Deadlock and Starvation Problems Priority Inversion Problem

Upload: jeffrey-mclaughlin

Post on 15-Jan-2016

223 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: RTOS Concepts and Defn From Pseudokernels to Operating Systems Miscellaneous Pseudokernels Interrupt-Only Systems Preemptive Priority Systems Hybrid Scheduling

RTOS Concepts and DefnFrom Pseudokernels to Operating Systems

Miscellaneous PseudokernelsInterrupt-Only Systems

Preemptive Priority SystemsHybrid Scheduling Systems

The Task Control Block ModelTheoretical Foundations of

Scheduling

Scheduling FrameworkRound-Robin SchedulingCyclic Code Scheduling

Fixed-Priority Scheduling: Rate-Monotonic ApproachDynamic Priority Scheduling: Earliest Deadline First Approach

System Services for Application ProgramsLinear BuffersRing BuffersMailboxes

SemaphoresDeadlock and Starvation Problems

Priority Inversion Problem

Page 2: RTOS Concepts and Defn From Pseudokernels to Operating Systems Miscellaneous Pseudokernels Interrupt-Only Systems Preemptive Priority Systems Hybrid Scheduling

Process

• Abstraction of running program• The logical unit schedule to be executed by OS• Represented by data strcuture– State – Identity– Attributes (exe time)– Resources

Page 3: RTOS Concepts and Defn From Pseudokernels to Operating Systems Miscellaneous Pseudokernels Interrupt-Only Systems Preemptive Priority Systems Hybrid Scheduling

RTOS functionality

• Process– Schedule– Dispatch– Intercommunication & Synch

• Provided by the OS kernel

Page 4: RTOS Concepts and Defn From Pseudokernels to Operating Systems Miscellaneous Pseudokernels Interrupt-Only Systems Preemptive Priority Systems Hybrid Scheduling

Illustrates

• real-time executive is a kernel that includes privatized memory blocks, I/O services, and other complex features.

• Most commercial real-time kernels are executives

Page 5: RTOS Concepts and Defn From Pseudokernels to Operating Systems Miscellaneous Pseudokernels Interrupt-Only Systems Preemptive Priority Systems Hybrid Scheduling

Pseudokernel

• Polled loop- – 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

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

process_data(); /* process data */packet_here=0; /* reset flag */

}}

Page 6: RTOS Concepts and Defn From Pseudokernels to Operating Systems Miscellaneous Pseudokernels Interrupt-Only Systems Preemptive Priority Systems Hybrid Scheduling

Synchronized Polled Loop• Such a system is used to treat

events that exhibit switch bounce

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

pause(20); /* wait 20 ms */process_event(); /* process event */flag=0; /* reset flag */

}}

Page 7: RTOS Concepts and Defn From Pseudokernels to Operating Systems Miscellaneous Pseudokernels Interrupt-Only Systems Preemptive Priority Systems Hybrid Scheduling

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.for(;;) { /* do forever */

Process_1();Process_2();...Process_N();}

}

for(;;) { /* do forever */ Process_1(); Process_2(); Process_3(); Process_3();}

Page 8: RTOS Concepts and Defn From Pseudokernels to Operating Systems Miscellaneous Pseudokernels Interrupt-Only Systems Preemptive Priority Systems Hybrid Scheduling

State-Driven Code

• uses nested if–then statements,case statements, to break up the processing of functions into code segments.

• The separation of processes allows each to betemporarily suspended before completion, without loss of critical data State-driven code works well in conjunction with cyclic executives when the processes are too long or non-uniform in size

• Not all processes lend themselves naturally to division into states; some processes are therefore unsuitable for this technique.

Page 9: RTOS Concepts and Defn From Pseudokernels to Operating Systems Miscellaneous Pseudokernels Interrupt-Only Systems Preemptive Priority Systems Hybrid Scheduling

Coroutines

Page 10: RTOS Concepts and Defn From Pseudokernels to Operating Systems Miscellaneous Pseudokernels Interrupt-Only Systems Preemptive Priority Systems Hybrid Scheduling

Interrupt Driven

• The various tasks in the system are scheduled via either hardware or software interrupts, whereas dispatching is performed by the interrupt-handling routines.

• Interrupt Service Routines– Hardware Interrupt A signal generated by a peripheral device

and sent to the CPU. In turn, the CPU executes an interrupt service routine (ISR), which takes action in response to the interrupt.

– Software Interrupt Similar to the hardware interrupt, in that it causes one code module to pass control to another.

Page 11: RTOS Concepts and Defn From Pseudokernels to Operating Systems Miscellaneous Pseudokernels Interrupt-Only Systems Preemptive Priority Systems Hybrid Scheduling

• Reentrant code can execute simultaneously in two or more contexts. An ISR is said to be reentrant if, while the ISR is handling an interrupt, the same interrupt can occur again and the ISR can process the second occurrence of the interrupt before it has finished processing the first.

• 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. The context is ordinarily saved to a stack data structure.

• Context-switching time is a major contributor to response time and therefore must be minimized. The rule for saving context is simple: save the minimum amount of information necessary to safely restore any process after it has been interrupted. – This information ordinarily includes

• Contents of general registers• Contents of the program counter• Contents of coprocessor registers (if present)• Memory page register• Images of memory-mapped I/O locations (mirror images)

Page 12: RTOS Concepts and Defn From Pseudokernels to Operating Systems Miscellaneous Pseudokernels Interrupt-Only Systems Preemptive Priority Systems Hybrid Scheduling

void main(void) { /*initialize system, load interrupt handlers */init();while(TRUE); /* infinite wait loop */ }

void intl (void) { /* interrupt handler 1 */save(context); /* save context on stack */task1(); /* execute task 1 */restore(context); /* restore context from stack */ }

void int2(void) { /* interrupt handler 2 */save(context); /* save context on stack */task2(); /* execute task 2 */restore(context); /* restore context from stack */}

void int3(void) { /* interrupt handler 3 */save(context); /* save context on stack */task3(); /* execute task 3 */restore(context); /* restore context from stack */}

Page 13: RTOS Concepts and Defn From Pseudokernels to Operating Systems Miscellaneous Pseudokernels Interrupt-Only Systems Preemptive Priority Systems Hybrid Scheduling

Preemptive-Priority Systems

• A higher-priority task is said to preempt a lower-priority task if it interrupts the lower-priority task.

• The priorities assigned to each interrupt are based on the urgency of the task associated with the interrupt.

• Prioritized interrupts can be either fixed priority or dynamic priority.

• Fixed priority systems are less flexible, since the task priorities cannot be changed. (Rate/Deadline Monotonic)

• Dynamic-priority systems can allow the priority of tasks to be adjusted at runtime to meet changing process demands. ( Earliest Deadline First)

Page 14: RTOS Concepts and Defn From Pseudokernels to Operating Systems Miscellaneous Pseudokernels Interrupt-Only Systems Preemptive Priority Systems Hybrid Scheduling

Hybrid System• 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. This type of system is common in embedded applications

• Another type of hybrid system found in commercial operating systems is a combination of round-robin and preemptive systems.

Page 15: RTOS Concepts and Defn From Pseudokernels to Operating Systems Miscellaneous Pseudokernels Interrupt-Only Systems Preemptive Priority Systems Hybrid Scheduling

Types of Hybrid SystemForeground/Background Systems • Foreground/background systems are an improvement over

the interrupt-only systems in that the polled loop is replaced by code that performs useful processing. Foreground/background systems are the most common architecture for embedded applications. They involve a set of interrupt-driven or real-time processes called the foreground and a collection of noninterrupt-driven processes called the background.

• The foreground tasks run in round-robin, preemptive priority, or hybrid fashion.

• The background task is fully preemptable by any foreground task and, in a sense, represents the lowest priority task in the system.

Page 16: RTOS Concepts and Defn From Pseudokernels to Operating Systems Miscellaneous Pseudokernels Interrupt-Only Systems Preemptive Priority Systems Hybrid Scheduling

..cont

• All real-time solutions are just special cases of the foreground/ background systems. For example, the polled loop is simply a foreground/background system with no foreground, and a polled loop as a background. Adding interrupts for synchronization yields a full foreground/ background system.

• State-driven code is a foreground/background system with no foreground and phase-driven code for a background. Coroutine systems are just a complicated background process.

• Finally, interrupt-only systems are foreground/ background systems without background processing.

Page 17: RTOS Concepts and Defn From Pseudokernels to Operating Systems Miscellaneous Pseudokernels Interrupt-Only Systems Preemptive Priority Systems Hybrid Scheduling

The Task-Control Block Model• The task-control block model is the most popular

method for implementing commercial, full-featured, real-time operating systems because the number of real-time tasks can vary.

• This architecture is used in interactive on-line systems where tasks (associated with users) come and go.

• Implement thru 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 structures, such as a linked list.

• Task State, Task Management, Resource Management

Page 18: RTOS Concepts and Defn From Pseudokernels to Operating Systems Miscellaneous Pseudokernels Interrupt-Only Systems Preemptive Priority Systems Hybrid Scheduling

RTOS TheoryProcess State

Page 19: RTOS Concepts and Defn From Pseudokernels to Operating Systems Miscellaneous Pseudokernels Interrupt-Only Systems Preemptive Priority Systems Hybrid Scheduling

Process Schuduling• In order to meet a program’s timing requirements in real-time systems a strategy

is needed for ordering the use of system resources, and a mechanism needed for predicting the worst case performance (or response time) when a particular scheduling policy is applied.

• There are two general classes of scheduling policies: pre-run-time and run-timescheduling. The goal of both types of scheduling is to satisfy time constraints.

• In pre-run-time scheduling, the objective is to create a feasible schedule offline, which guarantees the execution order of processes and prevents simultaneous access to shared resources. Pre-run-time scheduling also takes into account and reduces the cost of context switching overhead, increasing the chance that a feasible schedule can be found.

• In run-time scheduling, static priorities are assigned and resources are allocated on a priority basis. Run-time scheduling relies on a complex run-time mechanism for process synchronization and communication. This approach allows events to interrupt processes and demand resources randomly. In terms of performance analysis, engineers must rely on stochastic simulations to verify these types of system designs.

Page 20: RTOS Concepts and Defn From Pseudokernels to Operating Systems Miscellaneous Pseudokernels Interrupt-Only Systems Preemptive Priority Systems Hybrid Scheduling

Task Characteristics of a Real Workload

• Precedence Constraints Specify if any task(s) needs to precede other tasks.

• Release or Arrival Time ri , j The release time of the j th instance of task τi .

• Phase φi The release time of the first instant of task τi .• Response Time Time span between the task activation and its

completion.• Absolute Deadline di The instant by which the task must complete.

• Relative Deadline Di The maximum allowable response time of the task.• Laxity Type Notion of urgency or leeway in a task’s execution.• Period pi The minimum length of intervals between the release times of

consecutive tasks.• Execution Time ei The (maximum) amount of time required to complete

the execution of a task i when it executes alone and has all the resources it requires.

Page 21: RTOS Concepts and Defn From Pseudokernels to Operating Systems Miscellaneous Pseudokernels Interrupt-Only Systems Preemptive Priority Systems Hybrid Scheduling

Do the mAthS

Page 22: RTOS Concepts and Defn From Pseudokernels to Operating Systems Miscellaneous Pseudokernels Interrupt-Only Systems Preemptive Priority Systems Hybrid Scheduling

Scheduling Algo

• Round Robin• Cyclic Executive• Fixed-Priority Scheduling–Rate-Monotonic• Dynamic-Priority Scheduling: Earliest-

Deadline–First

Page 23: RTOS Concepts and Defn From Pseudokernels to Operating Systems Miscellaneous Pseudokernels Interrupt-Only Systems Preemptive Priority Systems Hybrid Scheduling

Inter Task Communication & Synch