Vous êtes sur la page 1sur 19

Ekta Khandelwal 1060 M.

Tech CS&E

Problem definition:
One CPU with a number of processes. Only one process can use the CPU at a time and each process is specialized in one, and one task. Whats the best way to organize the processes (schedule them) ? [1] How will the CPU time be divided among the processes and threads competing to use it ? [2]

No one right approach


Many different criteria for different situations Many different factors to optimize

A pool of runnable processes are contending for one CPU; The processes are independent and compete for resources; The job of the scheduler is to distribute the scarce resource of the CPU to the different processes fairly and in an optimal way; The job of the dispatcher is to provide the mechanism for running the processes; The OS is a multitasking, but not a multiprocessor, one;

CPU utilization Throughput

Waiting time

Response time

Scheduler efficiency Turnaround time

Keep it as high as possible Number of processes completed per unit time Amount of time spent ready to run but not runnin Amount of time between submission of requests and first response to the request Minimize the overhead Mean time from submission to

Resources:
Preemptible:
Take resource away, use it for something else, then give it back. (e.g. processor or I/O channel)

Processes:
IO bound:
Perform lots of IO operations.

CPU bound:
Perform lots of computation and do little IO

Non-preemptible:
Once give, it cant be reused until process gives it back. (e.g. file space or terminal)

The states of a process, at any given time, is comprised of the following minimal set:
Running: The CPU is currently executing the code belonging to the process. Ready: The process could be running, but another process has the CPU. Waiting: Before the process can run, some external event must occur.

First-Come First-Serve (FCFS)


One ready queue; OS runs the process at head of the queue; New processes come in at the end of the queue; Running process does not give up the CPU until it terminates or it performs IO.

Round Robin
Process runs for one time slice, then moved to back of the queue; Each process gets equal share of the CPU.

Priority Systems
The highest priority ready process is selected In case of a tie, FCFS can be used Priorities could be assigned:
Externally (e.g. by a system manager) Internally (e.g. by some algorithm) Combination of external and internal

Preemptive schemes:
Once a process starts executing, allow it to continue until it voluntarily yields the CPU

Non-preemptive schemes:
A running process may be forced to yield the CPU by an external event rather than by its own action

Non-preemptive FCFS (no priority scheme)


Simplest implementation of scheduling algorithms Used on timeshared systems (with timer interruption)

Non-preemptive FCFS (with priority scheme)


Next highest priority process is picked when CPU is yielded Once process grabs CPU, former keeps latter until completion Rarely used in real-time systems

Preemptive FCFS (with priority scheme)


Most popular FCFS algorithm

Allows multiple users slices of the CPU on a round robin basis Majority of users have the same priority Not a popular scheme with dynamic priority systems

For each process, identify duration (i.e., length) of its next CPU burst. Use these lengths to schedule process with shortest burst Two schemes:
Non-preemptive once CPU given to the process, it is not preempted until it completes its CPU burst Preemptive if a new process arrives with CPU burst length less than remaining time of current executing process, preempt.
This scheme is known as the Shortest-Remaining-Time-First (SRTF)

of long one. SJF is provably optimal gives minimum average waiting time for a given set of process bursts
Moving a short burst ahead of a long one reduces wait time of short process more than it lengthens wait time

ProcessArrival TimeBurst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4 SJF (non-preemptive)


P1 P3 P2 P4

Average waiting time 8 (0 +12 + 3 + 7)/4 = 6 0 3 7 16 =4

CS-502 Fall 2007

Scheduling

13

ProcessArrival TimeBurst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4 SJF (preemptive)

Average waiting time = (9 + 1 + 0 +2)/4 = 11 16 0 3 2 4 5 7

P1

P2

P3

P2

P4

P1

CS-502 Fall 2007

Scheduling

14

A priority number (integer) is associated with each process CPU is allocated to the process with the highest priority (smallest integer highest priority)
Preemptive nonpreemptive

CS-502 Fall 2007

Scheduling

15

(Usually) preemptive Process are given priorities and ranked

SJF = priority scheduling where priority is


next predicted CPU burst time Recalculate priority many algorithms
E.g. increase priority of I/O intensive jobs E.g. favor processes in memory Must still meet system goals e.g. response time

Highest priority runs next May be done with multiple queues multilevel

CS-502 Fall 2007

Scheduling

16

Problem: Starvation low priority processes may never execute Solution: Aging as time progresses, increase priority of waiting processes

CS-502 Fall 2007

Scheduling

17

General theme what is the best way to run n processes on k resources? ( k < n) Conflicting Objectives no one best way

Incomplete knowledge
Real world limitations

Latency vs. throughput Speed vs. fairness

E.g. does user know how long a job will take E.g. context switching takes CPU time Job loads are unpredictable

CS-502 Fall 2007

Scheduling

18

Vous aimerez peut-être aussi