A method, device and equipment supporting a default network card single queue

By setting the initial number of queues of the network card to 1 and scaling the received packets, the problem of out-of-order packet transmission caused by multiple queues of the network card is solved, and stable and reliable single-thread packet transmission is achieved.

CN114265686BActive Publication Date: 2025-04-22CHINA STANDARD SOFTWARE
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111348299.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-15
Publication Date
2025-04-22
Estimated Expiration
2041-11-15

AI Technical Summary

Technical Problem

In the prior art, multiple network card queues lead to the problem of out-of-order packet transmission. Especially in cases where hardware performance is average, a solution that supports default network card single queues is needed.

Method used

By obtaining the queue information of the network card, setting the default initial queue number of the network card is 1, and adding it to the buffer, using the delayed process call to zoom the received packet, and filling the received packet data into the buffer for processing.

Benefits of technology

Ensure that packet transmission is in single-threaded mode, avoiding the out-of-order problem caused by multi-queue processing, and improving the stability and reliability of packet transmission.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114265686B_ABST
    Figure CN114265686B_ABST
Patent Text Reader

Abstract

The present invention provides a method, device and equipment supporting a default single queue of a network card, the method comprising: obtaining queue information of a network card; obtaining a buffer when the network card receives data according to the queue information of the network card; assigning a default initial queue number of the network card to 1 for the initial queue number of the network card according to the queue information of the network card; registering a network card interrupt, and adding the default initial queue number of the network card to the buffer; scaling the received packet by using a delayed procedure call, and filling the data of the received packet into the buffer for processing. By setting the default initial queue number of the network card to 1 and adding the queue number to the buffer of the network card, only a single-queue network card driver exists inside the network card buffer, thereby ensuring that the transmission of data packets is in a single-threaded mode, and effectively solving the problem that multiple queues of the network card easily lead to disordered transmission of data packets.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of network card drivers, and more specifically, relates to a method, a device and equipment for supporting a default network card single queue. Background Art

[0002] At present, domestic operating systems are mainly developed based on Linux. Domestic operating systems have been widely used in defense, government, finance and other industries. There will be more and more software and hardware development based on domestic operating systems. As an indispensable component of domestic software and hardware platforms, network cards have exposed many problems in the development of basic software and hardware. During the software and hardware adaptation process, it was found that multiple queues of network cards would cause packet out of order, while network cards set to a single queue would not have this problem.

[0003] NIC single queue is a technology that only one core processes NIC received packets at the same time. NIC multi-queue has high requirements on the number of CPU cores and NIC hardware. NIC single queue is needed in occasions with general hardware performance. NIC single queue implements single-thread transmission to ensure normal packet reception.

[0004] Most network card drivers on the market default to multi-queue. It is complicated for hardware manufacturers to set multi-queue to single queue. In actual use, operational errors may occur, causing the network card to malfunction. Therefore, a solution that supports the default single queue of the network card is needed. Summary of the invention

[0005] The purpose of the present invention is to provide a method, device and equipment supporting a default single queue of a network card, so as to solve the problem of disordered transmission of data packets caused by multiple queues of a network card in the prior art.

[0006] A first aspect of an embodiment of the present invention provides a method for supporting a default network card single queue, including:

[0007] Get the queue information of the network card;

[0008] According to the queue information of the network card, obtain the buffer when the network card receives data;

[0009] According to the queue information of the network card, the default initial queue number of the network card is assigned to 1;

[0010] Register the network card interrupt and add the default initial queue number of the network card to the buffer;

[0011] The received packet is scaled using a delayed procedure call and the data of the received packet is filled into a buffer for processing.

[0012] A second aspect of an embodiment of the present invention provides a device supporting a default network card single queue, including:

[0013] A data acquisition module is used to obtain queue information of the network card;

[0014] The data processing module is used to obtain the buffer area when the network card receives data according to the queue information of the network card;

[0015] The data modification module is used to assign a default initial queue number of the network card to 1 according to the queue information of the network card and the initial queue number of the network card;

[0016] The data writing module is used to register the network card interrupt and add the default initial queue number of the network card to the buffer.

[0017] According to a third aspect of an embodiment of the present invention, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above-mentioned method of supporting a default single network card queue when executing the computer program.

[0018] According to a fourth aspect of an embodiment of the present invention, a computer-readable storage medium is provided, wherein the computer storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above-mentioned method for supporting a default network card single queue are implemented. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0020] Figure 1 A schematic flow chart of a method for supporting a default network card single queue provided by an embodiment of the present invention;

