0% found this document useful (0 votes)
47 views7 pages

I/O Hardware Management in Operating Systems

The document discusses the role of operating systems in managing I/O devices, categorizing them into block and character devices, and explaining the communication methods between the CPU and I/O devices. It details the structure and function of device drivers, interrupt handlers, and the layers of I/O software, including user-level libraries and kernel-level modules. Additionally, it covers the concepts of synchronous vs asynchronous I/O, Direct Memory Access (DMA), and the structure of secondary storage, particularly magnetic disks.
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)
47 views7 pages

I/O Hardware Management in Operating Systems

The document discusses the role of operating systems in managing I/O devices, categorizing them into block and character devices, and explaining the communication methods between the CPU and I/O devices. It details the structure and function of device drivers, interrupt handlers, and the layers of I/O software, including user-level libraries and kernel-level modules. Additionally, it covers the concepts of synchronous vs asynchronous I/O, Direct Memory Access (DMA), and the structure of secondary storage, particularly magnetic disks.
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

Module-6: Operating System - I/O Hardware

One of the important jobs of an Operating System is to manage various I/O devices
including mouse, keyboards, touch pad, disk drives, display adapters, USB devices, Bit-
mapped screen, LED, Analog-to-digital converter, On/off switch, network connections,
audio I/O, printers etc.
An I/O system is required to take an application I/O request and send it to the physical
device, then take whatever response comes back from the device and send it to the
application. I/O devices can be divided into two categories −
 Block devices − A block device is one with which the driver communicates by
sending entire blocks of data. For example, Hard disks, USB cameras, Disk-On-Key
etc.
o Commands include read, write, seek
o Raw I/O, direct I/O, or file-system access
o Memory-mapped file access possible
o File mapped to virtual memory and clusters brought via demand paging
o DMA

 Character devices − A character device is one with which the driver communicates
by sending and receiving single characters (bytes, octets). For example, serial ports,
parallel ports, sounds cards etc
o Commands include get(), put()
o Libraries layered on top allow line editing

Device Controllers
Device drivers are software modules that can be plugged into an OS to handle a particular
device. Operating System takes help from device drivers to handle all I/O devices.
The Device Controller works like an interface between a device and a device driver. I/O
units (Keyboard, mouse, printer, etc.) typically consist of a mechanical component and an
electronic component where electronic component is called the device controller.
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. As an
interface its main task is to convert serial bit stream to block of bytes, perform error
correction as necessary.
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.
Synchronous vs asynchronous I/O
 Synchronous I/O − In this scheme CPU execution waits while I/O proceeds
 Asynchronous I/O − I/O proceeds concurrently with CPU execution
Communication to I/O Devices
The CPU must have a way to pass information to and from an I/O device. There are three
approaches available to communicate with the CPU and Device.

 Special Instruction I/O


 Memory-mapped I/O
 Direct memory access (DMA)
Special Instruction I/O
This uses CPU instructions that are specifically made for controlling I/O devices. These
instructions typically allow data to be sent to an I/O device or read from an I/O device.
Memory-mapped I/O
When using memory-mapped I/O, the same address space is shared by memory and I/O
devices. The device is connected directly to certain main memory locations so that I/O
device can transfer block of data to/from memory without going through CPU.
While using memory mapped IO, OS allocates buffer in memory and informs I/O device to
use that buffer to send data to the CPU. I/O device operates asynchronously with CPU,
interrupts CPU when finished.
The advantage to this method is that every instruction which can access memory can be used
to manipulate an I/O device. Memory mapped IO is used for most high-speed I/O devices
like disks, communication interfaces.
Direct Memory Access (DMA)
Slow devices like keyboards will generate an interrupt to the main CPU after each byte is
transferred. If a fast device such as a disk generated an interrupt for each byte, the operating
system would spend most of its time handling these interrupts. 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. 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.
Direct Memory Access needs a special hardware called DMA controller (DMAC) that
manages the data transfers and arbitrates access to the system bus. 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.

The operating system uses the DMA hardware as follows −

Step Description

1 Device driver is instructed to transfer disk data to a buffer address X.

2 Device driver then instruct disk controller to transfer data to buffer.

3 Disk controller starts DMA transfer.

4 Disk controller sends each byte to DMA controller.


5 DMA controller transfers bytes to buffer, increases the memory address, decreases the
counter C until C becomes zero.

6 When C becomes zero, DMA interrupts CPU to signal transfer completion.

