+ All Categories
Home > Documents > Chapter 4 - Processor Management Ivy Tech State College Northwest Region 01 CIS106 Microcomputer...

Chapter 4 - Processor Management Ivy Tech State College Northwest Region 01 CIS106 Microcomputer...

Date post: 28-Dec-2015
Category:
Upload: christopher-bond
View: 219 times
Download: 5 times
Share this document with a friend
Popular Tags:
34
Chapter 4 - Chapter 4 - Processor Management Processor Management Ivy Tech State College Northwest Region 01 CIS106 Microcomputer Operating Syste Gina Rue CIS Faculty
Transcript

Chapter 4 - Chapter 4 - Processor Management Processor Management

Ivy Tech State College Northwest Region 01

CIS106 Microcomputer Operating Systems

Gina RueCIS Faculty

2

Introduction - Introduction - Processor ManagementProcessor Management

• Process ManagerProcess Manager– Job SchedulingJob Scheduling

– Process SchedulingProcess Scheduling

– Interrupt ManagementInterrupt Management

3

Introduction - Introduction - Processor ManagementProcessor Management

• Single-user systemsSingle-user systems– the processor is busy only when the the processor is busy only when the

user is executing a job user is executing a job

– at other times it is idleat other times it is idle

4

Introduction - Introduction - Processor ManagementProcessor Management

• MultiprogrammingMultiprogramming– Many users with many jobs on the Many users with many jobs on the

systemsystem

– The processor must be allocated to The processor must be allocated to each job in a fair and efficient mannereach job in a fair and efficient manner

5

Introduction - Introduction - Processor ManagementProcessor Management

• Processor (CPU) Central Processing Processor (CPU) Central Processing UnitUnit

• CPU: performs calculations & executes CPU: performs calculations & executes programsprograms

• Process: single instance of executable Process: single instance of executable program, a calculation is a processprogram, a calculation is a process

• Job or Program: work (instructions) Job or Program: work (instructions) submitted by the Usersubmitted by the User

6

Processor ManagementProcessor Management

• Multiprogramming requires that Multiprogramming requires that the processor be:the processor be:

– Allocated to each job or each Allocated to each job or each processprocess

– deallocated at an appropriate deallocated at an appropriate momentmoment

7

Process ManagementProcess Management

A single processor can be shared A single processor can be shared by several jobs or processes if by several jobs or processes if the OS has:the OS has:• scheduling policyscheduling policy• scheduling algorithmscheduling algorithm

to determine when to stop one to determine when to stop one job & proceed with anotherjob & proceed with another

8

Job Scheduling vs. Job Scheduling vs. Process SchedulingProcess Scheduling

• Process Manager is two Process Manager is two submanagers:submanagers:

– Job SchedulerJob Scheduler

in charge of job schedulingin charge of job scheduling

– Process SchedulerProcess Scheduler

in charge of process schedulingin charge of process scheduling

9

Job Scheduler vs.Job Scheduler vs.Process SchedulingProcess Scheduling

Job SchedulerJob Scheduler• high-level schedulerhigh-level scheduler

• selects jobs from a queue of incoming jobs, selects jobs from a queue of incoming jobs, places them into a process queueplaces them into a process queue

• goal to put jobs in sequence to fully use goal to put jobs in sequence to fully use resourcesresources

• strives for balanced mix between jobs that strives for balanced mix between jobs that require large amount of I/O interaction & jobs require large amount of I/O interaction & jobs that require large amounts of computationthat require large amounts of computation

10

Process SchedulerProcess SchedulerTakes over after a job has been placed on Takes over after a job has been placed on

the READY queue by the Job Schedulerthe READY queue by the Job Scheduler

– (low-level scheduler ) assigns the CPU to (low-level scheduler ) assigns the CPU to execute each job in READY queueexecute each job in READY queue

– alternates between CPU cycles & I/O cyclesalternates between CPU cycles & I/O cycles

– I/O-bound jobs: printing series of documentsI/O-bound jobs: printing series of documents

– CPU-bound jobs: finding 100 prime numbersCPU-bound jobs: finding 100 prime numbers

See Fig. 4.1 p.79 11

Process SchedulerProcess Scheduler

• In highly interactive In highly interactive environments - environments -

– 3rd Layer - middle-level scheduler3rd Layer - middle-level scheduler

manages jobs swapped out & in to allow manages jobs swapped out & in to allow jobs to be completed fasterjobs to be completed faster

