CS8493 Operating Systems - Unit I
CS8493 Operating Systems - Unit I
CS8493 Operating Systems - Unit I
Basic Elements
A computer consists of processor, memory, and I/O components, with one or more modules of each
type.
These components are interconnected in some fashion to achieve the main function of the computer,
which is to execute programs.
There are four main structural elements:
Processor
I/O Modules
Main Memory
System Bus
Processor:
Controls the operation of the computer and performs its data processing functions.
When there is only one processor, it is often referred to as the central processing unit (CPU).
CS8493/Operating Systems
Main memory:
Stores data and programs.
This memory is typically volatile; that is, when the computer is shut down, the contents of the
memory are lost.
In contrast, the contents of disk memory are retained even when the computer system is shut down.
Main memory is also referred to as real memory or primary memory.
I/O modules:
Move data between the computer and its external environment.
The external environment consists of a variety of devices, including secondary memory devices
(e.g., disks), communications equipment, and terminals.
System bus:
Provides for communication among processors, main memory, and I/O modules.
Top level Components:
The top-level components are shown in the figure.
One of the processor’s functions is to exchange data with memory.
For this purpose, it typically makes use of two internal (to the processor) registers.
MAR:
A memory address register (MAR), which specifies the address in memory for the next read or
write;
MBR:
A memory buffer register (MBR), which contains the data to be written into memory or which
receives the data read from memory.
I/O AR:
An I/O address register (I/OAR) specifies a particular I/O device.
I/O BR:
An I/O buffer register (I/OBR) is used for the exchange of data between an I/O module and the
processor.
A memory module consists of a set of locations, defined by sequentially numbered addresses.
Each location contains a bit pattern that can be interpreted as either an instruction or data. An I/O
module transfers data from external devices to processor and memory, and vice versa.
It contains internal buffers for temporarily holding data until they can be sent on.
Processor Register
A processor register is a local storage space on a processor that holds data that is being processed by CPU.
Processor registers generally occupy the top-most position in the memory hierarchy, providing high-speed
storage space and fast access to data. A register may include the address of the memory location instead of the
real data itself.
User-visible registers
A user visible register (UVR) are the registers visible to programmers. Basically
this means that the programmer can only make use of these registers (UVA).
These registers includes general purpose or special purpose registers.
Example: Data Register, & Address Register.
Types of registers
Data Registers
o Some of the registers can be used for floating – point operations; Other registers can
be used for integer operations.
Address Registers
o Index register - Involves adding an index to a base value to get an address.
o Segment pointer - When memory is divided into segments, memory is referenced by
a segment and an offset.
o Stack pointer - Points to top of stack.
Control and status registers
Used by processor to control operating of the processor
Used by privileged operating-system routines to control the execution of programs
o Program Counter (PC) – Contains the address of an instruction to be fetched
o Instruction Register (IR) – Contains the instruction most recently fetched
o Program Status Word (PSW) – this contains the status information
o Condition codes/flags – these are the bits set by the process or hardware as a
result of operations. Example: Positive, Negative, Zero, Overflow result.
Instruction Execution
A program to be executed by a processor consists of a set of instructions stored in memory.
Instruction processing consists of two steps:
The processor reads ( fetches ) instructions from memory one at a time and executes each instruction.
Program execution consists of repeating the process of instruction fetch and instruction execution.
Instruction execution may involve several operations and depends on the nature of the instruction.
Interrupts
Interrupt is a signal which has highest priority from hardware or software which processor should
process its signal immediately.
Types of Interrupts:
Although interrupts have highest priority than other signals, there are many type of interrupts but basic
type of interrupts are
Hardware Interrupts: If the signal for the processor is from external device or hardware is called
hardware interrupts. Example: from keyboard we will press the key to do some action this pressing of
key in keyboard will generate a signal which is given to the processor to do action, such interrupts are
called hardware interrupts. Hardware interrupts can be classified into two types they are
1. Maskable Interrupt: The hardware interrupts which can be delayed when a much highest
priority interrupt has occurred to the processor.
2. Non Maskable Interrupt: The hardware which cannot be delayed and should process by the
processor immediately.
Software Interrupts: Software interrupt can also divided in to two types. They are
1. Normal Interrupts: the interrupts which are caused by the software instructions are called
software instructions.
2. Exception: unplanned interrupts while executing a program is called Exception. For example:
while executing a program if we got a value which should be divided by zero is called an
exception.
Interrupts
Interrupt the normal sequencing of the processor
Provided to improve processor utilization
most I/O devices are slower than the processor
processor must pause to wait for device
wasteful use of the processor
Virtually all computers provide a mechanism by which other modules (I/O, memory) may interrupt
the normal sequencing of the processor.
Interrupts are provided primarily as a way to improve processor utilization. For example, most I/O
devices are much slower than the processor.
Interrupt Processing
An interrupt triggers a number of events, both in the processor hardware and in software. When an I/O
device completes an I/O operation, the following sequence of hardware events occurs:
The device issues an interrupt signal to the processor.
The processor finishes execution of the current instruction before responding to the interrupt.
The processor tests for a pending interrupt request, determines that there is one, and sends an
acknowledgment signal to the device that issued the interrupt. The acknowledgment allows the device to
remove its interrupt signal.
The processor next needs to prepare to transfer control to the interrupt routine. To begin, it saves
information needed to resume the current program at the point of interrupt. The minimum information
required is the program status word 3 (PSW) and the location of the next instruction to be executed,
which is contained in the program counter (PC). These can be pushed onto a control stack
The processor then loads the program counter with the entry location of the interrupt-handling routine
that will respond to this interrupt. Depending on the computer architecture and OS design, there may be
a single program, one for each type of interrupt, or one for each device and each type of interrupt. If
there is more than one interrupt-handling routine, the processor must determine which one to invoke.
This information may have been included in the original interrupt signal, or the processor may have to
issue a request to the device that issued the interrupt to get a response that contains the needed
information.
Memory Hierarchy
Caching – copying information into faster storage system; main memory can be viewed as a last
cache for secondary storage.
Main memory – only large storage media that the CPU can access directly
Random access
Typically volatile
Secondary storage – extension of main memory that provides large nonvolatile storage capacity
Magnetic disks – rigid metal or glass platters covered with magnetic recording material
Disk surface is logically divided into tracks, which are subdivided into sectors
The disk controller determines the logical interaction between the device and the computer
The memory is characterized on the base of two factors –
1. Capacity : Capacity is the amount of information or data that a memory can store.
2. Access Time : Access time is the time interval between the read and write request and the
availability of data.
Storage systems organized in hierarchy.
Speed
Cost
Volatility
1. Registers
CPU registers are at the top most level of this hierarchy, they hold the most frequently used data. They
are very limited in number and are the fastest.
They are often used by the CPU and the ALU for performing arithmetic and logical operations, for
temporary storage of data.
2. Cache
The very next level consists of small, fast cache memories near the CPU. They act as staging areas for a
subset of the data and instructions stored in the relatively slow main memory.
There are often two or more levels of cache as well. The cache at the top most level after the registers is
the primary cache. Others are secondary caches.
Many a times there is cache present on board with the CPU along with other levels that are outside the
chip.
3. Main Memory:
The next level is the main memory, it stages data stored on large, slow disks often called hard disks.
These hard disks are also called secondary memory, which are the last level in the hierarchy. The main
memory is also called primary memory.
The secondary memory often serves as staging areas for data stored on the disks or tapes of other
machines connected by networks.
4. Electronic disk/Solid State Drive (SSD)
SSD incorporates the storage technique implemented in microchip-based flash memory, where data is
electronically stored on flash memory chips. An SSD is an entirely electronic storage device, and its
physical assembly contains no mechanical objects.
A SSD has two key components:
Flash memory: Contains storage memory.
Controller: An embedded microprocessor that processes functions, like error correction, data
retrieval and encryption. Manages access to input/output (I/O) and read/write (R/W) operations
between the SSD and host computer.
5. Magnetic disks:
rigid metal or glass platters covered with magnetic recording material
Disk surface is logically divided into tracks, which are subdivided into sectors
The disk controller determines the logical interaction between the device and the computer
6. Optical disk:
An optical disk is primarily used as a portable and secondary storage device. It can store more data than
the previous generation of magnetic storage media, and has a relatively longer lifespan. Compact disks
(CD), digital versatile/video disks (DVD) and Blu-ray disks are currently the most commonly used
forms of optical disks. These disks are generally used to:
Distribute software to customers
Store large amounts of data such as music, images and videos
Transfer data to different computers or devices
Back up data from a local machine
7. Magnetic tapes:
A magnetic disk is a storage device that uses a magnetization process to write, rewrite and access data.
It is covered with a magnetic coating and stores data in the form of tracks, spots and sectors.
Hard disks, zip disks and floppy disks are common examples of magnetic disks
Cache Memory
The Cache Memory is the volatile computer memory which is very nearest to the CPU so also called
CPU memory.
The cache memory stores the program (or its part) currently being executed or which may be executed
within a short period of time. The cache memory also stores temporary data that the CPU may
frequently require for manipulation.
The cache memory works according to various algorithms, which decide what information it has to
store. These algorithms work out the probability to decide which data would be most frequently needed.
This probability is worked out on the basis of past observations.
It acts as a high speed buffer between CPU and main memory and is used to temporary store very active
data and action during processing since the cache memory is faster than main memory, the processing
speed is increased by making the data and instructions needed in current processing available in cache.
The cache memory is very expensive and hence is limited in capacity.
For this purpose, the processor periodically checks the status of the I/O module until it finds that the
operation is complete.
With programmed I/O, the processor has to wait a long time for the I/O module of concern to be ready
for either reception or transmission of more data.
The processor, while waiting, must repeatedly interrogate the status of the I/O module.
As a result, the performance level of the entire system is severely degraded.
An alternative, known as interrupt-driven I/O , is for the processor to issue an I/O command to a
module and then go on to do some other useful work.
The I/O module will then interrupt the processor to request service when it is ready to exchange data
with the processor.
The processor then executes the data transfer, as before, and then resumes its former processing.
Interrupt-driven I/O, though more efficient than simple programmed I/O, still requires the active
intervention of the processor to transfer data between memory and an I/O module, and any data transfer
must traverse a path through the processor.
Thus, both of these forms of I/O suffer from two inherent drawbacks:
1. The I/O transfer rate is limited by the speed with which the processor can test and service a
device.
2. The processor is tied up in managing an I/O transfer; a number of instructions must be
executed for each I/O transfer.
When large volumes of data are to be moved, a more efficient technique is required: direct memory
access (DMA).
The DMA function can be performed by a separate module on the system bus or it can be
incorporated into an I/O module.
In either case, the technique works as follows.
When the processor wishes to read or write a block of data, it issues a command to the DMA
module, by sending to the DMA module the following information:
Whether a read or write is requested
The address of the I/O device involved
The starting location in memory to read data from or write data to
The number of words to be read or written
The processor then continues with other work.
It has delegated this I/O operation to the DMA module, and that module will take care of it.
The DMA module transfers the entire block of data, one word at a time, directly to or from memory
without going through the processor.
When the transfer is complete, the DMA module sends an interrupt signal to the processor.
Thus, the processor is involved only at the beginning and end of the transfer.
The DMA module needs to take control of the bus to transfer data to and from memory.
Because of this competition for bus usage, there may be times when the processor needs the bus and
must wait for the DMA module.
Note that this is not an interrupt; the processor does not save a context and do something else.
The processor pauses for one bus cycle (the time it takes to transfer one word across the bus). The
overall effect is to cause the processor to execute more slowly during a DMA transfer when processor
access to the bus is required.
Nevertheless, for a multiple-word I/O transfer, DMA is far more efficient than interrupt-driven or
programmed I/O.
I) Symmetric Multiprocessors
An SMP can be defined as a stand-alone computer system with the following characteristics:
1. There are two or more similar processors of comparable capability.
2. These processors share the same main memory and I/O facilities and are interconnected by a bus or
other internal connection scheme, such that memory access time is approximately the same for each
processor.
3. All processors share access to I/O devices, either through the same channels or through different
channels that provide paths to the same device.
4. All processors can perform the same functions (hence the term symmetric ).
5. The system is controlled by an integrated operating system that provides interaction between processors
and their programs at the job, task, file, and data element levels.
In an SMP, individual data elements can constitute the level of interaction, and there can be a high
degree of cooperation between processes.
Performance: If the work to be done by a computer can be organized so that some portions of the work
can be done in parallel, then a system with multiple processors will yield greater performance than one
with a single processor of the same type.
Availability: In a symmetric multiprocessor, because all processors can perform the same functions, the
failure of a single processor does not halt the machine. Instead, the system can continue to function at
reduced performance.
Incremental growth: A user can enhance the performance of a system by adding an additional
processor.
Scaling: Vendors can offer a range of products with different price and performance characteristics
based on the number of processors configured in the system.
Organization
Figure illustrates the general organization of an SMP. There are multiple processors, each of which
contains its own control unit, arithmetic logic unit, and registers.
Each processor has access to a shared main memory and the I/O devices through some form of
interconnection mechanism called a shared bus.
The processors can communicate with each other through memory (messages and status information left
in shared address spaces). It may also be possible for processors to exchange signals directly. The
memory is often organized so that multiple simultaneous accesses to separate blocks of memory are
possible.
II)Multicore Computers
A multicore computer, also known as a chip multiprocessor , combines two or more processors (called
cores) on a single piece of silicon (called a die).
Typically, each core consists of all of the components of an independent processor, such as registers,
ALU, pipeline hardware, and control unit, plus L1 instruction and data caches.
In addition to the multiple cores, contemporary multicore chips also include L2 cache and, in some
cases, L3 cache.
Example: Intel Core i7, which includes four x86 processors, each with a dedicated L2 cache, and with a
shared L3 cache.
The Core i7 chip supports two forms of external communications to other chips.
The DDR3 memory controller brings the memory controller for the DDR (double data rate) main
memory onto the chip.
Figure: Intel Core i7 Block Diagram
The interface supports three channels that are 8 bytes wide for a total bus width of 192 bits, for an
aggregate data rate of up to 32 GB/s.
With the memory controller on the chip, the Front Side Bus is eliminated.
The QuickPath Interconnect (QPI) is a point-to-point link electrical interconnect specification. It
enables high-speed communications among connected processor chips.
The QPI link operates at 6.4 GT/s (transfers per second).
Objectives of OS:
Convenience: An OS makes a computer more convenient to use.
Efficiency: An OS allows the computer system resources to be used in an efficient manner.
Ability to evolve: An OS should be constructed in such a way as to permit the effective
development, testing, and introduction of new system functions without interfering with service.
Functions of OS:
Program development:
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, while not strictly part of the core of the
OS, are supplied with the OS and are referred to as application program development tools.
Program execution:
A number of steps 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 these scheduling duties for the user.
Access to I/O devices:
Each I/O device requires its own peculiar set of instructions or control signals for operation.
The OS provides a uniform interface that hides these details so that programmers can access such
devices using simple reads and writes.
Controlled access to files:
For file access, the OS must reflect a detailed understanding of not only the nature of the I/O device
(disk drive, tape drive) but also the structure of the data contained in the files on the storage medium.
In the case of a system with multiple users, the OS may provide protection mechanisms to control
access to the files.
System access:
For shared or public systems, 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 division by zero, attempt to access forbidden memory location, and inability of the OS to
grant the request of an application.
In each case, the OS must provide a 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 will collect 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.
Evolution of Operating System
To understand the key requirements for an OS and the significance of the major features of a
contemporary OS, it is useful to consider how operating systems have evolved over the years
Serial Processing
In late 1940s to the mid-1950s, the programmer interacted directly with the computer hardware, there is
no operating system
Computers ran from a console with display lights, toggle switches, some form of input device, and a
printer
Programs in machine code were loaded via the input device (e.g., a card reader)and the outputs are
appeared on the printer.
These early systems presented two main problems:
1. Scheduling:
Most installations used a hardcopy sign-up sheet to reserve computer time
Time allocations could run short or long, resulting in wasted computer time
2. 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 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.
A considerable amount of time was spent just in setting up the program to run.
This mode of operation could be termed serial processing
The monitor controls the sequence of events and the monitor must always be in main memory and
available for execution. That portion is referred to as the resident monitor.
The rest of the monitor consists of utilities and common functions that are loaded as subroutines to the
user program at the beginning of any job that requires them
The monitor reads in jobs one at a time from the input device(card reader)and the current job is placed in
the user program area, and control is passed to this job.When the job is completed, it returns control to
the monitor and it read the next job. The results of each job are sent to an output device(Printer).
Memory Layout for a Resident Monitor
Processor point of view:
Memory protection:
While the user program is executing, it must not alter the memory area containing the monitor
Timer:
A timer is used to prevent a single job from monopolizing (control) the system.
Privileged instructions:
Certain machine level instructions are designated privileged and can be executed only by the monitor.
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.Considerations of memory protection and privileged
instructions lead to the concept of modes of operation.
1. User mode:
A user program executes in a user mode, in which certain areas of memory are protected from the
user’s use and in which certain instructions may not be executed.
Even with the automatic job sequencing provided by a simple batch OS, the processor is often idle. The
problem is that I/O devices are slow compared to the processor.
System Utilization Example
The calculation concerns a program that processes a file of records and performs, on average, 100
machine instructions per record. In this example, the computer spends over 96% of its time waiting for I/
O devices to finish transferring data to and from the file.
Uniprogramming:
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
Multiprogramming:
When one job needs to wait for I/O, the processor can switch to the other job, which may not be waiting.
Furthermore, we might expand memory to hold three, four, or more programs and switch among all of
them ( Figure 2.5c ). The approach is known as multiprogramming, or multitasking. It is the central
theme of modern operating systems.
This technique is referred to as time sharing, because processor time is shared among multiple users.
In a time-sharing system, multiple users simultaneously access the system through terminals, with the
OS interleaving the execution of each user program in a short burst or quantum of computation.
if there are n users actively requesting service at one time, each user will only see on the average 1/ n of
the effective computer capacity, not counting OS overhead. However, given the relatively slow human
reaction time, the response time on a properly designed system should be similar to that on a dedicated
computer.
Batch Multiprogramming vs. Time Sharing
3. Layered Approach
This approach breaks up the operating system into different layers.
This allows implementers to change the inner workings, and increases modularity.
As long as the external interface of the routines don’t change, developers have more freedom to change
the inner workings of the routines.
With the layered approach, the bottom layer is the hardware, while the highest layer is the user interface.
o The main advantage is simplicity of construction and debugging.
o The main difficulty is defining the various layers.
o The main disadvantage is that the OS tends to be less efficient than other implementations.
Fig: The Microsoft Windows NT Operating System. The lowest level is a monolithic kernel, but many OS
components are at a higher level, but still part of the OS.
4. Microkernels
This structures the operating system by removing all nonessential portions of the kernel and implementing them
as system and user level programs.
Generally they provide minimal process and memory management, and a communications facility.
Communication between components of the OS is provided by message passing.
Benefits:
Extending the operating system becomes much easier.
Any changes to the kernel tend to be fewer, since the kernel is smaller.
The microkernel also provides more security and reliability.
Disadvantage: poor performance due to increased system overhead from message passing.
Dual-Mode Operation
In order to ensure the proper execution of the operating system, we must be able to distinguish between the
execution of operating-system code and user defined code. We need two separate modes of operation: user
mode and kernel mode (also called supervisor mode, system mode, or privileged mode). A bit, called
the mode bit, is added to the hardware of the computer to indicate the current mode: kernel (0) or user (1).
With the mode bit, we are able to distinguish between a task that is executed on behalf of the operating system
and one that is executed on behalf of the user.
When the computer system is executing on behalf of a user application, the system is in user mode.
However, when a user application requests a service from the operating system (via a system call),
it must transition from user to kernel mode to fulfill the request. As we shall see, this
architectural enhancement is useful for many other aspects of system operation as well.
At system boot time, the hardware starts in kernel mode.
The operating system is then loaded and starts user applications in user mode.
Whenever a trap or interrupt occurs, the hardware switches from user mode to kernel mode (that is,
changes the state of the mode bit to 0).
Thus, whenever the operating system gains control of the computer, it is in kernel mode.
The system always switches to user mode (by setting the mode bit to 1) before passing control to a user
program.
The dual mode of operation - protecting the operating system from errant users: The hardware
allows privileged instructions to be executed only in kernel mode. If an attempt is made to execute a
privileged instruction in user mode, the hardware does not execute the instruction but rather treats it as illegal
and traps it to the operating system.
System Calls
System calls provide an interface to the services made available by an operating system. These calls are
generally available as routines written in C and C++, and assembly-language instructions.
Application developers often do not have direct access to the system calls, but can access them through
an application programming interface (API). The functions that are included in the API invoke the
actual system calls. By using the API, certain benefits can be gained:
Portability: as long a system supports an API, any program using that API can compile and run.
Ease of Use: using the API can be significantly easier then using the actual system call.
The bootstrap program can perform a variety of tasks. Usually, one task is to run diagnostics to
determine the state of the machine. If the diagnostics pass, the program can continue with the booting
steps.
It can also initialize CPU registers to device controllers and the contents of main memory.
Some systems—such as cellular phones, PDAs, and game consoles—store the entire operating system
in ROM. Storing the operating system in ROM is suitable for small operating systems. A problem with
this approach is that changing the bootstrap code requires changing the ROM hardware chips. All forms
of ROM are also known as firmware. A problem with firmware in general is that executing code there
is slower than executing code in RAM. Some systems store the operating system in firmware and copy
it to RAM for fast execution. A final issue with firmware is that it is relatively expensive, so usually
only small amounts are available.
For large operating systems, the bootstrap loader is stored in firmware, and the operating system is on
disk. In this case, the bootstrap runs diagnostics and has a bit of code that can read a single block at a
fixed location (say block zero) from disk into memory and execute the code from that boot block. A
disk that has a boot partition is called a boot disk or system disk.
Now that the full bootstrap program has been loaded, it can traverse the file system to find the operating
system kernel, load it into memory, and start its execution. It is only at this point that the system is said
to be running.