0% found this document useful (0 votes)
28 views

Input-Output Management-2

The document discusses I/O management in operating systems. It covers topics like programmed I/O, interrupt-initiated I/O, direct memory access, I/O devices like block and character devices, device controllers, interfacing with controllers, I/O commands, and the objectives of I/O management like generality and efficiency.

Uploaded by

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

Input-Output Management-2

The document discusses I/O management in operating systems. It covers topics like programmed I/O, interrupt-initiated I/O, direct memory access, I/O devices like block and character devices, device controllers, interfacing with controllers, I/O commands, and the objectives of I/O management like generality and efficiency.

Uploaded by

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

INTRODUCTION TO I/O MANAGEMENT

The I/O management module in the operating system provides


a means by which a process can communicate with the outside
world i.e. the mechanism for input and output information.

Traditionally the I/O system is regarded as the most difficult to


implement because of the different number of peripherals that
can be used with a different configuration.
CONT.
External devices mainly differ in the following ways:
• Speed:
There may be a difference between the data transfer rates of various
devices. A magnetic disk may be able to transfer 10^12 characters per
second. A keyboard may transfer only a few characters per second
depending on-the typist.

• Amount of Data Transferred:


Data may be transferred in units of characters; words, bytes, blocks or
records, according to the peripheral used.
Cont.
Data Representation:
Data may be encoded in different ways on different I/O
media. Even on a single medium, such as magnetic tape,
several different codes may be employed.

Permissible Operations: Devices differ, in the kind of


operation they can perform. One example is the distinction
between input and output. One ability is to rewind a magnetic
tape but not printer paper.
Cont.
Error Conditions:
Failure to complete a data transfer may have various causes.
A hardware detected data error or a printer that has run out of
paper depending on the peripheral being used.

It would make the operating system too large if it caters for


every specific detail. So I/O system must isolate the device
characteristics and treat all devices uniformly.
OBJECTIVES OF I/O MANAGEMENT
• Generality and Device Independence:
I/O devices are typically quite complex mechanically and
electronically.

• Much of this complexity is related to the electronic engineering


and is of no interest to the user or the programmer. The average
user is not aware of the complexities of positioning the heads on
a disk drive, reading the signal from the disk surface, waiting for
the required sector to rotate into position etc.
Cont.
• Device independence is the process of making a
software application able to function on a wide
variety of devices regardless of the local hardware on
which the software is used.
Cont.
• Efficiency:
 Perhaps the most significant characteristic of the I/O system is the
speed disparity between it and the processor.

 I/O devices involve mechanical operations. They cannot compete with


the microsecond or nanosecond speed of the processor and memory.

 I/O management module must try to minimize the disparity by the use
of techniques like buffering and spooling.
PRINCIPLES OF I/O HARDWARE

• Different people look at I/O hardware in different ways.

• Electrical engineers look at it in terms of chips, wires, power


supplies, motors, and all the other physical components that
comprise the hardware.
Cont.
• Programmers look at the interface presented to the software—
the commands the hardware accepts, the functions it carries
out, and the errors that can be reported back.

• Basically, we are concerned with programming I/O devices,


not designing, building, or maintaining them, so our interest is
in how the hardware is programmed, not how it works inside.
I/O Devices

• I/O devices can be roughly divided into two categories:

• Block devices
• A block device is one that stores information in fixed-size
blocks, each one with its own address.

• A block device communicates to device driver by sending


entire blocks of data.
Cont.
The essential property of a block device is that it is possible to
read or write each block independently of all the other ones.

Examples include: Hard disks, Blu-ray discs, and USB sticks


are common block devices
Cont.
• Character devices.
A character device delivers or accepts a stream of
characters, without regard to any block structure.

• A character device is one with which the driver


communicates by sending and receiving single
characters (bytes, octets).
Cont.
• It is not addressable and does not have any seek
operation.

• Printers, network interfaces, mice (for pointing),serial


ports, parallel ports, sound cards etc and most other
devices that are not disk-like can be seen as character
devices.
Cont.
• This classification scheme is not perfect. Some devices do
not fit in. Clocks, for example, are not block addressable.
Device Controllers

• I/O units often consist of a mechanical component and an


electronic component.

• The electronic component is called the device controller


or adapter.

• The Device Controller works like an interface between a


device and a device driver.
Cont.
• On personal computers, it often takes the form of a chip
on the parent board or a printed circuit card that can be
inserted into a (PCIe) expansion slot.