See Fig. 4.2 p.79 12

Job and Process StatusJob and Process Status

As a job moves through the system, As a job moves through the system, it’s always in one of five states (or it’s always in one of five states (or at least three)at least three)– HOLDHOLD

– READYREADY

– WAITINGWAITING

– RUNNINGRUNNING

– FINISHEDFINISHED

See Fig. 4.3 p.80 13

Process Control BlocksProcess Control Blocks

Each process in a system is Each process in a system is represented by data structures (PCB) represented by data structures (PCB) that contain basic job informationthat contain basic job information– Process IdentificationProcess Identification

– Process StatusProcess Status

– Process StateProcess State

– AccountingAccounting

See Fig. 4.4 p.82 14

PCBs and QueuingPCBs and Queuing

• PCBPCB

– created when Job Scheduler accepts the job created when Job Scheduler accepts the job & is updated as the job progresses from & is updated as the job progresses from beginning to end of its executionbeginning to end of its execution

• QueuesQueues

– use PCBs to track jobsuse PCBs to track jobs

– PCBs are lists of information linked to form PCBs are lists of information linked to form queuesqueues

15

Process Scheduling Process Scheduling PoliciesPolicies

Before the OS can schedule jobs in a Before the OS can schedule jobs in a multiprogramming environment, it needs to resolve multiprogramming environment, it needs to resolve three system limitations:three system limitations:– there are a finite number of resources (disk drives, there are a finite number of resources (disk drives,

printers, tape drives)printers, tape drives)

– some resources, once they’re allocated, can’t be shared some resources, once they’re allocated, can’t be shared with another job (printers)with another job (printers)

– some resources require operator intervention - they can’t some resources require operator intervention - they can’t be reassigned automatically from job to job (such as tape be reassigned automatically from job to job (such as tape drives)drives)

16

Process Scheduling Process Scheduling PoliciesPolicies

What is aWhat is a “good” “good” process scheduling policy?process scheduling policy?– Maximize Maximize

• throughputthroughput

• CPU efficiencyCPU efficiency

– MinimizeMinimize• response timeresponse time

• turnaround timeturnaround time

• waiting timewaiting time

– Ensure fairness for all jobsEnsure fairness for all jobs

17

Process Scheduling Process Scheduling PoliciesPolicies

““Good” Good” process scheduling policy contradictionsprocess scheduling policy contradictions– If a system favors one type of user, it may harm or If a system favors one type of user, it may harm or

does not efficiently use resourcesdoes not efficiently use resources

– System designer determines which criteria is most System designer determines which criteria is most important for a specific systemimportant for a specific system• ““maximize CPU utilization while minimizing response maximize CPU utilization while minimizing response

time and balancing the use of all system components time and balancing the use of all system components through a mix of I/O-bound and CPU-bound jobs”through a mix of I/O-bound and CPU-bound jobs”

18

Process Scheduling Process Scheduling PoliciesPolicies

Problem: Problem: Job claims the CPU for a very long time Job claims the CPU for a very long time before issuing an I/O requestbefore issuing an I/O request

Solution: Solution: Process Scheduler uses a timing Process Scheduler uses a timing mechanism and periodically interrupts running mechanism and periodically interrupts running processes when a predetermined slice of time has processes when a predetermined slice of time has expired.expired.– An I/O request is called a “natural wait” in An I/O request is called a “natural wait” in

multiprogramming environments to allow the processor multiprogramming environments to allow the processor to be allocated to another jobto be allocated to another job

19

Process Scheduling Process Scheduling PoliciesPolicies

Scheduling StrategiesScheduling Strategies

• Preemptive Scheduling PolicyPreemptive Scheduling Policy– interrupts the processing of a job and transfers the CPU to interrupts the processing of a job and transfers the CPU to

another job, widely used in time-sharing environmentsanother job, widely used in time-sharing environments

• Nonpreemptive Scheduling PolicyNonpreemptive Scheduling Policy– functions without external interrupts to the jobfunctions without external interrupts to the job

– once a job captures the processor and begins execution, it once a job captures the processor and begins execution, it remains RUNNING until it issues an I/O request (natural wait) remains RUNNING until it issues an I/O request (natural wait) or until finished (with exceptions made for infinite loops)or until finished (with exceptions made for infinite loops)

20

Process Scheduling Process Scheduling AlgorithmsAlgorithms

