Asynchronous IO, APC, IO Complete port, thread pool and high performance server (1)

xiaoxiao2021-03-06  40

Reprinted: http://www.vchelp.net/ Original author's name fang (fangguicheng@21cn.com) Text asynchronous IO, APC, IO completion port, thread pool and high performance server one asynchronous IO background: polling PIO DMA interrupt The speed of the early IO equipment is not too disappearing compared with the CPU. The CPU is timely polling over 10 IO devices to see if there is any processing requirements, and if it is handled, return to continue after completion. So far, the floppy drive also retains this polling work. As the performance of CPU is rapidly improved, this efficiency is wat a lot of CPU time. Therefore, the interruption work mode begins to become universally adopted. This technology allows the IO device to generate a hardware interrupt when the IO device needs to obtain the service, forcing the CPU to abandon the current processing task, enter the specific interrupt service process, and then continue the original processing after the interrupt service is completed. In this way, the IO device and the CPU can be treated simultaneously, thereby avoiding the CPU waiting for IO. The mode of transmission of early data is mainly PIO (program control IO) mode. The data is transmitted by programming the IO address program. For example, serial port, software writes one byte data each time, the serial port device completes the transfer task, and the software will generate an interrupt, and then the software repeats again until all data is sent. Performance Hardware devices provide a FIFO (advanced first buffer component) that allows the software to transfer more bytes at a time. Obviously, using the PIO method for high speed IO devices, there is still much CPU time (because it is required to be controlled by CPU). The DMA (direct memory access) can greatly reduce the CPU processing time. The CPU only needs to tell the start address and size of the DMA controller data block, and the DMA controller can transmit data between memory and devices, and the CPU can handle other tasks. An interrupt will occur after the data is completed. Synchronous files IO and asynchronous file IO are extracted under MSDN "Synchronous File I / O And Asynchronous File I / O". There are two types of file IO synchronization: synchronous file IO and asynchronous file IO. Asynchronous file IO is also overlapping IO. In the synchronization file IO, the thread starts an IO action and then immediately enters the waiting state until the IO operation is completed, then wake up to continue. In the asynchronous file IO method, the thread sends an IO request to the kernel, and then processes other things. After the kernel completes the IO request, it will notify the thread IO operation to complete. If the IO request requires a lot of time execution, the asynchronous file IO method can significantly improve efficiency, because the CPU will schedule other threads to perform, if there is no other thread, this time will be Wasting (may dispatch the zero page thread of the operating system). If the IO request operation is very fast, it is still not as low as an asynchronous IO method, it is better to use synchronous IO. Synchronous IO only allows only one IO operation at the same time, that is, for the IO operation of the same file handle is serialized, even if it is used to use two threads, it cannot simultaneously send a read and write operation at the same time. The overlapping IO allows one or more threads to simultaneously issue IO requests. When the asynchronous IO is completed, the application is notified to the application by setting the file handle to a signal state, or the application is notified if the IO request is completed via the GetoverlappedResult, or the application can be notified by an event object. Reference Bibliography 1, MSDN Library 2, "Windows Advanced Programming Guide" 3, "Windows Core Programming" 4, "Windows 2000 Device Driver Design Guide"

转载请注明原文地址:https://www.9cbs.com/read-54558.html

New Post(0)