A method and system for optimizing CPU resource occupation of PMD model
By introducing dynamic switching between polling and interrupt modes into the PMD model, combined with timer and timestamp judgment, CPU resource allocation is optimized, solving the problem of CPU resource waste and achieving efficient utilization of CPU resources and power saving.
Patent Information
- Application Number
- CN202410802183.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Priority Date
- 2023-12-14
- Filing Date
- 2024-06-20
- Publication Date
- 2026-02-27
- Estimated Expiration
- 2044-06-20
AI Technical Summary
In existing technologies, the PMD model cannot effectively utilize CPU resources due to the waste of CPU resources caused by interrupts, system calls, context switching, and multiple memory copies.
By dynamically switching between polling and interrupt modes, combined with timer and timestamp judgment, CPU resource usage is optimized. This includes configuration management, packet processing, interrupt and time management modules, enabling flexible allocation of CPU resources.
Without sacrificing overall performance and throughput, this reduces CPU resource usage, saves power, and improves CPU resource utilization efficiency.
Smart Images

Figure CN118796463B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of cloud computing device virtualization, and is a method and system for optimizing CPU resource occupation of a PMD model. BACKGROUND
[0002] With the rapid development of network and storage hardware devices, the traditional device packet processing method based on CPU interruption has reached the performance bottleneck of the CPU. In the current cloud computing scenario, the data packet acceleration software library and development platform based on the PMD model represented by DPDK and SPDK are widely used.
[0003] In the existing disclosed invention technology, a patent with application publication number CN112003797A discloses a virtualized DPDK network performance improvement method, system, terminal and storage medium, which comprises: collecting the queue transceiving amount of all network cards; calculating the CPU resource usage rate of each queue according to the queue transceiving amount of each network card; sorting all queues in descending order of CPU resource usage rate; sequentially distributing the queues to idle CPU cores in order of queue, until there is no idle CPU core, the CPU core carries a PMD thread; and the remaining queues are evenly distributed to all CPU cores.
[0004] For example, a patent with application publication number CN115391003A discloses a queuing delay control method and device for DPDK data packet processing, which comprises: polling the receiving queue of the network card, and determining the state of the receiving queue according to the current number of DPDK data packets in the receiving queue; if the state of the receiving queue is an idle state, then the PAUSE instruction is executed in a loop, and the time slice is obtained, and when the time slice is not used up, the current number of DPDK data packets in the receiving queue is reacquired; if the current number exceeds a preset threshold, then the state of the receiving queue is switched from the idle state to the busy state, and the DPDK data packets are processed.
[0005] The above-mentioned patent uses the method of dividing time slices by PAUSE instruction to reduce power consumption, while the present application uses the polling and interruption switching mode, which is more sensitive to burst traffic and can reduce the latency of burst data packets; at the same time, the number of CPU cores used will be reduced when the traffic is less, while the present application does not reduce the number of threads, but gives up CPU resources through polling and interruption switching, which reacts faster to burst traffic. SUMMARY
[0006] This section is intended to summarize some aspects of the embodiments of the present application and briefly introduce some preferred embodiments. Some simplifications or omissions may be made in this section and the abstract and title of the specification of the present application in order to avoid obscuring the purpose of this section, the abstract and the title, and such simplifications or omissions cannot be used to limit the scope of the present application.
[0007] The technical problem solved by the present application is that the prior art has the problem of huge overhead caused by processing interruption, system call, context switching and multiple memory copying, and the present application avoids waste of CPU resources and allows CPU resources to be used reasonably.
[0008] To achieve the above-mentioned purpose, the technical scheme of the method for optimizing CPU resource occupation of the PMD model comprises the following steps:
[0009] S1: reading and analyzing user requirements and configurations, and setting default configurations;
[0010] S2: starting to poll data packets, and extracting the number of data packet processing in a monitoring time;
[0011] S3: performing mode switching judgment and executing mode switching strategy;
[0012] S4: obtaining a timestamp by a timer and performing timestamp interval judgment, and executing an optimization strategy.
[0013] Specifically, in S1, the default configurations include: PMD_WINDOW_SEC=1, PMD_THRESHOLD=10, PMD_ROUND=60, INTR_WINDOW_USEC=1000, and INTR_THRESHOLD=10.
[0014] Specifically, in S1, the user requirements and configurations include: the user can modify the configurations according to requirements and perform accurate matching of user scenarios.
[0015] Specifically, in S1, when the user needs to use the polling mode forcibly and does not want to switch to the interruption mode, PMD_THRESHOLD can be set to 0.
[0016] Specifically, in S2, the extraction of the number of data packet processing in a monitoring time includes: when the application is in the polling mode, the number of data packets processed in a period of PMD_WINDOW_SEC seconds is counted once every PMD_WINDOW_SEC seconds.
[0017] Specifically, in S3, the mode switching judgment includes:
[0018] S31: when the number of data packets in a monitoring time is less than PMD_THRESHOLD, the pmd_cound count value is increased by 1;
[0019] S32: when the number of data packets in a monitoring time is greater than or equal to PMD_THRESHOLD, the pmd_cound count value is set to 0;
[0020] PMD_THRESHOLD.
[0021] S33: executing a mode switching strategy.
[0022] Specifically, in S33, the mode switching strategy comprises: when the pmd_count count value is equal to PMD_ROUND, switching to the interrupt mode.
[0023] Specifically, in S4, the time stamp interval judgment comprises: calculating the difference value Delta of the latest two recorded time stamps, and the calculation formula of the time stamp difference value is as follows: Delta = t i -t i+1 .
[0024] Specifically, in S4, the optimization strategy comprises: if the difference value of the latest two recorded time stamps is less than INTR_WINDOW_USEC microseconds, it indicates that there is burst traffic and it is necessary to switch to the polling mode immediately.
[0025] In addition, the system for optimizing the CPU resource occupation of the PMD model comprises the following modules:
[0026] a configuration management module, a data packet processing module, an interrupt module, and a time management module.
[0027] The configuration management module is configured to obtain user configurations and parse the user configurations.
[0028] The data packet processing module is configured to process the data packets sent by the interrupt or the data packets polled by the CPU.
[0029] The interrupt module is configured to receive device interrupt information and send the data packets to the data packet processing module for processing.
[0030] The time management module is configured to provide a timer function and obtain time stamps.
[0031] A storage medium, wherein instructions are stored in the storage medium, and when a computer reads the instructions, the computer executes the method for optimizing the CPU resource occupation of the PMD model according to any one of the preceding embodiments.
[0032] An electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, and when the processor executes the computer program, the method for optimizing the CPU resource occupation of the PMD model according to any one of the preceding embodiments is implemented.
[0033] Compared with the prior art, the technical effects of the present application are as follows:
[0034] 1. The present application can reduce the occupation of CPU resources without losing overall performance and throughput.
[0035] 2、The application can save electric energy in the time period of low traffic volume.
[0036] 3、The application uses the existing infrastructure, and compared with the prior art, compatibility is not lost. BRIEF DESCRIPTION OF DRAWINGS
[0037] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings needed to be used in the embodiment description will be briefly introduced as follows. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.
[0038] In the formula, n is an integer greater than or equal to 1.
[0039] Figure 1 A flowchart of a method for optimizing CPU resource occupation of a PMD model of the present application is shown in the figure.
[0040] Figure 2 A structural schematic diagram of a system for optimizing CPU resource occupation of a PMD model of the present application is shown in the figure. DETAILED DESCRIPTION
[0041] In order to make the above-mentioned objects, features and advantages of the present application more apparent and easy to understand, the specific embodiments of the present application will be described in detail below with reference to the drawings.
[0042] In the following description, many specific details are set forth in order to provide a thorough understanding of the present application, but the present application can also be practiced in other ways different from those described herein, and those skilled in the art can make similar generalizations without departing from the scope of the present application, therefore the present application is not limited to the specific embodiments disclosed below.
[0043] Secondly, the "one embodiment" or "embodiment" referred to herein means that the specific features, structures or characteristics can be included in at least one implementation of the present application. In this specification, "in one embodiment" appearing in different places does not mean the same embodiment, nor is it an independent or alternative embodiment that excludes other embodiments.
[0044] Embodiment one:
[0045] The polling mechanism of PMD also introduces new problems: the application process will continue to poll even when there is no packet or only a small amount of packet to be processed, and the CPU core used is always in full load, resulting in a large waste of computing resources and power.
[0046] The main implementation scenario of the embodiment is a cloud computing device virtualization scenario. An application program emulating a device runs in a user mode of a host on which a virtual device is located, uses a user mode device driver, and can switch between an interrupt mode and a polling mode.
[0047] As shown in Figure 1 , a method for optimizing CPU resource occupation of a PMD model according to an embodiment of the application includes the following specific steps: Figure 1
[0048] S1: reading and analyzing user requirements and configurations, and setting default configurations;
[0049] In S1, the default configurations include PMD_WINDOW_SEC = 1, PMD_THRESHOLD = 10, PMD_ROUND = 60, INTR_WINDOW_USEC = 1000, and INTR_THRESHOLD = 10.
[0050] In S1, the user requirements and configurations include that a user can modify the configurations according to requirements and perform accurate matching of user scenarios.
[0051] S2: starting polling processing of data packets, and extracting a number of data packets processed in a monitoring time;
[0052] In S2, the extracting of the number of data packets processed in the monitoring time includes that when the application program is in the polling mode, the number of data packets processed in a PMD_WINDOW_SEC second is counted every time.
[0053] S3: performing mode switching judgment and executing a mode switching strategy;
[0054] In S3, the mode switching judgment includes:
[0055] S31: when the number of data packets in a monitoring time is less than PMD_THRESHOLD, increasing a pmd_count value by 1;
[0056] S32: when the number of data packets in a monitoring time is greater than or equal to PMD_THRESHOLD, setting the pmd_count value to 0;
[0057]
[0058] S33: executing the mode switching strategy.
[0059] In S33, the mode switching strategy includes: when the pmd_count value is equal to PMD_ROUND, switching to the interrupt mode.
[0060] S4: obtaining a timestamp by timing a timer, and performing a timestamp interval judgment, and executing an optimization strategy.
[0061] In S4, the timestamp interval judgment includes calculating a timestamp difference value Δ of the last two recorded timestamps, and the formula for calculating the timestamp difference value is as follows: Δ = t i -t i+1 .
[0062] In S4, the optimization strategy includes: if the difference value of the last two recorded timestamps is less than INTR_WINDOW_USEC microseconds, it indicates that there is burst traffic, and it is necessary to switch to the polling mode immediately.
[0063] Embodiment two:
[0064] In this embodiment, the PMD model can bring high performance and high throughput, but because it is a polling mode, it cannot flexibly control the CPU computing power used, and the CPU core is always in maximum load; the traditional interrupt mode has a large overhead in processing data packets, and the overall performance and throughput are low, but thanks to the asynchronous mechanism, it has high flexibility, and the CPU resource overhead depends entirely on the number of data packets, and even when there is no data packet, there will be no resource overhead.
[0065] As shown in FIG. 1, a system for optimizing CPU resource occupation of a PMD model according to an embodiment of the present application includes the following modules: Figure 2 As shown in FIG. 1, a system for optimizing CPU resource occupation of a PMD model according to an embodiment of the present application includes the following modules: Figure 2 As shown in FIG. 1, a system for optimizing CPU resource occupation of a PMD model according to an embodiment of the present application includes the following modules:
[0066] A configuration management module, a data packet processing module, an interrupt module, and a time management module.
[0067] The configuration management module is configured to obtain user configuration and parse the user configuration.
[0068] The data packet processing module is configured to process data packets sent by an interrupt or obtained by CPU polling.
[0069] The interrupt module is configured to receive device interrupt information and send data packets to the data packet processing module for processing.
[0070] The time management module is configured to provide a timer function and obtain a timestamp.
[0071] Embodiment three:
[0072] The embodiment provides an electronic device, including a processor and a memory, wherein the memory stores a computer program that can be called by the processor.
[0073] The processor executes the above-mentioned optimization of CPU resource occupation of a PMD model by calling the computer program stored in the memory.
[0074] The electronic device can have a large difference due to configuration or performance, and can include one or more processors (Central Processing Units, CPUs) and one or more memories, wherein the memory stores at least one computer program, and the computer program is loaded and executed by the processor to implement the method for optimizing CPU resource occupation of the PMD model provided in the above method embodiments. The electronic device can also include other components for implementing device functions, for example, the electronic device can also have a wired or wireless network interface and an input and output interface, and the like, so as to perform input and output of data. This embodiment will not be described here.
[0075] Embodiment four:
[0076] The embodiment provides a computer readable storage medium, which stores an erasable computer program.
[0077] When the computer program runs on the computer device, the computer device executes the method for optimizing CPU resource occupation of the PMD model.
[0078] For example, the computer readable storage medium can be a read-only memory (Read-Only Memory, ROM for short), a random access memory (Random Access Memory, RAM for short), a read-only compact disc (Compact Disc Read-Only Memory, CD-ROM for short), a magnetic tape, a floppy disk and an optical data storage device, etc.
[0079] It should be understood that, in various embodiments of the present application, the size of the sequence number of each process described above does not mean the order of execution, and the execution order of each process should be determined according to its function and inherent logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0080] It should be understood that, according to A, B is determined, which does not mean that B is determined only according to A, but also can be determined according to A and / or other information.
[0081] The above-described embodiments can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented in software, the above-described embodiments can be implemented in the form of a computer program product. The computer program product includes one or more computer instructions or computer programs. When the computer instructions or computer programs are loaded or executed on a computer, the processes or functions according to the embodiments of the present application are wholly or partially generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium or transferred from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions can be transferred from one website, computer, server, or data center to another website, computer, server, or data center through a wired network or / and a wireless network. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. containing one or more available medium collections. The available medium can be a magnetic medium (for example, a floppy disk, a hard disk, a magnetic tape), an optical medium (for example, a DVD), or a semiconductor medium. The semiconductor medium can be a solid-state disk.
[0082] Those skilled in the art can clearly understand that the units and algorithm steps of the examples described in combination with the embodiments disclosed in the present application can be realized by electronic hardware or a combination of computer software and electronic hardware. Whether the functions are realized in hardware or software depends on the specific application and design constraints of the technical solution. The skilled person can use different methods to realize the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.
[0083] Those skilled in the art can clearly understand that, for the convenience and brevity of the description, the specific working processes of the above-described system, device, and unit can refer to the corresponding processes in the foregoing method embodiments, which will not be described here.
[0084] In several embodiments provided by the present application, it should be understood that the disclosed system, device, and method can be implemented in other ways. For example, the above-described device embodiments are merely schematic, for example, the division of units is only one, and actual implementation can have another division manner, for example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the displayed or discussed units can be indirect coupling or communication connection through some interfaces, devices, or units, which can be electrical, mechanical, or other forms.
[0085] The units described as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiment of the present application.
[0086] In addition, each functional unit in each embodiment of the present application can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit.
[0087] In the description of the present application, the description of the terms "one embodiment", "example", "specific example" and the like means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In the present application, the illustrative description of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any one or more embodiments or examples in a suitable manner.
[0088] In summary, compared with the prior art, the technical effects of the present application are as follows:
[0089] 1. The present application can reduce the occupation of CPU resources without losing overall performance and throughput.
[0090] 2. The present application can save power energy during the time period of low traffic volume.
[0091] 3. The present application uses existing infrastructure, and compared with the prior art, it does not lose compatibility.
[0092] The above shows and describes the basic principles and main features of the present application and the advantages of the present application. It should be understood by those skilled in the art that the present application is not limited by the above embodiments, and the above embodiments and descriptions in the specification are only to illustrate the principles of the present application. Without departing from the spirit and scope of the present application, various changes and improvements can be made to the present application, and these changes and improvements all fall within the scope of the present application. The scope of protection of the present application is defined by the appended claims and their equivalents.
Claims
1. A method for optimizing CPU resource usage in a PMD model, characterized in that: The method includes the following specific steps: S1: Read and parse user requirements and configurations, and set default configurations; S2: Start polling and processing data packets, and extract the number of data packets processed within the monitoring time. The extraction of the number of data packets processed within the monitoring time includes: when the application is in polling mode, counting the number of data packets processed within this time period every PMD_WINDOW_SEC seconds. S3: Perform mode switching judgment and execute the mode switching strategy; S4: Obtain timestamps by timing with a timer, determine the timestamp interval, and execute optimization strategies; The timestamp interval determination includes: calculating the timestamp difference Δ between the two most recent records. The formula for calculating the timestamp difference is as follows: Δ = t i -t i+1 ; The optimization strategy includes: if the difference between the timestamps of the current and subsequent records is less than INTR_WINDOW_USEC microseconds, it indicates that there is a sudden traffic surge and it is necessary to immediately switch to polling mode; In step S3, the mode switching determination includes: S31: When the number of data packets is less than PMD_THRESHOLD within a monitoring period, increment the pmd_cound count value by 1; S32: When the number of data packets within a monitoring period is greater than or equal to PMD_THRESHOLD, set the pmd_cound count value to 0; S33: Execution mode switching strategy; In S33, the mode switching strategy includes: when the pmd_count count value is equal to PMD_ROUND, switching to interrupt mode.
2. The method for optimizing CPU resource usage in a PMD model according to claim 1, characterized in that, In S1, the default configuration includes: PMD_WINDOW_SEC = 1, PMD_THRESHOLD = 10, PMD_ROUND = 60. INTR_WINDOW_USEC=1000, INTR_THRESHOLD=10.
3. The method for optimizing CPU resource usage in a PMD model according to claim 2, characterized in that, In S1, the user requirements and configurations include: users can modify the configuration according to their needs and perform precise matching of user scenarios.
4. The method for optimizing CPU resource usage in a PMD model according to claim 1, characterized in that, In S1, if a user needs to force the use of polling mode and does not want to switch to interrupt mode, PMD_THRESHOLD can be set to 0.
5. A system for optimizing CPU resource usage in a PMD model, implemented based on a method for optimizing CPU resource usage in a PMD model as described in any one of claims 1-4, characterized in that, The system includes the following modules: Configuration management module, data packet processing module, interrupt module, time management module; The configuration management module is used to obtain and parse user configurations. The data packet processing module is used to process data packets sent via interrupt or polled by the CPU; The interrupt module is used to receive device interrupt information and send data packets to the data packet processing module for processing. The time management module is used to provide timer functionality and obtain timestamps.
Citation Information
Patent Citations
Virtualized DPDK network performance improvement method and system, terminal and storage medium
CN112003797A
Queuing delay control method and device for DPDK data packet processing
CN115391003A
Data flow monitoring method, device and system
CN108076477A
DPDK (Data Plane Development Kit)-based resource scheduling method and device, terminal equipment and readable storage medium
CN108345502A
Hybrid polling method, apparatus and device, and readable storage medium
CN115686863A