Data Packet Receiving Method, Apparatus, Electronic Device, and Storage Medium

By optimizing the NAPI packet collection mechanism in Linux system, judging and limiting the number and duration of data packet reception, the problem of excessive CPU consumption when the data volume is large and excessive CPU time is occupied by small data volume, and the reliability of the device when network data floods is improved.

CN114371942BActive Publication Date: 2025-06-13RUIJIE NETWORKS CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202111595979.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-24
Publication Date
2025-06-13
Estimated Expiration
2041-12-24

AI Technical Summary

Technical Problem

In the prior art, Linux systems adopt NAPI mechanism when receiving data packets, resulting in excessive interruption when the data volume is large, consume a lot of CPU time, is not efficient, and takes up a lot of CPU time when the data volume is small, resulting in equipment failure when the network data is flooded, affecting the reliability of the equipment.

Method used

After responding to the packet receivable interrupt event and closing the packet receivable interrupt, it is determined whether the packet receiving number of data packets received by the packet collection work queue is greater than the first preset number threshold and the packet receiving time is less than the first preset time. If so, the second preset time is sleepy; otherwise, the packet receiving work queue is started to receive data packets, and the packet receiving number and packet receiving time of data packets collected this time are recorded.

Benefits of technology

By optimizing the NAPI packet collection mechanism of the network port driver, limiting the number of CPU packet collection within the preset time, avoiding device failures caused by network data flooding, and improving device reliability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114371942B_ABST
    Figure CN114371942B_ABST
Patent Text Reader

Abstract

An embodiment of the present invention provides a data packet receiving method, apparatus, electronic device, and storage medium. The method includes: after responding to a packet receiving interruption event and closing the packet receiving interruption, determining whether the number of received packets in the last received packet on the packet receiving work queue is greater than a first preset quantity threshold and the packet receiving time is less than a first preset duration; if so, sleeping for a second preset duration; if not, starting the packet receiving work queue to receive data packets, and recording the number of received packets and the packet receiving time of the currently received data packets. The data packet receiving method provided by the embodiment of the present invention effectively solves the problem of device failure caused by network data flooding by optimizing the NAPI packet receiving mechanism of the network interface driver, and improves the reliability of the device.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present invention relate to the field of communication technologies, and in particular, to a method, apparatus, electronic device, and storage medium for receiving data packets. Background Art

[0002] In the prior art, the Linux system adopts the NAPI (New API) mechanism when receiving data packets. This mechanism combines the interrupt mode and the polling mode. The advantage of the interrupt is that the response is timely. If the amount of data is small, it will not occupy too much CPU time. The disadvantage is that when the amount of data is large, too many interrupts will be generated, and each interrupt will consume a lot of CPU time, resulting in lower efficiency than polling. The polling mode is the opposite of the interrupt mode. It is more suitable for processing a large amount of data because each polling does not consume too much CPU time. The disadvantage is that even when only a small amount of data is received or no data is received, it will still occupy CPU time. NAPI is a combination of the two. The interrupt mode is used when the amount of data is low, and the polling mode is used when the amount of data is high.

[0003] When a data packet arrives, first store the data packet in the buffer area, then open the packet receiving interrupt, and enter the packet receiving interrupt processing flow. In the packet receiving interrupt processing flow, first close the packet receiving interrupt, and then wait for the corresponding polling function to be scheduled. When the polling function is scheduled, read a certain number of data packets each time. If there are still extra data packets in the buffer area after reading the data packets, wait to read them when the polling function is scheduled next time. If the data packets in the buffer area have been received completely, exit the polling and reopen the packet receiving interrupt.

[0004] When a large number of packets are received, the packet receiving driver will be in the polling state of the packet receiving work queue, which belongs to the soft interrupt level and will preempt CPU resources, resulting in other services being unable to be scheduled normally. Summary of the Invention

[0005] In view of the defects in the prior art, embodiments of the present invention provide a method, apparatus, electronic device, and storage medium for receiving data packets.

[0006] In a first aspect, an embodiment of the present invention provides a method for receiving data packets, including:

[0007] After responding to the packet receiving interrupt event and closing the packet receiving interrupt, determine whether the number of received packets in the packet receiving work queue last time is greater than a first preset quantity threshold and the packet receiving time is less than a first preset duration;

[0008] If so, sleep for a second preset duration;

