0% found this document useful (0 votes)
27 views17 pages

Os - Lecture - 08 - Io Device MNGNT

The document discusses I/O device management in operating systems. It covers I/O devices, differences between devices, techniques for I/O including programmed I/O, interrupt-driven I/O, and direct memory access (DMA). DMA allows I/O devices to access main memory directly without CPU involvement. The document also discusses I/O buffering which improves efficiency by transferring data in advance of or after requests.

Uploaded by

Kutemwa Mithi
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)
27 views17 pages

Os - Lecture - 08 - Io Device MNGNT

The document discusses I/O device management in operating systems. It covers I/O devices, differences between devices, techniques for I/O including programmed I/O, interrupt-driven I/O, and direct memory access (DMA). DMA allows I/O devices to access main memory directly without CPU involvement. The document also discusses I/O buffering which improves efficiency by transferring data in advance of or after requests.

Uploaded by

Kutemwa Mithi
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/ 17

Operating Systems

Lecture 8 - I/O Device Management

Ralph Tambala

MUST . CSIT

Lecture 8 1 / 17
Outline

1 I/O Devices

2 Direct Memory Access

3 I/O Buffering

4 Additional Tasks

Lecture 8 2 / 17
I/O Devices

I/O Devices

External devices that engage in I/O with computer systems can be


grouped into three categories:
1 Human readable

Suitable for communicating with the computer user


Examples include printers, visual display terminals, keyboards, mouse
2 Machine readable
Suitable for communicating with electronic equipment
Examples disk, USB keys, tape drives, sensors, actuators
3 Communications
Suitable for communicating with remote devices
Examples include modems, digital line drivers

Lecture 8 3 / 17
I/O Devices

Differences in I/O Devices


Devices differ in a number of areas
Data rates – there may be differences of magnitude between the data
transfer rates
Applications – how the device is used has an influence on the
software and policies in the OS and supporting utilities
Complexity of control – the effect on the OS is filtered by the
complexity of the I/O module that controls the device. For example,
a printer – simple control when compared to a disk
Unit of transfer – data may be transferred as a stream of bytes or
characters or in larger blocks
Data representation – different data encoding schemes
Error conditions – the nature of errors, the way in which they are
reported, their consequences, and the available range of responses
differs from one device to another
Lecture 8 4 / 17
I/O Devices

Differences in I/O Devices


Data transfer rates

Figure 1: Data transfer rates ranging from 101 to 109

Lecture 8 5 / 17
I/O Devices

Organization of the I/O Function


Three techniques for performing I/O are:
1 Programmed I/O (or Polled I/O)

The CPU manually check if there are any I/O requests available
periodically. If an I/O device is ready, the processor fully dedicates
itself in transferring the data between I/O and memory.
Transfers data at a high rate, but the major drawback is that the CPU
get involved in any other activity during data transfer.
2 Interrupt-Driven I/O
Whenever the device is ready for data transfer, then it raises an
interrupt to CPU. CPU completes executing its ongoing instruction and
saves its current state. CPU then switches to data transfer which
causes a delay. Here, the CPU does NOT keep scanning for peripherals
ready for data transfer. However, it is fully involved in the data transfer
process.
3 Direct Memory Access (DMA)
DMA is a mode of data transfer between the memory and I/O devices.
This happens without the involvement of the CPU.
Lecture 8 6 / 17
I/O Devices

Evolution of the I/O Function

The following are evolution steps of an I/O function:


1 The processor directly controls a peripheral device.
2 A controller or I/O module is added and processor uses programmed
I/O without interrupts.
3 Same configuration as step 2, but with interrupts.
4 The I/O module is given direct control of memory via DMA.
5 The I/O module is enhanced to become a separate processor, with a
specialized instruction set tailored for I/O
6 I/O module has a local memory of its own. With this architecture, a
large set of I/O devices can be controlled.

Lecture 8 7 / 17
Direct Memory Access

