Multiple Tasks and Multiple Processes-Preemptive RTOS
Multiple Tasks and Multiple Processes-Preemptive RTOS
In case a lower priority task is running and a higher priority task arrives in
the waiting state then the lower priority task is put on hold.
The higher priority task replaces it and once done executing the lower
priority task resumes execution from when it was paused. This process
requires special hardware like a timer.
Algorithms that are backed by preemptive Scheduling are round-robin (RR),
priority, SRTF (shortest remaining time first).
Non-Preemptive Scheduling
The OS allocates the CPU to a specific process that releases the CPU
either through context switching or after termination.
We can use this method on various hardware platforms because unlike
preemptive scheduling it doesn’t require any special hardware.
Algorithms that are based on non-preemptive Scheduling are non-
preemptive priority, and shortest Job first.
Preemptive Vs Non-Preemptive Scheduling
Characteristics of Priority Scheduling
Completion Time is the time required by the process to complete its execution
Turnaround Time is the time interval between the submission of a process and its
completion.
Turnaround Time = completion of a process – submission of a process
Waiting Time is the difference between turnaround time and burst time
Waiting Time = turnaround time – burst time
Example of Priority Scheduling
Following five processes have a unique priority, burst time, and arrival time.
ANALYSIS
ANALYSIS
ANALYSIS
ANALYSIS
Shortest job first scheduling
Shortest job first scheduling is the job or process scheduling algorithm that
follows the nonpreemptive scheduling discipline.
In this, scheduler selects the process from the waiting queue with the least
completion time and allocate the CPU to that job or process.
Shortest Job First is more desirable than FIFO algorithm because SJF is more
optimal as it reduces average wait time which will increase the throughput.
Shortest job first scheduling
Round robin is a CPU scheduling algorithm that is designed especially for time
sharing systems.
It is more like a FCFS scheduling algorithm with one change that in Round
Robin processes are bounded with a quantum time size. A small unit of time is
known as Time Quantum or Time Slice.
Time quantum can range from 10 to 100 milliseconds. CPU treat ready queue
as a circular queue for executing the processes with given time slice.
It follows preemptive approach because fixed time are allocated to processes.
The only disadvantage of it is overhead of context switching.
Round Robin Scheduling- Example
Round Robin Scheduling- Example
Priority Inversion
A system malfunction may occur if a high priority process is not provided the
required resources.
Priority inversion may also lead to implementation of corrective measures. These
may include the resetting of the entire system.
The performance of the system can be reduces due to priority inversion. This
may happen because it is imperative for higher priority tasks to execute
promptly.
Problems due to Priority Inversion
System responsiveness decreases as high priority tasks may have strict time
constraints or real time response guarantees.
Sometimes there is no harm caused by priority inversion as the late execution of
the high priority process is not noticed by the system.
Solutions of Priority Inversion
Priority Ceiling
All of the resources are assigned a priority that is equal to the highest priority of
any task that may attempt to claim them. This helps in avoiding priority
inversion.
Disabling Interrupts
There are only two priorities in this case i.e. interrupts disabled and preemptible.
So priority inversion is impossible as there is no third option.
Solutions of Priority Inversion
Priority Inheritance
This solution temporarily elevates the priority of the low priority task that is
executing to the highest priority task that needs the resource. This means that
medium priority tasks cannot intervene and lead to priority inversion.
No blocking
Priority inversion can be avoided by avoiding blocking as the low priority task
blocks the high priority task.
Advantages of priority scheduling in OS
Easy to use.
Processes with higher priority execute first which saves time.
The importance of each process is precisely defined.
A good algorithm for applications with fluctuating time and
resource requirements.
Disadvantages of priority scheduling in OS