Cpu resource control method and apparatus, and computer readable storage medium

By detecting and adjusting processes whose CPU resource usage exceeds a threshold in virtual machines, the number of VIPs is reduced, thus solving the problem of CPU resource waste in virtualization scenarios and achieving more efficient CPU load balancing.

CN116560840BActive Publication Date: 2026-11-20BLACK SESAME TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310524165.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-05-05
Publication Date
2026-11-20
Estimated Expiration
2043-05-05

AI Technical Summary

Technical Problem

Existing CPU load balancing technologies cannot identify the increased CPU consumption of the Hypervisor in virtualization scenarios when handling VPPI, resulting in wasted CPU resources.

Method used

By detecting processes in virtual machines that consume CPU resources exceeding a threshold, the number of virtual CPUs they use is adjusted, gradually reducing the number of VPPIs generated during migration, until a single virtual CPU is allocated to the target process, thus reducing resource waste.

Benefits of technology

It effectively reduces the waste of CPU resources in virtual machines, reduces CPU overhead caused by process migration, and optimizes CPU load balancing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116560840B_ABST
    Figure CN116560840B_ABST
Patent Text Reader

Abstract

The application provides a CPU resource control method, device and computer readable storage medium. The method comprises the following steps: detecting CPU resources occupied by multiple processes in a virtual machine, wherein the virtual machine has multiple virtual CPUs; regarding a process whose occupied CPU resources exceed a preset threshold as a target process which needs to adjust the used CPU, and calculating the number of CPUs to be used by the target process according to the number of times the target process has been adjusted, wherein the number of CPUs to be used by the target process decreases to 1 with the increase of the number of times the target process has been adjusted; when the number of CPUs to be used by the target process is 1, the target process is no longer detected; and selecting at least one CPU from the multiple CPUs for the target process to use according to the number of CPUs to be used by the target process, the occupied CPU resources of the target process and the remaining resources of the multiple CPUs. The application can effectively reduce the resource waste caused by the virtual machine CPU load balancing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and more specifically to a CPU resource control method, apparatus, and computer-readable storage medium. Background Technology

[0002] In SMP (Symetric Multiprocessing) systems, to effectively utilize the computing power of each CPU, the operating system automatically performs CPU load balancing. This operation results in process migration, such as moving a process from CPU A to CPU B. This migration operation is implemented at the underlying level by a hardware mechanism called IPI (Inter Processor Interrupt).

[0003] like Figure 1 As shown, when the operating system runs in a virtual machine, inter-core interrupts, which are originally implemented by hardware mechanisms, are handled by the hypervisor. Specifically, the vIPI (Virtual Interprocessor Interrupt) sent by vCPU1 (Virtual CPU) to vCPU2 will enter the hypervisor before vCPU2 receives the virtual interrupt. The hypervisor performs a series of combined hardware and software operations before exiting back into the virtual machine, allowing vCPU2 to receive the interrupt. From the operating system's perspective, the operating system is unaware of this "entering the hypervisor - exiting the virtual machine" process; it only observes that the vIPI processing is more time-consuming than on the physical CPU. From the system's overall perspective, the entire "entering the hypervisor - exiting the virtual machine" vIPI operation performed by the hypervisor introduces additional CPU overhead because it is longer than the original direct hardware operation path. This overhead consumes the process's CPU resources, thus representing a waste of CPU resources.

[0004] Furthermore, taking the sEL4 (a type of virtual machine monitor) hypervisor as an example, the processing time of a single VIP (Virtual IPI) by some hypervisors is affected by the total number of VIPs in the entire system. This is because all VIPs in the system are placed in a global queue, and the hypervisor traverses this global queue, performing corresponding operations on each VIP in turn. Therefore, the more VIPs issued by the virtual machine, the longer the global VIP queue that the hypervisor has to process, and the more CPU resources are wasted due to the overhead of processing a single VIP.

[0005] To reduce CPU resource waste, various technologies exist for virtual machine vCPU load balancing in virtualization scenarios. However, existing automatic CPU load balancing technologies lack the ability to identify the increased CPU consumption caused by the hypervisor handling VIPs. They simply balance based on the length of the process queue per CPU. When there are many processes, a large number of processes migrate between CPUs, resulting in a large number of VIPs. The original intention of these VIPs was to balance CPU computing resources, but instead, they have caused a significant waste of computing power. Summary of the Invention

