Chapter 4 Processor Management - PowerPoint PPT Presentation

1 / 39
About This Presentation
Title:

Chapter 4 Processor Management

Description:

A program (job) is an inactive unit, such as a file stored on the disk. ... program execution. Release any resources allocated to job are released. Job exits ... – PowerPoint PPT presentation

Number of Views:218
Avg rating:3.0/5.0
Slides: 40
Provided by: ahmer8
Category:

less

Transcript and Presenter's Notes

Title: Chapter 4 Processor Management


1
ICS-023 - PC Operating Systems Chapter
4 Processor Management King Fahd University
of Petroleum Minerals
2
Processor Management
  • A program (job) is an inactive unit, such as a
    file stored on the disk.
  • A process (task) is an active entity that
    requires a set of resources, including processor
    and memory.
  • Processor also known as CPU is the part of the
    machine that performs calculations and executes
    the programs.

3
Processor Management
  • Thread of control (thread) a portion of a
    process that can run independently.
  • Processor ( CPU, central processing unit) part
    of machine that performs calculations and
    executes programs.

4
Processor Management
  • Processor Manager performs job scheduling,
    process scheduling, and interrupt management.
  • In single-user systems, processor is busy only
    when user is executing a jobat all other times
    it is idle.
  • Processor management is simple.
  • In multiprogramming environment, processor must
    be allocated to each job in a fair and efficient
    manner.
  • Requires scheduling policy and a scheduling
    algorithm.
  • Requires that the processor be allocated to
    each job or to each process for a period of time
    and deallocated at an appropriate moment.

5
Context Switching
  • Disrupting a process during execution and giving
    the CPU to another process is called Context
    Switching.
  • Example We need to execute 2 jobs A and B.
  • Get the input for job A.
  • Identify resources.
  • Execute the process.
  • Interrupt
  • Context switch to job B.
  • Get the input for job B.
  • Identify resources
  • Execute the process.
  • Terminate job B.
  • Context switch to job A.
  • Resume executing interrupted process.
  • Terminate job A.

6
Processor Management
  • Processor Manager has 2 sub-managers
  • Job Scheduler
  • in charge of job scheduling.
  • Process Scheduler
  • in charge of process scheduling.

7
Job Scheduler
  • High-level scheduler.
  • Selects jobs from a queue of incoming jobs.
  • Places them in process queue, based on each jobs
    characteristics.
  • Goal is to put jobs in a sequence that uses all
    systems resources as fully as possible.
  • Strives for balanced mix of jobs with large I/O
    interaction and jobs with lots of computation.
  • Tries to keep most system components busy most of
    time.

8
Process Scheduler
  • Low-level scheduler
  • Assigns the CPU to execute processes of those
    jobs placed on ready queue by Job Scheduler.
  • After a job has been placed on the READY queue by
    Job Scheduler, Process Scheduler takes over.
  • Determines which jobs will get CPU, when, and for
    how long.
  • Decides when processing should be interrupted.
  • Determines queues job should be moved to during
    execution.
  • Recognizes when a job has concluded and should be
    terminated.

9
CPU Cycles and I/O Cycles
  • To schedule CPU, Process Scheduler uses common
    trait among most computer programs they
    alternate between CPU cycles and I/O cycles.

10
Processor Manager
  • I/O-bound jobs (such as printing a series of
    documents) have many brief CPU cycles and long
    I/O cycles.
  • CPU-bound jobs (such as finding the first 300
    prime numbers) have long CPU cycles and shorter
    I/O cycles.
  • In a highly interactive environment theres a
    third layer called Middle-level scheduler.
  • Removes active jobs from memory to reduce degree
    of multiprogramming and allows jobs to be
    completed faster.

11
Job and Process Status
  • Job status -- one of the 5 states that a job
    takes as it moves through the system.
  • HOLD
  • READY
  • WAITING
  • RUNNING
  • FINISHED

12
Job and Process Status
13
Transition Among Process States
  • HOLD to READY Job Scheduler using a predefined
    policy.
  • READY to RUNNING Process Scheduler using some
    predefined algorithm
  • RUNNING back to READY Process Scheduler
    according to some predefined time limit or other
    criterion.
  • RUNNING to WAITING Process Scheduler and is
    initiated by an instruction in the job.
  • WAITING to READY Process Scheduler and is
    initiated by signal from I/O device manager that
    I/O request has been satisfied and job can
    continue.
  • RUNNING to FINISHED Process Scheduler or Job
    Scheduler.

