# 2 program process abstract computing environment file manager memory manager device manager...

TRANSCRIPT

2

ProgramProgram ProcessProcess

Abstract Computing Environment

FileManager

MemoryManager

DeviceManager

ProtectionProtection

DeadlockDeadlockSynchronizationSynchronization

ProcessDescription

ProcessDescription

CPUCPU Other H/WOther H/W

SchedulerScheduler ResourceManager

ResourceManagerResource

Manager

ResourceManagerResource

Manager

ResourceManager

MemoryMemoryDevicesDevices

Process Mgr

Scheduling mechanism is the part of the process manager that handles the removal of the running process of CPU and the selection of another process on the basis of a particular strategy Scheduler chooses one from the ready threads

to use the CPU when it is available Scheduling policy determines when it is time

for a thread to be removed from the CPU and which ready thread should be allocated the CPU next

3

4

ReadyList

ReadyList SchedulerScheduler CPUCPU

ResourceManager

ResourceManager

ResourcesResources

Preemption or voluntary yield

Allocate Request

DoneNewThread job

jobjob

jobjob

“Ready”“Running”

“Blocked”

New threads put into ready state and added to ready list

Running thread may cease using CPU for any of four reasons Thread has completed its execution Thread requests a resource, but can’t get it Thread voluntarily releases CPU Thread is preempted by scheduler and

involuntarily releases CPU Scheduling policy determines which

thread gets the CPU and when a thread is preempted

5

6

Ready Process

EnqueuerEnqueuer ReadyList

ReadyList

DispatcherDispatcher ContextSwitcher

ContextSwitcher

ProcessDescriptor

ProcessDescriptor

CPUCPU

From OtherStates

Running Process

Adds processes which are ready to run to the ready list

May compute the priority for the waiting process (could also be determined by the dispatcher)

7

Saves contents of processor registers for a process being taken off the CPU If hardware has more than one set of

processor registers, OS may just switch between sets

Typically, one set is used for supervisor mode, others for applications

Depending on OS, process could be switched out voluntarily or involuntarily

8

Dispatcher module gives control of the CPU to the process selected by the short-term scheduler; this involves: switching context

From process, to dispatcher, to new process switching to user mode jumping to the proper location in the user

program to restart that program

9

10

R1R2

Rn

. . .

StatusRegisters

Functional Unit

Left Operand

Right Operand

Result ALU

PC

IRCtl Unit

11

CPU

New Thread Descriptor

Old ThreadDescriptor

Context switching is a time-consuming process Assuming n general registers and m status registers,

each requiring b store operations, and K time units to perform a store, the time required is

(n + m) b × K time units Then a processor requiring 50 ns to store 1 unit of

information, and assuming that n = 32 and m = 8, the time required is 2000 ns = 2 μs

A complete context switch involves removing process, loading dispatcher, removing dispatcher, loader new process at least 8 μs required

Note that a 1 Ghz processor could have executed about 4,000 instructions in this time

Some processors use several sets of registers to reduce this switching time (one set for supervisor mode, the other for user)

12

Need a mechanism to call the scheduler Voluntary call

Process blocks itself Calls the scheduler Non-preemptive scheduling

Involuntary call External force (interrupt) blocks the process Calls the scheduler Preemptive scheduling

13

Each process will voluntarily share the CPU By calling the scheduler periodically The simplest approach Requires a yield instruction to allow the

running process to release CPU

14

yield(pi.pc, pj.pc) { memory[pi.pc] = PC; PC = memory[pj.pc];}

pi can be “automatically” determined from the processor status registers So function can be written as

15

yield(*, pj.pc) { memory[pi.pc] = PC; PC = memory[pj.pc];}

16

yield(*, pj.pc);. . .yield(*, pi.pc);. . .yield(*, pj.pc);. . .

• pi and pj can resume one another’s execution

• Suppose pj is the scheduler:// p_i yields to scheduleryield(*, pj.pc);// scheduler chooses pk

yield(*, pk.pc);// pk yields to scheduleryield(*, pj.pc);// scheduler chooses ...

Every process periodically yields to the scheduler

Relies on correct process behavior Malicious Accidental

Need a mechanism to override running process

17

18

Periodic involuntary interruption Through an interrupt from an interval timer

device Which generates an interrupt whenever the

timer expires The scheduler will be called in the interrupt

handler A scheduler that uses involuntary CPU sharing

is called a preemptive scheduler

19

20

IntervalTimer() { InterruptCount--; if (InterruptCount <= 0) { InterruptRequest = TRUE; InterruptCount = K }}

