0% found this document useful (0 votes)
20 views78 pages

Os Unit1

Uploaded by

tr.anuvarshini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views78 pages

Os Unit1

Uploaded by

tr.anuvarshini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 78

OPERATING SYSTEMS (CS8493)

UNIT I

OPERARTING SYSTEMS OVERVIEW

Computer System Overview-Basic Elements, Instruction


Execution, Interrupts, Memory Hierarchy, Cache Memory,
Direct Memory Access, Multiprocessor and Multicore
Organization. Operating system overview-objectives and
functions, Evolution of Operating System.- Computer
System Organization- Operating System Structure and
Operations- System Calls, System Programs, OS Generation
and System Boot.
INTRODUCTION

An Operating System(OS) is a program that acts as an interface


between user and computer hardware.

OS performs all the basic tasks like File management, memory


management, process management, handling I/O.

COMPUTER SYSTEM ARCHITECTURE

Divided into four components:


Hardware - provides basic computing resources
Operating system - Controls and coordinates use of hardware
Application programs - User defined program to solve a problem
Users - people
COMPUTER SYSTEM ARCHITECTURE
COMPUTER SYSTEM ARCHITECTURE
Hardware
Provides basic computing resources such as CPU, memory, I/O
devices

Operating system
Controls and coordinates use of hardware among various
applications and users

Application programs
Define the ways in which the system resources are used to solve the
computing problems of the users e.g. Word processors, compilers, web
browsers, database systems, video games

Users
People, machines, other computers
OS Views

User View - ease of use and good performance don’t care about
resource utilization
Terminals connected to Mainframe computers – Maximize resource
utilization
Workstation connected to network – individual usability and
resource utilization
Handheld computers – Optimized for usability and battery life
Embedded computers in devices and automobiles – run without
user intervention

System View - as resource allocator and as control program


Goals of OS

Make the computer system convenient to use

Use the computer hardware in an efficient manner


Basic elements
Instruction Execution

Step 1: Fetch instruction


Step 2: Decode instruction and Fetch Operands
Step 3: Execute operation
Step 4: Store the result
Instruction Execution - Contd..
Fetch
PC->MAR
MAR Address->Content->MBR
MBR->IR
PC is Incremented

Decode
IR-> Decoded

Execute
Perform Specific Operation

Store
Store the result in ACC and Display
Interrupt
An interrupt is a signal to the processor emitted by hardware or
software indicating an event that needs immediate attention.

An interrupt alerts the processor to a high-priority condition requiring


the interruption of the current code the processor is executing.

The processor responds by suspending its current activities, saving


its state and executing interrupt handler to deal with the event.

After the interrupt handler finishes, the processor resumes normal


activities.

OS are interrupt driven.


Hardware & Software Interrupt
Hardware interrupt is used by devices to communicate that they require
attention from the OS.
Hardware interrupts are implemented using electronic alerting signals that
are sent to the processor from an external device

e.g. pressing a key on the keyboard or moving the mouse triggers hardware
interrupts

Software Interrupt is caused either by an exceptional condition in the


processor itself.
Often called a trap or exception and occurs during program execution that
are exceptional that they cannot be handled within the program itself.

e.g. divide-by-zero exception


Interrupt
Interrupt – Contd..

The OS preserves the state of the CPU by storing registers and the
program counter.

Determines which type of interrupt has occurred by polling

The interrupt controller polls each device to determine which one


made the request

Vectored interrupt system is used to identify the device which makes


the interrupt

Separate segments of code determine what action should be taken for


each type of interrupt
Interrupt – Contd..
Interrupts are provided primarily as a way to improve processor
utilization

For example, most I/O devices are much slower than the processor.

Suppose that the processor is transferring data to a printer using the


instruction cycle scheme.

After each write operation, the processor must pause and remain idle
until the printer catches up.

The length of this pause may be on the order of many thousands or


even millions of instruction cycles.

Clearly, this is a very wasteful use of the processor.


Contd..
The user program performs a series of WRITE calls interleaved with processing.
The solid vertical lines represent segments of code in a program.
Code segments 1, 2, and 3 refer to sequences of instructions that do not involve I/O.
The WRITE calls are to an I/O routine that is a system utility and that will perform the
actual I/O operation.

The I/O program consists of three sections:

• A sequence of instructions, labeled 4 in the figure, to prepare for the actual I/O
operation. This may include copying the data to be output into a special buffer and
preparing the parameters for a device command.

• The actual I/O command. Without the use of interrupts, once this command is issued,
the program must wait for the I/O device to perform the requested function (or
periodically check the status, or poll, the I/O device). The program might wait by simply
repeatedly performing a test operation to determine if the I/O operation is done.

