Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
33 views31 pages

IO Handling in OS

Chapter 13 of 'Operating System Concepts' discusses the structure and management of I/O systems within operating systems, detailing the roles of I/O hardware, device drivers, and the kernel I/O subsystem. It covers various methods of I/O communication, including synchronous and asynchronous I/O, memory-mapped I/O, and direct memory access (DMA), along with principles of I/O software such as device independence and error handling. The chapter emphasizes the importance of efficient I/O management for overall system performance and the abstraction provided by device-independent I/O software.

Uploaded by

ayush772005
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)
33 views31 pages

IO Handling in OS

Chapter 13 of 'Operating System Concepts' discusses the structure and management of I/O systems within operating systems, detailing the roles of I/O hardware, device drivers, and the kernel I/O subsystem. It covers various methods of I/O communication, including synchronous and asynchronous I/O, memory-mapped I/O, and direct memory access (DMA), along with principles of I/O software such as device independence and error handling. The chapter emphasizes the importance of efficient I/O management for overall system performance and the abstraction provided by device-independent I/O software.

Uploaded by

ayush772005
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/ 31

Chapter 13: I/O Systems

Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013
Chapter 13: I/O Systems
● Overview
● I/O Hardware
● Application I/O Interface
● Kernel I/O Subsystem
● Transforming I/O Requests to Hardware Operations
● STREAMS
● Performance

Operating System Concepts – 9th Edition 13.2 Silberschatz, Galvin and Gagne ©2013
Objectives
● Explore the structure of an operating system’s I/O subsystem

● Discuss the principles of I/O hardware and its complexity

● Provide details of the performance aspects of I/O hardware


and software

Operating System Concepts – 9th Edition 13.3 Silberschatz, Galvin and Gagne ©2013
Overview

● I/O management is a major component of operating system


design and operation
● Important aspect of computer operation
● I/O devices vary greatly
● Various methods to control them
● Performance management
● New types of devices frequent
● Ports, busses, device controllers connect to various devices
● Device drivers encapsulate device details
● Present uniform device-access interface to I/O subsystem

Operating System Concepts – 9th Edition 13.4 Silberschatz, Galvin and Gagne ©2013
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.
•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

Operating System Concepts – 9th Edition 13.5 Silberschatz, Galvin and Gagne ©2013
Device Controller
● 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.

Operating System Concepts – 9th Edition 13.6 Silberschatz, Galvin and Gagne ©2013
Device controller cont…

Operating System Concepts – 9th Edition 13.7 Silberschatz, Galvin and Gagne ©2013
Synchronous vs. Asynchronous
• Synchronous I/O − In this scheme CPU execution waits while I/O
proceeds
• Asynchronous I/O − I/O proceeds concurrently with CPU execution

Operating System Concepts – 9th Edition 13.8 Silberschatz, Galvin and Gagne ©2013
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.

Operating System Concepts – 9th Edition 13.9 Silberschatz, Galvin and Gagne ©2013
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.

Operating System Concepts – 9th Edition 13.10 Silberschatz, Galvin and Gagne ©2013
Direct Memory Access
● 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.

Operating System Concepts – 9th Edition 13.11 Silberschatz, Galvin and Gagne ©2013
Direct Memory Access Cont…