• PCIe (peripheral component interconnect express) is an


interface standard for connecting high-speed
components. Every desktop PC motherboard has a
number of PCIe slots you can use to add GPUs (aka video
cards aka graphics cards), RAID cards, Wi-Fi cards or
SSD (solid-state drive) add-on cards.
x16 PCIe Connector
For Graphics Card

Heat sink

x1 PCIe Connector

PCI Connectors
Cont.
• The controller card usually has a connector (port) on it,
into which a cable leading to the device itself can be
plugged.

• There is always a device controller and a device driver for


each device to communicate with the Operating Systems.

• A device controller may be able to handle multiple


devices.
Cont.
Any device connected to the computer is connected by a
plug and socket, and the socket is connected to a device
controller.

Following is a model for connecting the CPU, memory,


controllers, and I/O devices where CPU and device
controllers all use a common bus for communication.
PCI BUS STRUCTURE.
Interfacing With Controllers
The CPU must have a way to pass information to and
from an I/O device.

The method that is used to transfer information between


internal storage and external I/O devices is known as I/O
interface.

The CPU is interfaced using special communication


links by the peripherals connected to any computer
system.
Cont.
These communication links are used to resolve the
differences between CPU and peripheral.

There exists special hardware components between CPU


and peripherals to supervise and synchronize all the input
and output transfers that are called interface units.
Cont.
Mode of Transfer:
The binary information that is received from an external
device is usually stored in the memory unit.

The information that is transferred from the CPU to the


external device is originated from the memory unit.

CPU merely processes the information but the source and


target is always the memory unit.
Cont.
Data transfer between CPU and the I/O
devices(peripherals)may be done in three different ways:

 Programmed I/O.
 Interrupt- initiated I/O.
 Direct memory access( DMA).
Programmed I/O
 With programmed I/O, data are exchanged between the
processor and the I/O module.

 Each data item transfer is initiated by an instruction in the


program. Usually the transfer is from a CPU register and
memory.
memory In this case it requires constant monitoring by
the CPU of the peripheral devices.
Principle of operation
The processor executes a program that gives it direct
control of the I/O operation, including sensing device
status, sending a read or write command, and transferring
the data.

When the processor issues a command to the I/O module,


it must wait until the I/O operation is complete. If the
processor is faster than the I/O module, this is wasteful of
processor time. The overall operation of the programmed
I/O can be summaries as follow:
Cont.
 The processor is executing a program and encounters an
instruction relating to I/O operation.
 The processor then executes that instruction by issuing a
command to the appropriate I/O module.
 The I/O module will perform the requested action based on the
I/O command issued by the processor (READ/WRITE) and set
the appropriate bits in the I/O status register.
 The processor will periodically check the status of the I/O
module until it find that the operation is complete.
Programmed I/O Mode Input Data Transfer
Cont.
 Each input is read after first testing whether the device is
ready with the input (a state reflected by a bit in a status
register).

 The program waits for the ready status by repeatedly


testing the status bit and till all targeted bytes are read
from the input device.

 The program is in busy (non-waiting) state only after the


device gets ready else in wait state.
Programmed I/O Mode Output Data Transfer
Cont.
 Each output written after first testing whether the device is
ready to accept the byte at its output register or output
buffer is empty.

 The program waits for the ready status by repeatedly


testing the status bit(s) and till all the targeted bytes are
written to the device.

 The program in busy (non-waiting) state only after the


device gets ready else wait state.
I/O Commands

To execute an I/O-related instruction, the processor issues


an address, specifying the particular I/O module and
external device, and an I/O command.
command There are four types
of I/O commands that an I/O module may receive when it is
addressed by a processor:

 Control: Used to activate a peripheral and tell it what to do.


For example, a magnetic-tape unit may be instructed to
rewind or to move forward one record. These commands are
tailored to the particular type of peripheral device.
Cont .
 Test: Used to test various status conditions associated with an
I/O module and its peripherals. The processor will want to
know that the peripheral of interest is powered on and
available for use. It will also want to know if the most recent
I/O operation is completed and if any errors occurred.

 Read: Causes the I/O module to obtain an item of data


from the peripheral and place it in an internal buffer. The
processor can then obtain the data item by requesting that the
I/O module place it on the data bus.
Cont.
 Write: Causes the I/O module to take an item of data
(byte or word) from the data bus and subsequently
transmit that data item to the peripheral.
I/O Instruction

