A central processor utilization rate determination method, device, equipment and storage medium

By acquiring the total CPU runtime, waiting time, and stall cycle time, and comprehensively calculating CPU utilization, the problem of accuracy deviation in existing technologies is solved, and the accuracy of CPU utilization and accurate judgment of system bottlenecks are achieved.

CN116048909BActive Publication Date: 2026-11-10INSPUR BUSINESS MACHINE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211317795.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-10-26
Publication Date
2026-11-10
Estimated Expiration
2042-10-26

AI Technical Summary

Technical Problem

In existing technologies, the methods for calculating CPU utilization cannot accurately reflect CPU usage, leading to inaccuracies and failing to help users correctly identify system bottlenecks.

Method used

By obtaining the total running time, waiting time, and stall cycle time of the process execution cycle, the utilization of the central processing unit is comprehensively calculated, taking into account the impact of the stall state, thereby improving the accuracy of the calculation.

Benefits of technology

It provides accurate CPU utilization data, helping users identify system bottlenecks and avoid misjudgments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116048909B_ABST
    Figure CN116048909B_ABST
Patent Text Reader

Abstract

The application discloses a central processor utilization rate determination method, and relates to the field of computer system design, and comprises the following steps: acquiring the total running time and waiting time of the central processor in a process execution period; acquiring the stall period time of the central processor in the total running time; and calculating and determining the utilization rate of the central processor based on the stall period time, the total running time and the waiting time. It can be seen that the utilization rate of the central processor is calculated comprehensively by acquiring the total running time and the stall period time of the central processor, thereby providing the accuracy of the utilization rate of the central processor. The defects that the utilization rate of the central processor in the prior art is inaccurate and cannot assist people in making correct judgments are solved. The stall information of the central processor is reflected in the utilization rate of the central processor, and people can accurately find the system bottleneck.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer system design technology, and in particular to a method, apparatus, device, and storage medium for determining central processing unit utilization. Background Technology

[0002] The internet is the fastest-growing, most competitive, most innovative, most widely participated, most pervasive, and most far-reaching technology industry that human civilization has witnessed to date, and it has become a major driver of global economic growth. In the "Internet+" era, the diversification of people's needs has led to the diversification of applications, creating millions of business systems, and the cornerstone supporting these businesses is the computer server. The central processing unit (CPU) is the core component of a computer server; therefore, CPU utilization, also known as CPU usage, indicates the usage of the CPU in a computer service, showing how much CPU is occupied over a period of time. A higher utilization rate indicates a heavier load on the server during the sampling period, and vice versa, reflecting the server's overall utilization. Furthermore, CPU utilization is essential information for problem analysis and performance tuning, requiring it to be reflected and calculated as accurately as possible. Currently used operating systems, whether Windows, Linux, or macOS, are all multi-user, multi-tasking, time-sharing operating systems. Users of these operating systems can multitask "simultaneously," but in reality, the operating system divides CPU time into roughly equal-length time slices, which are then allocated to users in a rotating fashion. If a task is not completed before its time slice ends, it is paused, relinquishing the CPU and waiting for the next cycle. The CPU is then allocated to another task. Because computers process data very quickly, the pause between a user's time slice and the acquisition of the next CPU time slice is imperceptible to the user, making it appear as if the user has exclusive access to the entire system.

[0003] Based on the time-sharing characteristics of operating systems, the current method for calculating CPU utilization is: CPU% = CPU usage time / sampling time; where CPU usage time is the sum of the CPU usage time of each user task within the sampling time. This method is simple and easy to calculate, and can meet basic needs in the early stages. However, as the complexity of applications increases, this calculation method deviates from reality and cannot meet application requirements.

[0004] In summary, how to accurately reflect the usage of the central processing unit (CPU), improve the accuracy of determining CPU utilization, and reduce the deviation in accuracy are technical problems that need to be solved in this field. Summary of the Invention

[0005] In view of this, the purpose of this invention is to provide a method, apparatus, device, and storage medium for determining central processing unit (CPU) utilization, which can accurately reflect the usage of the CPU, improve the accuracy of determining CPU utilization, and reduce accuracy deviations. The specific solution is as follows:

