Scheduling Example 3 (1) Assume: FIFO Job Scheduling 100 K Main Memory Processor Sharing Process Scheduling (Cont…)
Scheduling Example 3 (2) JobArrivesRun Time Memory HOLDQ Ready / Running
Example 3 (Cont…) TimeEvent #Jobs Headway MM FreeTime Left A,S A,S F A,H A,S A,S F F S F F100 Must be memory size Must be sum of all Ri
T and W for Example 3 Job Run ArrivalFinish Ti Wi ===== ===== T = 0.72 W = 3.716
Scheduling Example 4 (1) Assume: FIFO Job Scheduling 100 K Main Memory Devices Processor Sharing Process Scheduling (Cont…)
Scheduling Example 4 (2) JobArrivesRun Time Memory Devices HOLDQ Ready / Running
Example 4 (Cont…) TimeEvent #Jobs Headway MM FreeDevices Time Left A,S A,S F A,H A,S A,H F S F F S F
T and W for Example 4 Job RunStartFinish Ti Wi ===== ===== T = 0.72 W = 4.026
Scheduling Example 5 (1) Assume: FIFO Job Scheduling 100 K Main Memory Devices Processor Sharing Process Scheduling (Cont…)
Scheduling Example 5 (2) JobArrivesRun Time Memory Tapes
Example 5 (Cont…) (1) TimeEvent #Jobs Headway MM FreeDevices Time Left 1.01 A,S A,S A,H A,S A,H F A,S
Example 5 (Cont…) (2) TimeEvent #Jobs Headway MM FreeDevices Time Left F S F F S F F
T and W for Example 5 Job Run ArrivalFinish Ti Wi ===== ===== T = 3.99 W = 4.35
Job Scheduling Also known as FCFS: first come, first served Scheduling based on arrival time Non-preemptible discipline Fair – no job is given preferential treatment, and every arriving job eventually runs Whey is this policy bad for interactive users Wait HoldReady Run
Process Management A multiprogramming OS must interleave the execution of multiple jobs The OS must decide when each process gets to use each resource (CPU,disk, etc.) The scheduler decides “when”
Time Quantums How does the OS interleave execution of many processes on the CPU? Ans: Time slicing Quantum: Amount of time given to jobs when time sharing
Process States Running: Process currently has CPU Ready: Process could use CPU, if CPU were free Blocked: Process is waiting for some event to occur: I/O Completion Buffer available from another process Data arrives from network (More states will be discussed later.)
Process State Transitions Running ReadyBlocked Wakeup Block Timeout Dispatch Is there a maximum number of processes in any state?
Suspend and Resume Ready Running Suspended ReadySuspended blocked Blocked Wakeup Suspend Resume Event (e.g., I/O) completion Timeout Dispatch Suspend Resume
Process Control Block (PCB) One PCB per process, containing all information about that process Process Identifier (pid) Parent’s pid State (e.g., Running, Blocked in ReadyQ) Priority Time at which its execution started Amount of CPU time consumed so far Copy of all register contents when process was last suspended Main memory used by process (e.g., base and bound registers, page table pointer) Accounting information Room for pointers to PCB into a queue File descriptor table
Context Switch A Context Switch occurs when a process exchange is made between the ready and run queues: Must: Save the state of the running process AND Restore the state of the ready process Run Ready
What happens on a Context Switch? (1) 1.Hardware: Resets Program Counter (PC to that of the interrupt handler (IH), which is an address in the OS kernel Switches from user to supervisor mode 2.Kernel: Copies A’s state from CPU registers to A’s PCB Sets A’s state to Ready or Blocked Inserts A’s PCB on ReadyQ or BlockedQ 3.Scheduler selects a new process to run (B), based on its scheduling discipline (Contd…)
What happens on a Context Switch? (2) 4. Kernel: Sets B’s state to Running Copies B’s state from B’s PCB to CPU registers 5.Kernel transfers control to B and thereby switches from kernel back to user context What machine instructions can achieve number 5?
Preemption Two classes of scheduling disciplines Premptive Scheduler takes CPU away from running job and gives it to another job Preempt upon arrival of higher priority job Non-premptive
Process Scheduling Algorithms (1) 1. Round Robin (RR) Each process runs either until Its time quantum expires or It blocks to perform I/O 2. Processor Sharing (PS) Limit of RR as time quantum goes to zero (Like giving each CPU cycle to a different process, in round robin fashion) N processes scheduled by PS = each job runs on dedicated N-fold slower CPU. Thus, READY = RUNNING
Process Scheduling Algorithms (2) 3. Priority Each process is statically assigned a priority; run high before low priority 4. Dynamic Priority Same as #3, except priority level of each process can change dynamically 5. Inverse of the Remainder of the Quantum Position in ready queue is determined by the amount of time remaining in the time slice (e.g., if ¾ of time slice is left, the job moves ¼ ahead in the ready queue)
Process Scheduling Algorithms (3) 6. Multiple-Level Feedback Variant on the Round Robin Current processes are forced to wait until new jobs “catch up” in time, then all RR 7. System Balance Balance system between I/O bound and CPU bound jobs 8. Preference to Interactive jobs Interactive jobs have higher priority