SetInterval( <programmableValue>) { K = <programmableValue>; InterruptCount = K;}

Interrupt occurs every K clock ticks

Interval timer device handler Keeps an in-memory clock up-to-date Invokes the scheduler

21

IntervalTimerHandler() { Time++; // update the clock TimeToSchedule--; if(TimeToSchedule <= 0) { <invoke scheduler>; TimeToSchedule = TimeSlice; }}

Involuntary CPU sharing – timer interrupts Time quantum determined by interval timer –

usually fixed size for every process using the system

Sometimes called the time slice length

22

Mechanism never changes Strategy = policy the dispatcher uses to

select a process from the ready list Different policies for different

requirements

23

Policy can control/influence: CPU utilization Average time a process waits for service Average amount of time to complete a job

Could strive for any of: Equitability Favor very short or long jobs Meet priority requirements Meet deadlines

24

Suppose the scheduler knows each process pi’s service time, pi -- or it can estimate each pi :

Policy can optimize on any criteria, e.g., CPU utilization Waiting time Deadline

To find an optimal schedule: Have a finite, fixed # of pi

Know pi for each pi

Enumerate all schedules, then choose the best25

The (pi) are almost certainly just estimates

General algorithm to choose optimal schedule is O(n2)

Other processes may arrive while these processes are being serviced

Usually, optimal schedule is only a theoretical benchmark – scheduling policies try to approximate an optimal schedule

26

The scheduling criteria will depend in part on the goals of the OS and on priorities of processes, fairness, overall resource utilization, throughput, turnaround time, response time, and deadlines

27

P will be a set of processes, p0, p1, ..., pn-1 S(pi) is the state of pi {running, ready,

blocked} τ(pi), the service time

The amount of time pi needs to be in the running state before it is completed

W (pi), the waiting time The time pi spends in the ready state before its

first transition to the running state TTRnd(pi), turnaround time

The amount of time between the moment pi first enters the ready state and the moment the process exits the running state for the last time

28

Simplified, but still provides analysis results Easy to analyze performance No issue of voluntary/involuntary sharing

29

ReadyList

ReadyList SchedulerScheduler CPUCPU

ResourceManager

ResourceManager

ResourcesResources

Allocate Request

DoneNewProcess job

jobjob

jobjob

“Ready”“Running”

“Blocked”

Preemption or voluntary yield

30

ReadyList

ReadyList SchedulerScheduler CPUCPU DoneNew

Process

System pi per second

Each pi uses 1/ μ units ofthe CPU

Let = the average rate at which processes are placed in the Ready List, arrival rate

Let μ = the average service rate 1/ μ = the average (pi)

31

ReadyList

ReadyList SchedulerScheduler CPUCPU DoneNew

Process

Let = the average rate at which processes are placed in the Ready List, arrival rate

Let μ = the average service rate 1/ μ = the average (pi)

Let = the fraction of the time that the CPU is expected to be busy = # pi that arrive per unit time * avg time each spends on CPU = * 1/ μ = / μ • Note: must have < (i.e., < 1)

• What if approaches 1?

Max CPU utilization Max throughput Min turnaround time Min waiting time Min response time Which one to use depends on the

system’s design goal

32

33

ReadyList

ReadyList SchedulerScheduler CPUCPU DoneNew

Process

• Try to use the simplified scheduling model

• Only consider running and ready states

• Ignores time in blocked state:– New process created when it enters ready state– Process is destroyed when it enters blocked state– Really just looking at “small phases” of a process

Blocked or preempted processes

First-come, first served (FCFS) Shorter jobs first (SJF)

or Shortest job next (SJN) Higher priority jobs first Job with the closest deadline first

34

35

36

Used to illustrate deterministic schedules Dependencies of a process on other processes

Plots processor(s) against time Shows which processes on executing on which

processors at which times Also shows idle time, so illustrates the

utilization of each processor In following, will only assume one

processor

37

First-Come-First-Served Assigns priority to processes in the order in

which they request the processor

i τ(pi)

0 350

1 125

2 475

3 250

4 7538

39

i (pi)0 3501 1252 4753 2504 75

p0

TTRnd(p0) = (p0) = 350 W(p0) = 0

0 350

40

i (pi)0 3501 1252 4753 2504 75

p0 p1

TTRnd(p0) = (p0) = 350TTRnd(p1) = ((p1) +TTRnd(p0)) = 125+350 = 475

W(p0) = 0W(p1) = TTRnd(p0) = 350

475350

41

i (pi)0 3501 1252 4753 2504 75

p0 p1 p2

TTRnd(p0) = (p0) = 350TTRnd(p1) = ((p1) +TTRnd(p0)) = 125+350 = 475TTRnd(p2) = ((p2) +TTRnd(p1)) = 475+475 = 950

W(p0) = 0W(p1) = TTRnd(p0) = 350W(p2) = TTRnd(p1) = 475

475 950

42

i (pi)0 3501 1252 4753 2504 75

p0 p1 p2 p3

TTRnd(p0) = (p0) = 350TTRnd(p1) = ((p1) +TTRnd(p0)) = 125+350 = 475TTRnd(p2) = ((p2) +TTRnd(p1)) = 475+475 = 950TTRnd(p3) = ((p3) +TTRnd(p2)) = 250+950 = 1200

W(p0) = 0W(p1) = TTRnd(p0) = 350W(p2) = TTRnd(p1) = 475W(p3) = TTRnd(p2) = 950

1200950

43

i (pi)0 3501 1252 4753 2504 75

p0 p1 p2 p3 p4

TTRnd(p0) = (p0) = 350TTRnd(p1) = ((p1) +TTRnd(p0)) = 125+350 = 475TTRnd(p2) = ((p2) +TTRnd(p1)) = 475+475 = 950TTRnd(p3) = ((p3) +TTRnd(p2)) = 250+950 = 1200TTRnd(p4) = ((p4) +TTRnd(p3)) = 75+1200 = 1275

W(p0) = 0W(p1) = TTRnd(p0) = 350W(p2) = TTRnd(p1) = 475W(p3) = TTRnd(p2) = 950W(p4) = TTRnd(p3) = 1200

1200 1275

44

i (pi)0 3501 1252 4753 2504 75

p0 p1 p2 p3 p4

TTRnd(p0) = (p0) = 350TTRnd(p1) = ((p1) +TTRnd(p0)) = 125+350 = 475TTRnd(p2) = ((p2) +TTRnd(p1)) = 475+475 = 950TTRnd(p3) = ((p3) +TTRnd(p2)) = 250+950 = 1200TTRnd(p4) = ((p4) +TTRnd(p3)) = 75+1200 = 1275

W(p0) = 0W(p1) = TTRnd(p0) = 350W(p2) = TTRnd(p1) = 475W(p3) = TTRnd(p2) = 950W(p4) = TTRnd(p3) = 1200

Wavg = (0+350+475+950+1200)/5 = 2974/5 = 595

127512009504753500

•Easy to implement•Ignores service time, etc•Not a great performer

In FCFS, when a process arrives, all in ready list will be processed before this job

Let μ be the service rate Let L be the ready list length Wavg(p) = L*1/μ + 0.5* 1/ μ = L/ μ +1/(2 μ)

(in queue) (active process) Compare predicted wait with actual in

earlier examples

45

Example: Process Burst Time P1 24 P2 3 P3 3

Suppose that the processes arrive in the order: P1, P2 , P3 The Gantt Chart for the schedule is:

Waiting time for P1 = 0; P2 = 24; P3 = 27

Average waiting time: (0 + 24 + 27)/3 = 17

46

P1 P2 P3

24 27 300

Suppose that the processes arrive in the order P2 , P3 , P1

The Gantt chart for the schedule is:

Waiting time for P1 = 6; P2 = 0; P3 = 3 Average waiting time: (6 + 0 + 3)/3 = 3 Much better than previous case.

47

P1P3P2

63 300

Associate with each process the length of its next CPU burst. Use these lengths to schedule the process

with the shortest time. SJN is optimal

gives minimum average waiting time for a given set of processes.

48

Two schemes: non-preemptive – once CPU given to the

process it cannot be preempted until 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 know as the Shortest-Remaining-Time-Next (SRTN).

49

50

i (pi)0 3501 1252 4753 2504 75

p4

TTRnd(p4) = (p4) = 75 W(p4) = 0

750

51

i (pi)0 3501 1252 4753 2504 75

p1p4

TTRnd(p1) = (p1)+(p4) = 125+75 = 200

TTRnd(p4) = (p4) = 75

W(p1) = 75

W(p4) = 0

200750

52

i (pi)0 3501 1252 4753 2504 75

p1 p3p4

TTRnd(p1) = (p1)+(p4) = 125+75 = 200

TTRnd(p3) = (p3)+(p1)+(p4) = 250+125+75 = 450TTRnd(p4) = (p4) = 75

W(p1) = 75

W(p3) = 200W(p4) = 0

450200750

53

i (pi)0 3501 1252 4753 2504 75

p0p1 p3p4

TTRnd(p0) = (p0)+(p3)+(p1)+(p4) = 350+250+125+75 = 800TTRnd(p1) = (p1)+(p4) = 125+75 = 200

TTRnd(p3) = (p3)+(p1)+(p4) = 250+125+75 = 450TTRnd(p4) = (p4) = 75

W(p0) = 450W(p1) = 75

W(p3) = 200W(p4) = 0

800450200750

54

i (pi)0 3501 1252 4753 2504 75

p0p1 p2p3p4

TTRnd(p0) = (p0)+(p3)+(p1)+(p4) = 350+250+125+75 = 800TTRnd(p1) = (p1)+(p4) = 125+75 = 200TTRnd(p2) = (p2)+(p0)+(p3)+(p1)+(p4) = 475+350+250+125+75 = 1275TTRnd(p3) = (p3)+(p1)+(p4) = 250+125+75 = 450TTRnd(p4) = (p4) = 75

W(p0) = 450W(p1) = 75W(p2) = 800

W(p3) = 200W(p4) = 0

1275800450200750

55

i (pi)0 3501 1252 4753 2504 75 p0p1 p2p3p4

TTRnd(p0) = (p0)+(p3)+(p1)+(p4) = 350+250+125+75 = 800TTRnd(p1) = (p1)+(p4) = 125+75 = 200TTRnd(p2) = (p2)+(p0)+(p3)+(p1)+(p4) = 475+350+250+125+75 = 1275TTRnd(p3) = (p3)+(p1)+(p4) = 250+125+75 = 450TTRnd(p4) = (p4) = 75

W(p0) = 450W(p1) = 75W(p2) = 800

W(p3) = 200W(p4) = 0

Wavg = (450+75+800+200+0)/5 = 1525/5 = 305

1275800450200750

•Minimizes wait time•May starve large jobs•Must know service times

Can only estimate the length. Can be done by using the length of

previous CPU bursts, using exponential averaging.

56

:Define 4.

10 , 3.

burst CPUnext for the valuepredicted 2.

burst CPU oflength actual 1.

1

n

thn nt

nnn t 1 1

=0 n+1 = n

Recent history does not count. =1

n+1 = tn

Only the actual last CPU burst counts. If we expand the formula, we get:

n+1 = tn+(1 - ) tn-1 + …+(1 - )j tn-j + …+(1 - )n+1 0

Since both and (1 - ) are less than or equal to 1, each successive term has less weight than its predecessor.

57

In priority scheduling, processes/threads are allocated to the CPU based on the basis of an externally assigned priority A commonly used convention is that lower

numbers have higher priority Static priorities vs. dynamic priorities

Static priorities are computed once at the beginning and are not changed

Dynamic priorities allow the threads to become more or less important depending on how much service it has recently received

58

There are non-preemptive and preemptive priority scheduling algorithms Preemptive nonpreemptive

SJN is a priority scheduling where priority is the predicted next CPU burst time.

FCFS is a priority scheduling where priority is the arrival time

59

60

Non-preemptive Priority Scheduling

i (pi) Pri0 350 51 125 22 475 33 250 14 75 4 p0p1 p2p3 p4

TTRnd(p0) = (p0)+(p4)+(p2)+(p1) )+(p3) = 350+75+475+125+250 = 1275TTRnd(p1) = (p1)+(p3) = 125+250 = 375TTRnd(p2) = (p2)+(p1)+(p3) = 475+125+250 = 850TTRnd(p3) = (p3) = 250TTRnd(p4) = (p4)+ (p2)+ (p1)+(p3) = 75+475+125+250 = 925 TTRnd = (1275+375+850+250+925)/5 = 735