[0006] In a first aspect, this application discloses a method for determining central processing unit utilization, including:

[0007] Get the total CPU runtime and waiting time during the process execution cycle;

[0008] Obtain the stall cycle time of the central processing unit in a stall state during the total running time;

[0009] The utilization rate of the central processing unit is calculated and determined based on the stall cycle time, the total running time, and the waiting time.

[0010] Optionally, obtaining the total runtime of the central processing unit within the process execution cycle includes:

[0011] The clock cycle count of the central processing unit is collected at the time of process execution and the time of process termination, and the total running time of the central processing unit is determined based on the clock cycle count.

[0012] Optionally, the step of collecting the number of clock cycles of the central processing unit at the process execution time and the process termination time, and determining the total running time of the central processing unit based on the number of clock cycles, includes:

[0013] The number of clock cycles of the central processing unit is collected at the time of process execution and the time of process termination, and the difference between the number of clock cycles at the time of process termination and the number of clock cycles at the time of process execution is calculated to obtain the target number of clock cycles.

[0014] The total running time of the central processing unit is determined based on the target number of clock cycles.

[0015] Optionally, obtaining the stall cycle time of the central processing unit in a stall state during the total running time includes:

[0016] The invalid clock cycles within the total runtime are obtained as the stall cycle time of the central processing unit, and the stall cycle time is stored using a newly added storage process.

[0017] Optionally, the process of obtaining the invalid clock cycles within the total runtime as the stall cycle time of the central processing unit further includes:

[0018] During process context switching, invalid clock cycles are collected and bound to the corresponding processes.

[0019] Optionally, the step of calculating and determining the CPU utilization based on the stall cycle time, the total running time, and the waiting time includes:

[0020] The total execution time of the process is determined based on the total running time and the waiting time; the utilization rate of the central processing unit is determined by the percentage of the total execution time of the process to the total running time and the percentage of the stall cycle time to the total running time.

[0021] Optionally, the method for determining central processing unit utilization further includes:

[0022] Users can choose whether to enable the operation of obtaining the stall cycle time based on their needs.

[0023] Secondly, this application discloses a central processing unit utilization determination device, comprising:

[0024] The first-time acquisition module 11 is used to acquire the total running time and waiting time of the central processing unit within the process execution cycle;

[0025] The second time acquisition module 12 is used to acquire the stall cycle time of the central processing unit in the stall state during the total running time.

[0026] The utilization determination module 13 is used to calculate and determine the utilization of the central processing unit based on the stall cycle time, the total running time, and the waiting time.

[0027] Thirdly, this application discloses an electronic device, comprising:

[0028] Memory, used to store computer programs;

[0029] A processor for executing the computer program to implement the steps of the aforementioned disclosed method for determining central processing unit utilization.

[0030] Fourthly, this application discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the steps of the aforementioned disclosed method for determining central processing unit utilization.

[0031] Therefore, this application discloses a method for determining CPU utilization, including: obtaining the total runtime and waiting time of the CPU within a process execution cycle; obtaining the stall period time during which the CPU is in a stall state within the total runtime; and calculating and determining the CPU utilization based on the stall period time, the total runtime, and the waiting time. It is evident that by obtaining the total CPU runtime and the stall period time, the CPU utilization is calculated comprehensively, thereby providing greater accuracy in CPU utilization. This addresses the shortcomings of existing technologies where CPU utilization is inaccurate and cannot assist in making correct judgments. By reflecting CPU stall information in the CPU utilization, it helps people accurately identify system bottlenecks. Attached Figure Description

[0032] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0033] Figure 1 This is a flowchart of a method for determining the utilization of a central processing unit disclosed in this application;

[0034] Figure 2 This is a diagram showing the original state partitioning of a central processing unit disclosed in this application;

[0035] Figure 3 This application discloses a novel state partitioning diagram for a central processing unit.

[0036] Figure 4 This application discloses a specific method for determining central processing unit utilization.

[0037] Figure 5 This is a schematic diagram of the structure of a central processing unit utilization determination device disclosed in this application;

[0038] Figure 6 This is a structural diagram of an electronic device disclosed in this application. Detailed Implementation