[0009] If not, start the packet receiving work queue to receive data packets, and record the number of received packets and the packet receiving time of the data packets received this time.

[0010] As in the above method, optionally, after determining whether the number of received packets in the last received packet on the packet receiving work queue is greater than a first preset number threshold and the packet receiving time is less than a first preset duration, the method further includes:

[0011] Clear the number of received packets and the packet receiving time recorded when the packet receiving work queue received the last packet.

[0012] As in the above method, optionally, the second preset duration is equal to the difference between the first preset duration and the packet receiving time.

[0013] As in the above method, optionally, before responding to the packet receiving interruption event, the method further includes:

[0014] Determine the first preset number threshold and the first preset duration according to the number of CPU cores.

[0015] As in the above method, optionally, after sleeping for the second preset duration, the method further includes:

[0016] Enable the packet receiving interruption.

[0017] As in the above method, optionally, starting the packet receiving work queue to receive packets and recording the number of received packets and the packet receiving time of the currently received packets includes:

[0018] Start the packet receiving work queue to receive packets:

[0019] Update the number of received packets of the currently received packets;

[0020] If the number of received packets is greater than a second preset number threshold or it is determined that all packets have been received, stop receiving packets and determine the packet receiving time of the currently received packets;

[0021] Enable the packet receiving interruption.

[0022] In a second aspect, an embodiment of the present invention provides a packet receiving device, including:

[0023] A judgment module, configured to judge whether the number of received packets in the last received packet on the packet receiving work queue is greater than a first preset number threshold and the packet receiving time is less than a first preset duration after responding to the packet receiving interruption event and closing the packet receiving interruption;

[0024] A sleep module, configured to sleep for a second preset duration if the number of received packets in the last received packet on the packet receiving work queue is greater than a first preset number threshold and the packet receiving time is less than a first preset duration;

[0025] A packet receiving module, which is used to start receiving packets by the packet receiving work queue if the number of received packets in the previous reception by the packet receiving work queue is not greater than a first preset quantity threshold or the packet receiving time is not less than a first preset duration, and record the number of received packets and the packet receiving time of the packets received this time.

[0026] For the above-mentioned device, optionally, it further includes: a recording module, and the recording module is used for:

[0027] After determining that the number of received packets in the previous reception by the packet receiving work queue is greater than the first preset quantity threshold and the packet receiving time is less than the first preset duration, clear the number of received packets and the packet receiving time recorded when the packet receiving work queue received packets last time.

[0028] For the above-mentioned device, optionally, the second preset duration is equal to the difference between the first preset duration and the packet receiving time.

[0029] For the above-mentioned device, optionally, it further includes a determination module, and the determination module is used for:

[0030] Before responding to the packet receiving interruption event, determine the first preset quantity threshold and the first preset duration according to the number of CPU cores.

[0031] For the above-mentioned device, optionally, it further includes an enabling module, and the enabling module is used for:

[0032] After sleeping for the second preset duration, enable the packet receiving interruption.

[0033] For the above-mentioned device, optionally, the packet receiving module is specifically used for:

[0034] Start receiving packets by the packet receiving work queue:

[0035] Update the number of received packets of the packets received this time;

[0036] If the number of received packets is greater than the second preset quantity threshold or it is determined that all packets have been received, stop receiving packets, and determine the packet receiving time of the packets received this time;

[0037] Enable the packet receiving interruption.

[0038] In a third aspect, an embodiment of the present invention provides an electronic device, including:

[0039] A memory and a processor, where the processor and the memory communicate with each other through a bus; the memory stores program instructions executable by the processor, and the processor can execute the following method by invoking the program instructions: after responding to a packet reception interrupt event and closing the packet reception interrupt, determine whether the number of received packets in the last packet reception on the packet reception work queue is greater than a first preset quantity threshold and the packet reception time is less than a first preset duration; if so, sleep for a second preset duration; if not, start the packet reception work queue to receive packets, and record the number of received packets and the packet reception time of the currently received packets.

[0040] In a fourth aspect, an embodiment of the present invention provides a storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the following method is implemented: after responding to a packet reception interrupt event and closing the packet reception interrupt, determine whether the number of received packets in the last packet reception on the packet reception work queue is greater than a first preset quantity threshold and the packet reception time is less than a first preset duration; if so, sleep for a second preset duration; if not, start the packet reception work queue to receive packets, and record the number of received packets and the packet reception time of the currently received packets.