W(p0) = 925W(p1) = 250W(p2) = 375

W(p3) = 0W(p4) = 850

Wavg = (925+250+375+0+850)/5 = 2400/5 = 480

12759258503752500

•Reflects importance of external use•May cause starvation•Can address starvation with aging

61

i (pi) Deadline0 350 5751 125 5502 475 10503 250 (none)4 75 200

p0p1 p2 p3p4

12751050550200

0

•Allocates service by deadline•May not be feasible

p0p1 p2 p3p4

p0 p1 p2 p3p4

575

Hard real-time systems – required to complete a critical task within a guaranteed amount of time.

Soft real-time computing – requires that critical processes receive priority over less fortunate ones.

62

63

ReadyList

ReadyList SchedulerScheduler CPUCPU

Preemption or voluntary yield

DoneNewProcess

• Highest priority process is guaranteed to be running at all times– Or at least at the beginning of a time slice

• Dominant form of contemporary scheduling

• But complex to build & analyze

Also called the shortest remaining job next

When a new process arrives, its next CPU burst is compared to the remaining time of the running process If the new arriver’s time is shorter, it will

preempt the CPU from the current running process

64

ProcessArrival TimeBurst TimeP1 0.0 7

P2 2.0 4

P3 4.0 1

P4 5.0 4