• A sequence of instructions, labeled 5 in the figure, to complete the operation. This may
include setting a flag indicating the success or failure of the operation.
Transfer of Control
Instruction Cycle with interrupt
Interrupt Processing
Sequential and Nested Interrupt Processing
Memory Hierarchy
Memory Hierarchy
Memory Hierarchy

As hierarchy goes down


a. Decreasing cost per bit
b. Increasing capacity
c. Increasing access time
d. Decreasing frequency of access to the memory by the
processor
Comparison of Levels of memory – To Know
Memory Access Time HIT Ratio

Average access time to a two-level memory as a function of the hit ratio


H , where H is defined as the fraction of all memory accesses that are
found in the memory.

Miss Ratio=1-Hit Ratio


Example
Suppose that the processor has access to two levels of memory.

Level 1 contains 1,000 bytes and has an access time of 0.1 μs

Level 2 contains 100,000 bytes and has an access time of 1 μs.

Assume that if a byte to be accessed is in level 1, then the processor


accesses it directly.

If it is in level 2, then the byte is first transferred to level 1 and then


accessed by the processor.
Example Contd..
In our example, suppose 95% of the memory accesses are found in the
memory (i.e. H 0.95) .

Then the average time to access a byte can be expressed as


(0.95)(0.1 µs)+(0.05) (0.1 µs+ 1 µs)

=0.095+0.055

=0.15µs
Cache Memory
A Small and Expensive Memory used to improve average Access Time.

It is a high speed memory store the part of main memory which is


present in between Main Memory and CPU(processor).

Used to store Frequently accessed data.

When a processor needs to read or write data in main memory it first


checks in cache whether a copy is present. If, so it read or write
immediately. Else it checks in Main Memory.

Cache Hit – If the content is present in cache


Cache Miss- If content is not present in cache

Hit Ratio = Number of Cache hit/Number of Memory access


Miss Ratio = 1-Hit Ratio (or) Number of Miss/Number of Memory access
Cache Memory – Contd..
Cache Vs. Main Memory Structure
Cache Read Operation Working
Some Issues in Cache Design
1. Cache Size

2. Block Size

3. Mapping Function

4. Replacement Algorithm

5. Write Policy

6. Number of cache Levels


Cache Size


Block Size
As Block Size - hit ratio will due to principle of spatial locality.

However if block becomes more bigger then probability of using newly


fetched data is < when compared to probability of reusing the data which is
moved out of cache.

Mapping Function

More flexible mapping function - Design a replacement algorithm with


maximum hit ratio.

More flexible mapping function - More complex circuit is.


Replacement Algorithm

Which block to replace when a new block is loaded.

Least Recently Used block should be replaced. LRU mechanism is needed.

Write Policy

Write can occur every time the block is updated else Write can occur once
block is replaced. User should choose effective write policy.

Number of cache Levels

As number of cache level the complexity of cache circuits


Some Definitions

Temporal Locality : The word referenced now is likely to be referenced


again soon. Hence keep the currently accessed word.

Spatial Locality : Words near the currently referenced word are likely
to be referenced again soon. So, pre fetch words near currently accessed
word and keep them.

Write Through : Writes data to memory and also to cache

Write Back : Don’t write to memory but writes to cache. It writes to


memory when cache is evicted.
I/O Operations
Three techniques are possible for I/O operations

1. Programmed I/O - Video

2. Interrupt-driven I/O
a. Processor issue an I/O command to a module and then do some other work.
b. The I/O module will then interrupt the processor to request service when it is
ready to exchange data with the processor.
c. The processor then executes the data transfer and then resumes its former
processing.

3. Direct Memory Access (DMA)


Drawbacks

The Programmed I/O and Interrupt Driven I/O techniques suffer from
two drawbacks

a) I/O transfer rate is limited to speed where CPU can service


another request.

b) Processor is tied up with I/O, a N number of instructions is


executed by processor.
Direct Memory Access (DMA)
DMA function is carried out by separate module on system bus or it can be
incorporated in I/O Module.

Processor is involved only at beginning and end of I/O transfer.

It is efficient if we want to transfer large volume of data.

Working:
1. When a process wish read or write data it issues a command to DMA module by
sending the following
a. Whether Read/Write(R/W)
b. Address of I/O device involved
c. Starting address of memory to R/W
d. Number of words to R/W
2. Processor continues with other work. It delegate's the I/O operation to DMA
module
3. DMA module transfers the entire block (1 word at a time) directly to or from
memory without the involvement of processor
4. DMA controller sends an interrupt signal if I/O transfer is complete
DMA Diagram
Multiprocessor Organization
There are two or more processors of similar type.