DMA (1)
Slow devices, such as keyboards (see Figure 1), will send an interrupt
to the CPU after each byte transferred. If a fast device, such as a
disk, generated an interrupt for every byte, the operating system
would spend the majority of its time handling these interrupts. To
reduce this overhead, a typical computer uses DMA.
DMA means CPU grants I/O module authority to read from or write
to memory without involvement. DMA module itself controls
exchange of data between main memory and the I/O device. CPU is
only involved at the beginning and end of the transfer and interrupted
only after entire block has been transferred.
A chip that controls the activity of accessing memory directly is called
a DMA controller (DMAC). The controllers are programmed with
source and destination pointers (where to read/write the data),
counters to track the number of transferred bytes, and settings, which
includes I/O and memory types, interrupts and states for the CPU
cycles.
Lecture 8 8 / 17
Direct Memory Access

DMA (2)

Figure 2: DMA Controller data transfer

Note thar the DMA Controller can be a separate unit that is shared by
various I/O devices, or it can also be a part of the I/O device interface.
Lecture 8 9 / 17
Direct Memory Access

DMA (3)
Here are the steps on how DMAC works: (refer to Figure 2)
1 Whenever an I/O device wants to transfer the data to or from
memory, it sends the DMA request (DRQ) to the DMA controller.
DMA controller accepts this DRQ and asks the CPU to hold for a few
clock cycles by sending it the Hold request (HLD).
2 CPU receives the HLD from DMA controller and relinquishes the bus
and sends the Hold acknowledgement (HLDA) to DMA controller.
3 After receiving the HLDA, DMA controller acknowledges I/O
device (DACK) that the data transfer can be performed and DMA
controller takes the charge of the system bus and transfers the data
to or from memory.
4 When the data transfer is accomplished, the DMA raises an interrupt
to let know the processor that the task of data transfer is finished and
the processor can take control over the bus again and start processing
where it has left.
Lecture 8 10 / 17
I/O Buffering

I/O Buffering

When a user process wants to read blocks of data from a disk,


process waits for the transfer.
The process then waits either by busy waiting or process suspension
on an interrupt.
The following are problems associated with this approach:
◦ Program waits for slow I/O
◦ Virtual locations should stay in the main memory during the course of
block transfer
◦ Risk of single-process deadlock
◦ Process is blocked during transfer and may not be swapped out

The above inefficiencies can be resolved if input transfers in advance of


requests are being made and output transfers are performed some time
after the request is made. This technique is known as buffering.

Lecture 8 11 / 17
I/O Buffering

I/O Buffering
Types of I/O devices

Block-oriented device
stores information in blocks that are usually of fixed size
transfers are made one block at a time
possible to reference data by its block number
disks and USB keys are examples

Stream-oriented device
transfers data in and out as a stream of bytes
no block structure
terminals, printers, communications ports, and most other devices
that are not secondary storage are examples

Lecture 8 12 / 17
I/O Buffering

I/O Buffering
Various types of I/O buffering techniques (1)

(a) No buffering – Without a buffer, the OS directly


accesses the device when it needs

(b) Single buffering – OS assigns a buffer in main


memory for an I/O request

(c) Double buffering – Use of two system buffers

(d) Circular buffering – Use of more than two buffers

Lecture 8 13 / 17
I/O Buffering

I/O Buffering
Various types of I/O buffering techniques (2)

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.
◦ Two blocks works simultaneously, when one block of data is processed
by the user process, the next block is being read in.
◦ OS can swap the processes.
◦ OS can record the data of system buffer to user processes.
Stream-oriented device
Line-at-a-time I/O: 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 I/O: operation is used on forms mode, terminals when
each keystroke is significant.
Lecture 8 14 / 17
I/O Buffering

I/O Buffering
Various types of I/O buffering techniques (3)

Double buffer – Use two system buffers instead of one. (Also known as
buffer swapping)
Block oriented device
◦ 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.
◦ 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 device
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.
Byte-at-a-time I/O operations: Double buffer offers no advantage over
a single buffer of twice the length.
Lecture 8 15 / 17
I/O Buffering

I/O Buffering
Various types of I/O buffering techniques (4)

Circular buffer – When more than two buffers are used. Each individual
buffer is one unit in a circular buffer.

Used when I/O operation must keep up with process.

Note that a circular buffer with n elements is usually used to implement a


queue with n − 1 elements – there is always one empty element in the
buffer. Otherwise, it becomes difficult to distinguish between a full and
empty queue–the read and write pointers would be identical in both cases.

Lecture 8 16 / 17
Additional Tasks

Additional Tasks
Discuss one advantage and one disadvantage of using DMA.

Lecture 8 17 / 17

You might also like