With programmed I/O, there is a close correspondence


between the I/O-related instructions that the processor
fetches from memory and the I/O commands that the
processor issues to an I/O module to execute the
instructions.

Typically, there will be many I/O devices connected


through I/O modules to the system. Each device is given a
unique identifier or address.
Cont.
When the processor issues an I/O command, the
command contains the address of the desired device.
Thus, the I/O module must interpret the address lines to
determine if the command is for itself and also which
external devices that the address refer to.

When the processor, main memory share a common bus,


two modes of addressing are possible:
 Memory mapped I/O
 Isolated I/O
Cont.
With memory mapped I/O, there is a single address
space for memory locations and I/O devices and the
processor treats the status and data registers of I/O
modules as memory locations and uses the same machine
instructions to access both memory and I/O devices.
Cont.
With isolated I/O, the bus may be equipped with memory
read and write plus input and output command lines.
Now, the command line specifies whether the address
refers to a memory location or an I/O device. The full
range of addresses may be available for both.
Differences between Isolated I/O and Memory
Mapped I/O:

Isolated I/O uses separate memory space while Memory


mapped I/O uses memory from the main memory.
Limited instructions can be used. Those are IN, OUT,
INS, OUTS while Any instruction which references to
memory can be used.
The address for Isolated I/O devices are called ports while
Memory mapped I/O devices are treated as memory
locations on the memory map.
Advantages & Disadvantages of Programmed I/O

Advantages
 simple to implement
 very little hardware support
Disadvantages
 busy waiting
 ties up CPU for long period with no useful work
Interrupt Driven I/O

Interrupt I/O is a way of controlling input/output activity


whereby a peripheral or terminal that needs to make or
receive a data transfer sends a signal. This will cause a
program interrupt to be set.

At a time appropriate to the priority level of the I/O


interrupt, the processors enter an interrupt service routine.

.
Cont.
The interrupt technique requires more complex hardware
and software, but makes far more efficient use of
the computer’s time and capacities.
Basic Operations of Interrupt

1. CPU issues read command.


2. I/O module gets data from peripheral whilst CPU does
other work.
3. I/O module interrupts CPU.
4. CPU requests data.
5. I/O module transfers data.
Interrupt Processing

1. A device driver initiates an I/O request on behalf of a


process.
2. The device driver signals the I/O controller for the
proper device, which initiates the requested I/O.
3. The device signals the I/O controller that is ready to
retrieve input, the output is complete or that an error has
been generated.
4. The CPU receives the interrupt signal on the interrupt-
request line and transfer control over the interrupt
handler routine.
Cont.
5. The interrupt handler determines the cause of the
interrupt, performs the necessary processing and
executes a “return from” interrupt instruction.

6. The CPU returns to the execution state prior to the


interrupt being signaled.

7. The CPU continues processing until the cycle begins


again.
Cont.
So a typical computer uses direct memory access (DMA)
hardware to reduce this overhead.

Direct Memory Access (DMA) means CPU grants I/O


module authority to read from or write to memory without
involvement.
Interrupt processing diagram
Advantages & Disadvantages of Interrupt Drive I/O

Advantages
 fast
 efficient
Disadvantages
 can be tricky to write if using a low level language
 can be tough to get various pieces to work well together
 usually done by the hardware manufacturer / OS maker, e.g.
Microsoft
Cont.
Note: Both the methods programmed I/O and Interrupt-
driven I/O require the active intervention of the processor
to transfer data between memory and the I/O module, and
any data transfer must transverse a path through the
processor.

Thus both these forms of I/O suffer from two inherent


drawbacks.
 The I/O transfer rate is limited by the speed with which the
processor can test and service a device.
 The pocessocer is tied up in managing the I/O transfer; a
number of instructions are needed for each I/O transfer.
Direct Memory Access (DMA)

The data transfer between a fast storage media such as


magnetic disk and memory unit is limited by the speed of
the CPU.

Thus we can allow the peripherals directly communicate


with each other using the memory buses, removing the
intervention of the CPU.

This type of data transfer technique is known as DMA or


direct memory access.
Cont.
Direct Memory Access is a technique for transferring
data within main memory and external device without
passing it through the CPU.

The DMA controller takes over the buses to manage the


transfer directly between the I/O devices and the memory
unit.
Basic Operation of DMA

When the processor wishes read or send a block of data, it


issues a command to the DMA module by sending some
information to DMA module.

