Device Management

11 Jun 2019

Von Neumann Computer Architecture

In 1945, Von Neumann described a “stored-program” digital computer in which memory stored both instructions and data. This simplified loading new programs and executing them without having to rewire the entire computer each time a new program needed to be loaded. Continuing forward, the next step was to have support for more devices (card readers, printers, display, disk storage, etc) thus, the system bus evolved to handle multiple I/O devices.

Device Manager

A device manager controls the operation of I/O devices. It needs to be able to issue I/O commands to the devices, catch interrupts, handle errors, and proved a simple and easy to use interface (POSIX).

Device System Call Interface

  • Every I/O device driver should support the following:
    • open, close, read, write, set (ioctl in UNIX), stop, etc. (POSIX)
  • Block vs. character
    • Need to specify how we talk to the device.
  • Sequential vs. direct/random access
    • Disk vs. an old tape.
  • Blocking I/O vs. Non-Blocking I/O
    • Blocking system call: process put on wait queue until I/O completes.
    • Non-blocking system call: returns immediately with partial number of bytes transferred, e.g. keyboard, mouse, network.
  • Synchronous vs. asynchronous
    • asynchronous returns immediately, but at some later time. The full number of bytes requested is transferred.

ioctl and fcntl (input/output control)

We want a richer interface for managing I/O devices than just open, close, read, write. ioctl allows a user-space application to configure parameters and/or actions of an I/O device e.g. set the speed of a device or eject a disk. It also avoids having to create new system calls for each new device and/or unforeseen device functionalities; therfore, it helps make the OS/kernel extensible.

Usage: int ioctl(int fd, int cmd, ..);

  • This invokes a system call to execute a device-specific cmd on I/O device fd.
  • Used for I/O operations and other operations that can’t be expressed by regular system calls.
  • Requests are directed to the correct device driver.

UNIX, Linux, and MacOS all support ioctl, and Windows has its own version.

In UNIX, each device is modeled as a file.

  • fcntl is for file control. It is related to ioctl and is used for configuring file parameters, hence in many cases: I/O communication. For example, you can use fcntl to set a network socket to non-blocking. It is also part of the POSIX API, so it’s portable across the platform.

Device Characteristics

I/O devices consist of two high-level components:

  • Mechanical components
  • Electrical components
    • The device is operated by device controllers. The OS deals with device controllers through the device driver.

Device Drivers

Device drivers support the device system call interface functions (open, read, write, etc.) for that device. They interact directly with the device controllers. Device drivers know the details of what commands the device can hadle, how to set/get bits in device controller registers, etc. Furthermore, they are part of the device-dependent component of the device manager.

Control Flow: An I/O system call traps to the kernel, invoking the trap handler for I/O (the device manager), which indexes into a table using the arguments provided to run the correct device driver.

Top