Basic Concepts of I/O Systems

The I/O system is the part of an operating system responsible for managing external devices and for the exchange of data with them. This lesson introduces what an I/O system is, which functions it performs, why it matters so much, and how it is assembled from layers.

The Definition of the I/O System

The I/O system (Input/Output System) is the part of the operating system that manages the various input and output devices and carries out the exchange of data between the host and those external devices. It is the bridge through which the operating system meets the outside world, ensuring that the machine can receive input and produce the results of processing.

Why the I/O System Matters

1. The Bridge for Data Exchange

  • Moves data back and forth between the computer and its external devices
  • Supports interaction between the user and the computer
  • Ensures that data enters and leaves the system correctly

2. The Key to System Performance

  • I/O operations are frequently the bottleneck in overall system performance
  • Efficient I/O management can noticeably raise the performance of the whole system
  • It directly affects user experience and how quickly the system responds

3. The Core of Device Management

  • Manages widely different kinds of device under a single scheme
  • Offers a standardized interface for accessing devices
  • Simplifies device handling for the applications on top

The Basic Functions of the I/O System

1. Device Management

The operating system needs to know, for every device it drives, what kind of device it is, what state it is in, and which operations may be issued to it. A device table entry of this shape is the usual way to hold that information.

// The basic structure of device management
typedef struct {
    int device_id;           // device identifier
    char device_name[64];    // device name
    int device_type;         // device type
    int status;              // device status
    void (*init)(void);      // initialization function
    void (*read)(void);      // read operation
    void (*write)(void);     // write operation
} device_t;

2. Data Transfer

  • Data input: read data from an external device into memory
  • Data output: write data held in memory out to an external device
  • Format conversion: cope with the differences in data format between devices

3. Error Handling

Almost any I/O operation can fail, and the failures are worth naming in advance so that they can be reported clearly instead of collapsing into a single generic error. An enumeration of error codes plus a handler that turns a code into a message is the simplest workable pattern.

// An example of I/O error handling
typedef enum {
    IO_SUCCESS = 0,
    IO_ERROR_DEVICE_NOT_FOUND,
    IO_ERROR_DEVICE_BUSY,
    IO_ERROR_TIMEOUT,
    IO_ERROR_INVALID_PARAMETER
} io_error_t;

io_error_t handle_io_error(io_error_t error) {
    switch(error) {
        case IO_ERROR_DEVICE_NOT_FOUND:
            printf("Device not found\n");
            break;
        case IO_ERROR_DEVICE_BUSY:
            printf("Device busy, please retry later\n");
            break;
        case IO_ERROR_TIMEOUT:
            printf("Operation timed out\n");
            break;
        default:
            printf("Unknown I/O error\n");
    }
    return error;
}

The Layered Structure of the I/O System

An I/O system is built as a stack of layers, each one hiding the details of the layer below it. The value of the layering is that a program written against the top layer keeps working when the hardware underneath it changes.

1. The User-Level Interface

  • Provides standardized I/O function calls
  • Shields the caller from differences between the underlying devices
  • Simplifies the development of applications

2. The Device-Independent Layer

  • Implements device abstraction
  • Provides a uniform interface for accessing devices
  • Handles the operations that are the same for every device

3. The Device Driver Layer

  • Implements communication with the specific piece of hardware
  • Handles the operations that are peculiar to that device
  • Manages the state and configuration of the device

4. The Hardware Control Layer

  • Controls the physical device directly
  • Handles hardware signals and timing
  • Carries out the transfer of data at the lowest level

The Evolution of I/O Systems

The way the CPU has taken part in I/O has changed several times, and each change moved work away from the CPU and toward the hardware.

1. The Early Stage

  • I/O was controlled by the program itself
  • The CPU controlled the device directly
  • Efficiency was low, and the CPU was occupied for most of the time

2. The Interrupt-Driven Stage

  • Introduced the interrupt mechanism
  • Raised CPU utilization
  • Allowed several devices to operate concurrently

3. The DMA Stage

  • Introduced direct memory access
  • Reduced the amount of work the CPU had to do
  • Improved the efficiency of large data transfers

4. Modern I/O Systems

  • A sophisticated I/O subsystem
  • Support for plug-and-play devices
  • Rich device management facilities

The Design Goals of an I/O System

1. Efficiency

  • Minimize the time the CPU spends on I/O
  • Raise the efficiency of data transfer
  • Support concurrent I/O operations

2. Reliability

  • Ensure that data is transferred correctly
  • Provide a complete error-handling mechanism
  • Support recovery from device failures

3. Generality

  • Support many different types of device
  • Provide a uniform access interface
  • Make it easy to add and upgrade devices

4. Ease of Use

  • Simplify the I/O that applications have to perform
  • Provide a friendly user interface
  • Support plug-and-play operation

Glossary

TermAbbreviationExplanation
Input/OutputIOThe exchange of data between a computer and its external devices
IO System-The subsystem that manages I/O devices
IO Device-An input or output device
Input Device-A device that feeds data into the computer
Output Device-A device that carries data out of the computer
Peripheral Device-A device outside the main unit of the computer
IO Interface-The connecting circuitry between the host and a peripheral
Port-An addressable register inside an interface
Data Port-The port through which data is transferred
Status Port-The port from which the device status is read
Control Port-The port to which control commands are sent
IO Control Method-The way the CPU exchanges data with a device
Programmed IOPIOThe CPU polls the device for its status
Interrupt Driven IO-The device interrupts the CPU once it is ready
Direct Memory AccessDMAThe device accesses memory on its own
Channel IO-A dedicated I/O processor controls the I/O
IO Hierarchy-The layered structure of an I/O system
Interrupt Handling-Handling an interrupt raised by a device
Device Driver-The program that controls a hardware device
Device Independence-Applications do not depend on any particular device
Error Handling-Handling errors raised during I/O
IO Scheduling-Optimizing the order in which I/O requests are served
Simultaneous Peripheral Operations On-LineSPOOLingA technique that turns a shared device into a virtual one

Found an issue with this content?

Tell us what could be improved.