[0041] The packet reception method provided by the embodiment of the present invention, after responding to a packet reception interrupt event and closing the packet reception interrupt, determines whether the number of received packets in the last packet reception on the packet reception work queue is greater than a first preset quantity threshold and the packet reception time is less than a first preset duration; if so, sleep for a second preset duration; if not, start the packet reception work queue to receive packets, and record the number of received packets and the packet reception time of the currently received packets. By optimizing the NAPI packet reception mechanism of the network interface driver, the problem of network data flooding causing device failures is effectively solved, and the reliability of the device is improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the following drawings are some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0043] Figure 1 It is a schematic flowchart of the packet reception method provided by the embodiment of the present invention;

[0044] Figure 2 It is a schematic flowchart of the packet reception method provided by another embodiment of the present invention;

[0045] Figure 3 It is a schematic structural diagram of the packet reception device provided by the embodiment of the present invention;

[0046] Figure 4 Schematic structural diagram of the electronic device provided by an embodiment of the present invention. Detailed implementation manners

[0047] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Apparently, the described embodiments are some but not all of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.

[0048] Figure 1 Schematic flowchart of the data packet receiving method provided by an embodiment of the present invention, as Figure 1 shown, the method includes:

[0049] Step S11: Respond to the packet receiving interruption event and turn off the packet receiving interruption;

[0050] Specifically, in the management network of the data center, data flooding may occur. When a large number of packets are received by the network interface, it will occupy the CPU resources, resulting in a high CPU utilization rate, and other services cannot run properly. Even worse, it may cause the watchdog timeout and reboot. The existing NAPI mechanism uses a hybrid interruption and polling method to receive packets. When a data packet arrives at the network interface, it will trigger a packet receiving interruption event. At this time, the interruption handling function of the network interface driver will turn off the packet receiving interruption and notify the packet receiving work queue in the CPU kernel to receive packets. The kernel soft interruption polls the current network interface and tries to receive as many packets as possible within a specified time. When the time runs out or there is no data to receive, the kernel turns on the packet receiving interruption again to prepare for the next packet receiving. However, the polling operation in NAPI belongs to the soft interruption level and will preempt the CPU resources, resulting in the inability to normally schedule other services. To solve this problem, in the embodiments of the present invention, after responding to the packet receiving interruption event and turning off the packet receiving interruption, instead of immediately entering the packet receiving process, a judgment on whether to limit the speed is made. For details, refer to step S12.

[0051] Step S12: Judge whether the number of received packets of the packet received by the packet receiving work queue last time is greater than a first preset number threshold and the packet receiving time is less than a first preset duration; if so, execute step S13, otherwise execute step S14;

[0052] Specifically, after turning off the packet receiving interruption, judge whether the number of received packets of the packet received by the packet receiving work queue last time is greater than a first preset number threshold N1, and whether the packet receiving time of the packet received by the packet receiving work queue last time is less than a first preset duration T1. If so, it indicates that a large number of packets have been received by the packet receiving work queue in a short time, and a packet receiving speed limiting operation needs to be performed on the network interface. If not, the packet receiving can continue.

[0053] Step S13: Sleep for a second preset duration;

[0054] Specifically, if packet reception rate limiting operation needs to be performed on the network interface, start the countdown work queue and sleep for a second preset duration T2. During the T2 duration of sleep, the CPU will stop receiving packets, and other threads can be normally scheduled to ensure the normal operation of the device. After the sleep ends, the packet reception interrupt can be enabled again to wait for the next packet reception interrupt event.

[0055] Step S14: Start the packet reception work queue to receive data packets, and record the number of received packets and the packet reception time consumption of the data packets received this time.

[0056] Specifically, if packet reception rate limiting operation does not need to be performed on the network interface, start the packet reception work queue to receive data packets, and record the number of received packets and the packet reception time consumption of the data packets received this time.

[0057] The data packet reception method provided by the embodiment of the present invention, after responding to the packet reception interrupt event and closing the packet reception interrupt, determines whether the number of received packets of the data packets received by the packet reception work queue last time is greater than a first preset quantity threshold and the packet reception time consumption is less than a first preset duration; if so, sleep for a second preset duration; if not, start the packet reception work queue to receive data packets, and record the number of received packets and the packet reception time consumption of the data packets received this time. By optimizing the network interface driver NAPI packet reception mechanism, the problem of device failure caused by network data flooding is effectively solved, and the reliability of the device is improved.

