Page 80 - DCAP403_Operating System
P. 80
Unit 5: Scheduling
Context Switching Notes
Typically there are several tasks to perform in a computer system.
So if one task requires some I/O operation, you want to initiate the I/O operation and go on to
the next task. You will come back to it later.
This act of switching from one process to another is called a “Context Switch”
When you return back to a process, you should resume where you left off. For all practical
purposes, this process should never know there was a switch, and it should look like this was the
only process in the system.
To implement this, on a context switch, you have to
1. Save the context of the current process
2. Select the next process to run
3. Restore the context of this new process.
Non-preemptive vs. Preemptive Scheduling
Non-preemptive
Non-preemptive algorithms are designed so that once a process enters the running state(is
allowed a process), it is not removed from the processor until it has completed its service time (or
it explicitly yields the processor).
context_switch() is called only when the process terminates or blocks.
Preemptive
Preemptive algorithms are driven by the notion of prioritized computation. The process with the
highest priority should always be the one currently using the processor. If a process is currently
using the processor and a new process with a higher priority enters, the ready list, the process on
the processor should be removed and returned to the ready list until it is once again the highest-
priority process in the system.
context_switch() is called even when the process is running usually done via a
timer interrupt.
5.2 CPU Scheduling Basic Criteria
CPU scheduling is the basics of multiprogramming. By switching the CPU among several
processes the operating systems can make the computer more productive. The objective of
multiprogramming is to have some process running at all times, in order to maximize CPU
utilization. On systems with 1 processor, only one process may run at a time; any other processes
must wait until CPU is free to be rescheduled.
In multiprogramming, a process executes until it must wait (either interrupted, or doing IO), at
which point, the CPU is assigned to another process, which again, executes until it must wait, at
which point another process gets the CPU, and so on.
Processes generally execute a CPU burst, followed by an IO burst, followed by the CPU burst,
followed by the CPU burst, etc. This cycle is central to all processes. Every process must have CPU
bursts, and every process must do some IO. The operating system maintains what is known as a
ready-queue. Processes on this queue are ready to be executed. Whenever a currently executing
LOVELY PROFESSIONAL UNIVERSITY 73