CS 111 Fall 2005Scribe Notes for 10/18/05by Eduardo Duque, Rafayel Ambartsumyan, Amit HalaniScheduling and a Bit of Synchronization!SchedulingSay you had the following 4 tasks with corresponding time units, priority, and quantum number. Quantum = 3.
Remember that a numerically lower priority value takes precedence. Strict Priority:
The scheduler running strict priority would provide the following Gantt Chart:
Process Isolation & RobustnessThe question to ask is "Does priority setting require privilege?"
Background Task/Process
Effective PrioritySay you set the time units for task C to be 3,000,000. Question: What would happen? Answer: Doing this will starve everyone but task C. Remember that our goal is Priority with no starvation.
AgingAging works like this: Penalize a process that has run for too long by doing the following:
Example: Suppose you had a quantum value of 1. Tasks A, B, C, and D all have time units (tau) equal to infinity.
The scheduler running this scheme will produce the following Gantt Chart:
A problem with aging: You can still starve! How? Converse of Aging: Favor processes that haven't run in a long time. This is used by systems like BSD and Linux.
Priority InversionSay you had the same tasks as before with the same priorities (A,B = 2, C = 0, and D = 1). Also note the following:
Question: Which task runs? Answer: D runs! Is this OK? Priority Inversion: This is when a high priority process is waiting for a lower priority process so the high priority is effectively lowered. Solution to priority inversion: When process P is blocked, waiting for process Q, we set Eprio(Q) to be the following: min(Eprio(P), Eprio(Q)). CPU Usage DiscountingSay you had the following two processes, A and B, executing the corresponding code:
Question: Does this code portray fairness? Answer: Because A voluntarily gave up CPU access, it has been penalized and receives less than fair share. CPU Usage Discount: If you don't use much CPU, you run more often. Proportional ShareIn proportional share every process gets a priority class share of the CPU that is "inversely proportional" to the priority class. Therefore the higher the priority, the less the share. The following table shows tasks A, B, C, and D with their corresponding priorities and proportional shares:
What happens if you had a process E with a priority of 2? You get the following:
Pros of proportional share:
Cons of proportional share:
Real Time Scheduling ("Hard Real Time")This scheduling provides a guarantee of when a process will run. It also brings forth a new set of scheduling preferences: Deadlines and Run Schedules. ReservationReservation occurs when the scheduler reserves a time where a task will be allowed to run. For examples consider the following for tasks A, B, C:
Note: There is some admission control. That is, the OS rejects scheduling requests if they cannot be fulfilled. Admission control is good for things like embedded systems for things like elevators and airplanes where it is important to ensure that certain things happen at certain times. Question: Can all the previous tasks get what they need and therefore given their requests? Let's take a look. After the scheduler reserves task A's request, the gantt chart looks something like the following:
After the scheduler reserves task B's request, the gantt chart looks something like the following:
Now notices that when the scheduler gets to reserving C's request there is not enough room to give C 2 quanta every 10 quanta, therefore the OS rejects scheduling task C. Best Effort: The OS will accept every scheduling request and will do its best to full those request. DeadlineDeadline fulfills such request from a process: "I need to run for X time units by time t, where we will refer to time t as being the deadline. Example: Consider the following tasks and their corresponding time units and deadlines.
Question: In what order can we run these tasks? EDF - Earliest Deadline First: As the name suggest, let the task with the earliest deadline run first. Notice that EDF will always give you a schedule that meets a deadline if such a deadline exists! The gant chart for EDF on tasks A, B, C, and D is as follows:
SynchronizationSynchronization is to ensure the safe sharing of resources. Resources include: memory objects, files, and the network. Problem statement: Read 3 files, output their lines in any order. Note: Please download the code for the following problem statement from the course website! As of now, the code will open the files in sequential order, doing the following:
That is, the files have to take CPU time and block while nothing else is going on, each file takes control at their own individual time. We want to make it so that while things are blocked, all three files are being read and opened at the same time, therefore taking up less of the CPU since there now isn't multiple blocks. In a graphical sense, we want the following to happen:
So for our program that reads 3 files and outputs their lines in any order, we should generate 3 threads, 1 for each file. |