32
MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Baile

MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

Embed Size (px)

Citation preview

Page 1: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

MM Process Management

Karrie KarahaliosSpring 2007

(based off slides created by Brian Bailey)

Page 2: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

Announcements

Page 3: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

CPU Scheduling

• Maintain many programs in memory

• Determine how to best schedule them

• Requires information about the processes and an understanding of the system goals

• Switch among processes rapidly so each user perceives direct ownership of system

Page 4: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

Process State

• New – being created

• Terminated – finishing execution

• Running – executing on the CPU

• Waiting – blocking on an event

• Ready – waiting for the CPU

Page 5: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

Process Control Block

• Represents a process in the OS– process state– program counter– CPU registers– scheduling information– virtual memory information (e.g., page tables)– I/O status information

Page 6: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

Resource Queues

Sem Queue

head

tail

Ready Queue

head

tail

PCB6

State

Registers

Disk Queue

head

tail

PCB5

State

Registers

PCB4

State

Registers

PCB3

State

Registers

PCB2

State

Registers

PCB1

State

Registers

Page 7: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

CPU Scheduler

• When CPU becomes idle, select next process from the ready queue

• CPU may become idle when:– allotted time slice expires– interrupt occurs (timer, I/O, user input)– application makes an I/O request– application terminates

Page 8: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

Evaluation Criteria

• Throughput: processes completed per unit time

• Turnaround: from submission to termination

• Wait: time waiting in the ready queue

• Response: from user request to system response

• Utilization: how busy the CPU is over time

• Want predictable system behavior

Page 9: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

Scheduling Algorithms

• FCFS

• Shortest Job First

• Priority scheduling

• Round-robin

• Multi-level queue

• Rate monotonic

• Earliest deadline first

Page 10: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

FCFS

• Process requests in order of arrival– non-preemptive algorithm– fairness (human vs. system perspective)– convoy effect

Page 11: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

Shortest-Job-First

• Schedule process with smallest burst– difficult to know next CPU burst– use weighted average of past performance

• Gives min wait time for processes– if preemptive, may lead to starvation

nnn t )1(1

Page 12: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

Priority

• Associate priority with each process

• Schedule process with highest priority– equal priority resolved via FCFS– if priority is a function of time, gives SJF

• Combat CPU starvation using aging– increase priority of long-waiting processes

Page 13: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

Round Robin

• Schedule process after a time quantum– circulate around queue, give each process

single time quantum to execute– results in lots of context switches

• Selection of time quantum– short quantum results in longer waits– infinite quantum results in FCFS– should be large relative to context switch time

Page 14: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

Take Home Exercise

• Assume workload shown on the right

• Compare FCFS, SJF, and RR (quantum=10)– compare along each

evaluation criteria

Process Arrival CPU Burst

P1 1 10

P2 2 29

P3 3 3

P4 4 7

P5 5 12

Page 15: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

Multimedia Processes

• Exhibit continuous, periodic behavior

• Execute along with other processes

• Have perceptual constraints (QoS)

Page 16: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

Scheduling

• Determine sharing of a resource such that all admitted tasks meet their deadlines

• Balance need to meet deadlines with maximizing throughput and utilization

Page 17: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

Admissibility Test

• If test succeeds, the task can be added, and all tasks will still meet deadlines– called a feasible schedule

• Process utilization (U)<1 if deadlines considered

n

i

ii TCU1

/

Page 18: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

Rate Monotonic Scheduling

• Static, fixed priority-based, periodic tasks– Ci is execution time of task i

– Ti is request period of task i

• Determines if a set of periodic tasks can be scheduled or not (feasible schedule)– no other fixed priority scheme can schedule a

set of tasks which can’t be scheduled by RM

Liu, C.L. and J.W. Layland. Journal of the ACM, 20(1): 46-61, 1973

Page 19: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

Model Assumptions

• All requests to process tasks are periodic

• Each task must finish before next request

• Each request is independent

• Execution time for each task is constant

• Non-periodic tasks are special

• Tasks are preemptive based on priority– static: priorities assigned once at initialization– dynamic: priorities change during execution

Page 20: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

Terminology

• Deadline– time of the next request for same task

• Feasible– no deadlines are missed

• Response time– time between request and completion of a task

• Critical instant– when a request for a task will have the largest response time– occurs when a task is requested simultaneously with requests

for all higher priority tasks• Critical time zone

– time between a critical instant and the end of the response to the corresponding request of the lowest priority task

Page 21: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

Example 1

T1 = 2

C1 = 1 C2 = 1

T2 = 5

T1 is higher priority

Utilization (U) =

Page 22: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

Example 2

T1 = 2

C1 = 1 C2 = 2

T2 = 5

T1 is higher priority

Utilization (U) =

Page 23: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

Feasibility Test

• If requests for all tasks at their critical instants can be fulfilled, then feasible

• Determine least upper bound of U– maximum utilization such that all deadlines

are still satisfied, in the general case

• Assigning highest priority to task with the smallest period yields best utilization

Page 24: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

Problem for Two Tasks

• Tasks (C1, T1) and (C2, T2), with T1 < T2

• Within request period of T2, there can be at most ceil(T2 / T1) requests from T1

• Adjust C2 to fully utilize CPU

Page 25: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

Case 1

• Requests for task1 completed within T2

– no overlap with T2

• In this case, largest value of C2 can be

C2 = T2 – C1*ceil(T2/T1)

• U = 1 + C1[ (1/T1) – (1/T2) *ceil(T2 / T1)]

Page 26: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

Case 2

• Execution of ceil(T2/T1)th request from task1 overlaps second request from task2

– e.g. (C1=1,T1=1.5); (C2=1, T2=5)

• In this case, largest value of C2 can be

C2 = T1*fl(T2/T1) – C1*fl(T2/T1)

• U = (T1/T2)*fl(T2/T1) + C1[ (1/T1) – (1/T2) *fl(T2 / T1)]

Page 27: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

Minimum Occurs at Boundary

• Minimum of U occurs at the boundary between these two cases

• Set equations equal and solve for C1

C1 = T2 – T1*fl(T2/T1)

• U = 2(21/2 – 1) =~ 0.83– highest utilization such that all deadlines met

Page 28: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

General Case

• For two tasks– U < 2 (2½ - 1), ~= 0.83

• For three tasks– U < 3 (21/3 - 1) ~= 0.78

• For n tasks– U < n (21/n – 1) -> ln 2 ~= 0.69

• If configuration of tasks pass the test, no deadlines will be missed– must limit utilization to 69% for large N !!!

Page 29: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

Example

• Is this configuration of tasks admissible?

C1 = 1.5 C2 = 2.1

T1 = 2.5 T2 = 6

Page 30: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

Example

• Is this configuration of tasks admissible?

C1 = 1 C2 = 2

T1 = 2 T2 = 4

Page 31: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

Deadline Driven Scheduling (EDF)

• Assign priorities to tasks based on the deadlines of their current requests

• Execute task with highest priority and yet unfulfilled request

• Optimal scheduling algorithm– If tasks can be scheduled by any algorithm,

then they can also be scheduled by EDF

Page 32: MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)

Compare Rate Monotonic vs. EDF

– C1 = 1.5 C2 = 2.1

– T1 = 2.5 T2 = 6

• Draw timing models for each– show failure with RM, but success with EDF