Presentation is loading. Please wait.

Presentation is loading. Please wait.

O PERATING S YSTEMS AND A RCHITECTURES CS-M98 P ART 7 S CHEDULING Benjamin Mora 1 Swansea University Dr. Benjamin Mora.

Similar presentations

Presentation on theme: "O PERATING S YSTEMS AND A RCHITECTURES CS-M98 P ART 7 S CHEDULING Benjamin Mora 1 Swansea University Dr. Benjamin Mora."— Presentation transcript:

1 O PERATING S YSTEMS AND A RCHITECTURES CS-M98 P ART 7 S CHEDULING Benjamin Mora 1 Swansea University Dr. Benjamin Mora

2 C ONTENT Main Principles behind Scheduling. Scheduling Algorithms. Comparison of Several Algorithms. 2 Benjamin Mora Swansea University

3 M AIN P RINCIPLES 3 Benjamin Mora Swansea University

4 R EMINDER : P ROCESS S TATES 4 Benjamin Mora Swansea University

5 S CHEDULING Scheduling consists of determining which processes are to be run by the processor. Mainly for multitasked environments. Mainly Pre-emptive. The scheduler is the part of the OS managing scheduling. The scheduling algorithm is the algorithm used by the scheduler. Process/Context Switching consists of switching between tasks. Consume resources 5 Benjamin Mora Swansea University

6 W HEN S CHEDULING When a process blocks (e.g. on I/O, a semaphore, or voluntarily). When a process terminates. When a new process is created. When an interrupt occurs e.g. blocking I/O operation now ready, so might want to activate waiting process. End of a quantum current process has had its time slot, OS will preempt it and run another process. Note that some operating systems and some scheduling algorithms are non-preemptive, so this never happens. 6 Benjamin Mora Swansea University

7 D ECISION M ODE Non-Multitask (Non-preemptive) Processes will be run sequentially. Co-operative (Non-preemptive) The process blocks itself when needed (termination, I/O, OS request). Preemptive The OS interrupts Processes. The process can be interrupted by the OS. When quantum time lapsed. More overhead. More interactive. 7 Benjamin Mora Swansea University

8 D IFFERENCES BETWEEN PROCESSES Different processes: Different goals! OS must have a good strategy. Adaptive mechanism. CPU-bound processes. Mainly computations, only a few I/O operations. More time can be allocated to these processes. I/O-bound processes. Most time waiting for events. 8 Benjamin Mora Swansea University

9 S CHEDULING A LGORITHM T YPE Different Operating Systems, different goals! Interactive Environment: Interact with the user. Personal computers. Preemptive scheduling. Event programming. Batch Environment: Send jobs to the system. Data centers, supercomputers, etc… Global performances improved. Can be cooperative, preemptive with long delays. 9 Benjamin Mora Swansea University

10 S UB -S CHEDULERS Long-Term Scheduler Not Frequently Used, only on coarse-grained programs. Decides which programs to add to the pool. Mid-Term Scheduler For virtual memory management. Short-Term Scheduler Often called, makes fast decisions. Favor short tasks (real-time programs). 10 Benjamin Mora Swansea University

11 S CHEDULING A LGORITHM T YPE Real-Time Operating Systems: Ensuring/Meeting/Predicting deadlines. Upper bound execution time. Required efficient programming methodologies! Planes, nuclear power plants, consoles, multimedia systems, etc… Process environment better known from the start. 11 Benjamin Mora Swansea University

12 S CHEDULING A LGORITHM T YPE Hard Real-Time. Deadlines must be met! System failing otherwise Deterministic and reliable. Though immediate detection & recovery must be implemented. Paging, Swapping & dynamic memory allocations usually not possible. Proven/normalized/deterministic compilers. Interrupts minimized. Planes, power plants, critical systems. Worst Case Executation Time must be known! Soft Real-Time. Deadlines should be met! Relaxed constraints. Priority given to real-time processes. Results sometimes discarded if not on time. Multimedia systems. Consoles. Phones. 12 Benjamin Mora Swansea University

13 S CHEDULING A LGORITHM T YPE Firm Real-Time. Intermediate between soft and hard Deadlines should be met. Any failure will degrade performance. “A few” misses could be accepted. Results are invalid if obtained after deadline! The opportunity is lost Interactive systems E.g, RealTime financial systems. High-Frequency Trading Loss of money 13 Benjamin Mora Swansea University

14 S CHEDULING O BJECTIVES Fairness. Make sure each process gets its fair share of the CPU, and no process suffers indefinite postponement. Priority settings possible. Balance resource usage. Efficiency. Keep the CPU and the other parts of the system as busy as possible. Reduced overhead. 14 Benjamin Mora Swansea University

15 S CHEDULING O BJECTIVES Batch Systems: Maximize throughput/jobs per hour. Turnaround time. Minimize time between submission and termination. Maximize CPU utilization. Interactive systems: Minimize response time. Increase productivity. Real-Time Systems: Quite specific to the context. 15 Benjamin Mora Swansea University

16 S CHEDULING A LGORITHMS 16 Benjamin Mora Swansea University

17 S CHEDULING A LGORITHMS First come, first served. Round Robin. Priority scheduling. Shortest process next. Shortest remaining time & Highest Response Ratio Next. Multilevel Feedback queues. Early Unix Priority Scheduling. Fair Share Scheduling. 17 Benjamin Mora Swansea University

