cpu scheduling
play

CPU Scheduling Scheduling processes (or kernel-level threads) onto - PowerPoint PPT Presentation

CPU Scheduling Scheduling processes (or kernel-level threads) onto the cpu is one of the most important OS functions. The cpu is an expensive resource so utilize it well. May have more than 1. With multiprogramming will have many processes


  1. CPU Scheduling Scheduling processes (or kernel-level threads) onto the cpu is one of the most important OS functions. The cpu is an expensive resource so utilize it well. May have more than 1. With multiprogramming will have many processes (threads) to pick from. The scheduler runs an algorithm to decide which to pick. Want to make efficient use of cpu(s).

  2. CPU Scheduling Remember process switching is expensive. Need to save state. *I/O Bound and cpu bound processes * A cpu bound process will use the cpu for long periods of time between I/O use. An I/O bound process will use the cpu for short periods of time, spending a lot of time doing I/O. When a process is doing I/O take it off of the cpu and let a process in ready state run.

  3. CPU Scheduling Non-preemptive algorithms let processes run until they give up the cpu or do I/O. Preemptive algorithms will interrupt a process after it has used up its time quantum (limit on cpu) and let another one run.

  4. CPU Scheduling Goals Fairness – give all processes a chance to have cpu. Balance – keep all parts of system that can be used busy. Throughput – maximize jobs per time. Turnaround time – average time for job to finish – minimize it. CPU utilization – keep cpu busy. Response time – be responsive to interactive users. Enforce policy and meet user expectations

  5. CPU Scheduling Goals Some of the goals contradict each other. For example, better utilization would lead to worse response time. A better response time would decrease utilization Also for real time systems: Meet deadlines Predictability We'll look at some algorithms next.

  6. First-Come First-Served (FCFS) Simple algorithm. Let first job in run first. Nonpreemptive. One queue of ready processes. Take off cpu when blocks and let next in line run. When process done blocking it goes to the end of the line. Like lines of people being served. Very simple to understand and code.

  7. Problems with FCFS Favors cpu-bound over I/O bound process Penalizes short and I/O bound processes turnaround time = execution + wait time Waiting in line at the store or bank analogies.

  8. Shortest Job First (SJF) Assumes know run times in advance. Nonpreemptive. Pick the shortest job in queue first and run Turnaround time is optimal. Penalizes long jobs. Good response time for short processes.

  9. Shortest Remaining Time Next Preemptive version of SJF. Pick process with shortest remaining time. If a new job needs less time than the current running one, give it the cpu. Good response time for short jobs. Need to know time required. May starve long processes.

  10. Round-Robin Scheduling Widely used, fair, simple, old, preemptive Time-slicing Define a time quantum – the amount of time a process can stay on cpu. Once used up take it off. Also taken off when blocks. Take next job on list. Overhead (waste of cpu) from context switch – make quantum long enough.

  11. Round-Robin Scheduling (cont) Too long of a quantum can give bad interactive response. Better performance if preemption is rare and process switch on I/O mostly. All jobs of equal importance.

  12. Priority Scheduling Assign priorities and let highest priority process have cpu. Priority may change as time goes by. May also use a quantum. Priorities may be static or dynamic. Group processes into priority classes and use round-robin on each class. Starvation of low-priority jobs possible. Unix nice values.

  13. Multiple Queues Idea: Give cpu-bound process a large quantum and schedule them infrequently Have priority classes. Highest class run for one quantum. Next class two quantum, next 4 quantum and so on. If a process uses up its quantum (cpu-bound) it gets put in lower class. Interactive use could raise priority.

  14. Fair share scheduling (FSS) Take into account who owns the process and be fair to the user rather than the processes. Added to Solaris 9. Very useful with zones (covered soon) Example: Give group A a share of 50, group B a share of 30 and group C a share of 20.

  15. Some other algorithms Shortest Process Next - Run process with shortest estimated time based on past use. Guaranteed Scheduling - For n users (or processes) let each get 1/n of the cpu. Lottery Scheduling - Have lottery tickets. The winning prize is time on the cpu. Give higher priority processes more tickets.

  16. Real-Time Scheduling Must get something done within a fixed period of time. Hard real time – absolute deadlines must be met. Soft real time – would rather not miss a deadline, but once in a while a miss is ok.

  17. Thread Scheduling With only user-level threads the kernel schedules the process and the thread scheduler of the process schedules the threads. With kernel-level threads the kernel picks a thread to run.

  18. Solaris Process Scheduling Kernel threads are scheduled. Derived from SVR4 and inherited 3 scheduling classes from it. - Time Share (TS) - Real Time (RT) - System (SYS) Later interactive (IA) was added.

  19. Solaris Process Classes Time Share (TS) – as threads run, their priority gets worse; as they wait, it gets better. Designed to fairly allocate cpu. Run thread until gives up cpu (blocking) or use up the time quantum. Real Time (RT) – for processes that need real-time requirements. Stay on cpu as long as need it. System (SYS) – Used by the OS. Interactive (IA) – To give better response to GUI desktop processes.

  20. Solaris Process Classes The Fixed priority class (FX) was added more recently. It gives processes a fixed priority. TS, IA, RT and FX are dynamically loadable kernel modules. SYS is integral to the kernel. priocntl -l Solaris has global priorities where higher priorities are better.

  21. Solaris Process Classes 169 high Interrupts If RT is not 160 159 loaded then Real time interrupts are 100 from 100-109 99 System 60 ps -eLc look at class 59 Time Share and priority and Interactive of LWPs 0 low

  22. More Solaris Process Classes The IA class is not much different than TS They share the same dispatch table and global priority range. Lower priority threads get a larger time quantum. The quantum gets smaller as priority increases as higher priority threads get scheduled more often. Time quantum is typically tens of ms. Priority of thread changes as time goes by Every thread will be within 50-59 every second.

  23. More Solaris Process Classes CPU hogs will end up in the low priority range as they keep using up quantum. If they do not use all of time quantum priority will increase. An IA class process has priority increased when it is the process with the current window focus. The SYS class has no dispatch table or time quantum. No time-slicing and no re-prioritization. Run until voluntarily give up processor.

  24. Priority Inversion Happens when a lower priority thread prevents a higher priority thread from running as it is holding a critical resource needed. Solved by letting the lower priority thread inherit a higher priority and continue to run. Done to prevent a deadlock.

  25. Linux Scheduling Schedules threads. 1. Real-Time FIFO- is highest priority with no preemption except by new ones in this class. 2. Real-Time RR – are preemptable with no deadlines. 3. Timesharing – standard class

Recommend


More recommend