• Based on a specific policy, Process Scheduler relies Based on a specific policy, Process Scheduler relies on a process scheduling algorithm to allocate the on a process scheduling algorithm to allocate the CPU and move jobs through the systemCPU and move jobs through the system

• Most current systems, with emphasis on interactive Most current systems, with emphasis on interactive use and response time, use an algorithm that takes use and response time, use an algorithm that takes care of immediate requests of interactive userscare of immediate requests of interactive users

Six common process scheduling algorithmsSix common process scheduling algorithms

See Fig. 4.5 & 4.6 p.85 21

Process Scheduling Process Scheduling AlgorithmsAlgorithms

• First Come First Served (FCFS)First Come First Served (FCFS)– nonpreemptive scheduling algorithmnonpreemptive scheduling algorithm

– handles jobs according to their arrivalhandles jobs according to their arrival

– the earlier jobs arrive, the sooner they’re servedthe earlier jobs arrive, the sooner they’re served

– simple algorithm to implement, it uses FIFO queuesimple algorithm to implement, it uses FIFO queue

– good for batch systems, not good for interactive good for batch systems, not good for interactive systems due to delay slow response timesystems due to delay slow response time

– turnaround time is unpredictableturnaround time is unpredictable

See Fig. 4.7 p.86 22

Process Scheduling Process Scheduling AlgorithmsAlgorithms• Shortest Job Next (SJN)Shortest Job Next (SJN)

