Chapter 4 Rtos Concepts Real Time Systems Concepts: Radio Transmissions, Etc..

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

1

CHAPTER 4 RTOS CONCEPTS

Real Time Systems Concepts


 Definition
– Real Time Systems are characterized by consequences that result if logical as well as timing
correctness properties of the system are not met
– A real-time deadline must be met, regardless of system load
 Examples
– Video Surveillance, Anti-Lock Braking Mechnanisms, Missile Guidance, Nucleur Reactors,
Radio Transmissions, etc..,

Types of RTS
 Soft Real Time
– Tasks are performed by the systems as fast as possible, but failing to complete within
specified deadlines is not catastrophic
– Video Surveillance, Radio Transmissions, Online Ticket reservation systems, etc..,
 Hard Real Time
– Tasks have to be performed not only correctly but in time. Failure to comply to the set
deadlines would result catastrophical
– Nucleur Reactors, Vehicle Braking, etc...
 Most RTS will have Combination of both.

GPOS vs RTOS
 Determinism
 Load-Independent Timing
 Task Scheduling
 Dynamic Memory Allocations
 Interrupts
 Intertask Communication

Task Level Response


 The time taken between the making a process ready to its execution is the Task Level Response
 BG executes only on its turn
 The worst case task level response time depends on how long the BG loop takes to execute
Resource & Shared Resource
 A resource is an entity used by the task.
 A resource can be an I/O device, or a variable, a structure or an array.
 A shared resource is a resource that can be used by more than one task.
 Each task should gain exclusive access to the shared resource to prevent data corruption.
Critical Section of Code
2

 Also called as Critical region.


 Should be treated indivisibly.
 Must not be Interrupted.
 To ensure this, interrupts are typically disabled before the critical code is executed & enabled when
the critical code is executed.
Multitasking
 Multitasking is the process of scheduling and switching the CPU between several tasks.
 A single CPU switches attention between several sequential tasks.
 Multitasking is like FG/BG with multiple BGs.
Advantages of Multitasking
 Maximizes the CPU Utilization.
 It Provides Modular construction of Applications.
 Application programs are typically easier to design & maintain if Multitasking is used.
Task
 A task, also called a thread, is a simple program that thinks it has the CPU all to itself.
 Real Time application involves splitting the work to be done in Tasks.
 Each Task is assigned its own set of CPU Registers, Stack Area and a Priority.
Multiple Tasks
 DORMANT
 READY
 RUNNING
 WAITING
 ISR
Note: Typically Tasks are infinite loops
Dormant State
 Corresponds to the task that resides in the memory but has not been made available to the
multitasking Kernel
Ready State
 A task is READY when it can execute but its priority is less than the currently running task.
Running Task
 A task is running when it has control of the CPU
Waiting State
 A Task is waiting when it requires a occurrence of a event (waiting for an I/O operation to complete,
a shared resource to be available, a timing pulse to occur, time to expire etc).
ISR State
A task is in the ISR State when an interrupt has occurred and the CPU is in the process of servicing the
Interrupt
Task State Diagram
Kernel
 Fundamental Service provided by the Kernel is Task Switching
 Kernel simplifies the design of a system allowing the application to be divided into several tasks
 Kernel adds overhead to the System (ROM & RAM) & also consumes CPU time (2-5%)‫‏‬
Context Switch (Task Switch)
 Save current CPU task’s context (CPU Registers) on the current task’s context storage area
 The new task context is restored & start executing the new task
 More the registers higher the overhead
Context Switch Transitions
3

Task Priority
 A priority is assigned to each task
 The more important the task the more the priority
 Two types of priority assigning
– Static (Assigned at Compile Time)‫‏‬
– Dynamic (Assigned at Execution Time)‫‏‬
Scheduler
 Part of the Kernel which will decide the next task to run
 Most RT Kernels are priority based
 Control is always given to highest priority task ready to run
 Two types of priority based Kernels
– Non-Preemptive
– Preemptive
 Reentrancy A reentrant function can be used by more than one task without data corruption
 A reentrant function can be interrupted at any time and resumed at a later time without loss of data
Mutual Exclusion
 Disabling and Enabling the Interrupt
 Test-and-Set
 Disabling and Enabling the Scheduler
 Semaphores
– Binary Semaphores
– Counting Semaphores
Semaphores
 Control Access to a shared resource (ME)‫‏‬
 Signal Occurrence of an event
 Allow two tasks to synchronize their activities
Intertask Communication
 Message Mailboxes
 Message Queues
4

Deadlock
 Two task unknowingly waiting for resources held by each other
 Solution for Deadlock:
– Acquire all resources before proceeding
– Acquire the resources in the same order, and
– Release the resources in the same order.
Interrupts
 Hardware mechanism to inform the CPU that asynchronous event has occurred
 What happens when an Interrupt occurs
– Saves the present context
– Jumps to the ISR
– Executes ISR & returns
Where does the Interrupt RETURN
 The Background for Foreground/ Background System
 Interrupted task for a Non-Preemptive Kernel
 The highest priority task ready to run for a Preemptive Kernel
Interrupt Latency
 One of the important specifications of a Real Time Kernel
 Longer the Interrupts are disabled the Higher the Interrupt Latency
 Equation
Max amount of time Interrupts are disabled +
Time to start executing the first Instruction in the ISR
Interrupt Response
 The time between the reception of the Interrupt and the start of the user code that handles the
Interrupt
 It involves all the overhead involved in handling an Interrupt
 Foreground/Background System
Interrupt Latency+Time to save CPU context

Interrupt Response Equation


 Non-Preemptive Kernel
Interrupt Latency + Time to save CPU context
 Preemptive Kernel
Interrupt Latency +Time to save CPU context+Execution time of the kernel ISR Entry Function

NOTE on Interrupt Response


 A systems’s worst case response is its only response
 Your system may respond to Interrupts in 50us 99% of the time, but if it responds to Interrupts in
250us the other 1% you must assume 250us Interrupt Response Time,
Interrupt Recovery
 Time required by the processor to return to the Interrupted Code
 Equation
Time to restore the CPU’s context +Time to execute the Return from Interrupt Instruction

Clock Tick
 The clock tick is a special interrupt that occurs periodically
 This interrupt can be viewed as the system heartbeat
 The time between Interrupts is application specific and is generally 10 to 200ms

You might also like