[0021] Figure 2 A schematic flow chart of a method for supporting a default network card single queue provided by another embodiment of the present invention;

[0022] Figure 3 A schematic block diagram of the structure of a device supporting a default network card single queue provided by an embodiment of the present invention;

[0023] Figure 4 A schematic block diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0024] In order to make the technical problems, technical solutions and beneficial effects to be solved by the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.

[0025] In one embodiment of the present invention, Figure 1 A flowchart of a method for supporting a single queue of a default network card is shown. The method includes:

[0026] S101. Get the queue information of the network card:

[0027] In this embodiment, the queue information of the network card can be obtained by using a system application in a wired manner, or by using a hardware device in a wireless manner. The queue information of the network card may include but is not limited to queue rules or queue numbers, etc., which are not limited here.

[0028] S102. According to the queue information of the network card, the buffer area when the network card receives data is obtained:

[0029] In this embodiment, firstly, the receive queue pointer array of the network card is obtained, wherein rx_queues is the receive queue pointer array, and each pointer points to a receive queue;

[0030] According to the receive queue pointer array, get all the receive queues of the network card;

[0031] Get the hardware descriptor and software descriptor corresponding to the receive queue. Each receive queue contains a hardware descriptor ring (rx_ring) and a software descriptor (sw_ring). The rx_ring is mainly used by the driver and hardware. The sw_ring is actually an mbuf pointer, which is mainly used by the application. Each hardware descriptor has a corresponding software descriptor, which is the bridge between the application and the data.

[0032] According to the information of all receive queues, a circular DMA buffer is formed using all network card descriptions e1000_adv_rx_decs. When receiving data, the network card DMA writes the message data to the corresponding memory space according to the physical address of the received message data, that is, pkt_addr points to rte_mbuf->buf_physaddr, so that when the network card receives the data, it writes the data to the data buffer corresponding to mbuf.

[0033] S103. According to the queue information of the network card, for the initial queue number of the network card, the default initial queue number of the network card is assigned to 1:

[0034] In this embodiment, firstly, all option types of the network card are obtained, and the range options of the network card are determined;

[0035] You can use ls / sys / class / net / enol / queues / in the operating system terminal to view how many receive queues and send queues there are. ethtool_channels indicates the number of network channels that can be configured. combines_count is used to record the receive queue and send queue. combines_count gets the value of the receive queue through ch->combined_count=adapter->num_rx_queues.

[0036] The types of network card options include enable, range, and list. The network card queue belongs to the range option. According to the range option of the network card, the queue range def module of the network card is determined;

[0037] Set the name of the network card queue to RSS, set DEFAULT_RSS to 1 in the def module of the network card option, and assign the module to the rss queue of the network adapter (adapter->rss_queues=opt.def);

[0038] Set the range of the network card queue to a minimum of 1 and a maximum of 8. Use the ethtool-leno1 command in the operating system terminal to see the maximum number of network card queues under the Pre-set maximums entry. The number of network card queues, maximum and minimum values ​​are determined by the three parameters of RSS. Set the value of #define DEFAULT_RSS to determine the initial number of queues, set the value of #define MAX_RSS to determine the maximum number of queues, and set the value of #define MIN_RSS to determine the minimum number of queues.

[0039] S104, registering the network card interruption, and adding the default initial queue number of the network card to the buffer:

[0040] In this embodiment, the network card interrupt is first registered, and the queue number of the initial network card adapter is set when registering the interrupt;

[0041] If there is data in the virtual NIC queue pool, the NIC adapter will get the queue number from the queue pool. If the queue pool is empty, when the NIC sets MSI-X, the receive queue of the NIC adapter gets the value from the rss queue (adapter->num_rx_queues = adapter->rss_queues), the receive queue and the send queue have the same value (adapter->num_tx_queues = adapter->num_rx_queues), and put the data into the virtual NIC queue pool. After the NIC adapter is initialized, the queue number is added to the NIC ring buffer and the queue number is saved in the NIC register.

[0042] S105, using the delayed procedure call to scale the received packet, and filling the data of the received packet into the buffer for processing:

[0043] In this embodiment, a delayed procedure call is scheduled to scale the received packets, thereby more efficiently processing the received packets. At the same time, the data of the received packets are filled into a single-thread buffer, thereby avoiding the problem of disorder caused by processing data packets in multiple queues.

