Do_direct_io and do_buffered_io of Windows drivers

Source: Internet
Author: User
Windows Device Driver do_direct_io and DO_BUFFERED_IO2009-09-05 with reference to Mr. Mao de fuck "Windows Kernel Scenario Analysis" 9.12mdl chapter.
Both are signs of Windows devices, not IRPs. Generally, system calls, such as ntreadfile and ntwritefile, are initiated by user programs and accompanied by a large number
. The simplest scenario is that the user program is congested on the system call and continues to be executed after the kernel completes data exchange. During this period, the kernel runs in the process context and cannot be preemptible.
Indicates the context where only one process can be run. Because data exchange requires simultaneous access to the kernel space and user space, the user space is process-specific. That is to say, the same virtual address is usually displayed in different processes.
Displays completely unrelated physical addresses. Therefore, once a process is switched, the kernel cannot obtain the correct data with the original virtual address. However, calls involving hardware operations, such as writing to a disk, can only be asynchronous,
The interrupt function and the subsequent DPC function cannot operate the user space correctly.
There are two solutions. 1. After the CPU enters the kernel space, apply for a suitable memory buffer in the kernel space and then copy the data in the user space to it. Because all processes and interruptions share the same kernel space page table, the CPU can always access the correct data. This is the do_buffered_io mode.
2. Add a system space ing to the user space buffer temporarily, so that two virtual address spaces are available for the same group of physical pages. One is in the original user space virtual address, second, the virtual
Proposed address. In this way, even if a process switchover occurs, or access to the user space in the interrupt function or DPC function can be accessed through the Virtual Address of the system space to access the user space buffer until the operation is completed and the user space is returned.
Undo system space. This is the do_direct_io mode.
You can use either of the two methods, but not both. If neither method is used, you must ensure that the buffer of the corresponding user space is not accessed by the interrupt program or DPC function.

Attached to the csdn Website:
Http://blog.csdn.net/Like_Thinking/archive/2008/04/18/2304683.aspx
1. do_direct_io or do_buffered_io? What are the differences between the two methods? What are the usage scenarios?
A:
Do_direct_io
It is often used to transmit large volumes of data with high speed. Do_buffered_io is often used to transmit small pieces of slow data. Do_direct_io is more efficient (Only Memory Locking is required
Yes. The cost is the sacrifice of physical memory. Do_buffered_io memory efficiency is high, but the speed is poor (it needs to allocate memory and copy data ). The main reason for this difference is the processor's
Ring 0 to ring4 traversal (Microsoft only uses two layers ). You cannot have the best of both worlds. You can only have one of them (of course, sometimes you can have the best of both worlds, which will be mentioned later ).
Do_direct_io is mainly used to use the underlying driver of DMA. Mass Storage is also used.
Do_buffered_io is mainly used for HID (including mouse and keyboard), video, serial port, and parallel port.
However, I think the vast majority of designers are selfish. Direct Io will be used when it comes up,

2. writefile and readfile in the application will enter write and read encapsulated by DS. But if I write several pipe transmissions in write and read, how can I control them in the application?
A:
Me
I don't quite understand what you mean. I guess you mean how to control the execution details in the Read and Write Functions in the driver in the application-selectively execute the specified code. If so,
You 'd better add an external control of Io CTRL or vendor request. Then use global variables in driver and firmware.

3. What is the relationship between the synchronous and asynchronous modes and isochronous transfer?
In my understanding, the synchronous mode and asynchronous mode refer to the processing of IRPs. Can the asynchronous mode also establish isochronous transfer?

A: Synchronous mode and asynchronous mode are a concept that can be used everywhere, making it more confusing and confusing. You can see them in the software, communication, and even motor fields. Similar to them, there is also an "interruption"-making the brothers on the Forum another killer!
You
The synchronous and asynchronous modes refer to the request operation modes. Corresponds to programming in software. In Windows, asynchronous mode is recommended, the interface is more friendly, and the efficiency is higher. Synchronization Method
It is simple and suitable for beginners. To put it simply, for a long operation (put in a function), the asynchronous operation immediately returns status_pending. as to when the operation is completed or times out, you
Query it by yourself. The synchronization operation will be silly until the operation is completed or times out. If you have already done serial programming or network programming, you can easily understand these two concepts. Asynchronous operations can be combined with Windows Message Mechanism
Provides beautiful interfaces and interfaces.
Isochronous
Transfer is a completely USB transmission mode: the master has been used for Multimedia Streams. You can imagine that if a USB transmission error occurs, re-transmission is required for data transmission (such as file transmission. And
For audio and video, it can be discarded completely, because synchronous continuity is the most important. Even if you re-transmit the video, the sound and image have paused or disturbed. Therefore, synchronous transmission is concerned with sending the current data at this moment.
Go out. Ignore the problem of a package before the meeting. Like a TV, it focuses on real-time performance.
Therefore, the conclusion is: "I understand the synchronous mode and asynchronous mode refer to the processing of IRP, And the asynchronous mode can also establish isochronous transfer.

Most
Later, we will discuss the best of both worlds: We can use do_direct_io and do_buffered_io to achieve both memory and efficiency. But (when it comes to "but", it is always
No way !) It can only be used for high-level drivers (that is, it runs in the user thread space), such as FSD. The use of this Io method also requires a bunch of loilogs, such
Probeforread, probeforwrite or something. Beginners can skip it for the moment.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.