[0039] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present invention.

[0040] The internet is the fastest-growing, most competitive, most innovative, most widely participated, most pervasive, and most far-reaching technological industry that human civilization has witnessed to date, and it has become a major driver of global economic growth. In the "Internet+" era, the diversification of people's needs has led to the diversification of applications, creating millions of business systems, and the cornerstone supporting these businesses is the computer server. The central processing unit (CPU) is the core component of a computer server; therefore, CPU utilization, also known as CPU usage rate, indicates the usage of the CPU in a computer service, showing how much CPU is occupied over a period of time. A higher utilization rate indicates a heavier load on the server during the sampling period, and vice versa, reflecting the server's overall utilization. Furthermore, CPU utilization is also fundamental information needed for problem analysis and performance tuning, requiring it to be reflected and calculated as accurately as possible. Currently used operating systems, whether Windows, Linux, or macOS, are all multi-user, multi-tasking, time-sharing operating systems. Users of these operating systems can multitask "simultaneously," but in reality, the operating system divides CPU time into roughly equal-length time slices, which are then allocated to users in a rotating fashion. If a task is not completed before its time slice ends, it is paused, relinquishing the CPU and waiting for the next cycle. The CPU is then allocated to another task. Because computers process data very quickly, the pause between a user's time slice and the acquisition of the next CPU time slice is imperceptible to the user, making it appear as if the user has exclusive access to the entire system.

[0041] Based on the time-sharing characteristics of operating systems, the current method for calculating CPU utilization is: CPU% = CPU usage time / sampling time; where CPU usage time is the sum of the CPU usage time of each user task within the sampling time. This method is simple and easy to calculate, and can meet basic needs in the early stages. However, as the complexity of applications increases, this calculation method deviates from reality and cannot meet application requirements.

[0042] Therefore, this application provides a scheme for determining CPU utilization, which can accurately reflect the usage of CPU, improve the accuracy of determining CPU utilization, and reduce the deviation in accuracy.

[0043] This invention discloses a method for determining central processing unit (CPU) utilization, comprising:

[0044] Step S11: Obtain the total running time and waiting time of the central processing unit during the process execution cycle.

[0045] In this embodiment, the clock cycle count of the central processing unit (CPU) is collected at both the process execution time and the process termination time, and the total running time of the CPU is determined based on the clock cycle count. It can be understood that the CPU clock cycle count is collected at both the process execution time and the process termination time, and the difference between the clock cycle count at the process termination time and the clock cycle count at the process execution time is calculated to obtain a target clock cycle count; the total running time of the CPU is then determined based on the target clock cycle count. Specifically, the data acquisition function collects relevant cycles when a process is scheduled to execute and when it is stopped. That is, the number of clock cycles at the corresponding process execution time and process stop time, and calculates the difference to determine the total number of CPU cycles within the process scheduling execution cycle. Since every computer or server has a performance indicator, the clock frequency, which is the frequency of the machine's internal main clock, and the reciprocal of the clock frequency is the CPU clock cycle, usually measured in megahertz, the total CPU running time can be determined based on the clock frequency and the number of collected clock cycles. For example, if the number of collected clock cycles is 200 and the computer's clock frequency is 10Hz, then the total CPU running time is 200 / 10 = 20 seconds.

[0046] Step S12: Obtain the stall cycle time of the central processing unit in the stall state during the total running time.

[0047] In this embodiment, the invalid clock cycles within the total running time are obtained as the stall cycle time of the central processing unit (CPU). It is understood that, according to the working principles of current computers and operating systems, the CPU's operating state should be divided into at least three states: busy, stall, and idle (i.e., waiting). The busy state is the clock cycle consumed by the CPU when executing instructions; the stall state is when the CPU is idling due to waiting for resources, resulting in some invalid clock cycles; the idle state is the clock cycle consumed when the CPU is not executing the current instruction. However, in existing technologies, the CPU's operating state is often divided into busy and idle (i.e., waiting) states, ignoring the stall state, and directly including the clock cycles occupied by the stall state within the scope of the busy state. It is understood that, according to the existing CPU operating state division, the impact of the stall state is not considered when calculating CPU utilization, affecting the accuracy of the calculated CPU utilization. For example: Refer to... Figure 2 As shown, Figure 2 The original CPU state is divided into states: the busy state occupies time T1, and the idle state occupies time T2; refer to... Figure 3As shown, the redefined CPU states are: busy state + stall state time is T1, and idle state time is T2. This way, the stall state is also included in the redefined CPU states, avoiding directly mixing the stall state time with the busy state time, making the subsequent determination of CPU utilization more accurate.