Operating System Concepts – 9th Edition 13.12 Silberschatz, Galvin and Gagne ©2013
Steps for How OS use DMA
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 Concepts – 9th Edition 13.13 Silberschatz, Galvin and Gagne ©2013
Polling vs Interrupts I/O
Polling I/O
●A computer must have a way of detecting the arrival of any type of input.
There are two ways that this can happen, known as polling and interrupts.
Both of these techniques allow the processor to deal with events that can
happen at any time and that are not related to the process it is currently
running.
●Polling I/O
●Polling is the simplest way for an I/O device to communicate with the
processor. The process of periodically checking status of the device to see if it
is time for the next I/O operation, is called polling. The I/O device simply puts
the information in a Status register, and the processor must come and get the
information.
●Most of the time, devices will not require attention and when one does it will
have to wait until it is next interrogated by the polling program. This is an
inefficient method and much of the processors time is wasted on unnecessary
polls.
●Compare this method to a teacher continually asking every student in a class,
one after another, if they need help. Obviously the more efficient method
would be for a student to inform the teacher whenever they require
assistance.
Operating System Concepts – 9th Edition 13.14 Silberschatz, Galvin and Gagne ©2013
Polling vs Interrupts I/O
Interrupts I/O
●An alternative scheme for dealing with I/O is the interrupt-driven
method. An interrupt is a signal to the microprocessor from a device
that requires attention.
●A device controller puts an interrupt signal on the bus when it needs
CPU’s attention when CPU receives an interrupt, It saves its current
state and invokes the appropriate interrupt handler using the
interrupt vector (addresses of OS routines to handle various events).
When the interrupting device has been dealt with, the CPU continues
with its original task as if it had never been interrupted.

Operating System Concepts – 9th Edition 13.15 Silberschatz, Galvin and Gagne ©2013
Principles of I/O Software
● I/O Software is used for interaction with I/O devices like mouse, keyboards,
USB devices, printers, etc. Several commands are made via external
available devices which makes the OS function upon each of them one by
one.
● I/O software is organized in the following ways:
● User Level Libraries– Provides a simple interface to program for
input-output functions.
● Kernel Level Modules– Provides device driver to interact with the
device-independent I/O modules and device controller.
● Hardware-A layer including hardware controller and actual hardware
which interact with device drivers.

Operating System Concepts – 9th Edition 13.16 Silberschatz, Galvin and Gagne ©2013
Principles of I/O Software cont…
1. Uniform naming: For example naming of file systems in Operating Systems
is done in a way that the user does not have to be aware of the underlying
hardware name.
2. Synchronous versus Asynchronous: When the CPU is working on some
process it goes into the block state when the interrupt occurs. Therefore most
of the devices are asynchronous. And if the I/O operation is in a blocking state
it is much easier to write the I/O operation. It is always the operating system’s
responsibility to create such an interrupt-driven user program.
3. Device Independence: The most important part of I/O software is device
independence. It is always preferable to write a program that can open all
other I/O devices. For example, it is not necessary to write the input-taking
program again and again for taking input from various files and devices. As
this creates much work to do and also much space to store the different
programs.

Operating System Concepts – 9th Edition 13.17 Silberschatz, Galvin and Gagne ©2013
Principles of I/O Software cont…
4. Buffering: Data that we enter into a system cannot be stored directly in
memory. For example, the data is converted into smaller groups and then
transferred to the outer buffer for examination. Buffer has a major impact on
I/O software as it is the one that ultimately helps store the data and copy data.
Many devices have constraints and just to avoid it some data is always put into
the buffer in advance so the buffer rate of getting filled with data and getting
empty remains balanced.
5. Error handling: Errors and mostly generated by the controller and also they
are mostly handled by the controller itself. When the lower level solves the
problem it does not reach the upper level.
6. Shareable and Non-Shareable Devices: Devices like Hard Disk can be
shared among multiple processes while devices like Printers cannot be shared.
The goal of I/O software is to handle both types of devices.

Operating System Concepts – 9th Edition 13.18 Silberschatz, Galvin and Gagne ©2013
Principles of I/O Software cont…
7. Caching: Caching is the process in which all the most accessible and most
used data is kept in a separate memory (known as Cache memory) for access
by creating a copy of the originally available data. The reason for
implementing this Caching process is just to increase the speed of accessing
the data since accessing the Cached copy of data is more efficient as compared
to accessing the original data.

