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.
Through the huge variety of I/O devices let us focus on the common concepts:
Normally, a device is identified by an address, which is used by:
- Direct I/O instructions
- Memory-Mapped I/O
A 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:
- DVI (Digital Visual Interface)
- Display Port
The bus can be built either by daisy chain or by shared direct access. The possible busses are:
- Expansion bus
A very useful component because it operates ports, busses and devices, and contains processor, microcode, and private memory. It can be:
- separated (host adapter)
The steps are:
- Read busy bit from status register until 0;
- Host sets read bit or write bit, and if write copies data into data-out register;
- Host sets command-ready bit;
- Controller sets busy bit, executes transfer;
- 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.
Basing our study on the polling, it can happen in three instruction cycles:
- read status;
- logical-and to extract status bit;
- 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
- 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:
- Memory-Mapped File Access
- Network Sockets
They includes the disk driver where read, write and seek operations are allowed. They permit, also, the memory-mapped file access.
The Character devices includes keyboard, mice, serial ports.
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:
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.
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.
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.
Operative Systems can help to manage and improve power management.
- 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
The streams are built as a full-duplex communicaiton channel to exchange data between user-level process and a device.
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.