Average time spent in ready queue = (9 + 1 + 0 +2)/4 = 3

65

P1 P3P2

42 110

P4

5 7

P2 P1

16

ProcessArrival TimeBurst TimeP1 0.0 7

P2 2.0 4

P3 4.0 1

P4 5.0 4 SJN (non-preemptive)

Average time spent in ready queue (0 + 6 + 3 + 7)/4 = 4

66

P1 P3 P2

73 160

P4

8 12

Each process gets a small unit of CPU time (time quantum), usually 10-100 milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue.

If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more than (n-1)q time units.

67

68

Good way to upset customers!

69

i (pi)0 3501 1252 4753 2504 75

p0

W(p0) = 0

0 50

70

i (pi)0 3501 1252 4753 2504 75

p0

W(p0) = 0W(p1) = 50

1000p1

71

i (pi)0 3501 1252 4753 2504 75

p0

W(p0) = 0W(p1) = 50W(p2) = 100

1000p2p1

72

i (pi)0 3501 1252 4753 2504 75

p0

W(p0) = 0W(p1) = 50W(p2) = 100W(p3) = 150

2001000p3p2p1

73

i (pi)0 3501 1252 4753 2504 75

p0

W(p0) = 0W(p1) = 50W(p2) = 100W(p3) = 150W(p4) = 200

