Os - Lecture - 08 - Io Device MNGNT
Os - Lecture - 08 - Io Device MNGNT
Ralph Tambala
MUST . CSIT
Lecture 8 1 / 17
Outline
1 I/O Devices
3 I/O Buffering
4 Additional Tasks
Lecture 8 2 / 17
I/O Devices
I/O Devices
Lecture 8 3 / 17
I/O Devices
Lecture 8 5 / 17
I/O Devices
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
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)
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
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)
Lecture 8 13 / 17
I/O Buffering
I/O Buffering
Various types of I/O buffering techniques (2)
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.
Lecture 8 16 / 17
Additional Tasks
Additional Tasks
Discuss one advantage and one disadvantage of using DMA.
Lecture 8 17 / 17