14
Process Control Block (PCB)
  • It is a data structure that contains basic info
    about the job
  • Process identification
  • Process status (HOLD, READY, RUNNING, WAITING)

15
Process state
  • It contains all the information needed to
    indicate the current status of the job.
  • Process Status Word contains the current
    instruction counter and register contents when
    the job isnt running (HOLD, READY, WAITING).
  • Register Contents show the contents of the
    register if the job has been interrupted and is
    waiting to resume.
  • Main Memory
  • Resources
  • Process Priority

16
Accounting
  • It contains information used mainly for billing
    purposes and performance measurement.
  • CPU time used.
  • Total job time.
  • Main storage occupancy.
  • System programs used (compilers, editors, and
    utilities).
  • No. and types of I/O operations.

17
PCBs and Queuing
  • PCB of job created when Job Scheduler accepts it
  • updated as job goes from beginning to
    termination.
  • Queues use PCBs to track jobs.
  • PCBs, not jobs, are linked to form queues.
  • PCBs for every ready job are linked on READY
    queue all PCBs for jobs just entering system are
    linked on HOLD queue.
  • Queues must be managed by process scheduling
    policies and algorithms.

18
Process Scheduling Policies
  • Before operating system can schedule all jobs in
    a multiprogramming environment, it must resolve
    three limitations of system
  • finite number of resources (such as disk drives,
    printers, and tape drives)
  • some resources cant be shared once theyre
    allocated (such as printers)
  • some resources require operator intervention
    (such as tape drives).

19
A Good Scheduling Policy
  • Maximize throughput by running as many jobs as
    possible in a given amount of time.
  • Maximize CPU efficiency by keeping CPU busy 100
    of time.
  • Ensure fairness for all jobs by giving everyone
    an equal amount of CPU and I/O time.
  • Minimize response time by quickly turning around
    interactive requests.
  • Minimize turnaround time by moving entire jobs
    in/out of system quickly.
  • Minimize waiting time by moving jobs out of READY
    queue as quickly as possible.

20
Interrupts
  • There are instances when a job claims CPU for a
    very long time before issuing an I/O request.
  • Builds up READY queue empties I/O queues.
  • Creates an unacceptable imbalance in the system.
  • Process Scheduler uses a timing mechanism to
    periodically interrupt running processes when a
    predetermined slice of time has expired.
  • Suspends all activity on the currently running
    job.

21
Preemptive Non-preemptiveScheduling Policies
  • Preemptive scheduling policy interrupts
    processing of a job and transfers the CPU to
    another job.
  • Non-preemptive scheduling policy functions
    without external interrupts.
  • Once a job captures processor and begins
    execution, it remains in RUNNING state
    uninterrupted.
  • Until it issues an I/O request (natural wait) or
    until it is finished (exception for infinite
    loops).

22
Process Scheduling Algorithms
  • First Come First Served (FCFS)
  • Shortest Job Next (SJN)
  • Priority Scheduling
  • Shortest Remaining Time (SRT)
  • Round Robin
  • Multiple Level Queues

23
First Come First Served (FCFS)
  • Non-preemptive.
  • Handles jobs according to their arrival time --
    the earlier they arrive, the sooner theyre
    served.
  • Simple algorithm to implement
  • Uses a FIFO queue.
  • Good for batch systems not so good for
    interactive ones.
  • Turnaround time is unpredictable.

24
FCFS Example
  • Process CPU cycle (Turnaround Time)
  • A 15 msecs, B 2 msecs, C 1 msec.
  • If they arrive in order of A, B, and C.
  • Turnaround time
  • 151718 16.67

3
25
FCFS Example
  • Job order C, B, A.
  • Turnaround time
  • 1831 7.3

Job C
Job B
Job A
0
3
1
18
3
26
Shortest Job Next (SJN)
  • Non-preemptive.
  • Handles jobs based on length of their CPU cycle
    time.
  • Use lengths to schedule process with shortest
    time.
  • Optimal for batch system when all of jobs are
    available at same time and the CPU estimates are
    available.
  • Doesnt work well in interactive systems because
    users dont estimate in advance CPU time required
    to run their jobs.