The information includes:


 read or write command, sending through read and write
control lines.
 number of words to be read or written, communicated on
the data lines and stored in the data count register.
Cont.
 starting location in memory to read from or write to,
communicated on data lines and stored in the address
register.
 address of the I/O device involved, communicated on the
data lines.

After the information are sent, the processor continues


with other work.
Cont.
The DMA module then transfers the entire block of data
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 to inform that it has
finished using the system bus.
Steps in DMA transfer.
Summary Flows of Using DMA by Processor

i. Issue command to DMA module, by sending necessary


information to DMA module.

ii. Processor does other work.

iii. DMA acquire control on the system, and transfers data to


and from within memory and external device.

iv. DMA sends a signal to processor when the transfer is


complete, system control is return to processor.
Advantages & Disadvantages of DMA

Advantages
 allows a peripheral device to read from/write to memory
without going through the CPU
 allows for faster processing since the processor can be
working on something else while the peripheral can be
populating memory
Disadvantages
 requires a DMA controller to carry out the operation, which
increases the cost of the system
 cache coherence problems
Buffering
A buffer is a memory area that stores data being transferred
between two devices or between a device and an application.

Buffering of I/O is performed for ( at least ) 3 major reasons:


 Speed differences between two devices. A slow device may write
data into a buffer, and when the buffer is full, the entire buffer is
sent to the fast device all at once.
Cont.
 Data transfer size differences. Buffers are used in particular in
networking systems to break messages up into smaller packets
for transfer, and then for re-assembly at the
receiving side.

 To support copy semantics.


For example, when an application makes a request for a disk
write, the data is copied from the user's memory area into a
kernel buffer. Now the application can change their copy of
the data, but the data which eventually gets written out to disk
is the version of the data at the time the write request was
made.
Cont.
Types of I/O buffering techniques :
 Single buffer :
A buffer is provided by the operating system to the system
portion of the main memory.

Block oriented device –System buffer takes the input.


After taking the input, the block gets transferred to the
user space by the process and then the process requests for
another block.
Cont.
Stream oriented device –Line- at a time operation is
used for scroll made terminals. User inputs one line at a
time, with a carriage return signaling at the end of a line.

Byte-at a time operation is used on forms mode, terminals


when each keystroke is significant.
Single I/O Buffering
Double buffer :

Block oriented –
 There are two buffers in the system. One buffer is used by
the driver or controller to store data while waiting for it to
be taken by higher level of the hierarchy.

 Other buffer is used to store data from the lower level


module.

 Double buffering is also known as buffer swapping.


Cont.
A major disadvantage of double buffering is that the
complexity of the process get increased.

If the process performs rapid bursts of I/O, then using


double buffering may be deficient.

Stream oriented –
Line- at a time I/O, the user process need not be
suspended for input or output, unless process runs ahead
of the double buffer.
Double Buffering
Circular buffer
When more than two buffers are used, the collection of
buffers is itself referred to as a circular buffer.

In this, the data do not directly passed from the producer
to the consumer because the data would change due to
overwriting of buffers before they had been consumed.

The producer can only fill up to buffer i-1 while data in


buffer i is waiting to be consumed
Circular Buffering
.
Cont
 ( Double buffering is often used in ( animated ) graphics, so
that one screen image can be generated in a buffer while the
other ( completed ) buffer is
displayed on the screen. This prevents the user from ever
seeing any half-finished screen
images. )
Caching
Caching involves keeping a copy of data in a faster-access
location than where the data is normally stored.

Buffering and caching are very similar, except that a


buffer may hold the only copy of a given data item,
whereas a cache is just a duplicate copy of some other
data stored elsewhere.
Spooling
It stands for Simultaneously Peripheral Operations
Online.

Spooling involves all processes directing any output data


to an un-sharable device to a component of the I/O
management module called the spooler.
Cont .
Function of Spooler:

On receiving output data, it stores it on hard disk and enters the
job in a spool queue.

When the un-sharable device become available it picks the first


job from the queue and transfers its data from the hard disk to
the un-sharable device.

Note that jobs in spool queue can be prioritized.


Cont.
Advantages of Spooling:
 It can produce multiple copies of the output without running
the process again.
 Processes are not suspended for a long time.
Disadvantages of Spooling:
 Need large amounts of disk space.
 Increase disk traffic.
 Not practical for real-time environment, because results are
produce at a later time.

You might also like