[0006] To overcome the above-mentioned shortcomings, this invention is proposed to provide a CPU resource control method, apparatus, and computer-readable storage medium for reducing unnecessary VIP and minimizing CPU resource waste in virtualization application scenarios.

[0007] In a first aspect, the present invention provides a CPU resource control method, comprising: detecting the CPU resources occupied by multiple processes in a virtual machine, wherein the virtual machine has multiple virtual CPUs; identifying processes among the multiple processes whose CPU resources are occupied exceeding a preset threshold as target processes whose CPU usage needs to be adjusted; calculating the number of CPUs to be used by the target process based on the number of times the target process has been adjusted, wherein as the number of times the target process has been adjusted increases, the number of CPUs to be used by the target process decreases until it reaches 1; when the number of CPUs to be used by the target process is 1, the target process is no longer detected; and selecting at least one CPU from the multiple CPUs for the target process to use based on the number of CPUs to be used by the target process, the CPU resources occupied by the target process, and the remaining resources of the multiple CPUs.

[0008] Preferably, the aforementioned CPU resource control method further includes, before the step of "selecting the process that occupies CPU resources exceeding a preset threshold among the plurality of processes as the target process that needs to adjust CPU usage", setting a corresponding threshold for each of the plurality of processes.

[0009] Preferably, in the aforementioned CPU resource control method, the step of "setting a corresponding threshold for each of the plurality of processes" includes: setting a corresponding threshold for each process based on the degree of dependence of the task executed by the virtual machine on each process.

[0010] Preferably, in the aforementioned CPU resource control method, the step of "setting a corresponding threshold for each of the plurality of processes" includes: setting a corresponding threshold for each process based on the degree of impact of each process on the stability of the virtual machine operating system.

[0011] Preferably, the aforementioned CPU resource control method further includes: if no process among the plurality of processes is found to be occupying CPU resources exceeding a preset threshold, re-detection is performed after a preset time.

[0012] Preferably, in the aforementioned CPU resource control method, the step of "calculating the number of CPUs to be used by the target process based on the number of times the target process has been adjusted" includes: when the total number of CPUs is n and the number of times the target process has been adjusted is m, setting M = m + 1, and taking the number of CPUs to be used by the target process as n / 2. M .

[0013] Preferably, in the aforementioned CPU resource control method, the step of "detecting the CPU resources occupied by multiple processes in the virtual machine" includes: querying and detecting the multiple processes from the virtual machine according to a preset configuration file that records the multiple processes; the step of "no longer detecting the target process when the number of CPUs to be used by the target process is 1" includes: deleting the target process from the configuration file.

[0014] Preferably, the aforementioned CPU resource control method further includes the step of "selecting at least one CPU from the plurality of CPUs for use by the target process" as follows: selecting the at least one CPU from the plurality of CPUs according to the resource usage of the plurality of CPUs from low to high.

[0015] Secondly, the present invention provides a CPU resource control device, comprising: a CPU resource detection module for detecting CPU resources occupied by multiple processes in a virtual machine, wherein the virtual machine has multiple virtual CPUs; a CPU quantity calculation module for identifying processes among the multiple processes whose CPU resources exceed a preset threshold as target processes whose CPU usage needs to be adjusted, and calculating the number of CPUs to be used by the target process based on the number of times the target process has been adjusted, wherein as the number of times the target process has been adjusted increases, the number of CPUs to be used by the target process decreases until it reaches 1; a detection control module for ceasing detection of the target process when the number of CPUs to be used by the target process is 1; and a CPU selection module for selecting at least one CPU from the multiple CPUs for the target process to use, based on the number of CPUs to be used by the target process, the CPU resources occupied by the target process, and the remaining resources of the multiple CPUs.

[0016] Thirdly, the present invention provides a computer-readable storage medium storing a plurality of program codes adapted to be loaded and run by a processor to perform the aforementioned CPU resource control method.

[0017] The above-described technical solutions of the present invention have at least one or more of the following beneficial effects:

[0018] The technical solution of this invention takes a process whose CPU resource usage in a virtual machine reaches a threshold as the target process, and adjusts the virtual CPU used by the process to achieve CPU load balancing. The difference from the existing technical solution is that as the number of load balancing cycles increases, the number of CPUs configured for the target process gradually decreases, thereby reducing the number of VIPs generated by the target process migrating between virtual CPUs, which reduces the waste of CPU resources in the virtual machine, until the number of virtual CPUs allocated to the target process is 1. At this point, it is impossible to further reduce the number of virtual CPUs for the target process, which minimizes the waste of CPU resources in the virtual machine. Therefore, it is not necessary to detect the target process. Attached Figure Description