[0058] On the basis of the above embodiments, further, after determining whether the number of received packets of the data packets received by the packet reception work queue last time is greater than a first preset quantity threshold and the packet reception time consumption is less than a first preset duration, it further includes:

[0059] Clear the number of received packets and the packet reception time consumption recorded when the packet reception work queue received data packets last time.

[0060] Specifically, after determining whether the number of received packets last time is greater than a first preset quantity threshold and the packet reception time consumption is less than a first preset duration, the previous data is no longer needed. Clear the number of received packets and the packet reception time consumption recorded when the packet reception work queue received data packets last time to prepare for the next record.

[0061] On the basis of the above embodiments, further, the second preset duration is equal to the difference between the first preset duration and the packet reception time consumption. Before responding to the packet reception interrupt event, it further includes:

[0062] Determine the first preset quantity threshold and the first preset duration according to the number of CPU cores.

[0063] Specifically, the first preset duration and the first preset quantity threshold can be understood as the time period and the number of received packets that need speed limiting. That is, within the first preset duration, at most the first preset number of packets can be received. Therefore, if the number of received packets in the previous time is greater than the first preset quantity threshold and the packet receiving time is less than the first preset duration, then the packet receiving can be prohibited in the remaining time period obtained by subtracting the packet receiving time from the first preset duration. That is, set the second preset duration equal to the difference between the first preset duration and the packet receiving time. When network data floods, the time taken to receive the first preset quantity threshold of packets at the network interface will be less than the first preset duration. During the remaining second preset duration, the CPU will stop receiving packets, and other threads can be normally scheduled to ensure the normal operation of the device. Among them, the granularity of the first preset duration should not be too large or too small. If it is too small, the speed limiting logic will be frequently entered; if it is too large, the speed limiting and packet receiving will not be uniform enough. In practical applications, the first preset quantity threshold and the first preset duration can be set according to the number of cores in the CPU. For example, if the CPU is a single-core CPU, set the first preset quantity threshold to 50 and the first preset duration to 50 ms, that is, the speed limit is 50 packets in 50 ms; for a multi-core CPU, set the first preset quantity threshold to 500 and the first preset duration to 50 ms, that is, 500 packets can be speed limited in 50 ms. After the sleep time is reached, the packet receiving interrupt is enabled again to wait for the next packet reception.

[0064] Based on the above embodiments, further, starting the packet receiving work queue to receive data packets and recording the number of received packets and the packet receiving time of the currently received data packets includes:

[0065] Starting the packet receiving work queue to receive data packets:

[0066] Updating the number of received packets of the currently received data packets;

[0067] If the number of received packets is greater than the second preset quantity threshold or it is determined that all data packets have been received, stop receiving data packets and determine the packet receiving time of the currently received data packets;

[0068] Enabling the packet receiving interrupt.

[0069] Specifically, if speed limiting of the network interface is not required, start the packet receiving work queue to receive data packets and record the number of received packets of the currently received data packets. If the number of received packets is greater than the second preset quantity threshold or it is determined that all data packets have been received, stop receiving data packets and determine the packet receiving time of the currently received data packets. Finally, enable the packet receiving interrupt to wait for the next packet reception, where the second preset quantity threshold is the number of received packets set by NAPI and can be set to 300, for example, that is, 300 data packets are received in response to one packet receiving interrupt.

[0070] Figure 2 It is a schematic flowchart of the data packet receiving method provided by another embodiment of the present invention, as Figure 2As shown in the figure, the method includes:

[0071] Step S20: Receive a packet reception interruption event and close the interruption

[0072] Step S21: Determine whether the number of packets received by the packet reception work queue in the previous packet reception is greater than the first preset quantity threshold N1 and the packet reception time is less than the first preset duration T1. If so, execute Step S22; otherwise, execute Step S23.

[0073] Step S22: Start the countdown work queue, sleep for the second preset duration T2. After the sleep is completed, execute Step S29.

[0074] Step S23: Start the packet reception work queue.

[0075] Step S24: The packet reception work queue starts to perform packet reception processing.

[0076] Step S25: The packet reception work queue records the number of packets received and the packet reception time for this packet reception.

