operating systems: introduction n 1. historical development n 2. the os as a resource manager n 3....
TRANSCRIPT
Operating Systems: Operating Systems: IntroductionIntroduction
1. Historical Development1. Historical Development 2. The OS as a Resource Manager2. The OS as a Resource Manager 3. Definitions 3. Definitions 4. The Process4. The Process
The OS as a Resource The OS as a Resource ManagerManager
ResourcesResources
– 4 functions4 functions Keep track of resourceKeep track of resource Enforce policy -Enforce policy - AllocateAllocate ReclaimReclaim
The OS as a Resource The OS as a Resource ManagerManager
Memory managementMemory management– Keep trackKeep track– If multiprogramming: If multiprogramming:
– AllocateAllocate
– Reclaim (pReclaim (pii relinquishes it or relinquishes it or terminates)terminates)
The OS as a Resource The OS as a Resource ManagerManager
Processor managementProcessor management– Keep track ofKeep track of– Scheduling: Scheduling: – Allocate :Allocate :
– Reclaim : pReclaim : pii relinquishes P, terminates, relinquishes P, terminates, exceeds TSexceeds TS
Device managementDevice management– Keep track of devices, channels, Keep track of devices, channels,
control unitscontrol units– Efficient allocation policy Efficient allocation policy
– Allocate : Allocate : – Reclaim : Normally automatic Reclaim : Normally automatic
terminationtermination
The OS as a Resource The OS as a Resource ManagerManager
Information managementInformation management– Keep track : Location, use, status ( Keep track : Location, use, status (
))– Who gets use of resources, enforce Who gets use of resources, enforce
protection, provide accessing routinesprotection, provide accessing routines– Allocate (“Open file”)Allocate (“Open file”)– Deallocate (“Close file”)Deallocate (“Close file”)
The OS as a Resource The OS as a Resource ManagerManager
Baremachine
Level 1
Processor managementlower module (P,V),
Process Scheduler
Level 2 Memory managementLevel 3
Processor management upper module
(messages, create-destroy process)
Level 4
Device management (I/O traffic control)
Info management (File system)
Level 5KernelKernel
I/O process
User-created process
I/O processworking with
User process 3
SPOOLing
Process 1 Process 2
Process 3
Supervisor process(Job scheduler)
Jobs
Hierarchical Hierarchical OS StructureOS Structure
Kernel (Layer 0)
Layer 1Layer 2
DefinitionsDefinitions Operating System (OS) :Operating System (OS) :
– Software governing control of resources Software governing control of resources – ( )( )– InterfaceInterface
Processor : Hardware which interprets and Processor : Hardware which interprets and executes instructionsexecutes instructions
Process (task) :Process (task) :
Job : Set of modules req’d to perform some taskJob : Set of modules req’d to perform some task
DefinitionsDefinitions Multiprogramming :Multiprogramming :
Privileged instruction :Privileged instruction :– Instruction available only toInstruction available only to– Executed in supervisor (executive) state as Executed in supervisor (executive) state as
opposed to problem (user) state. opposed to problem (user) state. Interrupt :Interrupt :
– Mechanism forcing processor to take notice of Mechanism forcing processor to take notice of eventevent
I.4 The ProcessI.4 The Process Process (pProcess (pii) : A program in a state ) : A program in a state
of executionof execution Life : (Higher level view)Life : (Higher level view)
– 1. Run : p1. Run : pii<-P<-P
– 2. Wait : For event2. Wait : For event– 3. Ready :3. Ready :
RUN
READY WAIT
pi P Wait for I/Ocompletion
I/O complete
Life of a ProcessLife of a Process
Lower level view :Lower level view :
RUN
WAITREADYHOLDSUBMIT
COMPLETE
Processor Management Processor Management and Schedulingand Scheduling
1. Introduction1. Introduction 2. Basic Concepts2. Basic Concepts 3. Processor Scheduling Algorithms3. Processor Scheduling Algorithms
IntroductionIntroduction
Given : 2 jobs, A and B.Given : 2 jobs, A and B. Each executes for 1 sec, waits for Each executes for 1 sec, waits for
1 sec1 sec Repeat this for 60 cycles [ 2 min ]Repeat this for 60 cycles [ 2 min ]
– 1. Let’s run A, then B1. Let’s run A, then BA:
B:
2 min
2 min
Elapsed Time : 4 min Compute Time : 2 min
CPU Utilization : 2/4 = 50%
– 2. Now multi-program A and B2. Now multi-program A and B
A:
B:
IntroductionIntroduction
Elapsed Time : 2+ minElapsed Time : 2+ min
Compute Time : 2 minCompute Time : 2 min
CPU Utilization : 2/2+ = ~100%CPU Utilization : 2/2+ = ~100%
– Compare to 1 : A finishes at same time,Compare to 1 : A finishes at same time, B in half the time.B in half the time.
So now we have multiprogramming:So now we have multiprogramming:– N jobs in memoryN jobs in memory– Job i PJob i P– When i waits for I/O, j P When i waits for I/O, j P
Overlap CPU and I/O to keep P busyOverlap CPU and I/O to keep P busy– Benefits : Increased CPU utilization Benefits : Increased CPU utilization
and and higher higher throughputthroughput.. Throughput : Work done in given Throughput : Work done in given
period.period.– E.g. 10 jobs per hour.E.g. 10 jobs per hour.
IntroductionIntroduction
Basic ConceptsBasic Concepts
Process : a program in a state of Process : a program in a state of execution. execution. – E.g. Batch job, transaction (in T-S system)E.g. Batch job, transaction (in T-S system)– Also called : job, program, task, activity.Also called : job, program, task, activity.
Process behavior : pProcess behavior : pi i alternate between alternate between execution(CPU burst) & I/O(I/O burst).execution(CPU burst) & I/O(I/O burst).– Generally begins and ends with CPU bursts.Generally begins and ends with CPU bursts.
Basic ConceptsBasic Concepts
ppii change state as they execute change state as they execute– READY, RUN, WAIT, HOLD.READY, RUN, WAIT, HOLD.
Process Control Block (PCB)Process Control Block (PCB)– Process is represented internally by its Process is represented internally by its
PCBPCB– Active representation of passive entity, Active representation of passive entity,
the PGM the PGM ““The only tangible part of a process”The only tangible part of a process”
– PCBPCB
Process idProcess id Current StateCurrent State PriorityPriority Other CPU Other CPU Scheduling infoScheduling info State infoState info : PC (address of NI to be executed) : PC (address of NI to be executed)
register, cc contentsregister, cc contents Memory management infoMemory management info : base-bounds : base-bounds
registers, page tablesregisters, page tables Accounting infoAccounting info : amount of CPU time, account # : amount of CPU time, account # I/O status infoI/O status info : I/O requests pending, I/O : I/O requests pending, I/O
devices allocated, list of open devices allocated, list of open filesfiles
PointerPointer to list of to list of all pall pii in same state in same state etc.etc.
Basic ConceptsBasic Concepts Scheduling queuesScheduling queues
– Ready queue : List of processes (PCBs) in Ready queue : List of processes (PCBs) in ready ready state state (awaiting assignment of P)(awaiting assignment of P)
– Device queue : List of pDevice queue : List of p ii waiting on this device waiting on this device
– I/O queue : pI/O queue : pii waiting for I/O (once served, p waiting for I/O (once served, p ii moves moves to Ready queue).to Ready queue).
HeadTail
PCB iRegisters
.
.
.
PCB j PCB nRegisters Registers
.
.
.
.
.
.
QueueQueue
headerheader
. . .
Basic ConceptsBasic Concepts
Schedulers : Schedulers : – Job (long-term) scheduler : Job (long-term) scheduler :
Selects job from spool queue to enter Selects job from spool queue to enter system, loads it into memorysystem, loads it into memory
– Processor (CPU, short-term) scheduler Processor (CPU, short-term) scheduler ::
Selects ready pSelects ready pii and dispatches (assigns and dispatches (assigns P to) itP to) it
– Difference : How often they executeDifference : How often they execute– Job scheduler Job scheduler
Infrequently once steady state is reachedInfrequently once steady state is reached Controls Controls degreedegree of multiprogramming (number of of multiprogramming (number of
ppii in memory) in memory)
– Processor schedulerProcessor scheduler Must select new pMust select new pii very frequently (every 10 ms) very frequently (every 10 ms) FAST or much of the processor time is spent in FAST or much of the processor time is spent in
scheduling !scheduling !
Basic ConceptsBasic Concepts
DispatcherDispatcher– Assigns P to pAssigns P to pii selected by Processor selected by Processor
schedulerscheduler
– Loads pLoads pii’s registers’s registers
– Changes to user modeChanges to user mode– Jumps to proper address [ to (re)start Jumps to proper address [ to (re)start
it ]it ]
Processor Scheduling Processor Scheduling AlgorithmsAlgorithms
Problem : Which pProblem : Which pii in Ready queue gets P? in Ready queue gets P? Performance Criteria (Comparing algorithms):Performance Criteria (Comparing algorithms):
– Throughput : Work done in given period.Throughput : Work done in given period.– CPU utilization : P busy time / Total elapsed timeCPU utilization : P busy time / Total elapsed time
Want it as busy as possible (40-90%).Want it as busy as possible (40-90%).– Turnaround time : Interval between submission to Turnaround time : Interval between submission to
completion of job (Batch OS).completion of job (Batch OS).
– Wait time : Time spent by pWait time : Time spent by pii in Ready queue. in Ready queue.
– Response time : Interval from submission until response Response time : Interval from submission until response produced (Interactive system).produced (Interactive system).
Processor Scheduling Processor Scheduling AlgorithmsAlgorithms
Let’s optimize as follows : Let’s optimize as follows : – Maximize CPU utilization, throughputMaximize CPU utilization, throughput– Minimize turnaround time (TT), wait, Minimize turnaround time (TT), wait,
response time.response time.– Operationally :Operationally :
Optimize average or max or minOptimize average or max or min e.g. Minimize the max response time e.g. Minimize the max response time
Minimize variance in Minimize variance in response time.response time.
Common Scheduling Common Scheduling AlgorithmsAlgorithms
(a) First Come First Served (FCFS)(a) First Come First Served (FCFS) (b) Shortest Job First (SJF)(b) Shortest Job First (SJF) (c) Priority(c) Priority
– Preemptive vs Non-preemptivePreemptive vs Non-preemptive (d) Round Robin(d) Round Robin (e) Multilevel Queues(e) Multilevel Queues
Scheduling AlgorithmsScheduling Algorithms
First Come First Served (FCFS)First Come First Served (FCFS)– Implementation : FIFO queueImplementation : FIFO queue
– ppjj enters ready q : enters ready q :
– ppii dispatched : dispatched :
– Consider :Consider : Job Job CPU burstCPU burst A A 24 24 B B 3 3 C C 3 3
pi pk pj
pk pj
...
...
RQRQ
RQRQ
FCFSFCFS– Suppose jobs arrive in order A, B, C and Suppose jobs arrive in order A, B, C and
are served FCFS.are served FCFS.
TT : For A = 24, For B = 27, For C = 30TT : For A = 24, For B = 27, For C = 30 Avg TT : (24 + 27 + 30) / 3 = 27Avg TT : (24 + 27 + 30) / 3 = 27
– Now, suppose they arrive in order B, C, ANow, suppose they arrive in order B, C, A
Avg TT : (3 + 6 + 30) / 3 = 13Avg TT : (3 + 6 + 30) / 3 = 13
A B C24 27 30
AB C30 6 3
0
0
Scheduling AlgorithmsScheduling Algorithms
Shortest Job First (SJF)Shortest Job First (SJF)– Associates with job the length of its next CPU Associates with job the length of its next CPU
burstburst– Example of Example of prioritypriority scheduling (job with scheduling (job with
shortest next CPU burst gets highest priority)shortest next CPU burst gets highest priority)– Consider :Consider : Job Job CPU burstCPU burst
A A 6 6 B B 3 3 C C 8 8
D D 7 7
SJFSJF
Avg TT : (3 + 9 + 16 + 24) / 4 = 13Avg TT : (3 + 9 + 16 + 24) / 4 = 13
– This algorithm can be proved optimalThis algorithm can be proved optimal Gives min avg wait time for given set of Gives min avg wait time for given set of
jobsjobs
– Problem : Length of next CPU burstProblem : Length of next CPU burst Batch jobs : Time limit supplied by userBatch jobs : Time limit supplied by user Processes : Can’t know [but can predict]Processes : Can’t know [but can predict]
B[3] D[7] C[8]A[6] 00 33 99 1616 2424
Scheduling AlgorithmsScheduling Algorithms Priority SchedulingPriority Scheduling
– Can be assigned : who is paying, type of workCan be assigned : who is paying, type of work– Can be computed :Can be computed :
Time limits, memory req., ratio avg I/O burst to CPU burst, Time limits, memory req., ratio avg I/O burst to CPU burst, number of open filesnumber of open files
– Major problem : StarvationMajor problem : Starvation Low priority Ready pLow priority Ready pii can wait indefinitely for CPU can wait indefinitely for CPU Eventually, load lightens and job gets run, or system crashes Eventually, load lightens and job gets run, or system crashes
and job is lostand job is lost
– Remedy Remedy Aging : Aging : Increase priority of low priority job over timeIncrease priority of low priority job over time
Scheduling algorithmsScheduling algorithms
Round Robin (RR)Round Robin (RR)– Designed for TS systemsDesigned for TS systems
Given defined TS (10-100 ms).Given defined TS (10-100 ms).– CPU scheduler traverses Ready queue, selects CPU scheduler traverses Ready queue, selects
ppii to be dispatched for interval to be dispatched for interval TS TS
– Implementation :Implementation : Ready queue = FIFO queueReady queue = FIFO queue CPU scheduler picks 1st job in Ready queueCPU scheduler picks 1st job in Ready queue Sets timer to interrupt after 1 TSSets timer to interrupt after 1 TS Dispatches processDispatches process
Multilevel QueueMultilevel Queue
– Good when jobs easily classified into groupsGood when jobs easily classified into groups e.g. foreground (FG - interactive) ande.g. foreground (FG - interactive) and
background (BG - batch)background (BG - batch)
– In a multilevel scheduling algorithm :In a multilevel scheduling algorithm : Ready queue partitioned into separate queuesReady queue partitioned into separate queues Each pEach pii assigned permanently to one queue assigned permanently to one queue
– Due to memory size, job type, …Due to memory size, job type, … Each queue has its own scheduling algorithmEach queue has its own scheduling algorithm
– FG : RR, BG : FCFSFG : RR, BG : FCFS Must have scheduling Must have scheduling betweenbetween the queues the queues
– e.g. Fixed priority preemptive (such as FG > BG)e.g. Fixed priority preemptive (such as FG > BG)
Scheduling algorithmsScheduling algorithms