Operating System 12: I/O System Functions, Models, Interfaces, and I/O Devices and Device Controllers

Table of contents

1. Function, model and interface of I/O system

(1) Basic functions of the I/O system

1.1 - Hide the details of the physical device

1.2 - Device independence

1.3 - Improve processor and I/O device utilization

1.4 - Controlling I/O Devices

1.5 - Ensure proper sharing of devices

1.6 - Error Handling

(2) Hierarchical structure and model of I/O system

2.1 - Hierarchy of the I/O software

2.2 - Hierarchical view between the various modules in the I/O system

(3) I/O system interface

3.1 - Block Device Interface

3.2 - Stream Device Interface

2.3 - Network communication interface

2. I/O devices and device controllers

(1) I/O equipment

1.1 - I/O Device Types

1.2 - Interface between device and controller

(2) Device controller

2.1 - Basic functions of the device controller

2.2 - Composition of the device controller

(3) Memory image I/O

(4) I/O path


        The main objects managed by the I/O system are I/O devices and corresponding device controllers . Its most important task is to complete the I/O request made by the user, increase the I/O rate, and improve the utilization rate of the device, and provide means for the higher-level process to use these devices conveniently.

1. Function, model and interface of I/O system

(1) Basic functions of the I/O system

1.1 - Hide the details of the physical device

        The I/O device controller is a hardware device used to control various types of I/O devices, including several registers for storing control commands and registers for storing parameters. Through these commands and parameters, users can control external devices to perform required operations.

        For different devices, different commands and parameters are required. For example, when operating a disk, it is not only necessary to give the command whether to read or write this time, but also to give the location of the source or target data, including the disk number, track number and sector number of the disk. It can be seen that it is extremely difficult to require programmers or users to write programs directly facing these devices. Therefore, the I/O system must properly abstract the device to hide the implementation details of the physical device , and only provide a small number of abstract read/write commands, such as read and write, to the upper layer process. // Make the device easy to use

1.2 - Device independence

        The independence from the device is realized on the basis of hiding the details of the physical device.

        On the one hand, the user can not only use the abstract I/O command, but also use the abstract logical device name to use the device . For example, when the user wants to output and print, he only needs to provide a read (or write) command. /O), and provide an abstract logical device name such as /dev/printer without specifying which printer it is.

        On the other hand, it can also effectively improve the portability and adaptability of the OS. For the OS itself, it should be allowed to add new device drivers without recompiling the entire operating system to facilitate Installation of new I/O devices. As in Windows, the system can automatically install and find drivers for new I/O devices, so as to achieve plug and play.

1.3 - Improve processor and I/O device utilization

        The I/O system should allow processors and I/O devices to operate in parallel as much as possible to improve their utilization.

  • On the one hand, the processor is required to quickly respond to the user's I/O request, so that the I/O device can run as soon as possible;
  • On the other hand, the intervention time of the processor during the operation of each IO device should also be minimized.

1.4 - Controlling I/O Devices

        It is the function of the driver to control the I/O device. There are currently four control methods for I/O devices:

  • Programmable I/O with Polling
  • Programmable I/O with interrupts
  • direct memory access mode
  • I/O channel mode.

        The specific control method to be adopted is related to factors such as the transmission rate of the I/O device and the data unit to be transmitted. //For example, whether the transmitted data is a byte or a data block, etc.

1.5 - Ensure proper sharing of devices

        From the shared attributes of the devices, the devices in the system can be divided into the following two categories:

  • Exclusive equipment , the process should access this kind of equipment mutually exclusive , that is, once the system allocates this kind of equipment to a certain process, it will be exclusively used by the process until it is used up and released. Typical exclusive devices are printers, tape drives, etc. When the system allocates exclusive devices, the security of the allocation should also be taken into consideration.
  • A shared device refers to a device that allows multiple processes to access it at the same time for a period of time . A typical shared device is a disk. When multiple processes need to perform read and write operations on the disk, they can be interleaved without affecting the correctness of the read and write operations.