[0048] Step S13: Calculate and determine the utilization rate of the central processing unit based on the stall cycle time, the total running time, and the waiting time.

[0049] In this embodiment, the total process execution time is determined based on the total running time and the waiting time; the CPU utilization is determined by the percentage of the total process execution time relative to the total running time and the percentage of the stall period relative to the total running time. It is understood that after determining the computer's total running time and waiting time, subtracting the waiting time from the total running time yields the total process execution time. However, this total process execution time includes the stall time of the CPU, making it inaccurate. Therefore, the accurate CPU utilization is determined by subtracting the percentage of the stall period relative to the total running time from the percentage of the total process execution time relative to the total running time. For example, if the collected total system execution time is T, the waiting time is T2, then the total process time is T1, where T1 + T2 = T, and the collected waiting time is T3. The CPU utilization is then calculated as follows: The original method for calculating CPU utilization was as follows: assuming the busy state time is T1 and the idle state time is T2 within the sampling period, then the sampling time T = T1 + T2, and the CPU utilization = T1 / (T1 + T2). T1 / T2 are based on the execution time of the relevant processes being scheduled. More precisely, this method calculates the non-idle utilization rate, excluding the time spent running idle threads. While this simple calculation method had limited impact on practical applications in the early days when CPU instruction execution speed and memory access speed were comparable, with the advancement of CPU technology, the instruction execution speed has far exceeded the memory access speed. The deviation caused by this simple calculation can no longer be ignored and may even affect people's ability to make correct judgments. This approach, by considering the impact of CPU stalling on CPU utilization, avoids simply focusing on the operating system scheduling layer and ignoring CPU stalling. For example, when technicians see high CPU utilization, they might assume the CPU is the bottleneck and decide to upgrade or expand it. However, the CPU might actually be experiencing severe stalling, not excessively high utilization. The stalling might be caused by problems with subsystems such as memory, resulting in prolonged CPU stalling and thus high CPU utilization. In other words, relying solely on the percentage of total process execution time to total runtime for CPU utilization is no longer an accurate reflection of CPU usage and cannot help in making correct judgments. This bias is now significant for modern computer servers.

[0050] Therefore, this application discloses a method for determining CPU utilization, including: obtaining the total runtime and waiting time of the CPU within a process execution cycle; obtaining the stall period time during which the CPU is in a stall state within the total runtime; and calculating and determining the CPU utilization based on the stall period time, the total runtime, and the waiting time. It is evident that by obtaining the total CPU runtime and the stall period time, the CPU utilization is calculated comprehensively, thereby providing greater accuracy in CPU utilization. This addresses the shortcomings of existing technologies where CPU utilization is inaccurate and cannot assist in making correct judgments. By reflecting CPU stall information in the CPU utilization, it helps people accurately identify system bottlenecks.

[0051] Reference Figure 4 As shown, this embodiment of the invention discloses a specific method for determining central processing unit (CPU) utilization. Compared to the previous embodiment, this embodiment further explains and optimizes the technical solution. Specifically:

[0052] Step S21: Obtain the total running time and waiting time of the central processing unit during the process execution cycle.

[0053] Step S22: Select whether to enable the operation of obtaining the stall cycle time based on user needs. If the operation of obtaining the stall cycle time is enabled, obtain the stall cycle time of the central processing unit in the stall state during the total running time.

[0054] In this embodiment, the user dynamically selects whether to enable the stall cycle time acquisition operation based on their needs. If stall cycle time acquisition is disabled, the total process runtime is calculated based on the acquired total runtime and waiting time. The CPU utilization can then be determined by the percentage of the total runtime occupied by the process runtime. If stall cycle time acquisition is enabled, invalid clock cycles are collected during process context switching, and these invalid clock cycles are bound to the corresponding processes. It should be noted that enabling this function can be determined by adding control parameters.