[0044] The embodiment of the present invention obtains the queue information of the network card, and then obtains the buffer when the network card receives data according to the queue information of the network card; according to the queue information of the network card, for the initial queue number of the network card, the default initial queue number of the network card is assigned to 1; the network card interrupt is registered, and the default initial queue number of the network card is added to the buffer; finally, the received packet is scaled by delaying the process call, and the data of the received packet is filled into the buffer for processing. By setting the default initial queue number of the network card to 1 and adding the queue number to the buffer of the network card, only a single-queue network card driver exists in the network card buffer, thereby ensuring that the transmission of the data packet is in a single-threaded mode, and effectively solving the problem that the multiple queues of the network card easily lead to disordered transmission of the data packet.

[0045] In the above Figure 1 Based on the embodiment shown, combined Figure 2 Another embodiment shown is a flow chart of a method for supporting a default network card single queue. The method shown in this embodiment includes:

[0046] S201, the network card driver schedules a delay process call to scale the received packet, and distributes the data of the received packet to the system CPU:

[0047] In this embodiment, in order to efficiently handle the packet reception, the driver's receiving server function schedules a delayed procedure call;

[0048] Since the receive packet scaling is set, the network card will provide the function of scheduling these packets to other processors. Its role is to issue a hash function with a predefined hash key on each incoming data packet. The hash function takes the IP address, protocol, and port of the data packet as the key and calculates the hash value;

[0049] The least significant bits of the hash value are used to index an indirection table, and the values ​​in the indirection table are used to distribute the data of the received packet to the CPU.

[0050] S202, the network card uses direct memory access to fill the data received by the system CPU into the buffer and interrupt the system:

[0051] In this embodiment, the network card uses DMA to fill the received data into the buffer and interrupt the system. During the initialization period, the microport driver allocates the receiving buffer in the shared memory. The network card can fill other buffers at any time during this interrupt cycle.

[0052] S203, the network driver interface type calls the miniport interrupt function of the miniport driver on the CPU confirmed by the system:

[0053] In this embodiment, the network driver interface type calls the miniport interrupt function of the miniport driver on the CPU confirmed by the system. It should be noted that, ideally, the miniport interrupt function should go to the least busy CPU, but in some systems, the system assigns the miniport interrupt function to an available CPU or a CPU associated with a network card.

[0054] S204, the interrupt service program disables interrupts and requests the network interrupt interface type to queue a delayed procedure call to process the received data:

[0055] In this embodiment, since the delayed procedure call sets up descriptors for all received buffers and specifies data on the driver stack, there may be many buffers for many different connections and there may be many processes to be completed, the network interrupt interface type is requested to queue the delayed procedure call to process the received data.

[0056] Another method for supporting a default single queue of a network card provided by an embodiment of the present invention performs received packet scaling by scheduling a delayed procedure call, thereby efficiently processing received packets.

[0057] Among them, the receiving packet scaling is a diversion mechanism provided by the network card, which diverts the report to different receiving queues to improve the receiving performance. By calculating the network layer and transport layer two / three / fourth group hash values ​​in the network data message, taking the least significant bit of the hash value, due to the index indirect addressing table, the saved index value in the indirect addressing table is used to allocate the data message to different CPUs for processing.

[0058] To obtain the receive packet scaling configuration information, the upper-level driver can send a legacy query to the miniport driver. During initialization, the network driver interface type also provides the receive packet scaling configuration information to the upper-level protocol driver in the network driver interface specification.

[0059] The upper driver selects the hash function, type, and indirection table. The upper driver can disable receive packet scaling for the network card. In this case, the driver sets the disable receive packet scaling flag in the flags bit of the network driver receive scale parameter. After setting this flag, the miniport driver should ignore all other flags and settings and disable receive packet scaling for the network card.

[0060] If receive hashing is enabled, the network driver interface disables receive hashing until receive packet scaling is enabled. All miniport adapters supported by the miniport must provide the same hashing configuration design for all subsequent protocol bindings. The key is 320 bits long and can contain any data chosen by the upper layer driver, such as a random byte stream.

[0061] To rebalance the processing load, the upper driver can set receive packet scaling parameters and modify the indirection table. Normally, all parameters except the indirection table remain unchanged. However, the upper driver may change other receive packet scaling initialization parameters after initializing receive packet scaling. If necessary, the miniport driver can reset the NIC hardware to change the hash function, hash key, hash type, base CPU number, or the number of bits used to index the indirection table.

