Chapter 2 - Overview of operating systems. Chapter 2 describes the different classes of operating systems, discusses the fundamental concepts and techniques used by each of them, and lists those of their techniques that are employed in modern operating systems as well.
Trang 2Overview of operating systems
• A modern OS contains a very large number of features
– Many of these features were first introduced in different classes
of operating systems, namely
* Batch Processing operating systems
* Multiprogramming operating systems
* Time sharing operating systems
* Real time operating systems
* Distributed operating systems
– These features are used in a modern OS as well
* We study these features in the context of the relevant OS
* Study their influence on system performance and user service
Trang 3Recap from Chapter 1
• The fundamental goals of an operating system
– Obtain
* High system performance
* Good user service
within a computing environment
– A computing environment consists of a computer system, its
interfaces with other systems, and user computations
* Measures of system performance and user service depend on the computing environment
Trang 4Recap from Chapter 1
• Fundamental tasks of an OS
– Management of Programs
* Organize their execution by sharing the CPU
* Ensure good user service
– Management of Resources
* Fast allocation and de-allocation without constraining user programs
* Efficient use of resources
– Security and Protection
* Ensure absence of interference with programs and resources by entities within and outside the OS
Trang 5In this chapter, we shall first study:
• Fundamentals of OS operation
– Features of a computer that are important for an OS
– How the OS controls execution of programs
– How a program interacts with an OS
• Efficiency, system performance and user convenience
– Measures of system performance
– User service as a measure of user convenience
Trang 6OS and the Computer System
• In this module, we study
– Fundamental features of computer systems that are important to
an OS
* Memory hierarchy
* Interrupt structure
* I/O organization
– How an OS uses these features to control operation of an OS
– Fundamentals of how a program interacts with an OS
Trang 7
Memory utilization during operation of an OS
• The kernel is the core of the OS; it is memory resident at all times
• Nonkernel programs are loaded in the transient area when needed
Trang 8Model of a computer system
• The CPU and the I/O subsystem have independent paths to memory
• The memory management unit plays a part in implementing virtual memory
Trang 9The program status word (PSW)
• The CPU contains two kinds of registers
– User accessible registers
* Used for arithmetic or logical operations, addressing, indexing, etc
These are called general purpose registers, or simply, CPU
registers
– Control registers
* Condition code register (also called the flags register), program counter, etc
* Their contents govern operation of the CPU
• Control registers are collectively called the program
status word (PSW)
Trang 10Fields of the Program Status Word (PSW)
• The ‘privileged mode’ field indicates whether the CPU is in the privileged mode, which is used by the OS, or user mode
* Some instructions can be executed only when CPU is in the privileged mode
• Condition code and Program counter registers were mentioned before
Trang 11Privileged mode of CPU
• The CPU can operate in two modes The privileged
mode (P) field of PSW controls the CPU mode
– Privileged mode (`P’ field contains 1)
* Certain sensitive instructions can be executed only when the CPU is
Trang 12State of the CPU
• The state of the CPU consists of
– The PSW and contents of the general purpose registers of the CPU
– It indicates
* What the CPU is engaged in doing at any moment
* What the CPU can do, in terms of privileges to perform certain operations
– The OS keeps track of the state of the CPU to know what the
program currently executing on the CPU is doing
Trang 13State of the CPU
(a) An assembly language program
(b) CPU state of the program after executing the COMPARE instruction
– 0 in the P field indicates that the CPU is in the user mode
Trang 14Memory hierarchy
• The memory hierarchy is a cost-effective method of
obtaining a large and fast memory
– It is an arrangement of several memories with different access speeds and sizes
* The CPU accesses only the fastest memory; i.e., the cache
* If a required byte is not present in the memory being accessed, it is loaded there from a slower memory
Trang 15Memory hierarchy
• Cache memory is the fastest and disk the slowest in the hierarchy
• The CPU accesses only the cache memory
• If required data or instruction is not present in the cache, it is loaded there from memory (if not present in memory, it is first loaded from disk)
Trang 16* A ‘write-through’ arrangement is typically used to update memory
– The cache hit ratio (h) indicates what percentage of accessed
bytes were already present in cache
* The cache hit ratio has high values because of
Temporal locality
Spatial locality
* Effective memory access time =
h x access time of cache memory +
(1 – h) x (time to load a cache block + access time of cache memory)
Trang 17Memory hierarchy
• Main memory
– Memory protection prevents access to memory by an
unauthorized program
* Memory bound registers indicate bounds of the memory allocated to
a program (see next slide)
• Virtual memory
– The part of memory hierarchy consisting of the main memory
and a disk is called virtual memory
* A program and its data are stored on the disk
* Required portions of the program and its data are loaded in memory when accessed
Trang 18Memory protection using bound registers
• The lower bound register (LBR) and upper bound register (UBR) contain
addresses of first and last bytes allocated to the program
• LBR, UBR are stored in the memory prot info (MPI) field of the PSW
• The CPU raises an interrupt if an address is outside the LBR–UBR range
Trang 19Input / Output organization
• An I/O operation slows down a program’s execution due
to mismatch of CPU and I/O speeds
– Involvement of the CPU in I/O operations should be the
Trang 20Input / Output modes
• Details of the Input/output modes
An interrupt is raised every time a unit of data is to be
transferred between memory and the I/O device
An interrupt processing program in the kernel actually transfers the data
Trang 21Input / Output modes
• Details of the Input/output modes (contd)
– Direct memory access (DMA)
* An I/O instruction indicates the operation to be performed and the number of bytes of data to be transferred Its execution starts the I/O operation
Data transfer is coordinated by the DMA controller; it does not involve the CPU
When the I/O operation completes, the DMA controller raises
an I/O interrupt to indicate its completion (interrupts are
discussed later)
CPU is free to execute other instructions while an I/O operation
is in progress
Trang 22• An interrupt signals the occurrence of an event to the
CPU
– An event is a situation that requires OS intervention
– At an interrupt, the interrupt action in the hardware diverts the CPU to execution of an interrupt processing routine (IPR)
* The IPR is a routine in the OS kernel
* It handles the situation that caused the interrupt
* After the IPR, kernel switches the CPU to execution of a user program
– Different classes of interrupts convey occurrences of different kinds of events
Trang 24The interrupt action
Trang 25Steps in interrupt action
• The interrupt action consists of three steps
1 Set interrupt code in the PSW
* The code describes the situation that caused the interrupt
* It is stored in the interrupt code field of the PSW
1 Save the PSW
* PSW is saved in a memory location
* Interrupt code gets saved as a part of the PSW
1 Load interrupt vector
* Interrupt vector of the occurred interrupt is chosen
It contains address of the interrupt processing routine (IPR)
Trang 26Interrupt driven operation of a kernel
Trang 27Servicing of an I/O interrupt and return to the same user
program
User program
→ IPR for I/O interrupt
→ Scheduler
→ User program
Trang 28Nested interrupts
• An interrupt may occur while a previous interrupt is being processed
– The interrupt action would divert the CPU to handle the new
interrupt On completion of its processing, processing of the
previous interrupt would be resumed
* It may delay processing of the previous interrupt
– The interrupt mask (IM) indicates whether a new interrupt should
be allowed to occur while a previous interrupt is being serviced
* Each bit in the mask controls masking of one class of interrupts
If an interrupt is masked off: it remains pending
If an interrupt is enabled: it can occur
Trang 29Simple and nested interrupt processing
(a) A single interrupt occurs and is serviced
(b) A nested interrupt occurs. Processing of the previous interrupt
Trang 30System Call
• A computer has a special instruction called a ‘software interrupt’ instruction
– Its sole purpose is to cause a program interrupt
– Its operand becomes the interrupt code
* A program uses the software interrupt instruction to make a request
Trang 31Types of system calls
• System calls are used to make diverse kinds of requests
Trang 32Efficiency, system performance and user
convenience
• The nature of a computing environment determines
– The nature of user computations
* Non-interactive computing environment
– Notions of efficiency, system performance and user service
* e.g., user service is
Response time for interactive computing
Deadline for real time computing
Trang 33* A sequence of job steps
Each job step is an execution of a program
It is executed only if previous job steps executed successfully
– Process
* A process is an execution of a program
– Subrequest
* A subrequest is a computational requirement presented by a user to
a process It produces a single response comprising of results or
Trang 34Measures of efficiency and user convenience
• We use the following measures
Trang 35Efficiency and user convenience in different
OS classes
• Service is a usercentric consideration
Trang 36Efficiency and user convenience in different
OS classes
• Explanation of the previous chart:
– A multiprogramming OS provides better efficiency than a batch processing OS because it services many processes in an
overlapped manner
* However, user convenience does not change
– A time sharing system provides better response times than a
multiprogrammed system
* Hence it provides the better user convenience
– A real time OS does not provide as much efficiency as a time sharing OS because it may reserve some resources for
exclusive use of a process
Trang 37Batch processing system
In early operating systems, the computer operator had to
manually set-up execution of every job
• Aim of batch processing:
– To reduce operator’s intervention in processing of user jobs
* A batch is a sequence of jobs
* The operator sets up processing of a batch, rather than processing
of individual jobs
It saves valuable time spent in human actions
Trang 38Batch processing system
Trang 39Turn-around time in a batch processing system
• ‘Turnaround time’ of a job is the time between the submission of a job and obtaining of its results
• If results are printed after entire batch is processed, turnaround time
Trang 40Batch processing
• Control statements are used to facilitate batch
processing
– Users insert control statements in their jobs to specify
* Start and end of a job, end of program or data
* Requirements concerning execution of a program
– The batch monitor processes the control statements to take
appropriate actions
* Initiate or terminate processing of a batch
* Initiate or terminate processing of a job
* Protect adjoining programs in the batch against interference
If a program tries to read more data than provided, the end-of- data card alerts the batch monitor
Batch monitor terminates the program (see next slide)
Trang 41Control statements in IBM 360/370 systems
• The // JOB and /& statements are startofjob and endofjob statements
Trang 42Multiprogramming Systems
In a batch processing system, the CPU remained idle while
a program performed I/O operations
• Aim of multiprogramming:
– Achieve efficient use of the computer system through
overlapped execution of several programs
* While a program is performing I/O operations, the OS schedules another program
Trang 43Operation of a multiprogramming system
(a) Program 1 performs I/O and Program 2 executes on the CPU
(b) Program 2 initiates I/O, so OS switches the CPU to Program 3
Trang 44Architectural support for multiprogramming
• The computer’s architecture must contain following
features to support multiprogramming
* To prevent corruption or disruption of a program by other programs
– Privileged mode of CPU
* CPU must be in privileged mode to execute sensitive instructions
* It is in the user mode, i.e., non-privileged mode, while executing user programs
Trang 45Functions of a multiprogramming kernel
• The kernel of a multiprogramming OS performs the
following functions
– Resource allocation and protection
* It uses memory protection to avoid interference between programs
– Keeping track of start and end of I/O operations through interrupt processing, so that it can
* Initiate I/O operations
* Perform scheduling
Trang 46Concepts and techniques of multiprogramming
• Three key concepts are
– Use a suitable program mix of CPU-bound and I/O-bound
programs
* A CPU-bound program performs computations most of the time, and
I/O operations seldom
* An I/O bound program performs I/O operations frequently
– Assign suitable priorities to programs
* Decide which program should be favoured for execution on the CPU
—an I/O-bound program or a CPU-bound program?
– Use a suitably high degree of multiprogramming
* Degree of multiprogramming = No of programs in memory
* Facilitates parallel operation of CPU and I/O system
Trang 47Priority in a multiprogramming OS
• Priority is a tie-breaking rule used when more than one
program is ready for execution
– At any moment, the highest priority program that is not waiting for an I/O operation to complete is chosen for execution
Trang 48Program priority in Multiprogramming OSs
The priority assignment rule for achieving better performance:
“I/O bound programs should have higher priorities than
CPU bound programs”
We shall discuss different priority assignments to I/O-bound and
CPU-bound programs, study their influence on performance, and conclude
accordingly
Trang 49Timing chart when a CPU-bound program has
Trang 50A CPU-bound program has higher priority
• Observations
– CPU utilization is reasonable
– I/O utilization is poor
– Periods of concurrent CPU and I/O activities are rare
Q: Can I/O utilization be improved?
A: No! Adding an I/O-bound program does not help much because it
has a low priority
Trang 51Timing chart when an I/O bound program has
higher priority
• prog iob is selected at time 0
Trang 52An I/O-bound program has higher priority
• Observations:
– CPU utilization is reasonable
– I/O utilization is reasonable
– Periods of concurrent CPU and I/O activities are frequent
Q: Can CPU and I/O utilization be improved?
A: Yes
* Addition of an I/O-bound program improves I/O utilization
Trang 53
Performance and user service in
multiprogramming
– Performance is measured as throughput
* Throughput is the number of programs serviced by the system in a
unit of time
* For high throughput, I/O-bound programs should have higher priorities than CPU-bound programs
– User service is measured as turn-around time of a job
* Turn-around time of a job is the elapsed time between submission
of a job and its completion