Operating System - I/O Softwares


I/O software is often organized in the following layers −
 User Level Libraries − This provides simple interface to the user program to
perform input and output. For example, stdio is a library provided by C and C++
programming languages.
 Kernel Level Modules − This provides device driver to interact with the device
controller and device independent I/O modules used by the device drivers.
 Hardware − This layer includes actual hardware and hardware controller which
interact with the device drivers and makes hardware alive.
A key concept in the design of I/O software is that it should be device independent where it
should be possible to write programs that can access any I/O device without having to
specify the device in advance. For example, a program that reads a file as input should be
able to read a file on a floppy disk, on a hard disk, or on a CD-ROM, without having to
modify the program for each different device.
Interrupt handlers
An interrupt handler, also known as an interrupt service routine or ISR, is a piece of
software or more specifically a callback function in an operating system or more specifically
in a device driver, whose execution is triggered by the reception of an interrupt.
When the interrupt happens, the interrupt procedure does whatever it has to in order to
handle the interrupt, updates data structures and wakes up process that was waiting for an
interrupt to happen.
The interrupt mechanism accepts an address ─ a number that selects a specific interrupt
handling routine/function from a small set. In most architectures, this address is an offset
stored in a table called the interrupt vector table. This vector contains the memory addresses
of specialized interrupt handlers.
Device Drivers
Device drivers are software modules that can be plugged into an OS to handle a particular
device. Operating System takes help from device drivers to handle all I/O devices. Device
drivers encapsulate device-dependent code and implement a standard interface in such a way
that code contains device-specific register reads/writes. Device driver, is generally written
by the device's manufacturer and delivered along with the device on a CD-ROM.
A device driver performs the following jobs −

 To accept request from the device independent software above to it.


 Interact with the device controller to take and give I/O and perform required error
handling
 Making sure that the request is executed successfully
How a device driver handles a request is as follows: Suppose a request comes to read a
block N. If the driver is idle at the time a request arrives, it starts carrying out the request
immediately. Otherwise, if the driver is already busy with some other request, it places the
new request in the queue of pending requests.
Device-Independent I/O Software
The basic function of the device-independent software is to perform the I/O functions that
are common to all devices and to provide a uniform interface to the user-level software.
Though it is difficult to write completely device independent software but we can write
some modules which are common among all the devices. Following is a list of functions of
device-independent I/O Software −

 Uniform interfacing for device drivers


 Device naming - Mnemonic names mapped to Major and Minor device numbers
 Device protection
 Providing a device-independent block size
 Buffering because data coming off a device cannot be stored in final destination.
 Storage allocation on block devices
 Allocation and releasing dedicated devices
 Error Reporting
User-Space I/O Software
These are the libraries which provide richer and simplified interface to access the
functionality of the kernel or ultimately interactive with the device drivers. Most of the user-
level I/O software consists of library procedures with some exception like spooling system
which is a way of dealing with dedicated I/O devices in a multiprogramming system.
I/O Libraries (e.g., stdio) are in user-space to provide an interface to the OS resident device-
independent I/O SW. For example putchar(), getchar(), printf() and scanf() are example of
user level I/O library stdio available in C programming.
Kernel I/O Subsystem
Kernel I/O Subsystem is responsible to provide many services related to I/O. Following are
some of the services provided.
 Scheduling − Kernel schedules a set of I/O requests to determine a good order in
which to execute them. When an application issues a blocking I/O system call, the
request is placed on the queue for that device. The Kernel I/O scheduler rearranges
the order of the queue to improve the overall system efficiency and the average
response time experienced by the applications.
 Buffering − Kernel I/O Subsystem maintains a memory area known as buffer that
stores data while they are transferred between two devices or between a device with
an application operation. Buffering is done to cope with a speed mismatch between
the producer and consumer of a data stream or to adapt between devices that have
different data transfer sizes.
 Caching − Kernel maintains cache memory which is region of fast memory that
holds copies of data. Access to the cached copy is more efficient than access to the
original.
 Spooling and Device Reservation − A spool is a buffer that holds output for a
device, such as a printer, that cannot accept interleaved data streams. The spooling
system copies the queued spool files to the printer one at a time. In some operating
systems, spooling is managed by a system daemon process. In other operating
systems, it is handled by an in kernel thread.
 Error Handling − An operating system that uses protected memory can guard
against many kinds of hardware and application errors.

Secondary Storage – Disk Structure