[0019] The disclosure of this invention will become more readily understood with reference to the accompanying drawings. It will be readily understood by those skilled in the art that these drawings are for illustrative purposes only and are not intended to limit the scope of protection of this invention. Wherein:

[0020] Figure 1 This is a schematic diagram of the CPU load balancing principle in existing technical solutions;

[0021] Figure 2 This is a flowchart of a CPU resource control method according to an embodiment of the present invention;

[0022] Figure 3 This is a flowchart of a CPU resource control method according to an embodiment of the present invention;

[0023] Figure 4 This is a flowchart illustrating the principle of a CPU resource control method according to an embodiment of the present invention;

[0024] Figure 5 This is a flowchart illustrating the principle of a CPU resource control method according to an embodiment of the present invention;

[0025] Figure 6 This is a block diagram of a CPU resource control device according to an embodiment of the present invention;

[0026] Figure 7 This is a block diagram of a CPU resource control device according to an embodiment of the present invention. Detailed Implementation

[0027] Some embodiments of the present invention will now be described with reference to the accompanying drawings. Those skilled in the art should understand that these embodiments are merely illustrative of the technical principles of the present invention and are not intended to limit the scope of protection of the present invention.

[0028] In the description of this invention, "module" and "processor" can include hardware, software, or a combination of both. A module can include hardware circuitry, various suitable sensors, communication ports, memory, and may also include software components, such as program code, or a combination of software and hardware. A processor can be a central processing unit, microprocessor, image processor, digital signal processor, or any other suitable processor. The processor has data and / or signal processing capabilities. The processor can be implemented in software, in hardware, or a combination of both. Non-transitory computer-readable storage media includes any suitable medium capable of storing program code, such as magnetic disks, hard disks, optical disks, flash memory, read-only memory, random access memory, etc. The term "A and / or B" means all possible combinations of A and B, such as only A, only B, or A and B. The terms "at least one A or B" or "at least one of A and B" have a similar meaning to "A and / or B" and can include only A, only B, or A and B. The singular terms "a" or "this" can also include plural forms.

[0029] like Figure 2 As shown, one embodiment of the present invention provides a CPU resource control method, the method comprising:

[0030] Step S210: Detect the CPU resources occupied by multiple processes in the virtual machine, wherein the virtual machine has multiple virtual CPUs (i.e., the aforementioned vCPUs).

[0031] In a virtual machine, the CPU usage of a single process is not constant, but rather a variable related to the total number of processes. As the number of processes increases, the CPU usage of a single process also increases. This is because the CPU usage metric for a single process includes the time overhead of a single virtual IPI (i.e., vIPI), and this overhead increases with the total number of virtual IPIs. Test data is as follows:

[0032] Number of test processes Average CPU usage per process (%) 4 7~8 8 7~8 12 12 20 14

[0033] Step S220: Select the processes that consume CPU resources exceeding a preset threshold from among multiple processes as target processes that need to adjust CPU usage. Calculate the number of CPUs the target process needs to use based on the number of times the target process has been adjusted. As the number of times the target process has been adjusted increases, the number of CPUs the target process needs to use decreases until it reaches 1.

[0034] In this embodiment, the process whose CPU resource usage in the virtual machine reaches the threshold is taken as the target process, and the virtual CPU used by it is adjusted to achieve CPU load balancing. The difference from the existing technical solution is that as the number of load balancing increases, the number of CPUs configured for the target process gradually decreases, thereby reducing the number of VIPs generated by the target process migrating between virtual CPUs, which also reduces the waste of CPU resources in the virtual machine.

[0035] Step S230: When the number of CPUs to be used by the target process is 1, the target process is no longer detected.

[0036] In this embodiment, when the number of virtual CPUs allocated to the target process is 1, it is impossible to further reduce the number of virtual CPUs for the target process, which means that the waste of CPU resources in the virtual machine is minimized. Therefore, it is not necessary to detect the target process.

[0037] Step S240: Select at least one CPU from multiple CPUs for the target process to use, based on the number of CPUs to be used by the target process, the CPU resources occupied by the target process, and the remaining resources of multiple CPUs.

[0038] In this embodiment, the waste of CPU resources in virtualization application scenarios is reduced by decreasing the number of VIPs used for CPU load balancing within the virtual machine. After using the technical solution of this embodiment, the CPU usage of each process initially increases, but becomes constant after reaching a configured threshold. When the total number of processes continues to increase, the CPU usage of a single process remains fixed, and the newly added processes do not introduce additional CPU usage. Test data is as follows:

[0039] Number of test processes Average CPU usage per process (%) 4 7~8 8 7~8 12 7~8 20 7~8

[0040] like Figure 3 As shown, one embodiment of the present invention provides a CPU resource control method, the method comprising:

[0041] Step S310: Set a corresponding threshold for each of the multiple processes.

[0042] This embodiment provides two ways to set thresholds for processes:

[0043] (1) Set a corresponding threshold for each process based on the degree of dependency of the task executed by the virtual machine on each process. Here, more CPU resources are provided for processes with a high degree of task dependency to ensure that the task can be executed normally in the virtual machine.

[0044] (2) Set a corresponding threshold for each process based on its impact on the stability of the virtual machine operating system. Here, more CPU resources are provided to processes that have a greater impact on system stability to ensure that the virtual machine can run smoothly.

[0045] Step S320: Based on the preset configuration file that records multiple processes, query and detect multiple processes from the virtual machine.

[0046] In this embodiment, process thresholds are recorded through a preset configuration file, which can take the following form:

[0047] [Process][Maximum CPU usage threshold]

[0048] [Process][Maximum CPU usage threshold]

[0049] [Process][Maximum CPU usage allowed]...

[0050] Step S330: If no process is found to be consuming CPU resources exceeding a preset threshold among multiple processes, the detection is repeated after a preset time.

[0051] In this embodiment, the preset time is not limited; for example, it can be 5 seconds. In this embodiment, the virtual machine processes are detected at the preset time to ensure that processes consuming excessive CPU resources are detected in a timely manner.

[0052] Step S340: Select processes that consume CPU resources exceeding a preset threshold as target processes whose CPU usage needs to be adjusted. When the total number of CPUs is n and the number of times the target process has been adjusted is m, set M = m + 1, and take the number of CPUs to be used by the target process as n / 2. M .

[0053] This section provides a specific scheme for calculating the number of CPUs a target process needs to use based on the number of adjustments. For example, assuming the total number of CPUs is n = 8, and the target process has been adjusted m = 0 times during the first adjustment, then M = m + 1 = 1, and the number of CPUs the target process needs to use is n / 2 = 4 times the target process has been adjusted. During the second adjustment, the target process has been adjusted m = 1 time, then M = m + 1 = 2, and the number of CPUs the target process needs to use is n / 2 times the target process has been adjusted. 2 =8 / 4=2.

[0054] Step S350: When the number of CPUs to be used by the target process is 1, delete the target process from the configuration file.

[0055] In this embodiment, the detection process range can be quickly controlled through a configuration file.

[0056] Step S360: Based on the number of CPUs to be used by the target process, the CPU resources occupied by the target process, and the remaining resources of multiple CPUs, select at least one CPU from multiple CPUs according to the resource usage of multiple CPUs from low to high.

[0057] In this embodiment, the CPU with the lowest current resource usage is preferentially selected to provide resources for the target process, which is beneficial for balancing the load level of each CPU.

[0058] Based on the technical solutions of the above embodiments, the following two procedures can be implemented:

[0059] Monitoring program, workflow as follows Figure 4 As shown, this is used to parse user configuration files and monitor the CPU usage of the process:

[0060] (1) Users configure the specified process groups that need to be optimized, such as processes a, b, c, and d, through configuration scripts, as well as the maximum allowed CPU usage threshold for each process, such as 11%.

[0061] (2) The thread interpretation configuration file of the monitoring program is parsed to show that the maximum CPU usage thresholds allowed for processes a, b, c, and d are 10%, 20%, 10%, and 15%, respectively.

[0062] (3) The monitoring thread removes the processes that need to be ignored from the process list based on the ignore request sent by the adjustment program thread. In this example, it is process a.

[0063] (4) The monitoring thread observes the CPU usage of each process in the process group that needs optimization, in this example, processes b, c, and d. If the CPU usage of each process does not exceed the maximum threshold, the monitoring thread sends a "wait" signal to the adjustment thread. If one or more processes exceed the maximum threshold, such as processes b and c, the monitoring program wakes up the sleeping adjustment program and sends the CPU usage of processes b and c to the adjustment thread.

[0064] (5) The monitoring thread enters a 5-second sleep waiting state, and returns to step (2) after 5 seconds.

[0065] Adjust the procedure and workflow as follows Figure 5 As shown, this is used to adjust the CPU affinity of a process:

[0066] (1) After the program is woken up, check the "wait" signal.

[0067] (2) If a “wait” signal is received, it will enter an indefinite sleep until it is awakened by the monitored process.

[0068] (3) If no “waiting” signal is received, it means that there is a process that needs to be adjusted. Proceed to the next step.

[0069] (4) The adjustment thread receives the processes that need adjustment and creates a corresponding M value for each process. M is initialized to 1. In this example, for processes b and c, M = 1 for processes b and c respectively.

[0070] (5) Perform the same operation on processes b and c in sequence. Taking process b as an example: Observe the current CPU usage status of each CPU in the system and find the set of CPUs with relatively small loads. The size of the set is (total number of CPUs in the system / (2 to the power of M)). Taking the total number of CPUs = 8 and M = 1 as an example, (8 / (2 to the power of 1) = 4, then observe the 4 CPUs with smaller loads among the 8 CPUs. In this example, CPU0, CPU1, CPU2, and CPU3 are selected. If the CPU selected in this step is already a single CPU, it means that the CPU affinity of this process has reached a single CPU. It means that the process is no longer affected by the load balancing operation. The operating system will not generate VIP for these processes. There is no more room for optimization. Then, send an "ignore" signal and this process to the monitoring thread to notify the monitoring thread to ignore monitoring this process. Set the CPU affinity of this process to the selected CPU set, and increment the M value of this process by 1. In this example, M = 2 for process b. Return to step (1) and repeat until all processes have been processed. In this example, both b and c have been processed.

[0071] (6) Enter indefinite sleep until awakened by the monitoring program.

[0072] According to the technical solution of this embodiment, the vIPI generated by process migration in the virtual machine can be effectively reduced, thereby reducing the waste of CPU resources caused by load balancing.

[0073] like Figure 6 As shown, one embodiment of the present invention provides a CPU resource control device, the device comprising:

[0074] CPU resource detection module 610 detects the CPU resources occupied by multiple processes in a virtual machine, wherein the virtual machine has multiple virtual CPUs (i.e., the aforementioned vCPUs).

[0075] In a virtual machine, the CPU usage of a single process is not constant, but rather a variable related to the total number of processes. As the number of processes increases, the CPU usage of a single process also increases. This is because the CPU usage metric for a single process includes the time overhead of a single virtual IPI (i.e., vIPI), and this overhead increases with the total number of virtual IPIs. Test data is as follows:

[0076] Number of test processes Average CPU usage per process (%) 4 7~8 8 7~8 12 12 20 14

[0077] The CPU quantity calculation module 620 identifies processes that consume more than a preset threshold of CPU resources among multiple processes as target processes that need to adjust their CPU usage. Based on the number of times the target process has been adjusted, it calculates the number of CPUs that the target process is waiting to use. As the number of times the target process has been adjusted increases, the number of CPUs that the target process is waiting to use decreases until it reaches 1.

[0078] In this embodiment, the process whose CPU resource usage in the virtual machine reaches the threshold is taken as the target process, and the virtual CPU used by it is adjusted to achieve CPU load balancing. The difference from the existing technical solution is that as the number of load balancing increases, the number of CPUs configured for the target process gradually decreases, thereby reducing the number of VIPs generated by the target process migrating between virtual CPUs, which also reduces the waste of CPU resources in the virtual machine.

[0079] The detection control module 630 stops detecting the target process when the number of CPUs to be used by the target process is 1.

[0080] In this embodiment, when the number of virtual CPUs allocated to the target process is 1, it is impossible to further reduce the number of virtual CPUs for the target process, which means that the waste of CPU resources in the virtual machine is minimized. Therefore, it is not necessary to detect the target process.

[0081] CPU selection module 640 selects at least one CPU from multiple CPUs for the target process to use, based on the number of CPUs to be used by the target process, the CPU resources occupied by the target process, and the remaining resources of multiple CPUs.

[0082] In this embodiment, the waste of CPU resources in virtualization application scenarios is reduced by decreasing the number of VIPs used for CPU load balancing within the virtual machine. After using the technical solution of this embodiment, the CPU usage of each process initially increases, but becomes constant after reaching a configured threshold. When the total number of processes continues to increase, the CPU usage of a single process remains fixed, and the newly added processes do not introduce additional CPU usage. Test data is as follows:

[0083] Number of test processes Average CPU usage per process (%) 4 7~8 8 7~8 12 7~8 20 7~8

[0084] like Figure 7 As shown, one embodiment of the present invention provides a CPU resource control device, the device comprising:

[0085] The threshold setting module 710 sets a corresponding threshold for each of the multiple processes.

[0086] This embodiment provides two ways to set thresholds for processes:

[0087] (1) Set a corresponding threshold for each process based on the degree of dependency of the task executed by the virtual machine on each process. Here, more CPU resources are provided for processes with a high degree of task dependency to ensure that the task can be executed normally in the virtual machine.

[0088] (2) Set a corresponding threshold for each process based on its impact on the stability of the virtual machine operating system. Here, more CPU resources are provided to processes that have a greater impact on system stability to ensure that the virtual machine can run smoothly.

[0089] The CPU resource detection module 720 queries and detects multiple processes from the virtual machine based on a preset configuration file that records multiple processes.

[0090] In this embodiment, process thresholds are recorded through a preset configuration file, which can take the following form:

[0091] [Process][Maximum CPU usage threshold]

[0092] [Process][Maximum CPU usage threshold]

[0093] [Process][Maximum CPU usage allowed]...

[0094] If no processes are found to be consuming CPU resources exceeding a preset threshold, the CPU resource detection module 720 will re-detect after a preset time.

[0095] In this embodiment, the preset time is not limited; for example, it can be 5 seconds. In this embodiment, the virtual machine processes are detected at the preset time to ensure that processes consuming excessive CPU resources are detected in a timely manner.

[0096] The CPU quantity calculation module 730 identifies processes that consume more CPU resources than a preset threshold as target processes requiring CPU adjustment. When the total number of CPUs is n and the number of times the target process has been adjusted is m, M = m + 1 is set, and the number of CPUs the target process needs to use is n / 2. M .

[0097] This section provides a specific scheme for calculating the number of CPUs a target process needs to use based on the number of adjustments. For example, assuming the total number of CPUs is n = 8, and the target process has been adjusted m = 0 times during the first adjustment, then M = m + 1 = 1, and the number of CPUs the target process needs to use is n / 2 = 4 times the target process has been adjusted. During the second adjustment, the target process has been adjusted m = 1 time, then M = m + 1 = 2, and the number of CPUs the target process needs to use is n / 2 times the target process has been adjusted. 2 =8 / 4=2.

[0098] The detection control module 740 deletes the target process from the configuration file when the number of CPUs to be used by the target process is 1.

[0099] In this embodiment, the detection process range can be quickly controlled through a configuration file.

[0100] The CPU selection module 750 selects at least one CPU from multiple CPUs based on the number of CPUs to be used by the target process, the CPU resources occupied by the target process, and the remaining resources of multiple CPUs, in order of increasing resource usage.

[0101] In this embodiment, the CPU with the lowest current resource usage is preferentially selected to provide resources for the target process, which is beneficial for balancing the load level of each CPU.

[0102] Based on the technical solutions of the above embodiments, the following two procedures can be implemented:

[0103] Monitoring program, workflow as follows Figure 4 As shown, this is used to parse user configuration files and monitor the CPU usage of the process:

[0104] (1) Users configure the specified process groups that need to be optimized, such as processes a, b, c, and d, through configuration scripts, as well as the maximum CPU usage threshold allowed for each process, such as 11%.

[0105] (2) The thread interpretation configuration file of the monitoring program is parsed to show that the maximum CPU usage thresholds allowed for processes a, b, c, and d are 10%, 20%, 10%, and 15%, respectively.

[0106] (3) The monitoring thread removes the processes that need to be ignored from the process list based on the ignore request sent by the adjustment program thread. In this example, it is process a.

[0107] (4) The monitoring thread observes the CPU usage of each process in the process group that needs optimization, in this example, processes b, c, and d. If the CPU usage of each process does not exceed the maximum threshold, the monitoring thread sends a "wait" signal to the adjustment thread. If one or more processes exceed the maximum threshold, such as processes b and c, the monitoring program wakes up the sleeping adjustment program and sends the CPU usage of processes b and c to the adjustment thread.

[0108] (5) The monitoring thread enters a 5-second sleep waiting state, and returns to step (2) after 5 seconds.

[0109] Adjust the procedure and workflow as follows Figure 5 As shown, this is used to adjust the CPU affinity of a process:

[0110] (1) After the program is woken up, check the "wait" signal.

[0111] (2) If a “wait” signal is received, it will enter an indefinite sleep until it is awakened by the monitored process.

[0112] (3) If no “waiting” signal is received, it means that there is a process that needs to be adjusted. Proceed to the next step.

[0113] (4) The adjustment thread receives the processes that need adjustment and creates a corresponding M value for each process. M is initialized to 1. In this example, for processes b and c, M = 1 for processes b and c respectively.

[0114] (5) For processes b and c, perform the same operation as follows. Taking process b as an example: Observe the current status of CPU usage in the system and find the set of CPUs with relatively low load. The size of the set is (total number of CPUs in the system / (2 to the power of M)). Taking the total number of CPUs = 8 and M = 1 as an example, (8 / (2 to the power of 1) = 4, then observe the 4 CPUs with low load among the 8 CPUs. In this example, CPU0, CPU1, CPU2, and CPU3 are selected. If the CPU selected in this step is already a single CPU, it means that the CPU affinity of this process has reached a single CPU. It means that the process is no longer affected by the load balancing operation. The operating system will not generate VIP for these processes. There is no more room for optimization. Then, send an "ignore" signal and this process to the monitoring thread to notify the monitoring thread to ignore monitoring this process. Set the CPU affinity of this process to the selected CPU set, and increment the M value of this process by 1. In this example, M = 2 for process b. Return to step (1) and repeat until all processes have been processed. In this example, both b and c have been processed.

[0115] (6) Enter indefinite sleep until awakened by the monitoring program.

[0116] According to the technical solution of this embodiment, the vIPI generated by process migration in the virtual machine can be effectively reduced, thereby reducing the waste of CPU resources caused by load balancing.

[0117] The present invention also provides a computer-readable storage medium. In one embodiment of the computer-readable storage medium according to the present invention, the computer-readable storage medium can be configured to store a program that executes the CPU resource control method of the above-described method embodiment. The program can be loaded and run by a processor to implement the above-described CPU resource control method. For ease of explanation, only the parts related to the embodiments of the present invention are shown; for specific technical details not disclosed, please refer to the method section of the embodiments of the present invention. The computer-readable storage medium can be a storage device comprising various electronic devices. Optionally, in the embodiments of the present invention, the computer-readable storage medium is a non-transitory computer-readable storage medium.

[0118] The algorithms and displays provided herein are not inherently related to any particular computer, virtual system, or other device. Various general-purpose systems can also be used in conjunction with the teachings herein. The required structure for constructing such systems is apparent from the above description. Furthermore, this invention is not directed to any particular programming language. It should be understood that the contents of the invention described herein can be implemented using various programming languages, and the above description of specific languages ​​is for the purpose of disclosing the best mode of implementation of the invention.

[0119] Numerous specific details are set forth in the specification provided herein. However, it will be understood that embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures, and techniques have not been shown in detail so as not to obscure the understanding of this specification.

[0120] Similarly, it should be understood that, in order to simplify this disclosure and aid in understanding one or more of the various aspects of the invention, in the above description of exemplary embodiments of the invention, various features of the invention are sometimes grouped together in a single embodiment, figure, or description thereof. However, this method of disclosure should not be construed as reflecting an intention that the claimed invention requires more features than are expressly recited in each claim. Rather, as reflected in the following claims, inventive aspects lie in fewer than all features of a single foregoing disclosed embodiment. Therefore, the claims following the detailed description are hereby expressly incorporated into this detailed description, wherein each claim itself is a separate embodiment of the invention.

[0121] Those skilled in the art will understand that modules in the device of the embodiments can be adaptively changed and placed in one or more devices different from that embodiment. Modules, units, or components in the embodiments can be combined into a single module, unit, or component, and further, they can be divided into multiple sub-modules, sub-units, or sub-components. Except where at least some of such features and / or processes or units are mutually exclusive, any combination can be used to combine all features disclosed in this specification (including the accompanying claims, abstract, and drawings) and all processes or units of any method or device so disclosed. Unless expressly stated otherwise, each feature disclosed in this specification (including the accompanying claims, abstract, and drawings) may be replaced by an alternative feature that serves the same, equivalent, or similar purpose.

[0122] Furthermore, those skilled in the art will understand that although some embodiments described herein include certain features but not others included in other embodiments, combinations of features from different embodiments are intended to be within the scope of the invention and form different embodiments. For example, in the following claims, any of the claimed embodiments can be used in any combination.

[0123] The various component embodiments of the present invention can be implemented in hardware, or as software modules running on one or more processors, or a combination thereof. Those skilled in the art will understand that microprocessors or digital signal processors (DSPs) can be used in practice to implement some or all of the functions of some or all of the components in the processing apparatus of the mobile terminal according to embodiments of the present invention. The present invention can also be implemented as a device or apparatus program (e.g., a computer program and computer program product) for performing part or all of the methods described herein. Such programs implementing the present invention can be stored on a computer-readable medium, or can be in the form of one or more signals. Such signals can be downloaded from an Internet website, provided on a carrier signal, or provided in any other form.

[0124] It should be noted that the above embodiments are illustrative of the invention and not restrictive, and that those skilled in the art can devise alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses should not be construed as limiting the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The invention can be implemented by means of hardware comprising several different elements and by means of a suitably programmed computer. In the unit claims enumerating several means, several of these means may be embodied by the same item of hardware. The use of the words first, second, and third, etc., does not indicate any order. These words can be interpreted as names.

Claims

1. A CPU resource control method, characterized in that, include: Detect the CPU resources occupied by multiple processes in a virtual machine, wherein the virtual machine has multiple virtual CPUs; The process that consumes CPU resources exceeding a preset threshold among the multiple processes is identified as the target process whose CPU usage needs to be adjusted. The number of CPUs to be used by the target process is calculated based on the number of times the target process has been adjusted. As the number of times the target process has been adjusted increases, the number of CPUs to be used by the target process decreases until it reaches 1. When the number of CPUs to be used by the target process is 1, the target process will no longer be detected; Based on the number of CPUs to be used by the target process, the CPU resources occupied by the target process, and the remaining resources of the multiple CPUs, at least one CPU is selected from the multiple CPUs for the target process to use.

2. The CPU resource control method according to claim 1, characterized in that, Before the step of "selecting processes that consume CPU resources exceeding a preset threshold from among the plurality of processes as target processes requiring adjustment of CPU usage", the following is also included: Set a corresponding threshold for each of the plurality of processes.

3. The CPU resource control method according to claim 2, characterized in that, The step of "setting a corresponding threshold for each of the plurality of processes" includes: Based on the degree of dependence of the tasks executed by the virtual machine on each process, a corresponding threshold is set for each process.

4. The CPU resource control method according to claim 2, characterized in that, The step of "setting a corresponding threshold for each of the plurality of processes" includes: Based on the degree of impact of each process on the stability of the virtual machine operating system, a corresponding threshold is set for each process.

5. The CPU resource control method according to claim 1, characterized in that, Also includes: If no process is found to be consuming CPU resources exceeding a preset threshold among the multiple processes, the detection will be repeated after a preset time.

6. The CPU resource control method according to claim 1, characterized in that, The step of "calculating the number of CPUs to be used by the target process based on the number of times the target process has been adjusted" includes: When the total number of CPUs is n and the number of times the target process has been adjusted is m, set M = m + 1, and take the number of CPUs to be used by the target process as n / 2. M .

7. The CPU resource control method according to claim 1, characterized in that, The steps for "detecting the CPU resources used by multiple processes in a virtual machine" include: According to a preset configuration file that records the multiple processes, the multiple processes are queried from the virtual machine and detected. The step of "stopping detection of the target process when the number of CPUs to be used by the target process is 1" includes: Remove the target process from the configuration file.

8. The CPU resource control method according to claim 1, characterized in that, The step of "selecting at least one CPU from the plurality of CPUs for use by the target process" further includes: At least one CPU is selected from the plurality of CPUs according to their resource usage from low to high.

9. A CPU resource control device, characterized in that, include: The CPU resource detection module detects the CPU resources occupied by multiple processes in a virtual machine, wherein the virtual machine has multiple virtual CPUs. The CPU quantity calculation module identifies processes among the multiple processes that consume CPU resources exceeding a preset threshold as target processes that need to have their CPU usage adjusted. Based on the number of times the target process has been adjusted, it calculates the number of CPUs that the target process needs to use. As the number of times the target process has been adjusted increases, the number of CPUs that the target process needs to use decreases until it reaches 1. The detection control module stops detecting the target process when the number of CPUs to be used by the target process is 1. The CPU selection module selects at least one CPU from the plurality of CPUs for the target process to use, based on the number of CPUs to be used by the target process, the CPU resources occupied by the target process, and the remaining resources of the plurality of CPUs.

10. A computer-readable storage medium storing a plurality of program codes, characterized in that, The program code is adapted to be loaded and run by a processor to perform the CPU resource control method according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • Multi-core computing resource management system based on virtual computing technology

    CN101488098A

  • Virtualization platform control device, virtualization platform control method, and virtualization platform control program

    US20220206829A1