1.6 - Error Handling

        Most equipment includes a large number of mechanical and electrical parts, which are prone to errors and failures during operation. From the perspective of processing, errors can be divided into temporary errors and persistent errors .

        For temporary errors, it can be corrected by retrying the operation, and only when a persistent error occurs, it needs to be reported to the upper layer. For example, if an error occurs during disk transmission, the system does not consider that the disk has failed, but can retransmit it again. After retransmitting several times, if there are still errors, the system considers that the disk has failed.

        Since most errors are closely related to the device, the error handling should be done as close to the hardware level as possible , that is, the errors that can be solved by the low-level software will not be reported to the upper layer, so the high-level cannot perceive it; only the low-level The errors that the software cannot solve are reported to the upper layer, and the upper layer software is requested to solve it. //The idea and guiding ideology of error resolution are also applicable to software, and errors should be resolved at the bottom as much as possible

Summarize:

  • The functions of aspects 1 and 2 are for the convenience of users to use I/O devices
  • The functions of the 3rd and 4th aspects are used to improve the utilization of CPU and I/O devices
  • The functions of the fifth and sixth aspects are to provide convenience for users when sharing equipment, so as to ensure that the system can run in an orderly manner, and when an error occurs in the system, the error can be found in time, and even the error can be automatically corrected .

(2) Hierarchical structure and model of I/O system

        The I/O software involves a wide range of aspects. It is closely related to the hardware downwards and directly interacts with the file system, virtual memory system and users upwards. They all require the I/O system to implement I/O operations. In order to make the very complex I/O software have a clear structure, better portability and adaptability, the hierarchical structure of the I/O system has been generally adopted . This is to divide the device management module in the system into several levels. Each level uses the services provided by its lower level to complete some sub-functions in the input and output functions, and shields the details of the implementation of these functions to provide services to the upper level. . //The guiding ideology of the computer network is also a hierarchical structure. In terms of object-oriented, this approach is called encapsulation

2.1 - Hierarchy of the I/O software

        I/O software is usually organized into four levels, as shown in the figure below, each level and its function are as follows, the arrows in the figure indicate the control flow of I/O: //Layering is a guiding ideology for solving complex problems : From complex to simple, from easy to difficult

  • User layer I/O software implements the interface for interacting with users. Users can directly call library functions related to I/O operations provided by this layer to operate the device.
  • Device independence software is used to realize the unified interface between user programs and device drivers, device naming, device protection, device allocation and release, etc., and provide necessary storage space for device management and data transmission.
  • The device driver is directly related to the hardware and is used to implement the operation instructions issued by the system to the device and drive the I/O device to work.
  • The interrupt handler is used to save the CPU environment of the interrupted process, transfer to the corresponding interrupt handler for processing, and return to the interrupted process after the processing is completed and then resumes the scene of the interrupted process. //The computer composition has a detailed introduction

2.2 - Hierarchical view between the various modules in the I/O system

        《1》The upper and lower interfaces of the I/O system

        I/O system interface : it is the interface between the I/O system and the upper system, and provides abstract I/O commands for operating the device to the upper layer to facilitate the use of the device by the upper layer. Many OSs provide library functions related to I/O operations in the user layer for users to use. There are file systems, virtual memory systems, and user processes in the upper system. //Entrance to operate the device

        Software/hardware (RW/HW) interface : The interface between software and hardware, which is quite complex due to the wide variety of devices.

        The figure below clearly shows the hierarchical structure between various modules in the I/O system: //Not complicated, just look at it

        《2》Layering of I/O system

        Corresponding to the hierarchical structure of the I/O software organization, the I/O system itself can also be divided into the following three levels:

  • Interrupt handler . It is at the bottom of the I/O system and interacts directly with the hardware.
  • device driver . It is the communication program between the process and the device controller . Its main function is to convert the abstract I/O request sent by the upper layer into specific commands and parameters for the I/O device, and load it into the command and parameter registers in the device controller, or vice versa. Due to the great differences between devices, the drivers for each type of device are different, so they must be provided by the device manufacturer rather than designed by the OS designer . Therefore, whenever a new device is added to the system, a new driver needs to be provided by the installation vendor. // The driver is provided by the device manufacturer
  • Device independent software . The I/O system in the modern OS basically implements device independence, also known as device-independent software. The basic meaning is: I/O software is independent of the specific physical device used . The biggest benefit is that it improves the adaptability and scalability of the I/O system. They can be applied to many types of equipment, and each time a new equipment is added or an old equipment is replaced, there is no need to modify the I/O software, which facilitates the update and expansion of the system. The content of device independence software includes software such as device naming, device allocation, data buffering and data high-speed buffering.

