Operating Systems: IO Systems

Spread the love

The io systems management is an important component of file systems because allows extendibility. Since the I/O devices vary greatly, there are various methods needed to interact with them. In fact the same ports and busses can be linked to different devices.

I/O Hardware

Through the huge variety of I/O devices let us focus on the common concepts:

  • port
  • bus
  • controller

Normally, a device is identified by an address, which is used by:

  • Direct I/O instructions
  • Memory-Mapped I/O

Port

port serves as an interface between the computer and other computers or peripheral devices. Electronically speaking, they can be divided into parallel and serial ports. Functionally speaking, they can be identified as:

  1. DVI (Digital Visual Interface)
  2. Display Port
  3. eSATA
  4. PS/2
  5. Serial
  6. DB/9
  7. SCSI

Bus

The bus can be built either by daisy chain or by shared direct access. The possible busses are:

  1. PCI
  2. PCIe
  3. Expansion bus

Controller

A very useful component because it operates ports, busses and devices, and contains processor, microcode, and private memory. It can be:

  1. integrated
  2. separated (host adapter)

Polling

The steps are:

  1. Read busy bit from status register until 0;
  2. Host sets read bit or write bit, and if write copies data into data-out register;
  3. Host sets command-ready bit;
  4. Controller sets busy bit, executes transfer;
  5. Controller clears busy bit, error-bit, command-ready bit when transfer done.

Step 1 – important to notice – is a busy-wait cycle for I/O from device, which is reasonable if device is fast, and very inefficient if device is slow.

Interrupts

Basing our study on the polling, it can happen in three instruction cycles:

  1. read status;
  2. logical-and to extract status bit;
  3. branch if not 0.

But if not 0, this three-instruction cycle cycles over them; so, how can we improve this? With interrupts.

The I/O device can trigger the CPU with an interrupt-request line (the processor checks this after each instruction) and wait that an interrupt handler receives the interrupt and manage the connection.

Two common scheme:

  • Interrupt-Driven I/O Cycle

i_o for I/O Systems

  • DMA (Direct Memory Access)
    Used to avoid programmed I/O for large data movement, because in that case is transferred one byte at a time. Here, instead, with the support of a DMA controller, we bypass the CPU to transfer data between I/O device and memory.
    The DMA has three modes of operation: burst mode, cycle stealing mode, transparent mode. In the cycle stealing mode the DMA controller steals the bus from the CPU.An improvement for the DMA, is the DVMA, a version which is aware of the virtual addresses.

 

Application I/O Interface

I/O system calls encapsulate the device behaviours into generic classes, creating in this way a layer of device drivers that hide all the I/O controllers. This management avoid new devices from extra work bacause they speak already-implemented protocols.

The I/O devices vary basing on:

  • Character or Block;
  • Sequential or Random Access ;
  • Synchronous or Asynchronous;
  • Sharable or Dedicated
  • Speed of operation;
  • Read-only, Write-only, Read & Write.

Common I/O devices can be grouped into:

  • Block
  • Character
  • Memory-Mapped File Access
  • Network Sockets

Block

They includes the disk driver where read, write and seek operations are allowed. They permit, also, the memory-mapped file access.

Character

The Character devices includes keyboard, mice, serial ports.

Network Devices

The network devices vary from character to block and usually they have their own interface. For example Unix, Linux and Windows OSes include the socket interface.

Systems integrate clocks and timers, basically for synchronization. The modes for I/O can be distinguished among:

  • blocking
  • nonblocking
  • asynchronous

There is also an other I/O mechanism called Vectored I/O where one single system call performs multiple I/O operations. This mechanisms, also known as Scatter-Gather Method, is better than using multiple individual I/O calls: in fact decreases context switching and system call overhead, and even some versions include the atomicity protection to avoid multiple threads from chaning data after read/write operations on a shared resource.

Kernel I/O Subsystem

Three common techniques used by the Kernels are:

  • Caching: when a faster device holds a copy of data;
  • Spooling: when the output of a process is kept because the device can handle one request at a time;
  • Device Reservation: that provides exclusive access to a device.

Error handling

A OS can recover a read or a write from disks or recover a device unavailable. Most OS return an error code when an I/O operation fails, although. For example, these errors are kept in memory in a system error log.

I/O Protection

Since a user process can accidentally or purposefully attempt to disrupt operations with illegal instruction two basic rules have been added:

  • I/O instructions have to be provileged;
  • I/O instructions can be executed only via system calls.

Kernel Data Structures

Normally, a Operative System keep in memory open file tables, network connections, character device state.

Power Management

Operative Systems can help to manage and improve power management.

Examples:
  • Cloud Computing Environment OS can move virtual machine between servers and then evacuate a whole system, before shutting it down.
  • Android implements
    • Component-Level Power Management, to power off component not used;
    • Wake Locks, to prevent the device to sleep when held by lock;
    • Power Collapse, to reduce at minimum energy and awakable by external stimuli like physical buttons, or incoming calls.

Transforming I/O Requests to Hardware Operations

//TODO: Life Cycle of an I/O Request

Streams

The streams are built as a full-duplex communicaiton channel to exchange data between user-level process and a device.

Performance

If we would to improve performance there are a bunch of common rules that we can follow:

  • Reduce the number of context switches;
  • Reduce data copy;
  • Reduce interrupts by using large transfer;
  • Use DMA
  • Move User-mode processes or deamons to kernel threads.

Leave a Reply

Your email address will not be published. Required fields are marked *