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

cpu scheduling
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 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).

slide-2
SLIDE 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.

slide-3
SLIDE 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.

slide-4
SLIDE 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

slide-5
SLIDE 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.

slide-6
SLIDE 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.

slide-7
SLIDE 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.

slide-8
SLIDE 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.

slide-9
SLIDE 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.

slide-10
SLIDE 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.

slide-11
SLIDE 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.

slide-12
SLIDE 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.

slide-13
SLIDE 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.

slide-14
SLIDE 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.

slide-15
SLIDE 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.

slide-16
SLIDE 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.

slide-17
SLIDE 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.

slide-18
SLIDE 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.

slide-19
SLIDE 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)

  • r 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.

slide-20
SLIDE 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.

slide-21
SLIDE 21

Solaris Process Classes

169 160 159 100 99 60 59 high Interrupts Real time System Time Share and Interactive low

If RT is not loaded then interrupts are from 100-109 ps -eLc look at class and priority

  • f LWPs
slide-22
SLIDE 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.

slide-23
SLIDE 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.

slide-24
SLIDE 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.

slide-25
SLIDE 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