[0077] Step S26: Determine whether the packet reception is completed. If so, execute Step S28; otherwise, execute Step S27.

[0078] Step S27: Determine whether the number of packets received is greater than the second preset quantity threshold N2. If so, execute Step S28; otherwise, execute Step S24.

[0079] Step S28: The packet reception ends.

[0080] Step S29: Open the interruption and wait for the next packet reception interruption.

[0081] The packet reception method provided by the embodiment of the present invention optimizes the NAPI packet reception mechanism of the network interface driver, limits the number of packets received by the CPU within a preset duration, avoids device failures caused by network data flooding, and improves the reliability of the device.

[0082] Based on the same inventive concept, the embodiment of the present invention further provides a packet reception device, as Figure 3 shown, including: a judgment module 31, a sleep module 32, and a packet reception module 33, where:

[0083] The determination module 31 is used to determine whether the packet receiving quantity of the packet received last time on the packet receiving work queue is greater than a first preset quantity threshold and the packet receiving time is less than a first preset duration after responding to the packet receiving interruption event and closing the packet receiving interruption; the sleep module 32 is used to sleep for a second preset duration if the packet receiving quantity of the packet received last time on the packet receiving work queue is greater than the first preset quantity threshold and the packet receiving time is less than the first preset duration; the packet receiving module 33 is used to start the packet receiving work queue to receive packets and record the packet receiving quantity and the packet receiving time of the packets received this time if the packet receiving quantity of the packet received last time on the packet receiving work queue is not greater than the first preset quantity threshold or the packet receiving time is not less than the first preset duration.

[0084] For the above device, optionally, it further includes: a recording module, and the recording module is used for:

[0085] After determining whether the packet receiving quantity of the packet received last time on the packet receiving work queue is greater than the first preset quantity threshold and the packet receiving time is less than the first preset duration, clear the packet receiving quantity and the packet receiving time recorded when the packet received last time on the packet receiving work queue.

[0086] For the above device, optionally, the second preset duration is equal to the difference between the first preset duration and the packet receiving time.

[0087] For the above device, optionally, it further includes a determination module, and the determination module is used for:

[0088] Before responding to the packet receiving interruption event, determine the first preset quantity threshold and the first preset duration according to the number of CPU cores.

[0089] For the above device, optionally, it further includes an enabling module, and the enabling module is used for:

[0090] After sleeping for the second preset duration, enable the packet receiving interruption.

[0091] For the above device, optionally, the packet receiving module 33 is specifically used for:

[0092] Start the packet receiving work queue to receive packets:

[0093] Update the packet receiving quantity of the packets received this time;

[0094] If the packet receiving quantity is greater than a second preset quantity threshold or it is determined that all packets have been received, stop receiving packets and determine the packet receiving time of the packets received this time;

[0095] Enable the packet receiving interruption.

[0096] The device provided by the embodiment of the present invention is used to implement the above method, and its functions are specifically referred to the above method embodiment, and will not be elaborated here.

[0097] Figure 4 A structural schematic diagram of the electronic device provided by an embodiment of the present invention is shown as Figure 4 shown. The device includes: a processor 41, a memory 42, and a bus 43;

[0098] Among them, the processor 41 and the memory 42 complete communication with each other through the bus 43;

[0099] The processor 41 is configured to call program instructions in the memory 42 to execute the methods provided by the above method embodiments. For example, it includes: after responding to a packet reception interrupt event and closing the packet reception interrupt, determining whether the packet reception quantity of the packet received last time on the packet reception work queue is greater than a first preset quantity threshold and the packet reception time consumption is less than a first preset duration; if so, sleeping for a second preset duration; if not, starting the packet reception work queue to receive packets, and recording the packet reception quantity and packet reception time consumption of the packets received this time.

[0100] An embodiment of the present invention discloses a computer program product. The computer program product includes a computer program stored on a non-transitory computer-readable storage medium. The computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the methods provided by the above method embodiments. For example, it includes: after responding to a packet reception interrupt event and closing the packet reception interrupt, determining whether the packet reception quantity of the packet received last time on the packet reception work queue is greater than a first preset quantity threshold and the packet reception time consumption is less than a first preset duration; if so, sleeping for a second preset duration; if not, starting the packet reception work queue to receive packets, and recording the packet reception quantity and packet reception time consumption of the packets received this time.