(3) I/O system interface

3.1 - Block Device Interface

        The block device interface is the interface between the block device manager and the upper layer. This interface reflects the essential characteristics of most magnetic disk storage and optical disk storage, and is used to control the input or output of such devices.

        The so-called block device refers to a device whose data access and transmission are based on data blocks . A typical block device is a disk .

        The basic characteristic of this device is a high transfer rate , usually a few megabytes to tens of megabytes per second. Another feature is addressability , that is, the input source address and output target address of the data can be specified, and any block in the disk can be read/written randomly; the I/O of the disk device often adopts the DMA method .

3.2 - Stream Device Interface

        The stream device interface is the interface between the stream device manager and the upper layer. This interface is also called character device interface, which reflects the essential characteristics of most character devices and is used to control the input or output of character devices.

        The so-called character device refers to the device whose data is accessed and transmitted in units of characters , such as keyboards and printers .

        The basic characteristic of a character device is a low transfer rate , usually a few bytes to several kilobytes per second. Another feature is that it is not addressable , that is, the input source address and output target address of the data cannot be specified. Character devices are often interrupt-driven when input/output .

        Since the character device is not addressable, it can only be accessed sequentially . Usually, a character buffer (queue) is established for a character device , and the I/O character stream of the device enters the character buffer (reading) sequentially, or is sent from the character buffer to the device sequentially (output). // Batch I/O read and write, improve I/O efficiency

        Since most stream devices are exclusive devices, they must be shared in a mutually exclusive manner . For this purpose, the stream device interface provides open and close operations. When using this type of device, the device must first be opened with the open operation. If the device is already open, it is being used by another process.

2.3 - Network communication interface

        In modern OS, network-oriented functions are provided. But first you need to connect your computer to the network somehow. At the same time, the operating system must also provide corresponding network software and network communication interface , so that the computer can communicate with other computers on the network or browse the Internet through the network. //This part is described in detail in the network operating system

2. I/O devices and device controllers

        An I/O device generally consists of a mechanical part that performs I/O operations and an electronic part that performs control I/O . These two parts are usually separated, the mechanical part that performs I/O operations is a general I/O device , and the electronic part that performs control I/O is called a device controller or adapter.

        The controllers in microcomputers and minicomputers are often made in the form of printed circuit cards , so they are often called control cards, interface cards or network cards, which can be inserted into the expansion slot of the computer. In some large and medium-sized computer systems, I/O channels or I/O processors are also configured.

(1) I/O equipment

1.1 - I/O Device Types

        There are many types of I/O devices. In addition to being able to divide them into block devices and character devices, exclusive devices and shared devices, they can also be divided into storage devices and I/O devices in terms of device usage characteristics; the transfer rate of slave devices On the basis, it is divided into low-speed equipment, medium-speed equipment and high-speed equipment. // various conceptual things

1.2 - Interface between device and controller

        Usually, the device does not directly communicate with the CPU, but communicates with the device controller . Therefore, the I/O device should contain an interface with the device controller. There are three types of signals in this interface, each corresponding to a signal line.

  • Data signal line . This type of signal line is used to carry data signals between the device and the device controller. For input devices, after the signal input from the outside is converted by the converter, the formed data is usually sent to the buffer first, and when the amount of data reaches a certain number of bits (characters), then a set of data is passed from the buffer. The signal line is sent to the device controller. For the output device, a batch of data transmitted from the device controller through the data signal line is temporarily stored in the buffer, and after being properly converted by the converter, it is output character by character. //Used to transfer I/O data
  • control signal line . This is the path through which the device controller sends control signals to the I/O device. This signal specifies the operation to be performed by the device, such as a read operation (referring to the transfer of data from the device to the controller) or a write operation (receiving data from the controller), or performing operations such as head movement. //Used to specify the type of operation, read or write
  • Status signal line . This signal line is used to carry signals indicating the current state of the device. The current state of the device is reading (or writing); the device has completed reading (writing) and is ready for new data transmission. //Send device status

