In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you about how to understand the principle of Icano. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
Principle of 1.IO software
Icano software goal
Device independence
Now let's turn to the research of Imax O software. A very important goal of Imax O software design is device independence (device independence). What do you mean? This means that we can write applications that access any device without having to specify a specific device in advance. For example, if you write an application that can read files from a device, the application can be read from a hard disk, DVD, or USB, without having to customize the application for each device. This actually embodies the concept of device independence.
For example, you can enter the following command
Sort input / output
Then the above input can be received from any type of disk or keyboard, and the output can be written to any type of disk or screen.
The computer operating system is the medium of these hardware. because the instruction sequences of different hardware are different, the operating system is needed to convert instructions.
One indicator closely related to device independence is uniform naming (uniform naming). The code of the device should be an integer or a string, and they should not depend on the specific device. In UNIX, all disks can be integrated into the file system, so users do not need to remember the specific name of each device, they can remember the corresponding path directly. If the path can not be remembered, they can also find the specific integration location through instructions such as ls. For example, if a USB disk is mounted to / usr/cxuan/backup, then copying a file to / usr/cxuan/backup/device is equivalent to copying a file to disk. In this way, writing a file to any disk is equivalent to outputting a file to a specified path.
Error handling
In addition to device independence, the second important goal achieved by Iamp O software is error handling (error handling). In general, errors should be left to the hardware level. If the device controller finds a read error, it will fix the error as much as possible. If the device controller cannot handle this problem, then the device driver should handle it, and the device driver will try to read the operation again, and many errors are accidental. If the device driver cannot handle this error, it will throw the error up to the hardware level (upper layer) to deal with it. In many cases, the upper layer does not need to know how the lower layer solves the error. It's much like the project manager doesn't have to tell the boss every decision; the programmer doesn't have to tell the project manager how to write each line of code. This treatment is not transparent enough.
Synchronous and asynchronous transmission
The third goal of iPUBO software is synchronous (synchronous) and asynchronous (asynchronous) transmission. Let's talk about synchronization and asynchronism first.
In synchronous transmission, data is usually sent in the form of blocks or frames. The sender and receiver should have synchronous clocks before data transmission. In asynchronous transmission, data is usually sent in bytes or characters, and asynchronous transmission does not require a synchronous clock, but parity bits are added to the data before transmission. Here are the main differences between synchronous and asynchronous
Let's get back to business. Most physical IO (physical Ithumb O) is asynchronous. CPU in physical CPU O is very smart. After the transfer of CPU is completed, it will switch to do something else. It is telepathically connected with the interrupt, and it will not return to the transmission until the interrupt occurs.
There are two kinds of Logical O: physical I-O and logical I-O (physical I-O).
Physical Icano usually actually gets data from a storage device such as a disk. Logic Icano is to get data from memory (block, buffer).
Buffer
The last problem with iPot O software is buffering. Typically, data sent from one device does not go directly to the last device. In the meantime, it can only be reached through a series of checking, checking, buffering and other operations. For example, sending a packet from the network first arrives at the buffer after a series of checks, eliminating the buffer filling rate and buffer overload.
Sharing and monopolization
The last problem caused by Icano software is the problem of shared and exclusive devices. Some Icano devices can be used by many users. For some devices, such as disks, it is generally not a problem for multiple users to use them, but some devices must be exclusive, that is, only a single user is allowed to use them before other users can use them.
Next, let's explore how to use the program to control the Imax O device. There are three ways to control the Istroke O device.
Use the program to control Imax O
Use interrupt-driven Ihamo
Use DMA to drive iCandle O
Use the program to control Imax O
The use of program control iCandle O, also known as programmable iCandle O, refers to the data transfer initiated by CPU under the control of the driver software to access registers or other memory on the device. The CPU issues a command and waits for the completion of the IAccord O operation. The problem with programmable CPU O is that CPU has to wait a long time for processing results, because it is much faster than the Istroke O module. CPU will use polling (polling) or busy wait (busy waiting) while waiting, as a result, the performance of the whole system is seriously degraded. Programmable Ihop O is very simple, and if the waiting time is very short, it is a good way to do it. A programmable Ibank O will go through the following operations
CPU requests an Icano operation
Icano module executes the response
Icano module sets the status bit
CPU checks the status bits periodically.
ICompo does not directly notify CPU that the operation is complete.
IPUBO will not interrupt CPU.
CPU may wait or return in a subsequent process
Use interrupt-driven Ihamo
In view of the shortcomings of the programmable iMab O above, we propose an improved scheme in which we want CPU to be able to do other things while waiting for the Imax O device to complete, and then it will generate an interrupt that stops the current process and saves the current state. A possible schematic diagram is as follows
Although the interruption reduces the burden of waiting time for CPU and Imax O devices, it is still very inefficient in a large number of data transfers because a large number of verbatim transmissions are needed before CPU and Imax O modules. Here are the basic operations of the interrupt
CPU performs read operation
The CPU device fetches data from the peripheral device and performs other operations at the same time
Notify CPU of device interruption
CPU request data
Icano module transmits data
So what we need to solve now is the efficiency of data transmission between CPU and Imax O modules.
Use DMA's iCando
The Chinese name of DMA is direct memory access, which means that CPU grants the I CPU O module permission to read or write to memory without involving CPU. That is, DMA does not need the participation of CPU. This process is managed by a chip called the DMA controller (DMAC). Because DMA devices can transfer data directly between memory, rather than using CPU as an intermediary, congestion on the bus can be alleviated. DMA improves system concurrency by allowing CPU to perform tasks while DMA systems transfer data through the system and memory bus.
2.I/O hierarchical structure
Icano software is usually organized into four levels, and their general structure is shown in the following figure.
Each layer and its upper and lower layers have clear functions and interfaces. Let's take a look at these programs from the bottom up, which is the opposite of the computer network.
Here is another diagram that shows all the layers of the input / output software system and its main functions.
Let's discuss the hierarchical structure above in detail.
Interrupt handler
In a computer system, interruptions occur all the time, just like a woman's temper, and interruptions are often very unpleasant. The interrupt handler, also known as the interrupt service program or ISR (Interrupt Service Routines), is the layer closest to the hardware. Interrupt handlers are interrupts caused by hardware interrupts, software interrupts, or software abnormal starts, and are used to convert between device drivers or protected modes of operation, such as system calls.
The interrupt handler is responsible for handling all operations when the interrupt occurs, blocks when the operation is completed, and then starts the interrupt driver to resolve the blocking. There are usually three ways of notification, depending on the specific implementation.
Semaphore implementation: using up for notification on semaphore
Pipe implementation: perform signal operations on the condition variables in the pipe process
There are also cases where some messages are sent.
Either way, the purpose is to get the blocked interrupt handler back to work.
There are many ways to handle interrupts, such as "ARM System Developer's Guide"
Some of the options listed by Designing and Optimizing System Software
Non-nested interrupt handlers process interrupts sequentially, and non-nested interrupt handlers are the simplest interrupt handlers.
Nested interrupt handlers handle multiple interrupts without having to assign priority
Reentrant interrupt handlers can use priority to handle multiple interrupts
Simple priority interrupt handlers can handle simple interrupts
Standard priority interrupt handlers can handle higher priority interrupts in less time than low-priority interrupt handlers.
High-priority interrupt handlers can handle higher-priority tasks in a short period of time and enter specific service routines directly.
Priority packet interrupt handlers can handle interrupt tasks with different priorities
Here are some steps for general interrupt handlers, with different implementation details for different operating systems
Save all registers that are not saved by interrupt hardware
Setting up the context for interrupt service programs may include setting up TLB, MMU, and page tables. If you are not familiar with these three concepts, please refer to another article
Set up the stack for the interrupt service program
Respond to the interrupt controller and continue to respond to the interrupt if there is no centralized interrupt controller
Copy the register from where it is saved to the process table
Run the interrupt service program, which extracts information from the register of the device controller that issued the interrupt
The operating system selects an appropriate process to run. If the interruption causes some higher priority processes to become ready, choose to run those high priority processes
Setting the MMU context for the process may also require TLB, depending on the actual situation
Registers for the load process, including PSW registers
Start running a new process
We have listed some general interrupt steps above, and the interrupt steps and details that can be handled by different operating systems and interrupt handlers are also different. here is a concrete running step of a nested interrupt.
Device driver
In the above article, we know what the device controller does. We know that there are registers inside each controller to communicate with the device, send instructions, read the status of the device, and so on.
Therefore, every Iamp O device connected to a computer needs some device-specific code to control it, for example, the mouse controller needs to receive instructions from the mouse to tell where to move next, the keyboard controller needs to know which key is pressed, and so on. The code that provides the process of converting an I-O device to a device controller is called a device driver (Device driver).
In order to be able to access the hardware of the device, it actually means that the device driver is usually part of the operating system kernel, at least in the current architecture. But it is also possible to construct a device driver in user space and complete the read and write operation through system calls. This avoids a problem where problematic drivers interfere with the kernel and cause crashes. Therefore, the implementation of device drivers in user controls is a very useful measure to construct system stability. That's what MINIX 3 does. The following is the procedure for calling MINI 3
However, most desktop operating systems require drivers to run in the kernel.
The operating system usually classifies drivers as character devices and block devices, as we have described above.
In UNIX, the operating system is a binary program that contains all the drivers that need to be compiled into it. If you want to add a new device to UNIX, you need to recompile the kernel and install the new driver into the binary program.
However, with the emergence of most personal computers, the above static compilation method is no longer effective due to the wide use of I _ hand O devices, so starting from MS-DOS, the operating system turns to drivers that are dynamically loaded into the system during execution.
The device driver has many functions, such as accepting read and write requests, initializing the device, managing power and logs, checking the validity of input parameters, and so on.
After receiving the read and write request, the device driver checks whether the current device is in use, and if the device is in use, the request is queued for subsequent processing. If the device is idle at this time, the driver checks the hardware to see if the request can be processed. The device or motor is activated before the transmission begins. Wait for the equipment to be ready to complete, then carry on the actual control. To control the device is to give instructions to the device.
After issuing the command, the device controller begins to write them to the controller's device register. After each command is written to the controller, it is checked that the controller has accepted the command and is ready to accept the next command. The general control device will issue a series of instructions, which are called instruction sequences. the device controller will check whether each command is accepted and whether the next instruction can be received until all the sequences are issued.
After an instruction is issued, there are usually two possible situations. In most cases, the device driver waits until the controller finishes its job. We need to understand the concept of device controller here.
The main responsibility of the device controller is to control one or more Imax O devices to realize the data exchange between the Imax O device and the computer.
The device controller receives the instructions sent from the CPU to achieve the purpose of controlling the hardware.
A device controller is an addressable device, and when it controls only one device, it has only one unique device address; if the device controller controls multiple connectable devices, it should contain multiple device addresses and make each device address correspond to one device.
Device controllers are mainly divided into two types: character devices and block devices.
The main functions of the device controller are as follows
Receive and identify commands: the device controller can accept instructions from the CPU and identify them. There will also be registers inside the device controller to store instructions and parameters
Data exchange: data is exchanged between the CPU, the controller and the device. The CPU sends instructions to the controller through the bus, or reads the data from the controller in parallel. The controller writes the data to the designated device.
Address recognition: each hardware device has its own address, and the device controller can recognize these different addresses to achieve the purpose of controlling the hardware. In addition, in order to enable CPU to write or read data to registers, these registers should have unique addresses.
Error detection: the device controller also has the function of detecting the data transmitted by the device.
In this case, the device controller blocks until the interrupt unblocks the blocking state. There is also a situation where the operation can be completed without delay, so the driver does not need to block. In the first case, the operating system may be awakened by an interrupt; in the second case, the operating system will not be dormant.
The device driver must be reentrant because the device driver blocks and wakes up and then blocks again. Drivers do not allow system calls, but they usually need to interact with the rest of the kernel.
Device-independent Istroke O software
There are two kinds of Icano software, one is based on specific devices that we have introduced above, and the other is device-independent, which means that specific devices are not required. The boundaries between device drivers and device-independent software depend on the specific system. The functions shown below are implemented by device-independent software
The basic function of device-independent software is to perform the common Icano function for all devices and to provide a unified interface to the user-level software.
Buffer
Buffering is a very important consideration for both block and character devices. Here is the process of reading data from an ADSL (modem), the device we use to connect to the Internet.
The user program calls the read system call to block the user process and wait for the characters to arrive, which is a way to deal with the incoming characters. Each incoming character causes an interruption. The interrupt service program provides characters to the user process and unblocks it. After providing characters to the user program, the process reads other characters and continues to block, as shown in the following model
In this scheme, there is no buffer, because if the user process cannot read the data, it will block until the data is read, which is relatively inefficient, and the blocking way will directly prevent the user process from doing other things. this is unacceptable to the user. Another situation is that every time the user process will restart, for each character will restart the user process, this efficiency will be seriously reduced, so buffer-free software is not a good design.
As an improvement point, we can try to read n characters in user space using a buffer that can read n bytes. In this case, the interrupt service program places characters in the buffer until the buffer is full, and then wakes up the user process. This scheme is much better than the one above.
But there is also a problem with this scheme, what happens if the buffer is called out of memory when the characters arrive? The solution is to lock the buffer in memory, but this solution can also cause problems, if a small number of buffers are locked, and if a large number of buffers are locked in memory, then the pages that can be swapped in and out will shrink, resulting in a decline in system performance.
One solution is to create a buffer inside the kernel and let the interrupt service program put characters in the buffer inside the kernel.
When the buffer in the kernel is full, the pages in the user space will be called into memory, and then the buffer in the kernel space will be copied into the buffer in the user space. This solution also faces a problem, that is, if the pages in the user space are swapped into memory, at this time the buffer in the kernel space is full, and there are still new characters to come. What will happen at this time? Because the buffer is full, there is no room to store new characters.
A very simple way is to set up another buffer. After the first buffer is full, use the second buffer after the first buffer is full. This solution is as follows.
When the second buffer is full, it also copies the data into user space, and then the first buffer is used to accept new characters. This design with two buffers is called double buffering (double buffering).
Another form of buffer is cyclic buffering (circular buffer). It consists of a memory area and two pointers. A pointer points to the next free word, where the new data can be placed. Another pointer points to the first word in the buffer that has not been deleted. In many cases, the hardware moves the first pointer when adding new data, while the operating system moves the second pointer when deleting and processing useless data. When the two pointers reach the top, they go back to the bottom and start again.
Buffers are also important for output. The description of the output is similar to the input
Buffering technology is widely used, but it also has its shortcomings. If the data is buffered too many times, it will affect performance. Consider a situation such as the following
The data goes through the user process-> kernel space-> network controller, where the network controller should be equivalent to the socket buffer, and then sent to the network controller of the receiver-> the kernel buffer of the receiver-> the user buffer of the receiver. A data packet has been cached too many times, which can easily degrade performance.
Error handling
It is perfectly normal to make an error in IPUBO. When errors occur, the operating system must handle them as much as possible. Some errors can only be handled by a specific device, some are handled by the framework, and these errors are independent of the specific device.
One type of Icano error is programmer programming error, such as reading the stream before opening the file, or memory overflow caused by not closing the stream, and so on. This type of problem is handled by the programmer; the other is the actual Icano error, such as writing data to a bad block of disk that cannot be written no matter how. This kind of problem is handled by the driver, which can not be handled by the hardware, which we have mentioned above.
Device driver unified interface
We said in the operating system overview that a very important function of the operating system is to shield the differences between hardware and software and provide a unified standard for hardware and software. this standard is also reflected in providing a unified interface for device drivers, because different hardware and device drivers are written by different vendors, so it is impossible to provide separate interfaces for each driver. So it must be unified.
Allocation and release
Some devices, such as printers, can only be used by one process, which requires the operating system to judge whether the request of the device can be checked and whether it can accept other requests according to the actual situation. A relatively simple and direct way is to perform open operations on special files. If the device is not available, direct open will result in failure. Another way is not to cause the failure directly, but to block it, waiting for another process to release resources, and then perform the open open operation. In this way, the choice is given to the user, and it is up to the user to decide whether he should wait or not.
Note: there are many ways to implement blocking, such as blocking queues, etc.
Device-independent block
Different disks will have different sector sizes, but the software will not care about the sector size, just store it. Some character devices can deliver data one byte at a time, while others deliver data in larger units, and these differences can also be hidden.
Icano software in user space
Although most of the Iripple O software is in the kernel structure, there are also some Iripple O software implemented in user space, everything is not absolute. Some Icano software and library procedures exist in user space and are then implemented by providing system calls.
The above is the editor for you to share how to understand the principle of Ithumb O, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.