[0101] An embodiment of the present invention provides a non-transitory computer-readable storage medium. The non-transitory computer-readable storage medium stores computer instructions. The computer instructions cause the computer to execute the methods provided by the above method embodiments. For example, it includes: after responding to a packet reception interrupt event and closing the packet reception interrupt, determining whether the packet reception quantity of the packet received last time on the packet reception work queue is greater than a first preset quantity threshold and the packet reception time consumption is less than a first preset duration; if so, sleeping for a second preset duration; if not, starting the packet reception work queue to receive packets, and recording the packet reception quantity and packet reception time consumption of the packets received this time.

[0102] Those of ordinary skill in the art can understand that all or part of the steps of implementing the above method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps including those of the above method embodiments; and the aforementioned storage medium includes: various media such as ROM, RAM, magnetic disks, or optical discs that can store program codes.

[0103] The above-described device and other embodiments are merely illustrative. The units described as separate components may or may not be physically separated. The components shown as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art can understand and implement it without creative efforts.

[0104] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the essence of the above technical solution, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disks, optical discs, etc., and includes several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0105] Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the embodiments of the present invention, and not to limit them; although the embodiments of the present invention have been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements on some or all of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for receiving data packets, characterized in that, it includes: Determine a first preset quantity threshold and a first preset duration according to the number of CPU cores; After responding to the packet receiving interrupt event and closing the packet receiving interrupt, determine whether the number of received packets of the last received packet on the packet receiving work queue is greater than the first preset quantity threshold and the packet receiving time is less than the first preset duration; If so, sleep for a second preset duration; the second preset duration is equal to the difference between the first preset duration and the packet receiving time; If not, start the packet receiving work queue to receive data packets, and record the number of received packets and the packet receiving time of the currently received data packets.

2. The method according to claim 1, characterized in that, after determining whether the number of received packets of the last received packet on the packet receiving work queue is greater than the first preset quantity threshold and the packet receiving time is less than the first preset duration, it further includes: Clear the number of received packets and the packet receiving time recorded when the last received packet on the packet receiving work queue was received.

3. The method according to claim 1, characterized in that, after sleeping for the second preset duration, it further includes: Enable the packet receiving interrupt.

4. The method according to any one of claims 1-3, characterized in that, starting the packet receiving work queue to receive data packets, and recording the number of received packets and the packet receiving time of the currently received data packets includes: Start the packet receiving work queue to receive data packets: Update the number of received packets of the currently received data packets; If the number of received packets is greater than the second preset quantity threshold or it is determined that all data packets have been received, stop receiving data packets, and determine the packet receiving time of the currently received data packets; Enable the packet receiving interrupt.

5. A data packet receiving device, characterized in that, it includes: A determination module for determining a first preset quantity threshold and a first preset duration according to the number of CPU cores; A judgment module for determining whether the number of received packets of the last received packet on the packet receiving work queue is greater than the first preset quantity threshold and the packet receiving time is less than the first preset duration after responding to the packet receiving interrupt event and closing the packet receiving interrupt; A sleep module for sleeping for a second preset duration if the number of received packets of the last received packet on the packet receiving work queue is greater than the first preset quantity threshold and the packet receiving time is less than the first preset duration; The second preset duration is equal to the difference between the first preset duration and the packet receiving time; A packet receiving module for starting the packet receiving work queue to receive data packets and recording the number of received packets and the packet receiving time of the currently received data packets if the number of received packets of the last received packet on the packet receiving work queue is not greater than the first preset quantity threshold or the packet receiving time is not less than the first preset duration.

6. The device according to claim 5, characterized in that, the packet receiving module is specifically used for: Start the packet receiving work queue to receive data packets: Update the number of received packets of the currently received data packets; If the number of received packets is greater than the second preset quantity threshold or it is determined that all data packets have been received, stop receiving data packets, and determine the packet receiving time of the currently received data packets; Enable the packet receiving interrupt.

7. An electronic device, characterized in that, it includes: A memory and a processor, the processor and the memory communicate with each other through a bus; The memory stores program instructions executable by the processor, and the processor can execute the method according to any one of claims 1 to 4 by invoking the program instructions.

8. A computer-readable storage medium, on which a computer program is stored, characterized in that, when the computer program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.

Citation Information

Patent Citations

  • Network packet receiving mode automatic adjustment method

    CN111580949A