Operating System Concepts – 9th Edition 13.19 Silberschatz, Galvin and Gagne ©2013
Interrupt Handlers
● Interrupts are generally called signals which are generated by the software
or hardware when a particular event or process requires immediate
attention. So, the signal informs the processor about a high priority and
urgent information demand causing an interruption in the current working
process.
● Thus, whenever an interruption occurs the processor finishes the current
instruction execution and starts the execution of the interrupt known as
interrupt handling. Moreover, for every interrupt handling to occur there is
an Interrupt service routine (ISR) or interrupt handler.
● Interrupt handling in modern operating systems
● In several operating systems such as Linux. mac or windows Interrupt
handling is divided into two parts −
• First-level interrupt handlers (FLIH), also known as hard interrupt handlers or fast
interrupt handlers.
• Second-level interrupt handlers (SLIH), also known as slow interrupt handlers or soft
interrupt handlers.

Operating System Concepts – 9th Edition 13.20 Silberschatz, Galvin and Gagne ©2013
Uses of FLIH and SLIH
● FLIH
• These include platform specific interrupt handling.
• It causes jitter in the execution of the process.
• It also masks interrupts.
• FLIH is known as the upper half in Linux.
● SLIH
• It completes long interrupt processing tasks similar to the process or event.
• Have a dedicated thread for every single handler.
• It has a long-lived execution time
• SLIH is known as the Lower half or bottom half in Linux.

Operating System Concepts – 9th Edition 13.21 Silberschatz, Galvin and Gagne ©2013
Interrupt Handling
● The interrupt handling mechanism of an operating system accepts
a number which is an address and then selects what specific
action to be taken which is already mentioned in the interrupt
service routine. In most architecture, the address is stored in a
table known as a vector table.
● Now let us see the interrupt handling by OS scheme in pictorial
representation.

Operating System Concepts – 9th Edition 13.22 Silberschatz, Galvin and Gagne ©2013
Device Independent I/O Software
Device-independent I/O software, also known as the I/O subsystem or I/O
management, is an integral part of an operating system that provides a layer
of abstraction between hardware devices and user-level applications This
abstraction though performs input and output operations for applications It
can, without having to worry about the specifics of hardware devices.

Operating System Concepts – 9th Edition 13.23 Silberschatz, Galvin and Gagne ©2013
Device Independent I/O Software cont…
1. Abstraction Layer
The main goal of this I/O is to provide a bigger layer of abstraction to protect
applications from the complexities of communicating with hardware devices.
This gives abstraction from hardware application’s data to interface a
consistent. Moreover, it is very easy to use.
2. Device Driver
Non-device I/O software controls device drivers, which are software
components that manage communication between the operating system and
physical hardware devices These drivers interpret generic I/O requests from an
application types into device-specific commands.
3. Standard I/O Operations
It gives a general set of I/O operations that programs can use to read from and
write to devices. They are highly used for various operations such as starting a
device, opening the last tab, reading and writing a particular document, and
controlling the gadget.

Operating System Concepts – 9th Edition 13.24 Silberschatz, Galvin and Gagne ©2013
Device Independent I/O Software cont…
4. Device Independence
Device-impartial I/O software ensures that applications can use identical I/O
operations irrespective of the specific hardware tool they’re interacting with.
This approach that packages do not need to be rewritten or modified when the
underlying hardware changes.
5. Buffering and Caching
Buffering and caching are primarily used for I/O operations to optimize them.
Data may be buffered in memory to lessen the quantity of interactions with
the hardware, enhancing performance.
6. Error Handling
Error handling in tool-unbiased I/O (Input/Output) software programs is critical
thing of making the reliability and robustness of I/O operations across diverse
devices and systems. Device-impartial I/O software program is designed to
abstract the underlying hardware, allowing software program packages to
carry out I/O operations without having to address the specific info of different
devices.

