Documente Academic
Documente Profesional
Documente Cultură
ISR
ISR
1 2 3 4 5 6 7
Task 1 (H)
Task 2 (M)
Task 3 (L)
Priority Inversion
1. Task 1 and Task 2 are both waiting for an
event to occur and Task 3 is executing.
2. Task 3 acquires semaphore.
-- Semaphore needs before it can access resources.
3. An event of Task 1 is occurs, thus kernel
suspends Task 3and start execution of Task-1.
4. Task-1 want to access same resource.
1 2 3 4 5 6 7
Priority Inversion
-- Since the resource acquired by Task-3,
Task-1 is placed in a list of waiting task.
-- Task-3 resumes and continues execution.
5. Task-2 suspend Task-3 since its priority is
high than Task-3.
6. After execution of Task-2, kernel hand over
the control of CPU back to Task-3.
1 2 3 4 5 6 7
Priority Inversion
-- Task-3 finishes the execution with
resource and then releases the semaphore.
7. At this point Task-1 has the Semaphore
and can access the shared resource and
completes its execution.
The priority of Task-1 has virtually reduces
to that of Task-3.
1 2 3 4 5 6 7
Assigning Task Priorities
According to the importance of the task,
priorities are assign to them.
Some task are critical task and some task are
non critical.
High priority can assign to critical task and
low priority can assign to non-critical task.
Assigning Task Priorities
Rate Monotonic Scheduling is used to assign
task priorities based on how often task execute.
RMS assign high priority according to the rate
of execution of the task.
Semaphores
Semaphore is a key that the code acquires in order
to continue execution.
If the semaphore is already in use, the requesting
task is suspended until the semaphore is release
by its owner.
Semaphore is used to
Control access to a shared resource.
Signal the occurrence of an event.
Allow two tasks to synchronize their activities.
Semaphores
Two types of semaphore:
Binary semaphore
Take only two values 0 and 1
Counting semaphore
Allows value between 0 and 255 for the 8-bit
semaphore mechanism.
Allows value between 0 and 65535 for 16-bit
semaphore mechanism.
Semaphores
Three operations on semaphore:
Initialize
The semaphore get initial value when semaphore is
initialized.
Wait
A task desiring the semaphore performs wait operation.
If the semaphore is available, the semaphore value is
decremented by one and the task continues execution.
If the semaphore value is zero, the task performing a
wait.
Semaphores
Signal
A task releases a semaphore by performing a signal
operation.
If no task waiting for semaphore, the semaphore value is
simply incremented.
If any task waiting for semaphore and ready to run, then
the key is given to the task.
Mutual Exclusion
Mutual exclusion means, each task should gain
special access to the shared resource to prevent
data corruption.
The most common method to obtain special
access of shared resources are:
Disabling interrupts
Test and set
Disabling scheduling
Using Semaphores
Mutual Exclusion
Mutual Exclusion using disabling and enabling
interrupts
This the easiest and fastest way to gain exclusive access to
a shared resource.
Example:
Process-1 requests the printer, gets it
Process-2 requests the tape unit, gets it Process-1 and
Process-2 are
Process-1 requests the tape unit, waits
deadlocked
Process-2 requests the printer, waits
Deadlocks
Simplest way to avoid deadlock is for the task
to:
Acquire all resources before proceeding.
Acquire the resources in the same order.
Release the resources in the reverse order.
Fig. shows all higher priority and ISR tasks are slightly
less than one tick.
The task delays itself just before a clock tick.
The task will execute again almost immediately.
If designer need to delay a task for at least 1 clock tick,
designer must specify one extra tick.
Delaying a task for 1 tick
Fig. shows all higher priority and ISR tasks are extend
beyond one clock tick.
The task that tries to delay for 1 tick will actually execute
2 tick later.
In this case task missed its deadline. This might not be
acceptable in all cases
Memory requirement
For foreground/Background system, the amount
of memory required is depends on the application
software.
A multitasking kernel requires extra code space.
The space is depends on the features provided by
kernel and the n-bit CPU.
Features:
Scheduling, Text switching, Semaphore management,
delays and timeout etc.
The total code space is thus given by:
Application Code Size + Kernel Code Size
Memory requirement
If each task runs independently, then each task
needs its own stack area.
The stack size depends on
Task and ISR requirements
Local variable, function call, etc.
Maximum interrupt nesting: saved registers, local
storage in ISR.
[Application code requirements + Data space (i.e.
RAM) needed by the kernel + SUM(task stacks +
MAX(ISR nesting))]
Memory requirement
Some kernel supports a separate stack for
interrupts, then total RAM required is given
by:
[Application code requirements + Data space needed
by the kernel (i.e. RAM) + SUM(task stacks) +
MAX(ISR nesting)]
Advantages of Real-Time Kernels
RTOS, allows real-time applications to be easily
designed and expanded.
Functions can be added without requiring major
changes to the software.
RTOS simplifies the design process by splitting
the application code into separate tasks.
With a preemptive RTOS, all time-critical events
are handled as quickly and as efficiently as
possible.
RTOS allow you to make better use of your
resources by providing you with precious services
such as semaphores, mailboxes, queues, time
delays, timeouts, etc.
Disadvantages of Real-Time Kernels
Using a real-time kernel application, can afford
the extra requirements: extra cost of the kernel,
more ROM/RAM, and 2 to 4 percent additional
CPU overhead.
The cost of an RTOS varies from $50 to well over
$30,000.
The RTOS vendor may also require royalties on a
per-target-system basis.
This is like buying a chip from the RTOS vendor
that you include with each unit sold.
The RTOS vendors call this silicon software.
Assignment - 2
Q.1. Explain the following.
i. Different states of task.
ii. Context switching.