User mode network equipment driving framework in Linux system and implementation method
By designing a user-state network device driver framework in Linux system, using kernel modules and character device interfaces, the user-state driver directly operates network devices in the user space, solving the problems of large workload of DPDK rewrite drivers and high DMA capabilities requirements, and improving The network communication performance is provided and the switching and coexistence of kernel drivers and user-state drivers are supported.
Patent Information
- Application Number
- CN202411280285.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-13
- Publication Date
- 2024-12-31
AI Technical Summary
In actual applications, the DPDK, the user-state driver framework in the existing Linux system, has the problem of rewriting network device drivers with a large amount of workload, high DMA capability requirements, and does not support flexible switching between kernel drivers and user-state drivers.
A user-state network device driver framework under Linux system was designed, which loads the network device kernel driver and character device kernel driver through the kernel module, provides a virtual string device interface, allowing the user-state driver to directly operate the DMA and registers of the network device in the user space. Area, realizes high-performance network communication, and supports dynamic switching and coexistence between kernel drivers and user drivers.
It significantly reduces data memory copying and system call overhead, improves network communication performance, increases data transmission and reception rate by 3 times, reduces delay by 70%, and realizes flexible switching and coexistence between kernel drivers and user-state drivers.
Smart Images

Figure CN119226216A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of high-speed network transmission, and in particular to a user-mode driver framework and implementation method under a Linux system. Background Art
[0002] With the popularity of high-speed Ethernet devices, applications have higher and higher requirements for system network communication performance. Linux is the main network application operating system. The general driver devices in the system are running in the kernel space. There are inherent disadvantages in network communication processing, such as interrupt processing overhead, multiple memory copies, multiple context switches, system call overhead, etc. In response to these problems, people have proposed corresponding solutions, such as DPDK, which uses a user-mode driver framework to process data packets by using polling instead of interrupts. When receiving a data packet, the network card driver overloaded by DPDK will not notify the CPU through an interrupt, but directly store the data packet in the memory and deliver it to the application layer software for direct processing through the interface provided by DPDK. This saves a lot of CPU interrupt time and memory copy time, and implements the driver in user space, which improves network communication performance by an order of magnitude.
[0003] However, there are still some problems in the actual application of DPDK's user-mode driver. For example, the network device driver needs to be rewritten and integrated into the DPDK framework, which will inevitably bring a certain amount of work. At the same time, there are certain requirements for the DMA capabilities of network devices. The DPDK framework uses the user-mode memory area and then registers it into the network device. This requires the network device to support streaming memory and dynamically update the DMA address accessed by the network device. DPDK lacks control over the range of DMA addresses applied for, and requires the network device to support DMA addresses within the 64-bit range. The existing DPDK user-mode driver framework does not support flexible switching with kernel drivers, and it is necessary to explicitly bind network devices to different drivers to complete the switching. Summary of the invention
[0004] In view of the problems existing in the prior art, according to the first aspect of the present invention, a user-mode network device driver framework under a Linux system is proposed, comprising:
[0005] Network equipment hardware;
[0006] User-mode drivers for network devices;
[0007] The kernel module includes a network device kernel driver, a memory area and a character device kernel driver. When the network device kernel driver is loaded in the Linux system, it is used to realize the discovery of the network device, apply for a register storage area for the network device, initialize and configure the network device, apply for a DMA storage area, and register the system network device; when the character device kernel driver is loaded in the Linux system, it creates a virtual string device, provides an open / close / ioctl / mmap interface for the user mode driver to use, and saves the DMA and register storage area information allocated to the network device;
[0008] Among them, the user-state driver of the network device can obtain network device related information through a virtual string device file when loaded, and detach the network device from the network device kernel driver through an ioctl interface, stop the sending and receiving functions of the internal network device kernel driver or stop the sending and receiving functions of some queues of the internal network device kernel driver, and map the DMA and register storage area information of the network device to the process address space of the user-state driver through an mmap interface, so that the user-state driver of the network device can directly operate the network device registers and DMA areas, so that the network device can provide high-performance network communication functions.
[0009] In a further implementation manner, after the network device kernel driver is loaded under the Linux system, the network communication application accesses the network communication function provided by the network device through the Socket interface provided by the Linux system.
[0010] In a further implementation manner, the character device kernel driver is configured to obtain the DMA and register storage area information allocated to the network device through interaction with the network device kernel driver.
[0011] In a further implementation manner, the network device kernel driver is configured with an API interface related to the character device kernel driver.
[0012] In a further implementation, when the character device kernel driver is loaded, the character device kernel driver notifies the network device kernel driver by calling the network device kernel driver API, isolates the memory area used by the user-mode driver, and isolates the interaction between the kernel protocol stack and the network device.
[0013] In a further implementation, after the user-state driver of the network device is loaded and the network device is detached from the network device kernel driver, the user-state driver detects the arrival of a data message by polling the network device status or monitoring the interrupt status of the string device, directly obtains the data message content through the mapped DMA storage area, and returns to the user-state protocol stack and application processing.
[0014] In a further implementation, the messages sent from the application and the user-mode protocol stack are copied to the sending DMA area through the user-mode driver, and then the user-mode driver operates the relevant registers of the communication device to trigger the DMA operation and complete the data message sending process.
[0015] In a further implementation manner, the user-mode driver exit process is the reverse process of the user-mode driver loading process, including:
[0016] Automatically close virtual string device files;
[0017] Trigger the close operation of the character device kernel driver through the close interface;
[0018] The character device kernel driver notifies the network device driver to restart the corresponding receiving and sending functions or the receiving and sending functions of some queues that have been stopped by calling the API interface of the network device kernel driver;
[0019] The network device kernel driver reconfigures the network device and restores the message sending and receiving services of the kernel protocol stack.
[0020] According to a second aspect of the present invention, a method for implementing a user-mode network device driver framework in a Linux system is also provided, comprising the following steps:
[0021] Step 1: Connect the network device to the host system through the PCIE interface, interconnect the network device with the remote network communication device, and power on the host system. During the power-on process of the host system, scan the PCIE device and allocate system resources to the network device.
[0022] Step 2: The Linux system loads the network device kernel driver. The network device kernel driver finds the network device through the device information, applies for the register storage area, initializes the network device, applies for the DMA storage area, and registers the system network device, so that ordinary network communication applications can access the network communication function provided by the network device through the Socket interface provided by the Linux system.
[0023] Step 3: The Linux system loads the character device kernel driver, which creates a virtual string device, provides open / close / ioctl / mmap interfaces for the user-mode driver to use, and obtains the DMA and register storage area information allocated to the network device;
[0024] Step 4: The user runs a high-performance network communication application and loads the network device user mode driver, including:
[0025] The user-mode driver creates and opens a virtual string device file, obtains and maps the DMA and register storage areas of the network device to its own process space;
[0026] The character device kernel driver notifies the network device kernel driver to isolate the memory area used by the user-mode driver and isolate the interaction between the kernel protocol stack and the network device by calling the network device kernel driver API interface, decouples the network device from the network device kernel driver, stops the sending and receiving functions of the network device kernel driver, or stops the sending and receiving functions of some queues of the network device kernel driver;
[0027] Step 5: The user uses the high-performance network communication function provided by the network device through the user mode driver;
[0028] Step 6: When the high-performance network communication application exits, the user-mode driver exits and closes the virtual string device file at the same time, and triggers the close operation of the character device kernel driver through the close interface. The character device kernel driver notifies the network device driver to restart the sending and receiving functions of the network device or the sending and receiving functions of some queues that have been stopped by calling the API interface of the network device kernel driver;
[0029] Step 7: The network device kernel driver reconfigures the network device and restores the message sending and receiving service of the kernel protocol stack.
[0030] In a further embodiment, the step 5 further comprises the following steps:
[0031] If the network device supports multiple queues and the configuration information of the multiple queues is independent, different queues are allocated to the network device kernel driver and user mode driver for use to achieve the purpose of coexistence.
[0032] In a further implementation manner, in step 5, the process of user-mode driving the receiving and sending of data messages includes:
[0033] In the receiving direction, the user-state driver detects the arrival of data packets by polling the network device status or monitoring the interrupt status of the string device. Since the DMA memory of the user-state driver is a mapping of the DMA memory of the network device kernel driver and belongs to the same storage area, the data packet content is directly obtained through the mapped DMA storage area and returned to the user-state protocol stack and application for processing;
[0034] In the sending direction, the messages sent from the application and the user-mode protocol stack are copied to the sending DMA area of the user-mode driver through the user-mode driver, and then the user-mode driver operates the relevant registers of the communication device to trigger the DMA operation to complete the sending process of the data message.
[0035] The user-state network device driver framework under the Linux system of the above embodiment of the present invention completes the initialization and DMA memory allocation of the network device through the existing kernel-state driver, and maximizes the use of the existing driver code; at the same time, by creating a virtual string device to realize the management control and memory mapping interface, the mapped DMA memory and register area are mapped to the application space of the user-state driver, providing the ultimate performance of network communication, and based on the usage of the string device, coordinates the control of the network device by the user-state driver and the kernel driver, realizes the coexistence and dynamic switching of the user-state driver and the kernel driver, reduces the data memory copy and system call overhead, and greatly improves the end-to-end performance of network communication. The measured results of the user-state network device driver framework solution of the present invention show that the data transmission and reception rate is increased by about 3 times compared with the traditional method, and the network communication delay is reduced by 70%, which greatly improves the network communication performance.
[0036] It should be understood that all combinations of the aforementioned concepts and the additional concepts described in more detail below can be considered as part of the inventive subject matter of the present disclosure as long as such concepts are not mutually inconsistent. In addition, all combinations of the claimed subject matter are considered as part of the inventive subject matter of the present disclosure.
[0037] The foregoing and other aspects, embodiments and features of the present invention can be more fully understood from the following description in conjunction with the accompanying drawings. Other additional aspects of the present invention, such as the features and / or beneficial effects of the exemplary embodiments, will be apparent from the following description or learned from the practice of the specific embodiments according to the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] The accompanying drawings are not intended to be drawn to scale. In the accompanying drawings, each identical or nearly identical component shown in each figure may be represented by the same reference numeral. For clarity, not every component is labeled in each figure. Embodiments of various aspects of the present invention will now be described by way of example and with reference to the accompanying drawings.
[0039] Figure 1 It is a schematic diagram of a user-mode network device driver framework in a Linux system according to an embodiment of the present invention.
[0040] Figure 2 Schematic diagram of a kernel module loading process according to an embodiment of the present invention.
[0041] Figure 3 4 is a schematic diagram of a user mode driver loading process according to an embodiment of the present invention.
[0042] Figure 4 It is a schematic diagram of a process of sending and receiving data messages driven by a user mode according to an embodiment of the present invention.
[0043] Figure 5 4 is a schematic diagram of a user mode driver exit process according to an embodiment of the present invention. DETAILED DESCRIPTION
[0044] In order to better understand the technical content of the present invention, specific embodiments are given and described as follows in conjunction with the accompanying drawings.
[0045] Various aspects of the present invention are described in this disclosure with reference to the accompanying drawings, in which many illustrative embodiments are shown. The embodiments of the present disclosure are not necessarily intended to include all aspects of the present invention. It should be understood that the various concepts and embodiments introduced above, as well as those described in more detail below, can be implemented in any of many ways, because the concepts and embodiments disclosed by the present invention are not limited to any implementation. In addition, some aspects disclosed by the present invention can be used alone or in any appropriate combination with other aspects disclosed by the present invention.
[0046] {Example 1}
[0047] Combination Figure 1 The user-mode network device driver framework under the Linux system of the example shown includes a network device side, a kernel side, and a user space side.
[0048] The network device side includes network device hardware, which refers to the hardware devices in the network device used to provide network communication functions.
[0049] The user space side includes user-mode drivers for network devices, high-performance network communication applications, and ordinary network communication applications. It should be understood that high-performance network communication applications refer to applications that require the use of high-performance network communication functions (provided by network devices), which can achieve line-speed data message transmission and reception by using user-mode drivers. In particular, a third-party protocol stack is integrated at the same time to complete the protocol processing of the message. The aforementioned ordinary network communication application refers to a traditional network application program relative to the high-performance network communication function, which accesses the protocol stack provided by the kernel and the network device kernel driver through the socket interface to provide basic network communication functions.
[0050] Among them, the aforementioned line speed, namely line speed forwarding, is an advanced performance indicator of network devices such as switches and routers. It usually refers to the ability of a switch or router to forward data frames without errors when the device port is fully loaded.
[0051] The kernel modules on the kernel side include network device kernel drivers, memory areas, and character device kernel drivers.
[0052] The network device kernel driver refers to the existing kernel driver of the network device, which realizes the basic network communication function of the network device after being loaded in the kernel. The network device kernel driver in the embodiment of the present invention is a simple update based on the existing kernel driver of the network device, and adds an API interface related to the character device kernel driver to realize the interaction with the character device kernel driver.
[0053] The network device kernel driver of the embodiment of the present invention is used to complete the initialization configuration and DMA memory configuration of the network device when the Limux system is loaded, and integrate the network device into the kernel protocol stack system to complete the network communication function based on the kernel protocol stack.
[0054] As an example, the loading process of the above network device kernel driver includes: realizing the discovery of network devices through device information, applying for register storage area for network devices, initializing and configuring network devices, applying for DMA storage area, registering system network devices, integrating network devices into the kernel protocol stack system, and completing the network communication function based on the kernel protocol stack. At this time, the network communication application accesses the network communication function provided by the network device through the Socket interface provided by the Linux system.
[0055] In an embodiment of the present invention, the character device kernel driver creates a virtual string device when loaded under the Linux system, provides open / close / ioctl / mmap interfaces for user-state drivers to use, and is able to sense the usage status of the user-state driver to achieve dynamic switching between user-state drivers and kernel-state network device drivers.
[0056] At the same time, the character device kernel driver obtains the DMA and register storage area information allocated to the network device through interaction with the network device kernel driver, and maintains the obtained DMA and register storage area information.
[0057] Combination Figure 1 The system framework shown, in an embodiment of the present invention, the user-state driver of the network device can obtain network device related information through a virtual string device file when loaded, and detach the network device from the network device kernel driver through the ioctl interface, stop the sending and receiving functions of the network device kernel driver or stop the sending and receiving functions of some queues of the network device kernel driver, and map the DMA and register storage area information of the network device to the process address space of the user-state driver through the mmap interface, so that the user-state driver of the network device can directly operate the network device registers and DMA areas, so that the network device can provide high-performance network communication functions.
[0058] In a further implementation, the character device kernel driver notifies the network device kernel driver by calling the network device kernel driver API, isolates the memory area used by the user mode driver, and isolates the interaction between the kernel protocol stack and the network device.
[0059] In a further implementation, after the user-state driver of the network device is loaded and the network device is detached from the network device kernel driver, the user-state driver detects the arrival of a data message by polling the network device status or monitoring the interrupt status of the string device, directly obtains the data message content through the mapped DMA storage area, and returns to the user-state protocol stack and application processing.
[0060] In a further implementation, the messages sent from the application and the user-mode protocol stack are copied to the sending DMA area through the user-mode driver, and then the user-mode driver operates the relevant registers of the communication device to trigger the DMA operation and complete the data message sending process.
[0061] In a further implementation manner, the user-mode driver exit process is the reverse process of the user-mode driver loading process, including:
[0062] Automatically close the virtual string device file;
[0063] Trigger the close operation of the character device kernel driver through the close interface;
[0064] The character device kernel driver notifies the network device driver to restart the corresponding receiving and sending functions or the receiving and sending functions of some queues that have been stopped by calling the API interface of the network device kernel driver;
[0065] The network device kernel driver reconfigures the network device and restores the message sending and receiving services of the kernel protocol stack.
[0066] {Example 2}
[0067] Combination Figure 1 As well as the design of the user-mode network device driver framework under the Linux system of the above embodiment, the present disclosure also proposes a method for implementing the user-mode network device driver framework under the Linux system, comprising the following steps:
[0068] Step 1: Connect the network device to the host system through the PCIE interface, interconnect the network device with the remote network communication device, and power on the host system. During the power-on process of the host system, scan the PCIE device and allocate system resources to the network device.
[0069] Step 2: The Linux system loads the network device kernel driver. The network device kernel driver finds the network device through the device information, applies for the register storage area, initializes the network device, applies for the DMA storage area, and registers the system network device, so that ordinary network communication applications can access the network communication function provided by the network device through the Socket interface provided by the Linux system.
[0070] Step 3: The Linux system loads the character device kernel driver, which creates a virtual string device, provides open / close / ioctl / mmap interfaces for the user-mode driver, and obtains the DMA and register storage area information allocated to the network device by calling the API interface of the network device kernel driver;
[0071] Step 4: The user runs a high-performance network communication application and loads the network device user mode driver, including:
[0072] The user-mode driver creates and opens a virtual string device file, obtains and maps the DMA and register storage areas of the network device to its own process space;
[0073] The character device kernel driver notifies the network device kernel driver by calling the network device kernel driver API interface, isolates the memory area used by the user-mode driver, isolates the interaction between the kernel protocol stack and the network device, decouples the network device from the network device kernel driver, stops the sending and receiving functions of the network device kernel driver, or stops the sending and receiving functions of some queues of the network device kernel driver;
[0074] Step 5: The user uses the high-performance network communication function provided by the network device through the user mode driver;
[0075] Step 6: When the high-performance network communication application exits, the user-mode driver exits and closes the virtual string device file at the same time, and triggers the close operation of the character device kernel driver through the close interface. The character device kernel driver notifies the network device driver to restart the sending and receiving function of the network device or the sending and receiving function of some queues that have been stopped by calling the API interface of the network device kernel driver;
[0076] Step 7: The network device kernel driver reconfigures the network device and restores the message sending and receiving service of the kernel protocol stack.
[0077] In a further embodiment, the step 5 further comprises the following steps:
[0078] If the network device supports multiple queues and the configuration information of the multiple queues is independent, different queues are allocated to the network device kernel driver and user mode driver for use to achieve the purpose of coexistence.
[0079] In a further implementation manner, in step 5, the process of user-mode driving the receiving and sending of data messages includes:
[0080] In the receiving direction, the user-state driver detects the arrival of data packets by polling the network device status or monitoring the interrupt status of the string device. Since the DMA memory of the user-state driver is a mapping of the DMA memory of the network device kernel driver and belongs to the same storage area, the data packet content is directly obtained through the mapped DMA storage area and returned to the user-state protocol stack and application for processing;
[0081] In the sending direction, the messages sent from the application and the user-mode protocol stack are copied to the sending DMA area of the user-mode driver through the user-mode driver, and then the user-mode driver operates the relevant registers of the communication device to trigger the DMA operation to complete the sending process of the data message.
[0082] In step 7, when the high-performance network communication application exits, the user-mode driver will also exit at the same time, the network device kernel driver will reconfigure the network device and restore the message sending and receiving service of the kernel protocol stack, the network device will resume normal operation, and ordinary network applications can continue to access the network communication functions provided by the network device through the kernel interface.
[0083] {Example 3}
[0084] In this example, we will combine Figure 2-5 As shown, the implementation of the user mode network device driver framework of the present invention is described in more detail.
[0085] In this example, the implementation process of the user-mode network device driver framework includes a kernel module loading process, a user-mode driver loading process, a user-mode driver sending and receiving data message process, and a user-mode driver exit process.
[0086] Kernel module loading process
[0087] like Figure 2 As shown, an exemplary implementation of the kernel module loading process is shown.
[0088] Combination Figure 1 As shown, the kernel module includes the network device kernel driver and the character device kernel driver.
[0089] The network device kernel driver can reuse the original network device driver and add relevant interfaces with the character device kernel driver, interact with the character device kernel driver, inform the character device kernel driver of storage area information, receive character device kernel driver control interrupts and restore the network device's packet receiving and sending information.
[0090] The network device kernel driver first scans and identifies the PCIE network device, enables the PCIE register storage space, creates the operating system network device, initializes the network device hardware configuration, applies for DMA storage resources, and registers the relevant register and DMA information into the character device kernel driver.
[0091] When the string device driver is loaded, a virtual string device is created and relevant information of the network device is saved, including the registers and DMA storage area information assigned to the network device.
[0092] User mode driver loading process
[0093] Combination Figure 3 As shown, an exemplary implementation of the user-mode driver loading process is shown.
[0094] In combination with the process shown in the figure, the user-state driver first creates and opens the virtual string device file, and obtains the information related to the network device through the interface provided by the virtual string device file, including the number and size of DMA storage space, the size of register storage space, etc.; then, through the ioctl interface, the network device is detached from the kernel network device driver, the sending and receiving functions of the kernel network driver are stopped, and the register area and DMA area of the network device are mapped to the process address space through the mmap interface. In this way, the register and DMA area of the network device can be directly operated in the user-state driver; finally, the management information inside the user-state driver is initialized, and the sending and receiving functions of the network device are reset.
[0095] In some embodiments, if the network device supports multiple queues and the configuration information of the multiple queues is independent, different queues are allocated to the network device kernel driver and user-mode driver for use. The configuration only stops the sending and receiving functions of the relevant queues used by the user-mode driver, while the queues not used by the user-mode driver perform the sending and receiving functions normally, thereby realizing the coexistence of the kernel driver and the user-mode driver.
[0096] For example, under the premise that hardware configuration resources can be divided based on queues, user-mode drivers and kernel-mode drivers can operate network devices based on queue resources to achieve coexistence of dual-mode drivers.
[0097] User-mode driver sends and receives data packets
[0098] Combination Figure 4 As shown, an exemplary implementation of the process of user-mode driven sending and receiving data messages is shown.
[0099] In the receiving direction, the user-state driver detects the arrival of the data message by polling the network device status or monitoring the string device interrupt status. Since the DMA memory of the user-state driver is a mapping of the DMA memory of the network device kernel driver and belongs to the same storage area, the data message content is directly obtained through the mapped DMA storage area and returned to the user-state protocol stack and application processing.
[0100] In the sending direction, the messages sent from the application and the user-mode protocol stack are copied to the sending DMA area of the user-mode driver through the user-mode driver, and then the user-mode driver operates the relevant registers of the communication device to trigger the DMA operation to complete the sending process of the data message.
[0101] User mode driver exit process
[0102] Combination Figure 5 As shown, an exemplary implementation of the user-mode driven exit process is shown.
[0103] As shown in the example, the user mode driver exit process is the reverse process of the user mode driver loading process, including:
[0104] The exit of the user-mode driver will automatically close the string device file, triggering the close operation of the virtual string driver. The string driver will notify the network device driver to restart the corresponding sending and receiving functions. The network device driver will reconfigure the network device and restore the message sending and receiving service of the kernel protocol stack.
[0105] Automatically close virtual string device files;
[0106] Trigger the close operation of the character device kernel driver through the close interface;
[0107] The character device kernel driver notifies the network device driver to restart the corresponding receiving and sending functions or the receiving and sending functions of some queues that have been stopped by calling the API interface of the network device kernel driver;
[0108] The network device kernel driver reconfigures the network device and restores the message sending and receiving services of the kernel protocol stack.
[0109] In this way, when the high-performance network communication application exits, the user-mode driver will exit at the same time, the network device kernel driver will reconfigure the network device and restore the message sending and receiving service of the kernel protocol stack, the network device will resume normal operation, and ordinary network applications can continue to access the network communication functions provided by the network device through the kernel interface.
[0110] Therefore, in combination with the kernel module loading process, user-mode driver loading process, user-mode driver sending and receiving data message process and user-mode driver exit process of the user-mode network device driver framework implementation process of the above embodiments, the user-mode network device driver framework proposed in the present invention, on the one hand, completes the initialization and DMA memory allocation of the network device through the existing kernel-mode driver, and maximizes the use of the existing driver code. On the other hand, the invention realizes management control and memory mapping interface by creating a virtual string device, maps the mapped DMA memory and register area to the application space of the user-mode driver, provides the ultimate performance of network communication, and can coordinate the control of the network device by the user-mode driver and the kernel driver based on the usage of the character device, so as to realize the coexistence and dynamic switching of the user-mode driver and the kernel driver.
[0111] Compared with the prior art, the user-mode network device driver framework of the present invention has the following significant advantages:
[0112] 1. Reduces data memory copy and system call overhead, greatly improves the end-to-end performance of network communication. The measured results of the user-mode network device driver framework solution of the present invention show that the data transmission and reception rate is increased by about 3 times compared with the traditional method, and the network communication delay is reduced by 70%, which greatly improves the network communication performance;
[0113] 2. Dynamic switching and even coexistence of kernel drivers and user-mode drivers. The user-mode network device driver framework of the present invention can sense the operation of user-mode drivers and related applications, and dynamically switch between user-mode drivers and kernel-mode drivers. When hardware configuration resources can be divided based on queues, user-mode drivers and kernel-mode drivers can also operate network devices based on queue resources, thereby realizing the coexistence of dual-mode drivers.
[0114] 3. By reusing the initialization configuration function of the existing kernel-mode driver for network devices, the secondary development of the same function in the user-mode driver is avoided, and the original DMA memory registration management method is reused, which reduces the difficulty and cycle of the development cycle, and the development workload is small. High efficiency;
[0115] 4. The applicable network devices are wider. The user-mode network device driver framework of the present invention does not require the network devices to support streaming memory, and network devices with restrictions on DMA memory areas can also support applications.
[0116] Although the present invention has been disclosed as above with preferred embodiments, it is not intended to limit the present invention. A person with ordinary knowledge in the technical field to which the present invention belongs may make various changes and modifications without departing from the spirit and scope of the present invention. Therefore, the protection scope of the present invention shall be determined by the definition of the claims.
Claims
1. A user-mode network device driver framework under Linux system, characterized in that: include: Network equipment hardware; User-mode drivers for network devices; The kernel module includes a network device kernel driver, a memory area and a character device kernel driver. When the network device kernel driver is loaded in the Linux system, it is used to realize the discovery of the network device, apply for a register storage area for the network device, initialize and configure the network device, apply for a DMA storage area, and register the system network device; when the character device kernel driver is loaded in the Linux system, it creates a virtual string device, provides an open / close / ioctl / mmap interface for the user mode driver to use, and saves the DMA and register storage area information allocated to the network device; Among them, the user-state driver of the network device can obtain network device related information through a virtual string device file when loaded, and detach the network device from the network device kernel driver through an ioctl interface, stop the sending and receiving functions of the internal network device kernel driver or stop the sending and receiving functions of some queues of the internal network device kernel driver, and map the DMA and register storage area information of the network device to the process address space of the user-state driver through an mmap interface, so that the user-state driver of the network device can directly operate the registers and DMA areas, so that the network device can provide high-performance network communication functions.
2. The user-mode network device driver framework under Linux system according to claim 1, characterized in that: The character device kernel driver is configured to obtain the DMA and register storage area information allocated to the network device through interaction with the network device kernel driver.
3. The user-mode network device driver framework under Linux system according to claim 1 or 2, characterized in that: The network device kernel driver is configured with an API interface related to the character device kernel driver.
4. The user-mode network device driver framework under Linux system according to claim 1, characterized in that: The character device kernel driver notifies the network device kernel driver by calling the network device kernel driver API, isolates the memory area used by the user state driver, and isolates the interaction between the kernel protocol stack and the network device.
5. The user-mode network device driver framework under Linux system according to claim 1, characterized in that: After the user-mode driver of the network device is loaded and the network device is detached from the network device kernel driver, the user-mode driver detects the arrival of data packets by polling the network device status or monitoring the interrupt status of the string device, directly obtains the data packet content through the mapped DMA storage area, and returns to the user-mode protocol stack and application processing.
6. The user-mode network device driver framework under Linux system according to claim 5, characterized in that: The messages sent from the application and the user-mode protocol stack are copied to the send DMA area through the user-mode driver, and then the user-mode driver operates the relevant registers of the communication device to trigger the DMA operation and complete the data message sending process.
7. The user-mode network device driver framework under Linux system according to claim 5 or 6, characterized in that: The user-mode driver exit process is the reverse process of the user-mode driver loading process, including: Automatically close virtual string device files; Trigger the close operation of the character device kernel driver through the close interface; The character device kernel driver notifies the network device driver to restart the receiving and sending functions of the network device or the receiving and sending functions of some queues that have been stopped by calling the API interface of the network device kernel driver; The network device kernel driver reconfigures the network device and restores the message sending and receiving services of the kernel protocol stack.
8. A method for implementing a user-mode network device driver framework in a Linux system according to any one of claims 1 to 7, characterized in that: The following steps are involved: Step 1: Connect the network device to the host system through the PCIE interface, interconnect the network device with the remote network communication device, and power on the host system. During the power-on process of the host system, scan the PCIE device and allocate system resources to the network device. Step 2: The Linux system loads the network device kernel driver. The network device kernel driver finds the network device through the device information, applies for the register storage area, initializes the network device, applies for the DMA storage area, and registers the system network device. Step 3: The Linux system loads the character device kernel driver, which creates a virtual string device, provides open / close / ioctl / mmap interfaces for the user-mode driver to use, and obtains the DMA and register storage area information allocated to the network device; Step 4: The user runs a high-performance network communication application and loads the network device user mode driver, including: The user-mode driver creates and opens a virtual string device file, obtains and maps the DMA and register storage areas of the network device to its own process space; The character device kernel driver notifies the network device kernel driver to isolate the memory area used by the user-mode driver and isolate the interaction between the kernel protocol stack and the network device by calling the network device kernel driver API interface, decouples the network device from the network device kernel driver, stops the sending and receiving functions of the network device kernel driver, or stops the sending and receiving functions of some queues of the network device kernel driver; Step 5: The user uses the high-performance network communication function provided by the network device through the user mode driver; Step 6: When the high-performance network communication application exits, the user-mode driver exits and closes the virtual string device file at the same time, and triggers the close operation of the character device kernel driver through the close interface. The character device kernel driver notifies the network device driver to restart the sending and receiving functions of the network device or the sending and receiving functions of some queues that have been stopped by calling the API interface of the network device kernel driver; Step 7: The network device kernel driver reconfigures the network device and restores the message sending and receiving service of the kernel protocol stack.
9. The method for implementing the user-mode network device driver framework under the Linux system according to claim 8, characterized in that: The step 5 also includes the following steps: If the network device supports multiple queues and the configuration information of the multiple queues is independent, different queues are allocated to the network device kernel driver and user mode driver for use to achieve the purpose of coexistence.
10. The method for implementing the user-mode network device driver framework under the Linux system according to claim 8, characterized in that: In step 5, the process of the user mode driver sending and receiving data messages includes: In the receiving direction, the user-state driver detects the arrival of data packets by polling the network device status or monitoring the interrupt status of the string device. Since the DMA memory of the user-state driver is a mapping of the DMA memory of the network device kernel driver and belongs to the same storage area, the data packet content is directly obtained through the mapped DMA storage area and returned to the user-state protocol stack and application for processing; In the sending direction, the messages sent from the application and the user-mode protocol stack are copied to the sending DMA area of the user-mode driver through the user-mode driver, and then the user-mode driver operates the relevant registers of the communication device to trigger the DMA operation to complete the sending process of the data message.
Citation Information
Cited By
Memory data loading method and device, medium and product
CN120780541A