(2) Device controller

        The main function of the device controller is to control one or more I/O devices to realize data exchange between the I/O devices and the computer. It is the interface between the CPU and the I/O device. It receives commands from the CPU to control the work of the I/O device, freeing the processor from complicated device control tasks. A device controller is an addressable device. When it only controls one device, it has only one unique device address; if the controller can connect to multiple devices, it should contain multiple device addresses, and each device address corresponds to a device. . Device controllers can be divided into two categories: one is a controller used to control character devices, and the other is a controller used to control block devices.

2.1 - Basic functions of the device controller

  • Receive and recognize commands . The device controller can receive and recognize various commands sent by the processor. There are corresponding control registers in the controller, which are used to store received commands and parameters, and decode the received commands. //Set command decoder
  • data exchange . The device controller enables data exchange between the CPU and the controller, and between the controller and the device. //set data register
  • Identify and report the status of devices . The controller should record the state of the device for the CPU to know. //Set the status register
  • address identification . A device controller must be able to identify the address of each device it controls. // configure address decoder
  • data buffer . Due to the low rate of I/O devices and the high rate of CPU and memory, a buffer must be set in the controller. //set buffer
  • error control . For the data transmitted by the I/O device, the device controller is also in charge of error detection. If an error occurs during the transmission, the error detection code is usually set and reported to the CPU, so the CPU discards the data transmitted this time and performs a new transmission. This ensures correct data entry.

2.2 - Composition of the device controller

  • Interface of the device controller to the processor . This interface is used to realize the communication between the CPU and the device controller. There are three types of signal lines in this interface: data lines, address lines and control lines.
  • Interface of the device controller to the device .
  • I/O logic . Logic is used to implement the control of the device. It interacts with the processor through a set of control lines, and the processor uses this logic to send I/O commands to the controller.

(3) Memory image I/O

        The driver loads a series of specific commands, parameters and other data converted from the abstract I/O command into the corresponding registers of the device controller, and the controller executes these commands to implement the control of the I/O device . This can be done in two ways:

  • Using specific I/O instructions , the main disadvantage of this approach is that accessing memory and accessing devices require two different instructions.
  • Memory-mapped I/O , in this method, no longer distinguishes between memory unit addresses and register addresses in the device controller in addressing. The memory image I/O mode unifies the access methods to the memory and the controller, which is beneficial to simplify the programming of the I/O.

(4) I/O path

        Although the device controller is added between the CPU and the I/O device, the CPU's intervention on the I/O can be greatly reduced, but when the host computer is configured with many peripherals, the burden on the CPU is still heavy. For this reason, an I/O channel (I/O Channel) is added between the CPU and the device controller.

        Its main purpose is to establish independent I/O operations, not only to make data transmission independent of the CPU, but also to make the organization, management and end processing of I/O operations as independent as possible to ensure that the CPU has more resources. In other words, the purpose is to transfer some I/O tasks originally handled by the CPU to the channel, thereby freeing the CPU from the complicated I/O tasks. //Reason for using I/O channels

        After setting up a channel, the CPU only needs to send an I/O instruction to the channel. After the channel receives the command, it takes out the channel program to be executed from the memory and executes the channel program. Only when the channel completes the specified I/O task, it sends an interrupt signal to the CPU. // How the I/O channel works

        In fact, an I/O channel is a special kind of processor . It has the ability to execute I/O commands and control I/O operations by executing channel (I/O) programs. However, I/O channels are different from general processors, mainly in the following two aspects:

  • One is that its instruction type is single . This is because the channel hardware is relatively simple, and the commands it can execute are mainly limited to instructions related to I/O operations.
  • The second is that the channel does not have its own memory , and the channel program executed by the channel is placed in the memory of the host, in other words, the channel and the CPU share the memory.

Guess you like

Origin blog.csdn.net/swadian2008/article/details/131595455