– nonpreemptive scheduling algorithm (also known as Shortest nonpreemptive scheduling algorithm (also known as Shortest Job First or SFJJob First or SFJ

– handles jobs based on their length in their CPU cyclehandles jobs based on their length in their CPU cycle

– good for batch systems, estimates CPU time is required to run good for batch systems, estimates CPU time is required to run the job given in advancethe job given in advance

– not good for interactive systems that don’t estimate in not good for interactive systems that don’t estimate in advance the CPU time required to run their jobsadvance the CPU time required to run their jobs

– optimal only when all of the jobs are available at the same optimal only when all of the jobs are available at the same time & the CPU estimates are available & accuratetime & the CPU estimates are available & accurate

23

Process Scheduling Process Scheduling AlgorithmsAlgorithms

• Priority Scheduling Priority Scheduling – nonpreemptive scheduling algorithmnonpreemptive scheduling algorithm

– used in batch systems, although slower turnaround time used in batch systems, although slower turnaround time to some usersto some users

– gives preferential treatment to important jobsgives preferential treatment to important jobs

– allows programs with highest priority to be processed firstallows programs with highest priority to be processed first

– priorities can be assigned by system administratorspriorities can be assigned by system administrators

– jobs are usually linked to one of several READY queuesjobs are usually linked to one of several READY queues

24

Process Scheduling Process Scheduling AlgorithmsAlgorithms

• Priority Scheduling priorities can be Priority Scheduling priorities can be determined by the Process Manager based on determined by the Process Manager based on characteristics intrinsic to the job such as:characteristics intrinsic to the job such as:– memory requirementsmemory requirements

– number & type of peripheral devicesnumber & type of peripheral devices

– Total CPU timeTotal CPU time

– Amount of time already spent in the systemAmount of time already spent in the system

See Fig. 4.8 & 4.9 p.88-89 25

Process Scheduling Process Scheduling AlgorithmsAlgorithms

• Shortest Remaining Time (SRT) Shortest Remaining Time (SRT) – preemptive version of SJN algorithmpreemptive version of SJN algorithm

– processor is allocated to the job closest to completionprocessor is allocated to the job closest to completion

– requires advance knowledge of the CPU required to finish requires advance knowledge of the CPU required to finish each job, can’t be used for interactive systemeach job, can’t be used for interactive system

– often used in batch systems when it is desirable to give often used in batch systems when it is desirable to give preference to short jobspreference to short jobs

– context switching required, a job processing information context switching required, a job processing information must be save in its PCB for when a job is executed must be save in its PCB for when a job is executed

26

Process Scheduling Process Scheduling AlgorithmsAlgorithms

• Round Robin Round Robin – preemptive process scheduling algorithmpreemptive process scheduling algorithm

– used in interactive systems because it easy to used in interactive systems because it easy to implementimplement

– based on a predetermined slice of time that’s based on a predetermined slice of time that’s given to each job to ensure the CPU is shared given to each job to ensure the CPU is shared equally among all active processes & is not equally among all active processes & is not monopolized by any one jobmonopolized by any one job

See Fig. 4.10&11 p.90-91 27

Process Scheduling Process Scheduling AlgorithmsAlgorithms

• Round Robin Round Robin

time slicetime slice is called a time quantum & its size is crucial to is called a time quantum & its size is crucial to system performancesystem performance

– Two general rules of thumb for selecting the “proper” Two general rules of thumb for selecting the “proper” time quantumtime quantum• it should be long enough to allow for 80% of the CPU cycles it should be long enough to allow for 80% of the CPU cycles

to run to completionto run to completion

• it should be at least 100 times longer than the time it should be at least 100 times longer than the time required to perform on context switchrequired to perform on context switch

These rules are used in some systems are flexibleThese rules are used in some systems are flexible

28

Process Scheduling Process Scheduling AlgorithmsAlgorithms

• Multiple Level Queues Multiple Level Queues – not really scheduling algorithmnot really scheduling algorithm

– it works in conjunction with other schemesit works in conjunction with other schemes

– it is found in systems with jobs that can be it is found in systems with jobs that can be grouped according to common characteristicsgrouped according to common characteristics

– priority scheduling is one kind of multiple level priority scheduling is one kind of multiple level queue with different queues for each priority queue with different queues for each priority levellevel

29

Process Scheduling Process Scheduling AlgorithmsAlgorithms

• Multiple Level Queues Multiple Level Queues

Four primary methods of movementFour primary methods of movement– no movement between queuesno movement between queues

– movement between queuesmovement between queues

– variable time quantum per queuevariable time quantum per queue

– Called AgingCalled Aging• indefinite postponement-a job’s execution is delayed indefinite postponement-a job’s execution is delayed

indefinitely because it is repeatedly preempted so other jobs indefinitely because it is repeatedly preempted so other jobs can be processed which may lead to “starvation”can be processed which may lead to “starvation”

30

A Word About InterruptsA Word About Interrupts• Interrupts are a way for an OS to get the attention Interrupts are a way for an OS to get the attention

of the CPUof the CPU

• In Chapter 3, the Memory Manager issued In Chapter 3, the Memory Manager issued interrupts to accommodate job requestsinterrupts to accommodate job requests

• Other interrupts are caused by events internal to Other interrupts are caused by events internal to the processthe process

• I/O interrupts are issued when a READ or WRITE I/O interrupts are issued when a READ or WRITE command is issuedcommand is issued

31

A Word About InterruptsA Word About Interrupts• Internal Interrupts or synchronous interrupts occur as a result Internal Interrupts or synchronous interrupts occur as a result

of an arithmetic operation or job instruction being processed.of an arithmetic operation or job instruction being processed.

• Illegal arithmetic operationsIllegal arithmetic operations– attempts to divide by zeroattempts to divide by zero

– floating point operation generating an overflow or underflowsfloating point operation generating an overflow or underflows

• Illegal job instructionsIllegal job instructions– attempts to access protected or nonexistent storageattempts to access protected or nonexistent storage

– attempts to use an undefined operation code, operating on invalid attempts to use an undefined operation code, operating on invalid datadata

32

A Word About InterruptsA Word About Interrupts• Interrupts handler is the control program that Interrupts handler is the control program that

handles the interruption sequence. When the OS handles the interruption sequence. When the OS detects a nonrecoverable error, the interrupt detects a nonrecoverable error, the interrupt handler follows this sequence:handler follows this sequence:– type of interrupt is described & stored to be passed on type of interrupt is described & stored to be passed on

to the user as an error messageto the user as an error message

– state of the interrupt process is savedstate of the interrupt process is saved

– interrupt is processedinterrupt is processed

– processor resumes normal operationprocessor resumes normal operation

33

SummarySummary

• Process Manger allocates the CPU Process Manger allocates the CPU among all system usersamong all system users

• Distinctions between job schedulingDistinctions between job scheduling– selection of jobs based on selection of jobs based on

characteristicscharacteristics

– process schedulingprocess scheduling

– instant-by-instant allocation of CPUinstant-by-instant allocation of CPU

See Tab 4.1 p.95 34

SummarySummary• Interrupts are generated & resolved by interrupt Interrupts are generated & resolved by interrupt

handlerhandler

• Scheduling algorithms have uniqueScheduling algorithms have unique– characteristicscharacteristics

– objectivesobjectives

– applicationsapplications

• A system designer can choose the best policies & A system designer can choose the best policies & algorithm after evaluating their strengths & algorithm after evaluating their strengths & weaknessesweaknesses


Recommended