Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
29 views65 pages

08 - Operating System Support

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1/ 65

William Stallings

Computer Organization
and Architecture
8th Edition

Chapter 8
Operating System Support
Objectives and Functions
• An OS is a program that controls the
execution of application programs and
acts as an interface between the user of a
computer and the computer hardware.
• It can be thought of as having two
objectives:
• Convenience
—Making the computer easier to use
• Efficiency
—Allowing better use of computer resources
Layers and Views of a Computer System
The most important system program is the OS.
The OS masks the details of the hardware from the
programmer and provides the programmer with a
convenient interface for using the system.
It acts as mediator, making it easier for the
programmer and for application programs to access
and use those facilities and services.
Layers and Views of a Computer System
Operating System Services

Briefly, the OS typically provides


services in the following areas:
Program creation
• The OS provides a variety of facilities and
services, such as editors and debuggers,
to assist the programmer in creating
programs.
• Typically, these services are in the form of
utility programs that are not actually part
of the OS but are accessible through the
OS.
Program execution

• A number of tasks need to be performed


to execute a program.
• Instructions and data must be loaded into
main memory, I/O devices and files must
be initialized, and other resources must be
prepared.
• The OS handles all of this for the user.
Access to I/O devices

• Each I/O device requires its own specific


set of instructions or control signals for
operation.
• The OS takes care of the details so that
the programmer can think in terms of
simple reads and writes.
Controlled access to files

• In the case of files, control must include


an understanding of not only the nature of
the I/O device (disk drive, tape drive) but
also the file format on the storage
medium. Again, the OS worries about the
• details. Further, in the case of a system
with multiple simultaneous users, the
• OS can provide protection mechanisms to
control access to the files.
System access

• In the case of a shared or public system,


the OS controls access to the system as a
whole and to specific system resources.
• The access function must provide
protection of resources and data from
unauthorized users and must resolve
conflicts for resource contention.
Error detection and response

• A variety of errors can occur while a computer


system is running.
• These include internal and external hardware
errors, such as a memory error, or a device failure
or malfunction; and various software errors, such
as arithmetic overflow, attempt to access
forbidden memory location, and inability of the OS
to grant the request of an application.
• In each case, the OS must make the response
that clears the error condition with the least
impact on running applications.
• The response may range from ending the program
that caused the error, to retrying the operation, to
simply reporting the error to the application.
Accounting

• A good OS collects usage statistics for


various resources and monitor
performance parameters such as response
time.
• On any system, this information is useful
in anticipating the need for future
enhancements and in tuning the system
to improve performance.
• On a multiuser system, the information
can be used for billing purposes.
O/S as a Resource Manager
• A computer is a set of resources for the
movement, storage, and processing of
data and for the control of these
functions.
• The OS is responsible for managing these
resources.
• Figure, suggests the main resources that
are managed by the OS.
O/S as a Resource Manager
• A portion of the OS is in main memory.
This includes the kernel, which contains
the most frequently used functions in the
OS and, at a given time, other portions of
the OS currently in use.
• The remainder of main memory contains
user programs and data.
• The allocation of this resource (main
memory) is controlled jointly by the OS
and memory management hardware in
the processor, as we shall see.
O/S as a Resource Manager
Types of Operating System
• Interactive
• Batch
• Single program (Uni-programming)
• Multi-programming (Multi-tasking)
Interactive

• In an interactive system, the user/