Operating System Concepts – 9th Edition 13.25 Silberschatz, Galvin and Gagne ©2013
Device Independent I/O Software cont…
7. Concurrency Control
Concurrency manage in tool-unbiased I/O (Input/Output) software program is crucial to
control and synchronize access to I/O resources, making sure that multiple techniques or
threads can interact with I/O gadgets in a coordinated and consistent manner.
Concurrency control mechanisms are especially important in environments in which
more than one packages or thread may be acting I/O operations on distinct devices
concurrently.
8. Virtual File System (VFS)
A virtual document is created for some OS to provide a similar virtual environment for
various operations such as record structure diversification, network protocols, and
storage of the device. This lets in packages to paintings with files and data regardless of
their place or layout.
9. Device Management
Device Management conducts the key aspects necessary for the device such as its
configuration, its allocation of resources, the coordination required in between the
gadgets, and its management with the initial process of the device.

Operating System Concepts – 9th Edition 13.26 Silberschatz, Galvin and Gagne ©2013
Device Independent I/O Software cont…
10. Security and Access Control
The I/O subsystem enforces protection regulations and gets right of entry to
control, ensuring that the handiest authorized users or packages can get
admission to positive devices or carry out specific operations.
11. Portability
By presenting a device-impartial interface, the I/O subsystem complements
the portability of packages. Applications evolved on one platform may be
without problems adapted to run on exceptional platforms with minimal code
changes.

Operating System Concepts – 9th Edition 13.27 Silberschatz, Galvin and Gagne ©2013
Device Driver
● It is a software program that is utilized in computers to execute and operate
systems that communicate with a component of a device. It is a code that
is assigned to operating system users to enable the empowering of certain
commands connected with a device.

● It assists in the control and management of computer-connected devices.


It is accomplished by providing the required number of functions for
managing various portions of the device via programs generated by various
types of software. Each new device comes with a built-in device driver.

● These device drivers are essentially low-level programming software. It


enables the computer system to perform functions for communication via
many types of hardware devices. It is accomplished without needing to be
concerned with the specifics of how hardware works. It aids in offering
sufficient knowledge for carrying out these jobs.

Operating System Concepts – 9th Edition 13.28 Silberschatz, Galvin and Gagne ©2013
Device Controller
● It is a hardware program mainly utilized to connect a computer's operating system
and functions in the phase by connecting the device driver. It is an electronic
component that handles the link between incoming and outgoing signals in a
processor by using chips.

● It serves as a link between a device and any program that can receive commands
from the operating system. These functions include buttons like reading, writing, etc.
Every button and controller of various types of controllers differs from one another,
with differences based on how they are utilized.

● The device controller gets data from a connected system device and temporarily
saves such data in a special purpose register inside the controller known as a local
buffer. There is a device driver for every device controller. The memory is linked with
the memory controller. The monitor is linked with the video controller, and the
keyword is linked with the keyboard controller. The disk drive and USB drive are
each attached to their respective disk controllers. These controllers are linked to the
processor through the common bus.

Operating System Concepts – 9th Edition 13.29 Silberschatz, Galvin and Gagne ©2013
Difference between device driver and device controller

1. A device driver is a software method that is mainly utilized in


computers to execute and operate systems that interact with a
component of a device. On the other hand, a device controller is a
hardware method that is mainly utilized to connect a computer's OS
and functions in the phase by connecting the device driver.
2. The two types of device drivers are user and kernel device drivers. In
contrast, the SCSI is a serial portal that is sufficient for the operation of
a device controller.
3. A device driver is a type of software programming that assists in
connecting with various types of operating systems. In contrast, a
device controller is a type of hardware programming that acts as a
bridge between OS in a computer system.
4. A device driver aids in interacting with the OS of various computer
systems. In contrast, a device controller aids in understanding the links
between the running and incoming signals from a computer's OS.
5. A device driver is a wider concept. In contrast, a device controller is a
smaller concept.

Operating System Concepts – 9th Edition 13.30 Silberschatz, Galvin and Gagne ©2013
End of Chapter 13

Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013

You might also like