You are on page 1of 5

CHAPTER 5 : INPUT/OUTPUT MANAGEMENT

Introduction

So far, we have studied how resources like processor and main memory are managed. We
shall now examine the I/O management. Humans interact with machines by providing
information through I/O devices. Also, much of whatever a computer system provides as on-line
services is essentially made available through specialized devices such as screen displays,
printers, keyboards, mouse, etc. Clearly, management of all these devices can affect the
performance of a system. For this reason, input output management also becomes one of the
primary responsibilities of an operating system. In this chapter we shall examine the role of
operating systems in managing IO devices.

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

I- Input/output Hardware
a- I/O devices
There exists a wide variety classified as follows:
➢ Communication devices
Input only (keyboard, mouse, joystick)
Output only (printer, display)
Input/output (network card)
➢ Storage devices
Input/output (disk, tape)
Input only (CD-ROM)
b- Characteristics of I/O Devices

c- Controlling an I/O Device

It is a function of host CPU architecture. It can be through special I/O instructions or through
memory-mapped I/O registers.
➢ Special I/O instructions are used in kernel mode only and when there is a separated
I/O address space.
➢ With Memory-mapped I/O control registers,
• Each register has a physical memory address
• Writing to data register is output
• Reading from data register is input
• Writing to control register causes action
• Can be mapped to user-level virtual memory

d- Some examples of I/O device controller registers


➢ For a character Device
• Data register: It is the register or address where data is read from or written to. It
is of very limited capacity (at most a few bytes)
• Action register: writing to this register causes a physical action; Reading from it
yields zero
• Status register: Reading from it provides information, and writing to it is no-op
➢ For a block Transfer Device
• Buffer address register: It Points to area in physical memory to read or write
data or Addressable buffer for data(E.g., network cards)
• Action register
• Status register

e- Some device I/O Port Locations on PCs

f- Three common ways I/O can be performed

➢ Programmed I/O (Polling)

Polling is used when device and controller are relatively quick to process an I/O operation.
The following operations are performed by the device driver:
▪ Gains access to device
▪ Initiates I/O operation
▪ Loops testing for completion of I/O operation
▪ If there are more I/O operations, repeat
➢ Interrupt-Driven I/O (Programmed I/O with interrupt)

Here, CPU is responsible for Moving characters to/from controller buffer, but Interrupt signal
informs CPU when I/O operation completes. The Interrupt vector is used to dispatch interrupt to
the correct handler.
Interrupt-Driven I/O Cycle

➢ Direct Memory Access


DMA is used to avoid programmed I/O for large data movement. It requires DMA
controller that bypasses CPU to transfer data directly between I/O device and memory. CPU only
initiates operation. DMA controller transfers data directly to/from main memory and send an
interrupt when transfer is completed.
Operation of a DMA transfer
II- I/O software

a- Principles of I/O Software

➢ Efficiency: Do not allow I/O operations to become system bottleneck ( Especially for
slow devices)
➢ Device independence: isolate OS and application programs from device specific
details and peculiarities
➢ Uniform naming: support a way of naming devices that is scalable and consistent
➢ Error handling: isolate the impact of device errors, retry where possible, provide
uniform error codes (Errors are abundant in I/O)
➢ Buffering: provide uniform methods for storing and copying data between physical
memory and the devices
➢ Uniform data transfer modes: synchronous and asynchronous, read, write, ..
➢ Controlled device access: sharing and transfer modes
➢ Uniform driver support: specify interfaces and protocols that drivers must adhere to

b- I/O Software “Stack”

c- I/O Subsystem

It is the largest, most complex subsystem in OS:


• Most lines of code
• Highest rate of code changes
• Where OS engineers most likely to work
• Difficult to test thoroughly
The main tasks of I/O system are:
– Present logical (abstract) view of devices
• Hide details of hardware interface
• Hide error handling
– Facilitate efficient use (Overlap CPU and I/O)
– Support sharing of devices
• Provide a protection mechanism when device is shared (disk for example)
• Provide a scheduling when exclusive access is needed (printer for example)

d- A Kernel I/O Structure

I/O system calls encapsulate device behaviors in generic classes; Device-driver layer hides
differences among I/O controllers from kernel. I/O subsystem signals process when I/O
completed. Device Drivers accept command from application (get/put character, read/write
block, send/receive packet) and Interact with (hardware) device controller to carry out command.

e- Blocking and No blocking I/O

➢ Blocking: process suspended until I/O completed. It is easy to use and understand ,
and insufficient for some needs
➢ No blocking: I/O call returns as much as available. It is implemented via multi-
threading. It returns quickly with count of bytes read or written

III- Other issues


a- I/O Protection

A User process may accidentally or purposefully attempt to disrupt normal operation via illegal
I/O instructions. Consequently, All I/O instructions are defined to be privileged and I/O must be
performed via system calls. Memory-mapped and I/O port memory locations must be protected
too.

b- Kernel Data Structures

Kernel keeps state information for I/O components, including open file tables, network
connections, character device state…

Many complex data structures to track buffers, memory allocation, “dirty” blocks.

Some use object-oriented methods and message passing to implement I/O.

You might also like