2001000p4p3p2p1

74

i (pi)0 3501 1252 4753 2504 75

p0

W(p0) = 0W(p1) = 50W(p2) = 100W(p3) = 150W(p4) = 200

3002001000p0p4p3p2p1

75

i (pi)0 3501 1252 4753 2504 75

p0

TTRnd(p4) =

W(p0) = 0W(p1) = 50W(p2) = 100W(p3) = 150W(p4) = 200

4754003002001000p4p0p4p3p2p1 p1 p2 p3

76

i (pi)0 3501 1252 4753 2504 75

p0

TTRnd(p1) =

TTRnd(p4) =

W(p0) = 0W(p1) = 50W(p2) = 100W(p3) = 150W(p4) = 200

4754003002001000p4 p1p0p4p3p2p1 p1 p2 p3 p0

550

77

i (pi)0 3501 1252 4753 2504 75

p0

TTRnd(p1) =

TTRnd(p3) = TTRnd(p4) =

W(p0) = 0W(p1) = 50W(p2) = 100W(p3) = 150W(p4) = 200

4754003002001000p4 p1p0p4p3p2p1 p1 p2 p3 p0 p3p2

p0 p3p2 p0 p3p2

550 650

650 750 850 950

78

i (pi)0 3501 1252 4753 2504 75

p0

TTRnd(p0) = TTRnd(p1) =

TTRnd(p3) = TTRnd(p4) =

W(p0) = 0W(p1) = 50W(p2) = 100W(p3) = 150W(p4) = 200

4754003002001000p4 p1p0p4p3p2p1 p1 p2 p3 p0 p3p2

p0 p3p2 p0 p3p2 p0 p2 p0

550 650

650 750 850 950 1050

79

i (pi)0 3501 1252 4753 2504 75

p0

TTRnd(p0) = TTRnd(p1) = TTRnd(p2) = TTRnd(p3) = TTRnd(p4) =

W(p0) = 0W(p1) = 50W(p2) = 100W(p3) = 150W(p4) = 200

4754003002001000p4 p1p0p4p3p2p1 p1 p2 p3 p0 p3p2

p0 p3p2 p0 p3p2 p0 p2 p0 p2 p2 p2 p2

550 650

650 750 850 950 1050 1150 1250 1275

80

i (pi)0 3501 1252 4753 2504 75

p0

TTRnd(p0) = TTRnd(p1) = TTRnd(p2) = TTRnd(p3) = TTRnd(p4) =

W(p0) = 0W(p1) = 50W(p2) = 100W(p3) = 150W(p4) = 200

Wavg = (0+50+100+150+200)/5 = 500/5 = 100