These processors share same main memory and I/O and are
interconnected by bus.

System is controlled by integrated OS that has interaction between


processors.

All processors access the I/O devices through same channel or different
channel of their own.

Memory access time for all processor is same.

OS takes care of scheduling of task to processors and synchronization


among processor.
Multiprocessor Organization Contd..

Advantages:
Performance
Availability
Incremental Growth
Scaling

Each processor has a local cache (level 1).

If P1 and P2 has same data in level 1 cache then if P1 updates the data
in its cache then it invalidates the data in P2 cache.

This is called cache coherence problem.


Multiprocessor Architecture Diagram
Multicore Organization
There are two or more processors called cores on a single silicon chip.

These processors have individual registers, ALU,CU, Pipeline


hardware,L1,L2 and in some cases L3 caches.

It is developed to increase the clock frequency and to make the cache


closer to processor.

Intel core i7 has 4 x86 processors on a single chip.

DDR3 memory controller brings the content of main memory into chip.

Quick Path Interconnect is a point to point link for faster


communication among chips.
Multicore Architecture Diagram for intel i7
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

Application Program development


Program execution
Access to I/O devices
Controlled access to files
System access
Accounting
Error detection and response
Evolution of OS
1. Batch Systems
2. Multi-programmed Systems
3. Time Sharing Systems
4. Desktop systems
5. Multiprocessor Systems
6. Distributed Systems
1. Client Server Systems
2. Peer to Peer Systems
7. Clustered Systems
8. Real-time Systems
9. Handheld Systems
Batch Systems
• I/P - Card readers, Tape drivers
• O/P - line printers, Punched card
• User did not interact directly with system.
• User submit job to computer operator.
• Operator executes the job and give the output to users.
• To increase speed operator group the job with similar
needs and run them as a group.
Disadvantages
• Lack of interaction between the user and job.
• CPU is often idle, because the speeds of the mechanical
• I/O devices are slower than CPU.
Multi-programmed Systems
• OS keeps several jobs in memory simultaneously.
• OS picks 1 job and executes. If it wants to wait for a task to complete the
OS picks another job and executes.
• Thus if job 1 completes it task then it is resumed back and executed.
• So, CPU will not be idle at any time.
• If there are N number of jobs ready to brought into memory and there is
not enough space - Job Scheduling.
• If several jobs in memory are ready to run then – CPU Scheduling.
Time-Sharing Systems

• Multiple jobs are executed by the CPU by switching between them,


but the switches occur so frequently.

• Thus, the user can receives an immediate response.

• CPU time is shared among multiple users simultaneously.

• Time-Sharing Systems its objective is minimize response time.

• E.g. IBM's OS/360.


Desktop systems

• Developed for maximizing user convenience and responsiveness.

• Security of files is initially not implemented in Desktop Systems.



So, Malicious programs destroy data on systems.

• These programs may be self-replicating and may spread rapidly via


worm or virus mechanisms to disrupt entire companies or even
worldwide networks.

• e.g. MS-DOS, Microsoft Windows and Apple Macintosh


Multiprocessor Systems
• More than one processor in close communication.
• Also called parallel systems or tightly coupled systems.

Symmetric multiprocessing each processor runs an identical copy of


OS and communicate with each other when needed.
Asymmetric multiprocessing A master processor controls entire
system and assigns task for another processor.

Advantages
• Increased Throughput
• Economy of scale
• Increased Reliability
Distributed Systems
• Two or more computers are connected to form distributed systems.
• Also called as loosely coupled systems
• Distributed systems distribute computation among several processors.
• The processors do not share memory or a clock. Instead, each processor
has its own local memory.
• Networks are classified into LAN- within room or floor, WAN- between
buildings or cities ,MAN- between cities.
Client Server Systems Terminals are connected to centralized system.
Centralized system- server, Terminals- clients
Peer to Peer systems All nodes act as server and also client
Clustered Systems
• Gather together multiple CPU’s to accomplish computational work.
• Share storage and connected through LAN.
• Provide high availability.
• Distributed systems should provide locking and control of to files so
that no conflict occurs.
• Distributed Lock manager(DLM) will provide those access control.

Asymmetric Clustering 1 machine is in hot stand by mode. It does not


do anything but monitors the active server. If server fails then it
becomes active server.
Symmetric Clustring Each node monitors each other. So, If a node fails
its work is shared by other systems in the cluster.
Real-time Systems
Real-time operating system has well-defined, fixed time constraints
otherwise system will fail.
Hard real-time systems
guarantees that critical tasks complete on time.
In hard real-time systems secondary storage is limited.

Soft real-time systems


Critical real-time task gets priority over other tasks and retains the
priority until it completes.
Soft real-time systems have limited utility than hard real-time systems.