[0055] Step S23: Store the stall cycle time using the newly added storage process.

[0056] In this embodiment, the number of clock cycles during CPU stall during process execution is stored in the data storage module. The relevant structure of the data storage module is as follows:

[0057]

[0058] Where *total* represents the total number of CPU cycles during the scheduled execution period of the process, and *stall* represents the number of CPU stall cycles during the corresponding period. *Cycles* refers to the cycles records associated with each process; each process has its own record. Then, the data acquisition module collects relevant cycles when the process is scheduled to execute and when it is stopped, performs difference calculations when the process stops, and saves the results to the data storage unit. The functional block diagram is as follows:

[0059] total_sched=total_schedout–total_schedin;

[0060] stall_sched=stall_schedout–stall_schedin;

[0061] During the sampling period:

[0062] total = total + total_sched;

[0063] stall = stall + stall_sched;

[0064] Step S24: Calculate and determine the utilization rate of the central processing unit based on the stall cycle time, the total running time, and the waiting time.

[0065] In this embodiment, the CPU utilization rate is calculated using the data processing module based on the existing collected data. The calculation formula is as follows: CPU utilization rate = T1*(1-stall / total) / (T1+T2), which calculates the CPU utilization rate.

[0066] Therefore, it can be seen that data collection and binding can be performed by performing data acquisition during process context switching and binding the acquisition results with the process. Then, by combining the acquired data information with the total CPU cycle time, CPU stall time and process running time, the accuracy of CPU utilization can be improved, thereby helping people to make correct judgments.

[0067] Reference Figure 5 As shown, an embodiment of the present invention discloses a central processing unit utilization determination device, comprising:

[0068] The first-time acquisition module 11 is used to acquire the total running time and waiting time of the central processing unit within the process execution cycle;

[0069] The second time acquisition module 12 is used to acquire the stall cycle time of the central processing unit in the stall state during the total running time.

[0070] The utilization determination module 13 is used to calculate and determine the utilization of the central processing unit based on the stall cycle time, the total running time, and the waiting time.

[0071] Therefore, this application discloses a method for determining CPU utilization, including: obtaining the total runtime and waiting time of the CPU within a process execution cycle; obtaining the stall period time during which the CPU is in a stall state within the total runtime; and calculating and determining the CPU utilization based on the stall period time, the total runtime, and the waiting time. It is evident that by obtaining the total CPU runtime and the stall period time, the CPU utilization is calculated comprehensively, thereby providing greater accuracy in CPU utilization. This addresses the shortcomings of existing technologies where CPU utilization is inaccurate and cannot assist in making correct judgments. By reflecting CPU stall information in the CPU utilization, it helps people accurately identify system bottlenecks.

[0072] Furthermore, embodiments of this application also disclose an electronic device, Figure 6 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content of the diagram should not be construed as limiting the scope of this application.

[0073] Figure 6This is a schematic diagram of the structure of an electronic device 20 provided in an embodiment of this application. Specifically, the electronic device 20 may include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the central processing unit utilization determination method disclosed in any of the foregoing embodiments. Alternatively, the electronic device 20 in this embodiment may specifically be an electronic computer.

[0074] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 25 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.

[0075] The processor 21 may include one or more processing cores, such as a quad-core processor or an octa-core processor. The processor 21 may be implemented using at least one hardware form selected from DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor 21 may also include a main processor and a coprocessor. The main processor, also known as a CPU (Central Processing Unit), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, the processor 21 may integrate a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the screen. In some embodiments, the processor 21 may also include an AI (Artificial Intelligence) processor, which is used to handle computational operations related to machine learning.

[0076] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk or optical disk, etc. The resources stored thereon can include operating system 221, computer program 222, etc., and the storage method can be temporary storage or permanent storage.

