Scheduling Mechanisms
A multiprogramming operating system allows more than one process to be loaded into the executabel memory at a time and for the loaded process to share the CPU using time-multiplexing.Part of the reason for using multiprogramming is that the operating system itself is implemented as one or more processes, so there must be a way for the operating system and application processes to share the CPU. Another main reason is the need for processes to perform I/O operations in the normal course of computation. Since I/O operations ordinarily require orders of magnitude more time to complete than do CPU instructions, multiprograming systems allocate the CPU to another process whenever a process invokes an I/O operationGoals for Scheduling
Make sure your scheduling strategy is good enough with the following criteria:- Utilization/Efficiency: keep the CPU busy 100% of the time with useful work
- Throughput: maximize the number of jobs processed per hour.
- Turnaround time: from the time of submission to the time of completion, minimize the time batch users must wait for output
- Waiting time: Sum of times spent in ready queue - Minimize this
- Response Time: time from submission till the first response is produced, minimize response time for interactive users
- Fairness: make sure each process gets a fair share of the CPU
Context Switching
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
- save the context of the current process
- select the next process to run
- restore the context of this new process.
What is the context of a process?
- Program Counter
- Stack Pointer
- Registers
- Code + Data + Stack (also called Address Space)
- Other state information maintained by the OS for the process (open files, scheduling info, I/O devices being used etc.)
Comments