E.g. Scientific experiments, medical imaging systems, industrial


control systems, robots, and home appliance controllers.
Handheld Systems

• Include PDA’s with internet.

• Small memory.

• Slow processor needs less power is used to increase the battery life.

• Small Display screen with 5 inch height and 3 inch width.

• To display the content of web page in small screen web clipping


software is used.
Computer System Organization
Computer system Organization

One or more CPU’s Device Controllers are connected through common


bus providing access to share memory.

CPU and I/O devices can execute concurrently.

Each device controller is in-charge of particular I/O device.

Each device controller has a local buffer.

CPU mover data to/or from memory to devices through local buffers.
Computer system Organization
Initial Program or bootstrap program is stored in read only memory
(ROM) or erasable programmable read only memory (EEROM) also
called firmware.

It initialize all aspects to system and locate the OS kernel and load it
into memory.

Once OS is booted system waits for an event to occur. Occurrence of


event is signaled by an interrupt.

Interrupt transfers the control to interrupt service routine through


interrupt vector which contains all address of interrupt service routine.

Incoming interrupts are disabled while another interrupt is in process.

OS is interrupt driven.
OS Structure
OS should be Multiprogramming to increase the CPU utilization.

Since main memory is too small to accommodate all jobs, the jobs are
initially kept on disk in the job pool.

Response time of OS should be as low as possible.

Job scheduling – Selects the job from job pool and loads into main
memory

CPU Scheduling – Selects the job from memory and loads into CPU for
execution.

Swapping is done to swap in and out the process from min memory to
disk.
OS Structure – Contd..

Simple Structure
OS Structure – Contd..
Layered Approach
OS Structure – Contd..
Microkernels
OS Structure – Contd..
Modules
OS Structure – Contd..
Hybrid OS

• Mac OS
• iOS
• Android
OS Operations
• OS is interrupt driven.

• Events are informed to OS by the interrupts or trap.

• Trap is a software generated interrupt caused by error e.g. Division


by Zero.

• OS should ensure that incorrect programs or errors should not affect


the other programs.

• In order to ensure proper execution we should distinguish between


execution of user code and OS code.
Dual Mode and Multimode Operation
Dual Mode - 2 modes namely,
• User mode
• kernel mode (supervisor mode, system mode or privileged mode)

A mode bit is included in hardware to indicate current mode.


Kernel mode - 0 & User mode – 1

Extend beyond two modes.


• Kernel Mode
• Virtual Machine Manger Mode (support virtualization frequently)
• User Mode
Timer
• In order to control infinite loop in user program we can use timer.

• A timer can be set to interrupt the computer after specific period.

• Timer can be fixed or Variable.

• Variable Timer can be implemented by fixed rate clock and counter.

• Infinite loop can be avoided because automatically the timer


interrupts the OS after particular period even though the process is
not completed.
OS Services
System Calls
System call provides an interface to services made available by OS.
These calls are available as routine in C,C++.
System call interface serves as a link to system calls and OS.
Example to copy content of one file to another file
Passing parameters to system calls
3 possible ways
• Pass parameters in registers
• Parameters can be pushed onto stack by program and popped off
from stack by OS
• If number of parameters is more than no of registers then
parameters are stored in table or block and address of block is
placed in register and is passed.

Passing parameters as table


Types of System Calls
Types of System Calls – Contd..

Information Maintenance
• Get time or date, set time or date
• Get system data, set system data
• Get process, file or device attributes
• Set process, file or device attributes

Communications
• Create, delete communication connection
• Send, receive connections
• Transfer status information
• Attach or detach remote devices
Examples of Windows and Unix System calls
OS Generation
System must be configured or generated for specific computer site
which is called system generation
OS is normally an ISO image which is in CD-ROM or DVD-ROM.
SYSGEN reads from file and loads
Following kinds of information is determined
• What CPU is used? What options are installed?
• How will the boot disk formatted? How many partition?
• How much memory available? It can be done automatically by
reading till illegal address
• What devices are available?
• What OS options are desired or CPU scheduling algorithm,
maximum no of process supported?
System Boot
• The procedure of starting the computer and loading kernel is called
booting the system.
• A small piece of code called bootstrap program or bootstrap loader
locates the kernel and loads it into main memory and start
execution.
• When reboot is performed instruction register is loaded and
execution starts there.
• Bootstrap program is in ROM since RAM is in unknown state.
• Changing the bootstrap code require changing the ROM. So to avoid
this we use EPROM.
• GRUB is an exampl for open source bootstrap program.
• If full bootstrap program is loaded and loads the kernel then only
the system will be in running state

You might also like