Presentation is loading. Please wait.

Presentation is loading. Please wait.

2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.

Similar presentations


Presentation on theme: "2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming."— Presentation transcript:

1 2.5 Scheduling

2 Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). The scheduler (using a scheduling algorithm) decides which process will run next. The scheduler (using a scheduling algorithm) decides which process will run next. User satisfaction is important. User satisfaction is important.

3 Context switch When the CPU changes from one process to another. When the CPU changes from one process to another. Expensive operation. Expensive operation. 1. User mode to kernel mode 2. Save state of current process Registers, invalidate cache, MMU (Note: Pipeline becomes useless.) Registers, invalidate cache, MMU (Note: Pipeline becomes useless.) 3. Run scheduler Pick next process to run Pick next process to run Load state of next process Load state of next process 4. Run next process

4 Process behavior Types: Types: 1. I/O bound – spend most time performing I/O 2. Compute bound – spend most time performing computation 3. Mixture

5 When do we need to schedule? creation (before/after parent?) creation (before/after parent?) exit exit block (I/O, semaphore, sleep, wait, etc.) block (I/O, semaphore, sleep, wait, etc.) I/O interrupt/completion I/O interrupt/completion clock interrupt clock interrupt non preemptive (run until you block or “cooperate”) non preemptive (run until you block or “cooperate”) preemptive preemptive

6 Scheduling environments 1. Batch 2. Interactive 3. Real time

7 Scheduling algorithm goals (for all systems)

8 Scheduling algorithm goals (for batch systems)

9 Scheduling algorithm goals (for interactive systems)

10 Scheduling algorithm goals (for real-time systems)

11 Concepts & definitions Throughput = # of jobs completed per hour Throughput = # of jobs completed per hour

12 Concepts & definitions Turnaround time = avg of “start (submit) to completion” times; avg wait time Turnaround time = avg of “start (submit) to completion” times; avg wait time

13 Concepts & definitions CPU utilization = avg of CPU busyness CPU utilization = avg of CPU busyness

14 Concepts & definitions Response time = time between issuing a command and getting the result Response time = time between issuing a command and getting the result

15 Concepts & definitions Proportionality = user perception that “complex” things take a long time and that is fine, but “simple” things must be quick Proportionality = user perception that “complex” things take a long time and that is fine, but “simple” things must be quick

16 Concepts & definitions Predictability = regularity, especially important for audio and video streaming Predictability = regularity, especially important for audio and video streaming

17 BATCH SCHEDULING

18 Batch scheduling 1. First-come first-served 2. Shortest job first 3. Shortest remaining time next 4. Three-level scheduling

19 Batch scheduling 1. First-come first-served Simple Simple Non preemptive Non preemptive Process runs until it either blocks on I/O or finishes Process runs until it either blocks on I/O or finishes

20 Batch scheduling 2. Shortest job first Optimal turnaround time (when all start together) Optimal turnaround time (when all start together) Requires that we know run times a priori Requires that we know run times a priori

21 Batch scheduling 3. Shortest remaining time next Preemptive version of shortest job first Preemptive version of shortest job first Requires a priori information Requires a priori information When a new job arrives, its total time is compared to the current process’ remaining time. If the new job needs less time to finish, the new job is started. When a new job arrives, its total time is compared to the current process’ remaining time. If the new job needs less time to finish, the new job is started. New, short jobs get good service New, short jobs get good service

22 Batch scheduling 4. Three-level scheduling 1. Admission scheduler – chooses next job begin 2. Memory scheduler – which jobs are kept in memory and which jobs are swapped to disk How long swapped in or out? How long swapped in or out? How much CPU time recently? How much CPU time recently? How big is the process? How big is the process? How important is the process? How important is the process? 3. CPU scheduler – picks which runs next Degree of multiprogramming – number of processes in memory Degree of multiprogramming – number of processes in memory

23 INTERACTIVE SCHEDULING

24 Interactive scheduling 1. Round-robin scheduling 2. Priority scheduling 3. Multiple queues 4. Shortest process next 5. Guaranteed scheduling 6. Lottery scheduling 7. Fair-share scheduling

25 Interactive scheduling 1. Round-robin scheduling Simple, fair, widely used, preemptive Simple, fair, widely used, preemptive Quantum = time interval Quantum = time interval Process/context switch is expensive Process/context switch is expensive Too small and we waste time Too small and we waste time Too large and interactive system will appear sluggish Too large and interactive system will appear sluggish ~20-50 msec is good ~20-50 msec is good Every process has equal priority Every process has equal priority

26 Interactive scheduling 2. Priority scheduling Each process is assigned a priority; process with highest priority is next to run. Each process is assigned a priority; process with highest priority is next to run. Types: Types: 1. static 2. dynamic (ex. I/O bound jobs get a boost) Unix/Linux nice command Unix/Linux nice command

27 Interactive scheduling Ex. 4 priorities & RR w/in a priority Ex. 4 priorities & RR w/in a priority