Secondary storage devices are those devices whose memory is non volatile, meaning, the
stored data will be intact even if the system is turned off. Here are a few things worth noting
about secondary storage.

 Secondary storage is also called auxiliary storage.


 Secondary storage is less expensive when compared to primary memory like RAMs.
 The speed of the secondary storage is also lesser than that of primary storage
 Hence, the data which is less frequently accessed is kept in the secondary storage.
 A few examples are magnetic disks, magnetic tapes, removable thumb drives etc.

Magnetic Disk Structure


In modern computers, most of the secondary storage is in the form of magnetic disks. Hence,
knowing the structure of a magnetic disk is necessary to understand how the data in the disk
is accessed by the computer.
Structure of a magnetic disk

A magnetic disk contains several platters. Each platter is divided into circular shaped tracks.
The length of the tracks near the centre is less than the length of the tracks farther from the
centre. Each track is further divided into sectors, as shown in the figure.
Tracks of the same distance from centre form a cylinder. A read-write head is used to read
data from a sector of the magnetic disk.
The speed of the disk is measured as two parts:

 Transfer rate: This is the rate at which the data moves from disk to the computer.
 Random access time: It is the sum of the seek time and rotational latency.

Seek time is the time taken by the arm to move to the required track. Rotational latency is
defined as the time taken by the arm to reach the required sector in the track.
Even though the disk is arranged as sectors and tracks physically, the data is logically
arranged and addressed as an array of blocks of fixed size.

Common questions

Powered by AI

When a device driver receives a request to read a block but is already busy, it places the new request in a queue of pending requests. The driver will then handle each request in the order they arrive, ensuring that each is executed successfully once the driver becomes idle .

Secondary storage, being non-volatile and less expensive, operates slower than primary memory like RAM. Its magnetic disk structure, with multiple platters and tracks divided into sectors, influences access speed. Random access time, involving seek time and rotational latency, affects how quickly data is accessed, making it slower compared to primary memory which lacks these mechanical constraints .

Interrupt handlers, or ISRs, are essential in OS as callback functions triggered by interrupts. When an interrupt occurs, the handler executes routines to manage the interrupt, update data structures, and wake waiting processes. A vector table stores addresses of specialized handlers, ensuring quick access to appropriate routines. This mechanism allows efficient handling of events without constant CPU polling .

Device-independent I/O software aims to perform I/O tasks uniformly across different devices, allowing user-level software to interact without device specificity. Functions include uniform interfacing for device drivers, device naming, device protection, providing device-independent block size, buffering, storage allocation, device allocation, and error reporting .

Memory-mapped I/O allows the device to be connected directly to certain main memory locations, enabling the transfer of blocks of data to/from memory without involving the CPU. This leads to asynchronous operation with the CPU, which is only interrupted once the data transfer is complete. As every instruction that can access memory can also access an I/O device, it simplifies programming and is efficient for high-speed I/O devices like disks .

Spooling allows dedicated I/O devices like printers to handle output without data streams interleaving, orchestrating orderly processing in a multiprogrammed environment. Queuing files in a spool ensures devices receive data correctly and maintains system responsiveness, as processing occurs in the background without stalling other processes .

DMA is preferred for fast devices because it reduces CPU overhead. Unlike slower devices like keyboards that generate an interrupt per byte, fast devices would overwhelm the CPU with interrupts if not for DMA. The DMAC manages data transfers and arbitrates access to the system bus, controlling the data exchange between memory and I/O devices. The CPU is involved only at the start and end of the transfer, significantly improving efficiency .

Block devices communicate with drivers by sending entire blocks of data and support commands like read, write, seek. They allow raw I/O, direct I/O, or file-system access, and can utilize memory-mapped file access . Character devices communicate by sending and receiving single characters (bytes, octets) and support commands like get() and put(). Libraries layered on top of character device drivers enable line editing .

A uniform interface allows developers to design applications without needing to tailor them for specific devices, promoting code portability and easing development. It abstracts device specifics, enabling flexible OS design and reducing complexity in managing diverse hardware. Developers can rely on the interface to interact with distinct devices uniformly, minimizing errors and improving maintainability .

The kernel I/O subsystem enhances system efficiency by scheduling I/O requests to optimize their execution order, improving overall system throughput and application response time. Buffering allows temporary data storage during transfers, accommodating speed mismatches between data production and consumption or devices with different transfer sizes, further contributing to efficiency .

You might also like