4754003002001000

•Equitable•Most widely-used•Fits naturally with interval timer

p4 p1p0p4p3p2p1 p1 p2 p3 p0 p3p2

p0 p3p2 p0 p3p2 p0 p2 p0 p2 p2 p2 p2

550 650

650 750 850 950 1050 1150 1250 1275

TTRnd_avg = (1100+550+1275+950+475)/5 = 4350/5 = 870

Performance q large FIFO q small q must be large with respect to

context switch, otherwise overhead is too high.

81

82

83

84

i (pi)0 3501 1252 4753 2504 75

•Overhead must be considered

p0

TTRnd(p0) = TTRnd(p1) = TTRnd(p2) = TTRnd(p3) = TTRnd(p4) =

W(p0) = 0W(p1) = 60W(p2) = 120W(p3) = 180W(p4) = 240

Wavg = (0+60+120+180+240)/5 = 600/5 = 120

5404803602401200p4 p1p0p4p3p2p1 p1 p2 p3 p0 p3p2

p0 p3p2 p0 p3p2 p0 p2 p0 p2 p2 p2 p2

575 790

910 1030 1150 1270 1390 1510 1535

TTRnd_avg = (1320+660+1535+1140+565)/5 = 5220/5 = 1044

635 670

790

85

Ready List0Ready List0

Ready List1Ready List1

Ready List2Ready List2

Ready ListnReady Listn

SchedulerScheduler CPUCPU

Preemption or voluntary yield

DoneNewProcess

•Each list may use a different policy•FCFS•SJN•RR

Ready queue is partitioned into separate queues foreground (interactive) background (batch)

Each queue has its own scheduling algorithm foreground – RR background – FCFS

86

Scheduling must be done between the queues. Fixed priority scheduling; i.e., serve all from

foreground then from background. Possibility of starvation.

Time slice – each queue gets a certain amount of CPU time which it can schedule amongst its processes; i.e., 80% to foreground in RR 20% to background in FCFS

87

88

A process can move between the various queues; aging can be implemented this way.

Multilevel-feedback-queue scheduler defined by the following parameters: number of queues scheduling algorithms for each queue method used to determine when to upgrade a

process method used to determine when to demote a

process method used to determine which queue a process

will enter when that process needs service89

90

Three queues: Q0 – time quantum 8 milliseconds

Q1 – time quantum 16 milliseconds

Q2 – FCFS

Scheduling A new job enters queue Q0 which is served FCFS.

When it gains CPU, job receives 8 milliseconds. If it does not finish in 8 milliseconds, job is moved to queue Q1.

At Q1 job is again served FCFS and receives 16 additional milliseconds. If it still does not complete, it is preempted and moved to queue Q2.

91

92

93

CPU scheduling more complex when multiple CPUs are available.

Homogeneous processors within a multiprocessor.

Load sharing Asymmetric multiprocessing – only one

processor accesses the system data structures, alleviating the need for data sharing.

94

Deterministic modeling – takes a particular predetermined workload and defines the performance of each algorithm for that workload.

Queuing models Implementation

95

96

Involuntary CPU sharing -- timer interrupts Time quantum determined by interval timer --

usually fixed for every process using the system

Sometimes called the time slice length Priority-based process (job) selection

Select the highest priority process Priority reflects policy

With preemption Usually a variant of Multi-Level Queues

97

All use a multiple-queue system UNIX SVR4: 160 levels, three classes

time-sharing, system, real-time Solaris: 170 levels, four classes

time-sharing, system, real-time, interrupt OS/2 2.0: 128 level, four classes

background, normal, server, real-time Windows NT 3.51: 32 levels, two classes

regular and real-time Mach uses “hand-off scheduling”

98

Involuntary CPU Sharing Preemptive algorithms 32 Multi-Level Queues

Queues 0-7 are reserved for system functions Queues 8-31 are for user space functions nice influences (but does not dictate) queue

level

99

Involuntary CPU Sharing across threads Preemptive algorithms 32 Multi-Level Queues

Highest 16 levels are “real-time” Next lower 15 are for system/user threads

Range determined by process base priority Lowest level is for the idle thread

100

In file kernel/sched.c The policy is a variant of RR scheduling

101

The scheduler is responsible for multiplexing the CPU among a set of ready processes / threads It is invoked periodically by a timer interrupt,

by a system call, other device interrupts, any time that the running process terminates

It selects from the ready list according to its scheduling policy Which includes non-preemptive and preemptive

algorithms

102