[0062] See also Figure 3 , Figure 3 This is a schematic block diagram of a structure of a device supporting a default network card single queue provided by an embodiment of the present invention. For ease of explanation, only the part related to the embodiment of the present invention is shown. Figure 3 , the device comprises:

[0063] The data acquisition module 301 is used to acquire the queue information of the network card;

[0064] The data processing module 302 is used to obtain the buffer of the network card when receiving data according to the queue information of the network card, and use the delay procedure call to scale the received packet and fill the data of the received packet into the buffer for processing;

[0065] The data modification module 303 is used to assign a default initial queue number of the network card to 1 according to the queue information of the network card and the initial queue number of the network card;

[0066] The data writing module 304 is used to register the network card interruption and add the default initial queue number of the network card to the buffer.

[0067] Optionally, the data acquisition module 301 may also be used to acquire a receiving queue pointer array of the network card, and to acquire all option types of the network card.

[0068] Optionally, the data processing module 302 can also be used to obtain all receiving queues of the network card according to the receiving queue pointer array, and the pointers in the receiving queue pointer array correspond to the receiving queues one by one; for each receiving queue, obtain the hardware descriptor and software descriptor corresponding to the receiving queue; according to the hardware descriptors of all receiving queues, build a circular direct memory access buffer, that is, the buffer when the network card receives data. And, according to the range option of the network card, determine the queue range setting module of the network card; according to the queue range setting module, obtain the maximum number of queues, the minimum number of queues and the default initial number of queues of the network card queue.

[0069] Optionally, the data modification module 303 may also be used to set the maximum number of queues of the network card queue to 8, and at the same time, set the minimum number of queues of the network card queue to 1, and set the default initial number of queues of the network card queue to 1.

[0070] Optionally, the data writing module 304 can also be used to register the network card interrupt and the initial queue number of the network card; if there is data in the queue pool, the queue number in the queue pool is called; if the queue pool is empty, when the network card sets the interrupt, it obtains the queue number from the queue information of the network card and puts the queue number into the queue pool; the network card calls the default initial queue number in the queue pool and adds the default initial queue number of the network card to the buffer.

[0071] See also Figure 4 , Figure 4 FIG. 1 is a schematic block diagram of an electronic device provided by an embodiment of the present invention. Figure 4 The electronic device 400 in the embodiment shown may include but is not limited to at least one of the following: one or more processors 401, one or more input devices 402, one or more output devices 403, and one or more memories 404. The processors 401, input devices 402, output devices 403, and memories 404 communicate with each other via a communication bus 405. The memory 404 is used to store computer programs, which include program instructions. The processor 401 is used to execute the program instructions stored in the memory 404.