18 F IRST C OME, F IRST S ERVED FIFO list of ready processes. When a process terminates its execution, the next process in the queue is executed. Nonpreemptive. High response time. Minimum overhead. Penalize short processes. No starvation. 18 Benjamin Mora Swansea University

19 R OUND R OBIN (T IME S LICING ) FIFO list. Widely used. Simple Fair preemptive. minimum overhead. no starvation. good response time for short processes A quantum of time is defined. Must be carefully chosen. Depends on the processor type. 19 Benjamin Mora Swansea University P1 P2 P3 P4 FIFO List 10 ms

20 P RIORITY S CHEDULING Adding priorities to processes is sometimes required. Highest priority processes are run. Several priority queues have to be handled. Round-Robin can be performed inside each queue. May lead to starvation. The OS has to detect starvation. Priority may be decreased. 20 Benjamin Mora Swansea University

21 S HORTEST P ROCESS N EXT Select the expected shortest process. High throughput. High overhead. Better for short processes. Non-preemptive. Requires estimating the amount of time required by each process. Can be estimated by the user for batch jobs. Can be done based on statistics acquired from the running processes. 21 Benjamin Mora Swansea University

22 R UNNING T IME P REDICTION With S n : Predicted evaluation of running time for the n th time the process uses the CPU. T i : Time used for the i th execution of the process. To give more importance to the recent executions of the process, one can use: 22 Benjamin Mora Swansea University

23 S HORTEST R EMAINING T IME, H IGHEST R ESPONSE R ATIO N EXT Based on the same idea as Short Process Next. Shortest Remaining Time: Preemptive version of Short Process Next. Highest Response Ratio Next: Non-Preemptive. Minimization of the normalized turn around time. Minimize starvation. Priority =1+ (waiting_time/estimated_run_time) 23 Benjamin Mora Swansea University

24 M ULTILEVEL F EEDBACK Q UEUES 24 Benjamin Mora Swansea University

25 M ULTILEVEL F EEDBACK Q UEUES Based on multi-level queues. Lowest levels have increased priorities, but also shortest quantum times. A new process enters the lowest level queue and may preempt the current running process. All levels but the last one (round-robin) are usually first come, first served. 25 Benjamin Mora Swansea University

26 M ULTILEVEL F EEDBACK Q UEUES Main characteristics: Preemptive. Throughput and response times OK, although not best. Possibly high overhead. May favor I/O bound processes. Possible starvation. 26 Benjamin Mora Swansea University

27 E ARLY U NIX P RIORITY S CHEDULING Every active process has a scheduling priority. The CPU is given to the process having the highest priority The lowest priority value in implementation! User process priorities change every quantum. Cannot go beyond a specific priority. Not for super-user processes. 27 Benjamin Mora Swansea University

28 E ARLY U NIX P RIORITY S CHEDULING Each process control block contains: the CPU usage of the process. (cpu) a scheduling priority. (prio) Rules: If a process does not use its entire time slice, the algorithm will tend to run sooner. At every clock interupt, the CPU usage is incremented. At the end of every quantum (60 time units in example): cpu = cpu / 2 prio = cpu / 2 + BASE_LEVEL_PRIORITY; 28 Benjamin Mora Swansea University

29 E ARLY U NIX P RIORITY S CHEDULING 29 Benjamin Mora Swansea University

30 S YSTEM V R 4 AND S OLARIS 30 Benjamin Mora Swansea University

31 F AIR SHARE SCHEDULING Fixed distribution of CPU usage among users and groups. A weight is given to every user/group. A grp_cpu variable must be added per user/group After every quantum, for every process: 31 Benjamin Mora Swansea University cpu = cpu / 2; grp_cpu = grp_cpu / 2; prio = cpu / 2 + weight*(grp_cpu/2)+ BASE_LEVEL_PRIORITY;

32 F AIR SHARE SCHEDULING : E XAMPLE 32 Benjamin Mora Swansea University =

33 C OMPLETELY F AIR S CHEDULER Linux Not O(1) Scheduler. Schedule classes. Different scheduling policies: SCHED_NORMAL, SCHED_BATCH, SCHED_IDLE. Real-time scheduler: SCHED_RR and SCHED_FIFO. Uses a time-ordered red-black tree. Nano-second granularity. 33 Benjamin Mora Swansea University

34 C OMPARISON OF S EVERAL A LGORITHMS 34 Benjamin Mora Swansea University

35 A SSUMPTIONS 5 Processes arrive at time 0. The CPU ready queue is empty at time 0. The time needed for context switches can be ignored. 35 Benjamin Mora Swansea University

36 A SSUMPTIONS In round robin scheduling, a process will release the CPU voluntarily if it needs less than a quantum. A newly arrived process is placed in the ready queue before a process whose quantum expires at the same time. 36 Benjamin Mora Swansea University

37 C OMPARISON 37 Benjamin Mora Swansea University

38 C RITERIA / A NALYSIS Average waiting time. Throughput. number of jobs finished in 30 ms. Fairness/Efficiency: number of processes getting the CPU after 30 ms. 38 Benjamin Mora Swansea University

39 C OMPARISON 39 Benjamin Mora Swansea University

Download ppt "O PERATING S YSTEMS AND A RCHITECTURES CS-M98 P ART 7 S CHEDULING Benjamin Mora 1 Swansea University Dr. Benjamin Mora."

Similar presentations

Ads by Google