28 Interactive scheduling 3. Multiple queues different Q’s for different types of jobs different Q’s for different types of jobs Ex. 4 queues for: Ex. 4 queues for: Terminal, I/O, short quantum, and long quantum Terminal, I/O, short quantum, and long quantum

29 Interactive scheduling 4. Shortest process next Shortest job first always produces min avg response time (for batch systems) Shortest job first always produces min avg response time (for batch systems) How do we estimate this (for interactive jobs)? How do we estimate this (for interactive jobs)?

30 Interactive scheduling 4. Shortest process next Shortest job first always produces min avg response time (for batch systems) Shortest job first always produces min avg response time (for batch systems) How do we estimate this (for interactive jobs)? How do we estimate this (for interactive jobs)? From recent behavior (of interactive commands, T i ) From recent behavior (of interactive commands, T i ) Example of aging (or IIR filter) Example of aging (or IIR filter) alpha near 1 implies little memory alpha near 1 implies little memory alpha near 0 implies much memory alpha near 0 implies much memory

31 Interactive scheduling Example of aging (or IIR filter) Example of aging (or IIR filter) alpha near 1 implies little memory alpha near 1 implies little memory alpha near 0 implies much memory alpha near 0 implies much memory How can we “increase” the “memory?” How can we “increase” the “memory?”

32 Interactive scheduling 5. Guaranteed scheduling Given n processes, each process should get 1/n of the CPU time Given n processes, each process should get 1/n of the CPU time Say we keep track of the actual CPU used vs. what we should receive (entitled to/deserved). Say we keep track of the actual CPU used vs. what we should receive (entitled to/deserved). K = actual / entitled K = actual / entitled K = 1  we got what we deserved K = 1  we got what we deserved K < 1  we got less than deserved K < 1  we got less than deserved K > 1  we got more than deserved K > 1  we got more than deserved Pick process w/ min K to run next Pick process w/ min K to run next

33 Interactive scheduling 6. Lottery scheduling Each process gets tickets; # of tickets can vary from process to process. Each process gets tickets; # of tickets can vary from process to process. If your ticket is chosen, you run next. If your ticket is chosen, you run next. Highly responsive (new process might run right away) Highly responsive (new process might run right away) Processes can cooperate (give each other their tickets) Processes can cooperate (give each other their tickets)

34 Interactive scheduling 7. Fair-share scheduling Consider who (user) owns the process Consider who (user) owns the process Ex. Ex. User A has 1 process User A has 1 process User B has 9 processes User B has 9 processes Should user A get 10% and user B get 90%? Should user A get 10% and user B get 90%? Or should A get 50% and B get 50% (5.6% for each of the 9 processes)? Or should A get 50% and B get 50% (5.6% for each of the 9 processes)? Latter is fair-share. Latter is fair-share.

35 REAL TIME SCHEDULING

36 Real time scheduling Time plays an essential role. Time plays an essential role. System must react w/in a fixed amount of time. System must react w/in a fixed amount of time.

37 Real time scheduling Categories: Categories: 1. Hard – absolute deadlines must be met 2. Soft – missing an occasional deadline is tolerable

38 Real time scheduling Event types: Event types: 1. Periodic = occurring at regular intervals 2. Aperiodic = occurring unpredictably

39 Real time scheduling Algorithm types: Algorithm types: 1. Static (before the system starts running) 2. Dynamic (scheduling decisions at run time)

40 Real time scheduling Given m periodic events. Given m periodic events. Event i occurs w/ period P i, and requires C i seconds of CPU time. Event i occurs w/ period P i, and requires C i seconds of CPU time. Schedulable iff: Schedulable iff: We’re basically normalizing C (event length) by P (event frequency).

41 Schedulable example Given periods P i = 100, 200, and 500 msec and CPU time requirements of C i = 50, 30, 100 msec Given periods P i = 100, 200, and 500 msec and CPU time requirements of C i = 50, 30, 100 msec Can we handle another event w/ P 4 =1 sec? Can we handle another event w/ P 4 =1 sec? Yes, as long as C 4 <=150 msec Yes, as long as C 4 <=150 msec

42 THREADS & THREAD SCHEDULING

43 Thread scheduling types: 1. User level 2. Kernel level

44 Thread scheduling 1. User level threads No clock interrupts (per thread) No clock interrupts (per thread) A compute bound thread will dominate its process but not the CPU A compute bound thread will dominate its process but not the CPU A thread can yield to other threads within the same process A thread can yield to other threads within the same process Typically round robin or priority Typically round robin or priorityTradeoffs: + Context switch from thread to thread is simpler + App specific thread scheduler can be used - If a thread blocks on I/O, the entire process (all threads) block

45 Thread scheduling 2. Kernel level threads Threads scheduled like processes. Threads scheduled like processes.Tradeoffs: - Context switch from thread to thread is expensive (but scheduler can make more informed choices). + A thread, blocking on I/O, doesn’t block all other threads in process.


Download ppt "2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming."

Similar presentations


Ads by Google