[0077] The operating system 221 manages and controls the various hardware devices and computer programs 222 on the electronic device 20 to enable the processor 21 to perform calculations and processing on the massive amounts of data 223 in the memory 22. The operating system 221 can be Windows Server, Netware, Unix, Linux, etc. The computer program 222, in addition to including a computer program capable of performing the central processing unit utilization determination method executed by the electronic device 20 as disclosed in any of the foregoing embodiments, may further include computer programs capable of performing other specific tasks. The data 223 may include data received by the electronic device from external devices, as well as data collected by its own input / output interface 25.

[0078] Furthermore, this application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned method for determining central processing unit utilization. Specific steps of this method can be found in the corresponding content disclosed in the foregoing embodiments, and will not be repeated here.

[0079] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.

[0080] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in connection with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can implement the described functions using different methods for each specific application, but such implementation should not be considered beyond the scope of this application. The steps of the methods or algorithms described in connection with the embodiments disclosed herein can be implemented directly in hardware, software modules executed by a processor, or a combination of both. Software modules can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disks, removable disks, CD-ROMs, or any other form of storage medium known in the art.

[0081] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0082] The present invention has provided a detailed description of a method, apparatus, device, and storage medium for determining central processing unit utilization. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.

Claims

1. A method for determining central processing unit utilization, characterized in that, include: Get the total CPU runtime and waiting time during the process execution cycle; Obtain the stall cycle time of the central processing unit in a stall state during the total running time; The utilization rate of the central processing unit is calculated and determined based on the stall cycle time, the total running time, and the waiting time; The total runtime of the central processing unit within the process execution cycle includes: The clock cycle count of the central processing unit is collected at the process execution time and the process termination time, and the total running time of the central processing unit is determined based on the clock cycle count; The step of obtaining the stall cycle time of the central processing unit in a stall state during the total running time includes: The invalid clock cycles within the total runtime are obtained as the stall cycle time of the central processing unit, and the stall cycle time is stored using a newly added storage process. The step of calculating and determining the CPU utilization based on the stall cycle time, the total running time, and the waiting time includes: The total execution time of the process is determined based on the total running time and the waiting time; the utilization rate of the central processing unit is determined by the percentage of the total execution time of the process to the total running time and the percentage of the stall cycle time to the total running time.

2. The method for determining central processing unit utilization according to claim 1, characterized in that, The step of collecting the number of clock cycles of the central processing unit (CPU) at the process execution time and the process termination time, and determining the total running time of the CPU based on the number of clock cycles, includes: The number of clock cycles of the central processing unit is collected at the time of process execution and the time of process termination, and the difference between the number of clock cycles at the time of process termination and the number of clock cycles at the time of process execution is calculated to obtain the target number of clock cycles. The total running time of the central processing unit is determined based on the target number of clock cycles.

3. The method for determining central processing unit utilization according to claim 1, characterized in that, The process of obtaining the invalid clock cycles within the total runtime as the stall cycle time of the central processing unit further includes: During process context switching, invalid clock cycles are collected and bound to the corresponding processes.

4. The method for determining central processing unit utilization according to any one of claims 1 to 3, characterized in that, Also includes: Users can choose whether to enable the operation of obtaining the stall cycle time based on their needs.

5. A central processing unit utilization determination device, characterized in that, The CPU utilization determination device is used to implement the CPU utilization determination method as described in any one of claims 1 to 4, wherein the CPU utilization determination device comprises: The first-time acquisition module (11) is used to acquire the total running time and waiting time of the central processing unit within the process execution cycle; The second time acquisition module (12) is used to acquire the stall cycle time of the central processing unit in the stall state during the total running time. The utilization determination module (13) is used to calculate and determine the utilization of the central processing unit based on the stall cycle time, the total running time and the waiting time.

6. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the steps of the central processing unit utilization determination method as described in any one of claims 1 to 4.

7. A computer-readable storage medium, characterized in that, Used to store computer programs; wherein, when the computer programs are executed by a processor, they implement the steps of the central processing unit utilization determination method as described in any one of claims 1 to 4.

Citation Information

Patent Citations

  • Evaluation method for data center virtual machine migration scheduling strategies

    CN104636197A

  • Load rate measuring method of central processing unit and electronic equipment

    CN110968480A