[0072] It should be understood that in the embodiment of the present invention, the processor 401 may be a central processing unit (CPU), and the processor may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0073] The input device 402 may include a touch panel, a fingerprint sensor (for collecting the user's fingerprint information and fingerprint direction information), a microphone, etc., and the output device 403 may include a display (LCD, etc.), a speaker, etc.

[0074] The memory 404 may include a read-only memory and a random access memory, and provide instructions and data to the processor 401. A portion of the memory 404 may also include a non-volatile random access memory. For example, the memory 404 may also store information about the device type.

[0075] In a specific implementation, the processor 401, input device 402, and output device 403 described in the embodiment of the present invention can execute the implementation method described in the method embodiment provided in the embodiment of the present invention, which will not be described in detail here.

[0076] In another embodiment of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, wherein the program instructions are executed by a processor to implement all or part of the processes in the above-mentioned embodiment method, and may also be completed by instructing the relevant hardware through the computer program, wherein the computer program may be stored in a computer-readable storage medium, and wherein the computer program may be executed by the processor to implement the steps of the above-mentioned various method embodiments. Among them, the computer program includes computer program code, and the computer program code may be in source code form, object code form, executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the contents contained in the computer-readable medium may be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, the computer-readable medium does not include electric carrier signal and telecommunication signal.

[0077] The computer-readable storage medium may be an internal storage unit of the terminal of any of the foregoing embodiments, such as a hard disk or memory of the terminal. The computer-readable storage medium may also be an external storage device of the terminal, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the terminal. Further, the computer-readable storage medium may also include both an internal storage unit of the terminal and an external storage device. The computer-readable storage medium is used to store computer programs and other programs and data required by the terminal. The computer-readable storage medium may also be used to temporarily store data that has been output or is to be output.

[0078] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

Claims

1. A method for supporting a single queue of a default network card, characterized in that: The method comprises: Get the queue information of the network card; According to the queue information of the network card, obtaining the buffer zone when the network card receives data; According to the queue information of the network card, for the initial queue number of the network card, assigning a default initial queue number of the network card to 1; Registering the interrupt of the network card, and adding the default initial queue number of the network card to the buffer; The received packet is scaled by using a delayed procedure call, and the data of the received packet is filled into the buffer for processing.

2. A method for supporting a default network card single queue as claimed in claim 1, characterized in that: The step of obtaining a buffer zone when the network card receives data according to the queue information of the network card includes: Obtaining a receive queue pointer array of the network card; According to the receive queue pointer array, all receive queues of the network card are acquired, wherein the pointers in the receive queue pointer array correspond to the receive queues one by one; For each receiving queue, obtain the hardware descriptor and software descriptor corresponding to the receiving queue; According to the hardware descriptors of all the receiving queues, a circular direct memory access buffer is constructed, that is, the buffer when the network card receives data.

3. A method for supporting a default network card single queue as claimed in claim 1, characterized in that: The step of assigning a value of 1 to the initial queue number of the network card according to the queue information of the network card comprises: Obtain all option types of the network card and determine the range options of the network card; Determining a queue range setting module of the network card according to a range option of the network card; According to the queue range setting module, the maximum number of queues, the minimum number of queues and the default initial number of queues of the network card queue are obtained; The maximum number of queues of the network card queue is set to 8, the minimum number of queues of the network card queue is set to 1, and the default initial number of queues of the network card queue is set to 1.

4. A method for supporting a default network card single queue as claimed in claim 1, characterized in that: The registering the interruption of the network card and adding the default initial queue number of the network card to the buffer zone comprises: Register the interrupt of the network card and initialize the queue number of the network card; If there is data in the queue pool, call the queue number in the queue pool; If the queue pool is empty, the network card obtains the queue number from the queue information of the network card when setting an interrupt, and puts the queue number into the queue pool; The network card calls the default initial queue number in the queue pool, and adds the default initial queue number of the network card to the buffer.

5. A method for supporting a default network card single queue as claimed in claim 1, characterized in that: The method of scaling the received packet by using a delayed procedure call and filling the data of the received packet into the buffer for processing includes: The network card driver schedules a delayed procedure call to perform received packet scaling and distributes data of the received packet to the system CPU; The network card uses direct memory access to fill the data received by the system CPU into a buffer and interrupt the system; The network driver interface type calls the miniport interrupt function of the miniport driver on the CPU confirmed by the system; The interrupt service routine disables interrupts and requests the network interrupt interface type to queue the deferred procedure call to process the received data.

6. A method for supporting a default network card single queue as claimed in claim 5, characterized in that: The network card driver schedules a delayed procedure call to perform received packet scaling and distributes the data of the received packet to the system CPU, including: The network card driver schedules a delayed procedure call to append a hash function with a predefined hash key to the received packet; The network card driver calculates a hash value according to the hash key, and uses a plurality of least significant bits of the hash value to index an indirect table; The network card driver distributes the data of the received packet to the system CPU according to the value in the indirect table.

7. A method for supporting a default network card single queue as claimed in claim 5, characterized in that: The network driver interface type calls the miniport interrupt function of the miniport driver on the CPU confirmed by the system, including: The network driver interface type calls the miniport interrupt function of the miniport driver on the least busy CPU in the system, or the network driver interface type calls the miniport interrupt function of the miniport driver on an available CPU in the system, or the network driver interface type calls the miniport interrupt function of the miniport driver on the CPU associated with the network card in the system.

8. A device supporting a default network card single queue, characterized in that: The device comprises: A data acquisition module is used to obtain queue information of the network card; A data processing module, used for obtaining a buffer when the network card receives data according to the queue information of the network card, scaling the received packet by using a delayed procedure call, and filling the data of the received packet into the buffer for processing; A data modification module, configured to assign a default initial queue number of the network card to 1 according to the queue information of the network card and the initial queue number of the network card; The data writing module is used to register the interruption of the network card and add the default initial queue number of the network card to the buffer.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method steps according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Data receiving method and computer

    CN102571580A

  • Hash-based network card soft interrupt and load balancing method

    CN103049336A