27
SJN Example
  • Job A (5 cycles), B (2 cycles), C (6 cycles), D
    (4 cycles)
  • Turnaround time
  • 261117 9.0

Job B
Job D
Job A
Job C
0
6
2
17
11
4
28
Priority Scheduling
  • Non-preemptive.
  • Gives preferential treatment to important jobs.
  • Programs with highest priority are processed
    first.
  • Arent interrupted until CPU cycles are completed
    or a natural wait occurs.
  • If 2 jobs with equal priority are in READY
    queue, processor is allocated to one that arrived
    first (first come first served within priority).
  • Many different methods of assigning priorities by
    system administrator or by Processor Manager.

29
Prioritizing Criteria
  • Memory Requirements.
  • No. and types of devices required.
  • Total CPU time.
  • Amount of time already spent in the system.

30
Shortest Remaining Time (SRT)
  • Preemptive version of the SJN algorithm.
  • Processor allocated to job closest to completion.
  • This job can be preempted if a newer job in READY
    queue has a time to completion that's shorter.
  • Cant be implemented in interactive system
    requires advance knowledge of CPU time required
    to finish each job.
  • SRT involves more overhead than SJN.
  • OS monitors CPU time for all jobs in READY queue
    and performs context switching.

31
SRT Example
  • 4 jobs coming in quick succession (1 cycle
    apart).
  • Job A (6 cycles), B (3 cycles), C (1 cycle), D (4
    cycles)
  • Turnaround time for a job completion time -
    arrival time
  • Total 14416 6.25

Job B
Job B
Job A
Job C
Job D
Job A
0
14
9
5
3
2
1
4
32
Context Switching Is Required by All Preemptive
Algorithms
  • When Job A is preempted
  • All of its processing information must be saved
    in its
  • PCB for later (when Job As execution is
    continued).
  • Contents of Job Bs PCB are loaded into
    appropriate registers so it can start running
    again (context switch).
  • Later when Job A is once again assigned to
    processor another context switch is performed.
  • Info from preempted job is stored in its PCB.
  • Contents of Job As PCB are loaded into
    appropriate registers.

33
Round Robin
  • Preemptive.
  • Used extensively in interactive systems because
    its easy to implement.
  • Isnt based on job characteristics but on a
    predetermined slice of time thats given to each
    job.
  • Ensures CPU is equally shared among all active
    processes and isnt monopolized by any one job.
  • Time slice is called a time quantum
  • size crucial to system performance (100 ms to 1-2
    secs)

34
Example
  • Arrival time 0 1 2 3
  • Job A B C D
  • CPU cycle 8 4 9 5
  • Turnaround time
  • 2072422 18.25

Job A
Job C
Job D
Job C
Job A
Job D
Job C
Job B
0
8
4
16
12
24
20
26
25
4
35
If Jobs CPU Cycle lt Time Quantum
  • If the job finishes before the time quantum
    expires, then all resources allocated to it are
    released completed job is returned to user.
  • If CPU cycle was interrupted by I/O request, then
    info about the job is saved in its PCB it is
    linked at end of the appropriate I/O queue.
  • Later, when I/O request has been satisfied, it is
    returned to end of READY queue to await
    allocation of CPU.

36
Cache memory
  • It is a quickly accessible memory thats designed
    to alleviate speed differences between a very
    fast CPU and slower main memory.
  • Stores copy of frequently used data in an easily
    accessible memory area instead of main memory.

37
Cache memory
38
Types of Interrupts
  • Page interrupts to accommodate job requests.
  • Time quantum expiration.
  • I/O interrupts when issue READ or WRITE command.
  • Internal interrupts (synchronous interrupts)
    result from arithmetic operation or job
    instruction currently being processed.
  • Illegal arithmetic operations (e.g., divide by
    0).
  • Illegal job instructions (e.g., attempts to
    access protected storage locations).

39
Interrupt Handler
  • Describe store type of interrupt (passed to
    user as error message).
  • Save state of interrupted process (value of
    program counter, mode specification, and contents
    of all registers).
  • Process the interrupt
  • Send error message state of interrupted process
    to user.
  • Halt program execution
  • Release any resources allocated to job are
    released
  • Job exits the system.
  • Processor resumes normal operation.
Write a Comment
User Comments (0)
About PowerShow.com