programmer interacts directly with the
computer, usually through a
keyboard/display terminal, to request the
execution of a job or to perform a
transaction.
• Furthermore, the user may, depending on
the nature of the application,
communicate with the computer during
the execution of the job.
batch
• A batch system is the opposite of
interactive.
• The user’s program is batched together
with programs from other users and
submitted by a computer operator.
• After the program is completed, results
are printed out for the user.
• Pure batch systems are rare today.
• However, it will be useful to the
description of contemporary operating
systems to examine batch systems briefly.
multiprogramming
& uniprogramming
• An independent dimension specifies whether
the system employs multiprogramming or
not.
• With multiprogramming, the attempt is
made to keep the processor as busy as
possible, by having it work on more than
one program at a time.
• Several programs are loaded into memory,
and the processor switches rapidly among
them.
• The alternative is a uniprogramming
system that works only one program at a
time.
Early Systems
• Late 1940s to mid 1950s, No Operating System
• Programs interact directly with hardware
• These processors were run from a console,
consisting of display lights, toggle switches,
some form of input device, and a printer.
Programs in processor code were loaded via the
input device (e.g., a card reader).
• If an error halted the program, the error
condition was indicated by the lights. The
programmer could proceed to examine registers
and main memory to determine the cause of the
error. If the program proceeded to a normal
completion, the output appeared on the printer
• Two main problems:
— Scheduling
— Setup time
Scheduling
• Scheduling: Most installations used a
sign-up sheet to reserve processor time.
• Typically, a user could sign up for a block
of time in multiples of a half hour or so.
• A user might sign up for an hour and
finish in 45 minutes; this would result in
wasted computer idle time.
• On the other hand, the user might run
into problems, not finish in the allotted
time, and be forced to stop before
resolving the problem.
Setup time:
• A single program, called a job, could involve
loading the compiler plus the high-level language
program (source program) into memory, saving
the compiled program (object program), and
then loading and linking together the object
program and common functions.
• Each of these steps could involve mounting or
dismounting tapes, or setting up card decks.
• If an error occurred, the hapless user typically
had to go back to the beginning of the setup
sequence.
• Thus a considerable amount of time was spent
just in setting up the program to run.
Simple Batch Systems
• To improve utilization, simple batch
operating systems were developed.
• With Such a system, also called a
monitor, the user no longer has direct
access to the processor.
• Rather, the user submits the job on cards
or tape to a computer operator, who
batches the jobs together sequentially and
places the entire batch on an input device,
for use by the monitor.
Simple Batch Systems
• Resident Monitor program
• monitor controls the sequence of events.
• Users submit jobs to operator (typically a
card reader or magnetic tape drive)
• Operator batches jobs
• Monitor controls sequence of events to
process batch
• When one job is finished, control returns
to Monitor which reads next job
• Monitor handles scheduling
Memory Layout for Resident Monitor
• We see that the monitor, or batch OS, is
simply a computer program.
• It relies on the ability of the processor to
fetch instructions from various portions of
main memory in order to seize and
relinquish control alternately.
• Certain other hardware features are also
desirable:
Desirable Hardware Features
• Memory protection
—While the user program is executing, it must
not alter the memory area containing the
monitor.
—If such an attempt is made, the processor
hardware should detect an error and transfer
control to the monitor.
—The monitor would then abort the job, print
out an error message, and load the next job.
Desirable Hardware Features
• Timer
—A timer is used to prevent a single job from
monopolizing the system.
—The timer is set at the beginning of each job.
—If the timer expires, an interrupt occurs, and
control returns to the monitor.
Desirable Hardware Features
• Interrupts
• Early computer models did not have this
capability.
• This feature gives the OS more flexibility
in relinquishing control to and regaining
control from user programs.
Multi-programmed Batch Systems
• I/O devices very slow
• When one program is waiting for I/O,
another can use the CPU
• In this example the computer spends over
96% of its time waiting for I/O devices to
finish transferring data! Figure 8.5a
illustrates this situation.
• The processor spends a certain amount of
time executing, until it reaches an I/O
instruction.
• It must then wait until that I/O instruction
concludes before proceeding.
• This inefficiency is not necessary. We know
that there must be enough memory to hold
the OS (resident monitor) and one user
program.
• Suppose that there is room for the OS and
two user programs.
• Now, when one job needs to wait for I/O,
the processor can switch to the other job,
which likely is not waiting for I/O (Figure
8.5b).
• Furthermore, we might expand memory to
hold three, four, or more programs and
switch among all of them (Figure 8.5c). This
technique is known as multiprogramming,
or multitasking.
• It is the central theme of modern operating
systems.
Single Program
Multi-Programming with
Two Programs
Multi-Programming with
Three Programs
Utilization
Time Sharing Systems
• Allow users to interact directly with the
computer
—i.e. Interactive
• Multi-programming allows a number of
users to interact with the computer
Scheduling
• Key to multi-programming
• Long term
• Medium term
• Short term
• I/O
Long Term Scheduling
• Determines which programs are submitted
for processing
• i.e. controls the degree of multi-
programming
• Once submitted, a job becomes a process
for the short term scheduler
• (or it becomes a swapped out job for the
medium term scheduler)
Medium Term Scheduling
• Part of the swapping function (later…)
• Usually based on the need to manage
multi-programming
• If no virtual memory, memory
management is also an issue
Short Term Scheduler
• Dispatcher
• Fine grained decisions of which job to
execute next
• i.e. which job actually gets to use the
processor in the next time slot
• PROCESS STATES To understand the
operation of the short-term scheduler, we
need to consider the concept of a process
state. During the lifetime of a process, its
status will change a number of times.
• Its status at any point in time is referred
to as a state.
• The term state is used because it
connotes that certain information exists
that defines
• The status at that point. At minimum, there are five
defined states for a process
• (Figure 8.7):
• • New: A program is admitted by the high-level scheduler
but is not yet ready to execute.
• The OS will initialize the process, moving it to the ready
state.
• • Ready: The process is ready to execute and is awaiting
access to the processor.
• • Running: The process is being executed by the
processor.
• • Waiting: The process is suspended from execution
waiting for some system resource, such as I/O.
• • Halted: The process has terminated and will be
destroyed by the OS.
Five State Process Model
Process Control Block
• Identifier
• State
• Priority
• Program counter
• Memory pointers
• Context data
• I/O status
• Accounting information
• Identifier: Each current process has a unique
identifier.
• • State: The current state of the process (new,
ready, and so on).
• • Priority: Relative priority level.
• • Program counter: The address of the next
instruction in the program to be
• executed.
• • Memory pointers: The starting and ending
locations of the process in memory.
• • Context data: These are data that are present
in registers in the processor while
• the process is executing, and they will be
discussed in Part Three. For now, it is
• enough to say that these data represent the
“context” of the process.The context
• data plus the program counter are saved when
the process leaves the running state.
• They are retrieved by the processor when it
resumes execution of the process.
• • I/O status information: Includes outstanding
I/O requests, I/O devices (e.g., tape
• drives) assigned to this process, a list of files
assigned to the process, and so on.
• • Accounting information: May include the
amount of processor time and clock
• time used, time limits, account numbers, and so
on.
PCB Diagram
Memory Management
• Uni-program
—Memory split into two
—One for Operating System (monitor)
—One for currently executing program
• Multi-program
—“User” part is sub-divided and shared among
active processes
Swapping
• Problem: I/O is so slow compared with
CPU that even in multi-programming
system, CPU can be idle most of the time
• Solutions:
—Increase main memory
– Expensive
– Leads to larger programs
—Swapping
What is Swapping?
• Long term queue of processes stored on
disk
• Processes “swapped” in as space becomes
available
• As a process completes it is moved out of
main memory
• If none of the processes in memory are
ready (i.e. all I/O blocked)
—Swap out a blocked process to intermediate
queue
—Swap in a ready process or a new process
—But swapping is an I/O process…
Use of Swapping
Partitioning
• Splitting memory into sections to allocate
to processes (including Operating System)
• Fixed-sized partitions
—May not be equal size
—Process is fitted into smallest hole that will
take it (best fit)
—Some wasted memory
—Leads to variable sized partitions
Fixed
Partitioning
Relocation
• No guarantee that process will load into
the same place in memory
• Instructions contain addresses
—Locations of data
—Addresses for instructions (branching)
Paging
• Split memory into equal sized, small
chunks -page frames
• Split programs (processes) into equal
sized small chunks - pages
• Allocate the required number page frames
to a process
• Operating System maintains list of free
frames
• Use page table to keep track
Allocation of Free Frames
Logical and Physical Addresses - Paging
Virtual Memory
• Demand paging
—Do not require all pages of a process in
memory
—Bring in pages as required
• Page fault
—Required page is not in memory
—Operating System must swap in required page
—May need to swap out a page to make space
—Select page to throw out based on recent
history
Thrashing
• Too many processes in too little memory
• Operating System spends all its time
swapping
• Little or no real work is done
• Disk light is on all the time

• Solutions
—Good page replacement algorithms
—Reduce number of processes running
—Fit more memory
Bonus
• We do not need all of a process in
memory for it to run
• We can swap in pages as required
• So - we can now run processes that are
bigger than total memory available!

• Main memory is called real memory


• User/programmer sees much bigger
memory - virtual memory
Translation Lookaside Buffer
• Every virtual memory reference causes
two physical memory access
—Fetch page table entry
—Fetch data
• Use special cache for page table
—TLB
Segmentation
• Paging is not (usually) visible to the
programmer
• Segmentation is visible to the
programmer
• Usually different segments allocated to
program and data
• May be a number of program and data
segments
Advantages of Segmentation
• Simplifies handling of growing data
structures
• Allows programs to be altered and
recompiled independently, without re-
linking and re-loading
• Lends itself to sharing among processes
• Lends itself to protection
• Some systems combine segmentation
with paging

You might also like