Method, device and medium for controlling central processing unit
By dynamically adjusting the utilization rate of multi-core CPUs, the problems of task termination and performance degradation caused by mechanical power consumption reduction in existing technologies are solved, and power consumption is effectively reduced while ensuring performance and lifespan.
Patent Information
- Application Number
- CN202411519652.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-29
- Publication Date
- 2025-10-21
- Estimated Expiration
- 2044-10-29
AI Technical Summary
Existing methods for reducing multi-core CPU power consumption are too mechanical and easily lead to task termination and CPU performance degradation.
By obtaining the usage parameters of the central processing unit, the utilization rate of each core is dynamically adjusted, the core with the lowest utilization rate is determined and its operation is interrupted until the utilization rate exceeds the preset range, and the core is dynamically enabled or disabled to control CPU power consumption.
While ensuring CPU performance and service life, flexibly reduce CPU power consumption to avoid task termination and performance degradation.
Smart Images

Figure CN119440829B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure generally relates to the field of computer technology, and more particularly to a method, apparatus, device, and medium for controlling a central processing unit (CPU). Background Art
[0002] Linux systems are often equipped with multi-core central processing units (CPUs). Each core of a multi-core CPU runs one process at the same time, and multiple cores run different processes serially.
[0003] To reduce the power consumption of multi-core CPUs during use, related technologies often adjust and control the CPU clock frequency to control CPU energy consumption. Specifically, software tools can be used to find and modify the CPU's power management settings to reduce or increase the CPU clock frequency, thereby controlling CPU operating energy consumption. Alternatively, software tools can be used to manually modify the CPU's operating parameters to control CPU operating energy consumption.
[0004] However, in the process of modifying and controlling the CPU's operating energy consumption through software tools, since the CPU's originally selected operating parameters are directly modified, the CPU terminal load may be too high, leading to task termination and CPU performance degradation. Summary of the Invention
[0005] In view of the above-mentioned defects or deficiencies in the relevant technologies, it is desired to provide a control method, device, equipment and medium for a central processing unit, which can solve the problem that the existing methods for reducing CPU power consumption are too mechanical and easily lead to task termination and CPU performance degradation, dynamically adjust the CPU performance according to the actual situation of CPU execution, and timely reduce the CPU power consumption while ensuring the CPU performance and service life.
[0006] In a first aspect, a method for controlling a central processing unit is provided, the method comprising:
[0007] Obtaining usage parameters of a central processing unit, wherein the usage parameters include usage parameters of the central processing unit, and the central processing unit is a multi-core central processing unit;
[0008] Obtaining, according to the usage parameter, a usage rate of each core currently enabled in the central processing unit;
[0009] When the usage rate of each of the currently enabled cores is within a preset usage rate range, determining a first core with the lowest usage rate among the currently enabled cores, determining a target process corresponding to the first core, releasing the correspondence between the target process and the first core, and interrupting the operation of the first core until the usage rate of any core among the currently enabled cores of the central processing unit exceeds the preset usage rate range, and the first core is the only core executing the target process;
[0010] Enable the first core.
[0011] In this application, the usage parameters of the central processing unit (CPU) are first obtained (the usage parameters include the CPU usage parameters, and the CPU is a multi-core CPU). Then, based on the usage parameters, the usage rate of each currently enabled core of the CPU is obtained. Then, if the usage rate of each core is within a preset usage rate range, the first core with the lowest usage rate among the currently enabled cores is determined, and a target process corresponding to the first core is determined. The correspondence between the target process and the first core is removed, and the operation of the first core is interrupted until the usage rate of any of the currently enabled cores of the CPU exceeds the preset usage rate range (the first core is the only core executing the target process). Finally, the first core is enabled. In this way, by continuously and dynamically determining the relationship between the currently enabled cores in the CPU and the preset usage rate range, the first core with the lowest usage rate is dynamically disabled or enabled based on the relationship, thereby timely reducing CPU power consumption while ensuring CPU performance, service life, and user experience.
[0012] In a second aspect, a credential requesting device is provided, the device comprising:
[0013] A communication unit, configured to receive a request message sent by the second node; the request message is used to request access to a credential of a third node;
[0014] a processing unit, configured to determine one or more authorized resource addresses of the third node, compress the one or more authorized resource addresses, and obtain compressed resource information; the authorized resource address is a resource address among the resource addresses of the third node that the second node is allowed to access;
[0015] The communication unit is further configured to send a certificate to the second node according to the compressed resource information; the certificate includes the compressed resource information
[0016] In a third aspect, a computer device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the method described in the first aspect is implemented.
[0017] In a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored, characterized in that when the program is executed by a processor, the method described in the first aspect is implemented.
[0018] In a fifth aspect, a computer program product is provided. The computer program product includes instructions, and when the instructions are executed by a processor, the method described in the first aspect is implemented.
[0019] Additional aspects and advantages of the present invention will be set forth in part in the description which follows and, in part, will be obvious from the description which follows, or may be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] Other features, objects and advantages of the present application will become more apparent upon reading the detailed description of non-limiting embodiments made with reference to the following drawings:
[0021] Figure 1 One of the flowcharts of the control method of the central processing unit provided in an embodiment of the present application;
[0022] Figure 2 The second flowchart of the control method of the central processing unit provided in the embodiment of the present application;
[0023] Figure 3 A schematic diagram of the structure of a control device of a central processing unit provided in an embodiment of the present application;
[0024] Figure 4 A schematic diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0025] The present application will be further described in detail below with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are merely for the purpose of explaining the relevant invention and are not intended to limit the invention. It should also be noted that, for ease of description, only portions relevant to the invention are shown in the accompanying drawings.
[0026] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The application scenarios of the present application will be described below.
[0027] Linux systems are often equipped with multi-core central processing units (CPUs). Each core of a multi-core CPU runs one process at the same time, and multiple cores run different processes serially.
[0028] In order to reduce the power consumption of a multi-core CPU during use, a popular strategy in related technologies is to control the energy consumption of the CPU by adjusting and controlling the CPU clock frequency.
[0029] It's understandable that because the CPU executes instructions step by step under the control of a clock signal, with each clock signal cycle completing one step, the clock frequency largely reflects the CPU's speed. Generally speaking, CPU clock frequency, computing performance, and power consumption are directly proportional. When the CPU clock frequency is reduced to its lowest (offline state), its computing performance and power consumption also reach their lowest values, achieving maximum energy savings.
[0030] For example, you can use software tools to find and modify the CPU's power management settings to reduce or increase the CPU's clock frequency, thereby controlling the CPU's operating energy consumption; or you can use software tools to directly modify the CPU's operating parameters to control the CPU's operating energy consumption.
[0031] Specifically, the above-mentioned software tool can be a cpupower tool, which is used to view and modify the CPU power management settings, such as frequency scaling and adjusting the operating mode. It can also directly access and modify / sys / devices / system / cpu / cpuid / ... as root, that is, modify the CPU operating parameters in the pseudo file system, reduce the clock frequency, and thus reduce the CPU operating frequency.
[0032] However, in response to the energy-saving needs of a multi-core CPU, the above two existing solutions simply mechanically reduce the clock frequency of one or more cores without considering the current load of each core in the multi-core system. For example, they do not specifically consider the actual current utilization rate of each core in the CPU, nor do they consider whether interrupting the load or reducing the operating frequency will lead to task termination and shorten the CPU life.
[0033] Based on this, implementing such a solution can indeed directly and significantly reduce CPU power consumption, but it will bring more adverse negative effects such as task termination and device performance degradation. Overall, the gains do not outweigh the losses.
[0034] Based on this, the present application proposes a control method, device, equipment and medium for a central processing unit, which can solve the problem that the existing method of reducing CPU power consumption is too mechanical and easily leads to task termination and CPU performance degradation. It dynamically adjusts the CPU performance according to the actual situation of CPU execution, and timely reduces the CPU power consumption while ensuring the CPU performance and service life.
[0035] Figure 3 FIG. 1 is a flow chart of a method for controlling a central processing unit provided by an embodiment of the present application. Figure 3 As shown, the method includes the following steps 301 to 304:
[0036] Step 301: Obtain the usage parameters of the central processing unit.
[0037] In the embodiment of the present application, the usage parameters include usage parameters of a central processing unit, and the central processing unit is a multi-core central processing unit.
[0038] In one example, the central processing unit may be a processor of a Linux system.
[0039] In an embodiment of the present application, the usage parameters of the above-mentioned central processing unit may include the usage status of each core in the above-mentioned central processing unit.
[0040] Exemplarily, the above-mentioned usage parameters may include system performance parameters and resource usage parameters of the central processing unit.
[0041] In one example, the system performance parameters may include a current CPU operating speed parameter, a CPU core number parameter, and a CPU energy saving mode parameter. Furthermore, the CPU operating speed parameter may include an operating speed parameter for each core in the CPU.
[0042] In one example, the resource usage parameters may include the resource occupancy rate and resource usage duration of the CPU. Further, the resource usage parameters of the CPU may include the resource occupancy rate and resource usage duration of each core in the CPU.
[0043] It is understandable that, in the case where the above-mentioned central processing unit is a Linux system central processing unit, during the normal operation of the Linux system, the use parameters of the Linux system central processing unit can be obtained using a preset command.
[0044] In one embodiment, the preset command may be a cat / proc / stat command, which can be used to obtain system performance parameters and resource usage parameters of a central processing unit (CPU) of a Linux system.
[0045] Step 302: Obtain the usage rate of each core currently enabled in the CPU according to the usage parameters.
[0046] In the embodiment of the present application, the above-mentioned usage parameters include operating rate parameters, resource occupancy rate and resource usage duration. Therefore, the usage parameters can be used to obtain the usage rate of each core currently enabled in the central processing unit.
[0047] It is understandable that the reason why the utilization rate of each currently enabled core in the CPU is obtained is that, in the embodiments of the present application, the cores of the CPU are constantly in a dynamically adjusted state. To achieve the function of reducing energy consumption, some cores in the CPU may be set to an interrupted state (for example, when the CPU is executing fewer processes), while other cores are set to an enabled state, or all cores of the CPU may be set to an enabled state. Therefore, the currently enabled cores may include all cores of the CPU, or may include some cores of the CPU.
[0048] Optionally, in an embodiment of the present application, the above-mentioned obtaining of the utilization rate of each core in the above-mentioned central processing unit according to the above-mentioned usage parameters includes: determining the idle time of each of the above-mentioned cores during the running time according to the above-mentioned usage parameters; determining the utilization rate of each core according to the running time of each of the above-mentioned cores and the idle time of each core.
[0049] In the embodiment of the present application, after obtaining the above-mentioned usage parameters, it is necessary to calculate and analyze the above-mentioned usage parameters.
[0050] Exemplarily, the key parameters in the usage parameters are: the time each CPU in a multi-core CPU spends on each process and the idle time of each CPU (i.e., idle time), and the total time spent by all processes in the CPU, i.e., the total time of each item.
[0051] According to the key parameters in the above usage parameters, there are the following ways to calculate the usage rate.
[0052] Example 1: According to the formula: , using the / proc / stat statistics obtained once, the total usage of each core from the time the system was started to the current time can be calculated.
[0053] Example 2: Get / proc / stat statistics twice at a certain interval T, calculate the difference between each item in the statistics to form a / proc / stat difference statistics, and then use the formula: The difference statistical information can be used to calculate the average usage rate of each core in the central processing unit within the interval length T, where the duration T can be specified or customized by the user, and this embodiment of the application does not limit this.
[0054] It is understandable that after calculating the utilization rate of each core, the utilization rate of the entire CPU can also be obtained accordingly. For example, the utilization rate of the entire CPU can be obtained by averaging the utilization rate of each core.
[0055] Furthermore, the above-mentioned method of averaging the utilization rate of each core to obtain the utilization rate of the entire central processing unit may include a direct addition and averaging method, and may also include a weighted addition and averaging method, which is not limited in the embodiment of the present application.
[0056] Step 303: When the usage rate of each of the currently enabled cores is within a preset usage rate range, determine the first core with the lowest usage rate among each of the currently enabled cores, and determine the target process corresponding to the first core, release the correspondence between the target process and the first core, and interrupt the operation of the first core until the usage rate of any of the currently enabled cores of the central processing unit exceeds the preset usage rate range.
[0057] In the embodiment of the present application, the first core is the only core that executes the target process.
[0058] In the embodiment of the present application, the above-mentioned preset usage rate range can be customized by the user or customized by the central processing unit, and the embodiment of the present application does not limit this.
[0059] In the embodiment of the present application, the above-mentioned preset usage rate range may be related to the number of enabled cores of the central processing unit. It is understood that when all cores are enabled, it means that the current central processing unit is in a non-energy-saving mode, and when some of the cores are in an interrupted operation state, it means that the central processing unit is already in an energy-saving mode.
[0060] Therefore, different numbers of activated cores of the CPU correspond to different preset usage rate ranges.
[0061] Furthermore, the preset usage rate range may be limited by a threshold value corresponding to the preset usage rate range. For details about the threshold value corresponding to the preset usage rate range, please refer to the subsequent description and will not be elaborated here.
[0062] In the embodiment of the present application, in order to save the energy consumption of the central processing unit in a flexible and timely manner to the greatest extent possible in combination with the actual usage of the central processing unit while ensuring the service life and performance of the central processing unit, it is necessary to flexibly and dynamically control the activation and interruption operation of each core in the central processing unit, that is, to continuously adjust the activation and interruption operation of multiple cores in the central processing unit.
[0063] It is understandable that for a central processing unit, it often runs multiple processes, and the number of processes may be the same as or different from the number of cores. In the process of running multiple processes, assuming that the utilization rate of each core is within the preset utilization rate range, the central processing unit has the conditions to shut down some cores to save energy. On this basis, in order to avoid problems such as sudden termination of processes when shutting down some cores, by obtaining the utilization rate of each core and filtering out the core with the lowest utilization rate, find the target process corresponding to the core, that is, in the current time period, only the process that can be run through the core with the lowest utilization rate, unbind this type of target process from the core with the lowest utilization rate, and then the terminal can run the first core.
[0064] Furthermore, the process of determining whether the utilization rate of each core is within the preset utilization rate range is a continuously cyclic process. If a core with the lowest utilization rate is successfully interrupted, the process will continue to check whether the utilization rate of the remaining cores that are still enabled is within the preset utilization rate range. Assuming that it is still within the preset utilization rate range, the first core with the lowest utilization rate among each currently enabled core can be further determined, and the target process corresponding to the first core can be determined. The correspondence between the target process and the first core is released and the operation of the first core is interrupted until the utilization rate of any core among the currently enabled cores of the above-mentioned central processor exceeds the preset utilization rate range, and the step of shutting down the first core with the lowest utilization rate will be stopped.
[0065] In one example, in a Linux system, each core runs only one process in the same time period. When the number of processes is greater than the number of enabled cores, different processes are executed serially in multiple cores.
[0066] Step 304: Activate the first core.
[0067] For example, if the usage rate of any core among the cores currently enabled in the central processing unit exceeds a preset usage rate range, the first core that was previously interrupted will be enabled.
[0068] It can be understood from the above content that the first core of the interrupt may be one core or multiple cores. The reason is that for the currently enabled core, a core with the lowest utilization rate will be selected as the first core interrupt each time. This process may be repeated multiple times, so the operation of multiple cores may be interrupted.
[0069] In an example, when the first core is one core, the one core may be directly enabled.
[0070] In one example, when the first core mentioned above is multiple cores, all the previously interrupted cores can be directly enabled, or multiple cores that were previously closed can be opened in sequence, that is, one previously interrupted core can be enabled at a time, and then another previously interrupted core can be enabled based on repeating steps 301 to 303.
[0071] In the method provided in an embodiment of the present application, usage parameters of a central processing unit (CPU) are first obtained (the usage parameters include CPU usage parameters, and the CPU is a multi-core CPU). Then, based on the usage parameters, the usage rate of each currently enabled core of the CPU is obtained. Then, if the usage rate of each core is within a preset usage rate range, the first core with the lowest usage rate among the currently enabled cores is determined, and a target process corresponding to the first core is determined. The correspondence between the target process and the first core is removed, and the first core is interrupted until the usage rate of any core currently enabled by the CPU exceeds the preset usage rate range (the first core is the only core executing the target process). Finally, the first core is enabled. In this way, by continuously and dynamically determining the relationship between the currently enabled cores in the CPU and the preset usage rate range, the first core with the lowest usage rate is dynamically disabled or enabled based on the relationship, thereby timely reducing CPU power consumption while ensuring CPU performance, service life, and user experience.
[0072] In another embodiment of the present application, a method for determining a preset usage range based on the number of enabled cores of the central processing unit is also provided. Exemplarily, when the usage rate of each of the above cores is within the preset usage range, the first core with the lowest usage rate among the above multiple cores is determined, and the target process corresponding to the above first core is determined, and the correspondence between the above target process and the above first core is released. In the control method of the central processing unit provided in the embodiment of the present application, the method includes: determining the number of enabled cores in the above central processing unit; determining the threshold value of the preset usage range corresponding to the above preset usage range based on the number of enabled cores in the above central processing unit; when the usage rate of each of the above cores is less than the threshold value of the above preset usage range, determining the first core with the lowest usage rate among the above multiple cores, and determining the target process corresponding to the above first core, and releasing the correspondence between the above target process and the above first core.
[0073] It can be understood from the foregoing that, in the embodiment of the present application, when determining whether the core usage of the CPU is within a preset usage range, the preset usage range is different when the number of enabled CPUs is different.
[0074] Furthermore, when all cores in the central processing unit are enabled, the preset usage threshold corresponding to the preset usage range is lower. The reason is that the central processing unit has used all core resources to execute process tasks. Only when all cores are within the preset usage range corresponding to the lower preset usage threshold, the conditions for further shutting down the first core in the central processing unit are met.
[0075] Correspondingly, when all core parts in the central processing unit are enabled, it means that some cores have been interrupted. At this time, the preset usage threshold corresponding to the preset usage range is higher. The reason is that the central processing unit only uses part of the core resources to execute process tasks, that is, the central processing unit can execute all tasks using part of the resources at this time. Then, the part of the cores that are currently enabled are within the preset usage range corresponding to the higher preset usage threshold, and also have the conditions to further shut down the first core in the central processing unit.
[0076] Optionally, the above-mentioned determination of the threshold of the preset usage range corresponding to the preset usage range based on the number of enabled cores in the central processing unit, in the central processing unit control method provided in the embodiment of the present application, includes: when the number of enabled cores in the above-mentioned central processing unit is the same as the total number of cores of the central processing unit, determining that the threshold of the preset usage range corresponding to the above-mentioned preset usage range is a first preset usage rate; when the number of running cores enabled in the above-mentioned central processing unit is less than the total number of cores of the central processing unit, determining that the threshold of the preset usage range corresponding to the above-mentioned preset usage range is a second preset usage rate.
[0077] Exemplarily, the first preset usage rate is less than the second preset usage rate.
[0078] For example, the first preset usage rate may be 50%, and the second preset usage rate may be 70%.
[0079] Exemplarily, the first preset usage rate and the second preset usage rate may be user-defined or preset, and this embodiment of the present application does not limit this.
[0080] Optionally, in the above-mentioned enabling of the above-mentioned first core, in the control method of the central processing unit provided in the embodiment of the present application, the control method of the central processing unit provided in the embodiment of the present application includes: obtaining the usage rate of each core in the currently enabled cores of the central processing unit, and enabling the above-mentioned first core when the usage rate of any core in the above-mentioned currently enabled cores is greater than the second preset usage rate.
[0081] It is understood that before the first core is activated, some of the cores in the CPU have already been interrupted. Therefore, the currently activated cores do not represent all of the cores in the CPU, but only some of them. As can be seen from the foregoing description, for a CPU with only some of its cores activated, the preset usage threshold used to determine its preset usage range is a higher second preset usage threshold. That is, if the usage of any of the currently activated cores exceeds the second preset usage threshold, the first core is activated.
[0082] Optionally, in an embodiment of the present application, when the usage rate of each of the cores is within a preset usage rate range, the first core with the lowest usage rate among each of the currently enabled cores is determined. The control method of the central processing unit provided in the embodiment of the present application includes: when the usage rate of each of the cores is within a preset usage rate range, determining that the current mode of the central processing unit is an energy-saving mode, and determining the first core with the lowest usage rate among each of the currently enabled cores, and updating the threshold of the preset usage rate range corresponding to the preset usage rate range from the first preset usage rate to the second preset usage rate or maintaining the second preset usage rate.
[0083] For example, in order to facilitate the central processing unit to determine the preset usage rate threshold corresponding to the preset usage rate range, the central processing unit can be assigned an energy-saving mode and a non-energy-saving mode, thereby distinguishing the preset usage rate threshold corresponding to the preset usage rate range that the current central processing unit needs to use as the first preset usage rate or the second preset usage rate.
[0084] Exemplarily, the energy-saving mode can be represented by using values assigned in parameters.
[0085] In one example, if the POWERSAVE_MODE in the usage parameter is 0, it indicates that the system is in a non-energy-saving mode; if the POWERSAVE_MODE in the usage parameter is 1, it indicates that the system is in an energy-saving mode.
[0086] Exemplarily, when in energy-saving mode, the preset usage rate threshold corresponding to the preset usage rate range required by the above-mentioned central processing unit is the second preset usage rate; when in non-energy-saving mode, the preset usage rate threshold corresponding to the preset usage rate range required by the above-mentioned central processing unit is the first preset usage rate.
[0087] Optionally, in an embodiment of the present application, the target process corresponding to the above-mentioned first core in the other cores is determined, and the correspondence between the above-mentioned target process and the above-mentioned first core is released. The control method of the central processing unit in the embodiment of the present application includes: traversing the list of executable cores corresponding to each process in all processes of the above-mentioned central processing unit; according to the list of executable cores corresponding to each of the above-mentioned processes, determining that the core in the executable list is the process corresponding to the above-mentioned first core as the target process; and modifying the core in the executable list of the above-mentioned target process to other cores, and the above-mentioned other cores are cores other than the first core in the above-mentioned central processing unit.
[0088] For example, each process in a CPU may not necessarily prefer to run on any one core. For example, a CPU includes four cores and ten processes, namely core 1, core 2, core 3, and core 4, and processes 1-10. Among processes 1-10, process 5 may only run on core 4 when all cores are enabled, and not on other cores.
[0089] Furthermore, the fact that process No. 5 runs only in core No. 4 and not in other cores does not mean that process No. 5 cannot run in other cores, but rather that it has the strongest affinity with core No. 4.
[0090] In one example, for a central processing unit (CPU), the affinity list, or list of executable cores, can be used to determine the cores on which each process prefers to run. Specifically, the Cpus_allowed_list for each core can be used to determine the cores on which each process prefers to run. For example, the affinity list for process 5 may only include cores 1, 2, and 3.
[0091] Exemplarily, based on the above introduction, it is necessary to traverse and obtain the list of runnable cores for each process. In the above process of shutting down the first core with the lowest utilization rate, for processes that can run on both the first core and other cores, even if the first core is shut down, it will not affect the subsequent running of these processes. As for the target process that has a corresponding relationship with the first core, that is, the target process that previously had only the first core in the runnable core list, it is necessary to unbind the target process from the first core before shutting down the first core, and modify the core in the runnable list of the target process to other cores, that is, bind the target process to other cores, so as to ensure the subsequent running process of the target process.
[0092] Optionally, in the embodiment of the present application, the above-mentioned acquisition of the usage parameters of the central processing unit, in the control method of the central processing unit in the embodiment of the present application, includes: acquiring the usage parameters of the above-mentioned central processing unit according to the resource acquisition cycle of the above-mentioned central processing unit.
[0093] Exemplarily, the resource acquisition cycle of the central processing unit is a cycle for acquiring systemic parameters corresponding to the central processing unit. The usage parameters of the central processing unit include the usage time of each core in the central processing unit and the energy-saving state parameters corresponding to the central processing unit.
[0094] It is understandable that the central processing unit needs to obtain various performance parameters of the central processing unit according to a certain period, and this period is the resource acquisition period.
[0095] In the embodiment of the present application, the usage parameters of the central processing unit may be synchronously acquired according to the resource acquisition cycle of the central processing unit.
[0096] In this way, in the process of obtaining the usage parameters of the central processing unit, there is no need to set a clock signal separately, which saves setting costs and setting procedures and improves the efficiency of obtaining the usage parameters of the central processing unit.
[0097] The following will be combined Figure 2 The operation process of this application is described by Example 3. In Example 3, the central processing unit is a multi-core central processing unit of the Linux system, and the description begins with the central processing unit not interrupting any core:
[0098] Step (1): Input the cat / proc / stat command according to the cycle length T. During the normal operation of the Linux system, use the cat / proc / stat command according to the cycle length T to obtain the statistical information of the system performance and resource usage of the central processing unit (i.e., the usage parameters of the central processing unit mentioned above). And based on the system performance and resource usage, define the value of the energy-saving mode flag POWERSAVE_MODE to be 0, where the value 0 represents that the energy-saving mode is not turned on (the default value), and the value 1 represents that the energy-saving mode is turned on.
[0099] Step (2): Obtain the time each core spends on different processes. Calculate and analyze the statistical information obtained in step (1) (i.e., the CPU usage parameters mentioned above). The key data in the statistical information is the time each core of the multi-core CPU spends on different processes, and the total time of each core and the relevant data of the entire CPU are used.
[0100] Step (3): Calculate the CPU usage of each core. Based on the above statistical information, calculate the CPU usage of each core.
[0101] Step (4): Based on the data obtained in step (3), the following judgments are made in steps A1 and A2:
[0102] Step A1: If all cores are enabled and the utilization of all cores is less than 50% (i.e., the first preset utilization), it indicates that the current CPU is in a low-load state. If so, the flag POWERSAVE_MODE is written from 0 to 1, indicating that the CPU is in power-saving mode, and then proceeds to step A2. Otherwise, jump to step (1) and repeat;
[0103] Step A2: Filter out the lowest-utilized core in the CPU, Lowest_cpu_id (i.e., the first core mentioned above). Then, use the command cat / proc / [PID] / status to traverse all processes in the current Linux system and obtain the affinity list for each process, i.e., Cpus_allowed_list. Further filter out the processes in the affinity list that only have the lowest-utilized core. Record the PIDs (i.e., the unique identifier of the process in the Linux system) of these processes bound to the Lowest_cpu_id core. Use the command taskset to migrate all these processes to cores other than the first core, and then execute step A3.
[0104] Step A3: shut down the Lowest_cpu_id core to reduce the power consumption of the CPU. Specifically, write the file: / sys / devices / system / cpu / <cpu_id> Set the value of / online to 0 to shut down the core, then return to step (1) and repeat.
[0105] Step (5): When some cores are enabled, that is, POWERSAVE_MODE is set to 1, and the usage rate of the enabled cores is less than 70% (that is, the second preset usage rate), execute the following steps B1 and B2;
[0106] Step B1: If the usage of all currently enabled cores is less than 70%, proceed to Step A2 again:
[0107] Step B2: If the usage of any CPU among all currently enabled cores is greater than 70%, enable the previously disabled cores in turn. Specifically, determine the ID of a core, that is, determine a cpu_id, by writing the file: / sys / devices / system / cpu / <cpu_id> / online is set to 1 to open the first core, then return to step (1) and repeat the execution. At the same time, the flag POWERSAVE_MODE is written to 0, that is, the power saving mode is turned off, and then the entire process is exited;
[0108] The present application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the training rule determination method described in the present application. For example, Figure 1 The individual steps of the method are shown.
[0109] The present invention provides a computer program product, which includes instructions that are executed by a processor when the processor executes the instructions. Figure 1 The individual steps of the method are shown.
[0110] It should be noted that although the operations of the present method are described in a particular order in the drawings, this does not require or imply that the operations must be performed in this particular order, or that all illustrated operations must be performed to achieve desirable results.
[0111] Figure 3 This is a block diagram of a credential requesting device according to an embodiment of the present application. The device may be deployed on an authorization node (eg, the first node described above). Figure 3 The device includes an acquisition unit 601 and an execution unit 602.
[0112] An acquiring unit 601 acquires usage parameters of a central processing unit (CPU), wherein the usage parameters include usage parameters of the CPU, and the CPU is a multi-core CPU;
[0113] The acquisition unit 601 is further configured to acquire the usage rate of each core currently enabled by the central processing unit according to the usage parameter;
[0114] The execution unit 602 is configured to, when the usage rate of each of the currently enabled cores is within a preset usage rate range, determine a first core with the lowest usage rate among the currently enabled cores, determine a target process corresponding to the first core, remove the correspondence between the target process and the first core, and interrupt the execution of the first core until the usage rate of any core among the currently enabled cores of the central processing unit exceeds the preset usage rate range, and the first core becomes the only core executing the target process;
[0115] The execution unit 602 is further configured to enable the first core.
[0116] In one embodiment, the execution unit 602 is specifically used to determine the number of enabled cores in the central processing unit; determine the threshold of the preset usage range corresponding to the preset usage range based on the number of enabled cores in the central processing unit; when the usage of each core is less than the threshold of the preset usage range, determine the first core with the lowest usage among the multiple cores, determine the target process corresponding to the first core, and release the correspondence between the target process and the first core.
[0117] In one embodiment, the execution unit 602 is specifically used to, when the number of enabled cores in the central processing unit is the same as the total number of cores in the central processing unit, determine that the threshold value of the preset usage range corresponding to the preset usage range is a first preset usage rate; when the number of enabled running cores in the central processing unit is less than the total number of cores in the central processing unit, determine that the threshold value of the preset usage range corresponding to the preset usage range is a second preset usage rate; and the first preset usage rate is less than the second preset usage rate.
[0118] In one embodiment, the execution unit 602 is specifically configured to obtain a usage rate of each core in the currently enabled cores of the central processing unit, and enable the first core if the usage rate of any core in the currently enabled cores is greater than a second preset usage rate.
[0119] In one embodiment, the execution unit 602 is specifically used to determine that the current mode of the central processing unit is the energy-saving mode, and determine the first core with the lowest usage among each of the currently enabled cores, when the usage rate of each core is within a preset usage rate range, and update the threshold of the preset usage rate range corresponding to the preset usage rate range from the first preset usage rate to the second preset usage rate or maintain the second preset usage rate.
[0120] In one embodiment, the acquisition unit 601 is specifically configured to determine the idle time of each core during its operation according to the usage parameters; and determine the utilization rate of each core according to the operation time of each core and the idle time of each core.
[0121] In one embodiment, the execution unit 602 is specifically used to traverse the list of executable cores corresponding to each process in all processes of the central processing unit; determine, based on the list of executable cores corresponding to each process, that the core in the executable list is the process corresponding to the first core as the target process; and modify the core in the executable list of the target process to other cores, where the other cores are cores other than the first core in the central processing unit.
[0122] In one embodiment, the acquisition unit 602 is specifically used to obtain the usage parameters of the central processing unit according to the resource acquisition cycle of the central processing unit. The resource acquisition cycle of the central processing unit is a cycle for obtaining the corresponding systematic parameters of the central processing unit. The usage parameters of the central processing unit include the usage time of each core in the central processing unit and the energy-saving state parameters corresponding to the central processing unit.
[0123] It should be understood that the units described in the control device of the central processing unit correspond to the various steps in the method described in the accompanying drawings. Therefore, the operations and features described above for the method are also applicable to the control device of the central processing unit and the units contained therein, and will not be repeated here. The control device of the central processing unit can be pre-implemented in the browser or other security application of the computer device, or can be loaded into the browser or its security application of the computer device by downloading or other means. The corresponding units in the control device of the central processing unit can cooperate with the units in the computer device to implement the solution of the embodiment of the present application.
[0124] The several modules or units mentioned in the detailed description above are not necessarily divided into one module or unit. In fact, according to the embodiments of the present disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided into multiple modules or units to be embodied.
[0125] It should be noted that for details not disclosed in the control device of the central processing unit in the embodiment of the present application, please refer to the details disclosed in the above embodiments of the present application, and no further details will be given here.
[0126] Reference below Figure 4 , Figure 4 FIG. 1 shows a schematic diagram of a computer device suitable for implementing an embodiment of the present application. Figure 4 As shown, computer system 1700 includes a central processing unit (CPU) 1701, which can perform various appropriate actions and processes according to programs stored in read-only memory (ROM) 1702 or programs loaded from storage 1708 into random access memory (RAM) 1703. RAM 1703 also stores various programs and data required for the system's operating instructions. CPU 1701, ROM 1702, and RAM 1703 are connected to each other via a bus 1704. An input / output (I / O) interface 1705 is also connected to bus 1704.
[0127] The following components are connected to the I / O interface 1705: an input section 1706 including a keyboard, mouse, and the like; an output section 1707 including devices such as a cathode ray tube (CRT), a liquid crystal display (LCD), and speakers; a storage section 1708 including devices such as a hard disk; and a communication section 1709 including a network interface card such as a LAN card or a modem. The communication section 1709 performs communication processing via a network such as the Internet. A drive 1710 is also connected to the I / O interface 1705 as needed. Removable media 1711, such as a magnetic disk, an optical disk, a magneto-optical disk, or a semiconductor memory, is installed in the drive 1710 as needed, so that computer programs read from the media can be installed in the storage section 1708 as needed.
[0128] In particular, according to the embodiment of the present application, the above reference flow chart Figure 1 The described processes can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for executing the method illustrated in the flowchart. In such an embodiment, the computer program contains program code for executing the method illustrated in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 1709 and / or installed from removable media 1711. When the computer program is executed by the central processing unit (CPU) 1701, the aforementioned functions defined in the system of the present application are performed.
[0129] It should be noted that the computer-readable medium described herein may be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to, an electrical connection having one or more conductors, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In this application, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this application, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. This propagated data signal may take a variety of forms, including, but not limited to, electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transfer a program for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium may be transmitted using any suitable medium, including but not limited to wireless, wire, optical cable, RF, or any suitable combination thereof.
[0130] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operating instructions of the systems, methods and computer program products according to various embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, program segment, or a part of code, and the aforementioned module, program segment, or a part of code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order than the order marked in the accompanying drawings. For example, the boxes represented by two connections can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of the boxes in the block diagram and / or flowchart, can be implemented using a dedicated hardware-based system that performs the specified function or operating instruction, or can be implemented using a combination of dedicated hardware and computer instructions.
[0131] The units or modules described in the embodiments of this application may be implemented in software or hardware. The units or modules described may also be provided in a processor. For example, a processor may be described as including a first receiving module, a second receiving module, and a sending module. The names of these units or modules do not, in some cases, limit the units or modules themselves.
[0132] As another aspect, the present application further provides a computer-readable storage medium, which may be included in the electronic device described in the above embodiments, or may exist independently and not be incorporated into the electronic device. The computer-readable storage medium stores one or more programs, which are used by one or more processors to execute the central processing unit control method described in the present application.
[0133] The above description is merely a preferred embodiment of the present application and an illustration of the technical principles employed. Those skilled in the art should understand that the scope of disclosure in this application is not limited to technical solutions formed by a specific combination of the aforementioned technical features. It also encompasses other technical solutions formed by any combination of the aforementioned technical features or their equivalents, without departing from the aforementioned disclosed concepts. For example, a technical solution formed by replacing the aforementioned features with (but not limited to) technical features with similar functions disclosed in this application.
Claims
1. A method for controlling a central processing unit, characterized in that: include: Obtaining usage parameters of a central processing unit, wherein the usage parameters include usage parameters of the central processing unit, and if the central processing unit is a multi-core central processing unit, the usage parameters of the central processing unit include an operating rate parameter, a resource occupancy rate, and a resource usage duration of the central processing unit; Obtaining, according to the usage parameter, a usage rate of each core currently enabled in the central processing unit; When the usage rate of each of the currently enabled cores is lower than a threshold value corresponding to a preset usage rate range, determining a first core with the lowest usage rate among the currently enabled cores, determining a target process corresponding to the first core, releasing the correspondence between the target process and the first core, and interrupting the operation of the first core until the usage rate of any core among the currently enabled cores of the central processing unit exceeds the preset usage rate range, and the first core becomes the only core executing the target process; enabling the first core; Wherein, when the usage rate of each core is lower than a threshold value corresponding to a preset usage rate range, determining a first core with the lowest usage rate among each of the currently enabled cores includes: In the case where the usage rate of each core is lower than the threshold value corresponding to the preset usage rate range, the current mode of the central processing unit is determined to be the energy-saving mode, and the first core with the lowest usage rate among each of the currently enabled cores is determined, and the threshold value of the preset usage rate range corresponding to the preset usage rate range is updated from the first preset usage rate to the second preset usage rate or maintains the second preset usage rate; the first preset usage rate is the preset usage rate threshold value corresponding to the preset usage rate range required for the central processing unit to use in the non-energy-saving mode, and the second preset usage rate threshold value is the preset usage rate threshold value corresponding to the preset usage rate range required for the central processing unit to use in the energy-saving mode; the first preset usage rate is less than the second preset usage rate; or, determining the number of enabled cores in the central processing unit when the usage rate of each core is lower than a threshold value corresponding to a preset usage rate range; determining the threshold value of a preset usage rate range corresponding to the preset usage rate range based on the number of enabled cores in the central processing unit; and determining a first core with the lowest usage rate among the multiple cores when the usage rate of each core is lower than the threshold value of the preset usage rate range; The determining, based on the number of enabled cores in the central processing unit, a threshold value of a preset usage rate range corresponding to the preset usage rate range includes: In a case where the number of enabled cores in the central processing unit is the same as the total number of cores in the central processing unit, determining that the threshold of the preset usage rate range corresponding to the preset usage rate range is a first preset usage rate; When the number of running cores enabled in the central processing unit is less than the total number of cores of the central processing unit, the threshold of the preset usage range corresponding to the preset usage range is determined to be a second preset usage rate; and the first preset usage rate is less than the second preset usage rate.
2. The method according to claim 1, characterized in that The enabling of the first core includes: Obtain the usage rate of each core in the currently enabled cores of the central processing unit, and enable the first core if the usage rate of any core in the currently enabled cores is greater than a second preset usage rate; wherein the usage rate of any core in the currently enabled cores exceeds the preset usage rate range specifically means that the usage rate of any core in the currently enabled cores is greater than the second preset usage rate.
3. The method according to claim 1, characterized in that The obtaining, according to the usage parameter, a usage rate of each core in the central processing unit, includes: Determining, based on the usage parameters, an idle time of each core during its runtime; The utilization rate of each core is determined according to the running time of each core and the idle time of each core.
4. The method according to claim 1, wherein The determining the target process corresponding to the first core and removing the correspondence between the target process and the first core includes: Traversing a list of executable cores corresponding to each process in all processes of the central processing unit; According to the list of executable cores corresponding to each process, determining that the process corresponding to the core in the executable list and the first core is the target process; The core in the runnable list of the target process is modified to another core, where the other core is a core other than the first core in the central processing unit.
5. The method according to claim 1, wherein The obtaining of the usage parameters of the central processing unit includes: According to the resource acquisition cycle of the central processing unit, the usage parameters of the central processing unit are obtained. The resource acquisition cycle of the central processing unit is a cycle for obtaining the system performance parameters corresponding to the central processing unit. The usage parameters of the central processing unit include the usage time of each core in the central processing unit and the energy-saving state parameters corresponding to the central processing unit.
6. A control device for a central processing unit, characterized in that: The device comprises: an acquisition unit, configured to acquire usage parameters of a central processing unit (CPU), wherein the usage parameters include usage parameters of the CPU, and if the CPU is a multi-core CPU, the usage parameters of the CPU include an operating rate parameter, a resource occupancy rate, and a resource usage duration of the CPU; The acquiring unit is further configured to acquire the usage rate of each core currently enabled by the central processing unit according to the usage parameter; an execution unit, configured to, when the usage rate of each of the currently enabled cores is lower than a threshold value corresponding to a preset usage rate range, determine a first core with the lowest usage rate among each of the currently enabled cores, determine a target process corresponding to the first core, cancel the correspondence between the target process and the first core, and interrupt the operation of the first core until the usage rate of any core among the currently enabled cores of the central processing unit exceeds the preset usage rate range, and the first core becomes the only core executing the target process; The execution unit is further configured to enable the first core; Wherein, when the usage rate of each core is lower than a threshold value corresponding to a preset usage rate range, determining a first core with the lowest usage rate among each of the currently enabled cores includes: In the case where the usage rate of each core is lower than the threshold value corresponding to the preset usage rate range, the current mode of the central processing unit is determined to be the energy-saving mode, and the first core with the lowest usage rate among each of the currently enabled cores is determined, and the threshold value of the preset usage rate range corresponding to the preset usage rate range is updated from the first preset usage rate to the second preset usage rate or maintains the second preset usage rate; the first preset usage rate is the preset usage rate threshold value corresponding to the preset usage rate range required for the central processing unit to use in the non-energy-saving mode, and the second preset usage rate threshold value is the preset usage rate threshold value corresponding to the preset usage rate range required for the central processing unit to use in the energy-saving mode; the first preset usage rate is less than the second preset usage rate; or, determining the number of enabled cores in the central processing unit when the usage rate of each core is lower than a threshold value corresponding to a preset usage rate range; determining the threshold value of a preset usage rate range corresponding to the preset usage rate range based on the number of enabled cores in the central processing unit; and determining a first core with the lowest usage rate among the multiple cores when the usage rate of each core is lower than the threshold value of the preset usage rate range; The determining, based on the number of enabled cores in the central processing unit, a threshold value of a preset usage rate range corresponding to the preset usage rate range includes: In a case where the number of enabled cores in the central processing unit is the same as the total number of cores in the central processing unit, determining that the threshold of the preset usage rate range corresponding to the preset usage rate range is a first preset usage rate; When the number of running cores enabled in the central processing unit is less than the total number of cores of the central processing unit, the threshold of the preset usage range corresponding to the preset usage range is determined to be a second preset usage rate; and the first preset usage rate is less than the second preset usage rate.
7. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the method according to any one of claims 1 to 5 is implemented.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.
9. A computer program product comprising instructions, characterized in that: When the instructions are executed by a processor, the method according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Power supply management method based on automatic adjustment of processor nuclear number
CN102520782A
Method and system for regulating and controlling multi-core central processing unit (CPU)
CN102866921A
Performing power management in a multicore processor
CN107209545A
Dynamic power management optimization
US20160378168A1