Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 5: CPU Scheduling (Continuation). 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Determining Length.

Similar presentations


Presentation on theme: "Chapter 5: CPU Scheduling (Continuation). 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Determining Length."— Presentation transcript:

1 Chapter 5: CPU Scheduling (Continuation)

2 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Determining Length of Next CPU Burst Can only estimate the length Can be done by using the length of previous CPU bursts, using exponential averaging contains the most recent information, contains the past history α is the relative weight of recent and past history; more commonly it is taken α=1/2, so recent history and past history are equally weighted

3 5.3 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Philosophy of Exponential Averaging  =0  n+1 =  n Recent history does not count  =1  n+1 =  t n Only the actual last CPU burst counts If we expand the formula, we get:  n+1 =  t n +(1 -  )  t n -1 + … +(1 -  ) j  t n -j + … +(1 -  ) n +1  0 Since both  and (1 -  ) are less than or equal to 1, each successive term has less weight than its predecessor

4 5.4 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Prediction of the Length of the Next CPU Burst

5 5.5 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Priority Scheduling A priority number (integer) is associated with each process Smaller number  higher priority, larger number  lower priority The CPU is allocated to the process with the highest priority (smallest integer  highest priority) Preemptive (preempt the CPU if the priority of newly arrived process is higher than the priority of the currently running process) Nonpreemptive (put the new process at the head of the ready queue if its priority is higher than the priority of other processes in the ready queue ) Equal-priority processes are scheduled in FCFS order.

6 5.6 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Priority Scheduling SJF is a special case of the general priority scheduling. In this case the priority is the inverse of the predicted next CPU burst time: the larger the CPU burst, the lower the priority, and vice versa. Problem  Starvation – low priority processes may never execute Solution  Aging – as time progresses increase the priority of the process that wait in the system for a long time

7 5.7 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Round Robin (RR) Scheduling Each process gets a small unit of CPU time (time quantum), usually 10-100 milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue. If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in the time frames of at most q time units at once. No process waits more than (n-1)q time units. Performance q large  FCFS q too small (about 1 millisecond)  processor sharing  q must be larger, with respect to context switch, otherwise overhead is too high

8 5.8 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Time Quantum and Context Switch Time

9 5.9 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Example of RR with Time Quantum = 20 ProcessBurst Time P 1 53 P 2 17 P 3 68 P 4 24 The Gantt chart is: Typically, higher average turnaround than SJF, but better response P1P1 P2P2 P3P3 P4P4 P1P1 P3P3 P4P4 P1P1 P3P3 P3P3 02037577797117121134154162

10 5.10 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Turnaround Time Varies With The Time Quantum If the time quantum is too large, RR scheduling degenerates to FCFS policy About 80% of the CPU bursts should be shorter than the time quantum

11 5.11 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Multilevel Queue Ready queue is partitioned into separate queues: foreground (interactive) background (batch) Each queue has its own scheduling algorithm foreground – Round Robin (RR) background – First come, first served (FCFS) Scheduling must be done between the queues Fixed priority scheduling; (i.e., serve all from foreground then from background). Possibility of starvation. Time slice – each queue gets a certain amount of CPU time which it can schedule amongst its processes; i.e., 80% to foreground in RR and 20% to background in FCFS

12 5.12 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Multilevel Queue Scheduling

13 5.13 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Multilevel Feedback Queue A process can move between the various queues; aging can be implemented this way Multilevel-feedback-queue scheduler is defined by the following parameters: number of queues scheduling algorithms for each queue method used to determine when to upgrade a process method used to determine when to demote a process method used to determine which queue a process will enter when that process needs service

14 5.14 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Example of Multilevel Feedback Queue Three queues: Q 0 – RR with time quantum 8 milliseconds Q 1 – RR time quantum 16 milliseconds Q 2 – FCFS, only when Q 0 and Q 1 are empty Scheduling A new job enters queue Q 0. When it gains CPU, job receives 8 milliseconds. If it does not finish in 8 milliseconds, job is moved to queue Q 1. At Q 1 job receives 16 additional milliseconds. If it still does not complete, it is preempted and moved to queue Q 2.

15 5.15 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Multilevel Feedback Queues

16 5.16 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Thread Scheduling On operating systems that support user-level and kernel-level threads the latter are being scheduled by the operating system User-level threads are managed by a thread library. To run on a CPU, user-level thread must be mapped to an associate kernel-level thread. This mapping may use a lightweight process (LWP - a mean of achieving multitasking. In contrast to a regular (full-blown) process, an LWP shares all (or most of) its logical address space and system resources with other process(es); in contrast to a thread, a lightweight process has its own private process identifier and parenthood relationships with other processes )

17 5.17 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Thread Scheduling Local Scheduling (Process-Contention Scope) – how the threads library decides which thread to put onto an available lightweight process (LWP) Global Scheduling (System-Contention Scope) – how the kernel decides which kernel thread to run next

18 5.18 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Windows XP Scheduling Windows XP schedules threads using a priority-based, preemptive scheduling algorithm. The Windows XP scheduler ensures that the higher priority thread will always run. The portion of the Windows XP kernel that handles scheduling is called the dispatcher. A thread selected to run by the dispatcher will run until it is preempted by a higher priority thread, until it terminates, until its time quantum ends, or until it calls a blocking system call (such as for Input/Output operation) If a higher priority real-time thread becomes ready while a lower priority thread is running, the lower-priority thread will be preempted.

19 5.19 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Windows XP Scheduling There are two priority classes: The variable class contains threads having priorities from 1 to 15 The real-time class contains threads with priorities from 16 to 31. A single thread running at priority 0 is used for memory management. Each scheduling priority has a separate queue of the corresponding processes The dispatcher uses a queue for each scheduling priority and traverses the set of queues from highest to lowest until it finds a thread that is ready to run. If no ready thread is found, the dispatcher will execute a special thread called the idle thread.

20 5.20 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Windows XP Priorities The relative prioritiesThe priority within a class classes By default, the base priority is the value of the Normal relative priority for the specific class

21 5.21 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Windows XP Priorities: Some Rules Processes are typically members of the NORMAL_PRIORITY_CLASS. A process will belong to this class unless the parent of the process was of the IDLE_PRIORITY_CLASS or unless another class was specified when the process was created. The initial priority of a thread is typically the base priority of the process the thread belongs to. When a thread’s time quantum runs out, the thread is interrupted; if the thread is in the variable-priority class, its priority is lowered. However, the priority is never lowered below the base priority.

22 5.22 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Windows XP Priorities: Some Rules Lowering the thread’s priority tends to limit the CPU consumption of compute-bound threads. When a variable-priority thread is released from a wait operation, the dispatcher boosts the priority. The amount of boost depends on what the thread is waiting for: A thread that was waiting for keyboard I/O would get a large increase A threat that was waiting for a disk operation would get a moderate increase Windows XP distinguishes between the foreground process that is currently selected on the screen and the background processes that are not currently selected. When a process moves into the background, Windows XP increases the scheduling quantum by some factor – typically by 3.

23 End of Chapter 5


Download ppt "Chapter 5: CPU Scheduling (Continuation). 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Determining Length."

Similar presentations


Ads by Google