TECHNICAL FIELD

This application relates to the field of electronic technologies, and more specifically, to a frequency scaling method and apparatus and a computer-readable storage medium.

BACKGROUND

In recent years, with the rapid development of mobile devices, especially smartphones, a mobile use habit means that a user has a high requirement on power consumption and heat generation of a smartphone. To reduce the power consumption of the smartphone and prolong a battery life of the smartphone, a frequency of a central processing unit (CPU) may be scaled based on a load. In this way, the frequency of the CPU can quickly respond to a load requirement (or a performance requirement), to reduce the power consumption of the smartphone and prolong the battery life of the smartphone.

In the prior art, a window assisted load tracking (WALT) method or a per-entity load tracking (PELT) method is used for frequency scaling scheduling. When WALT is used, a duty cycle or CPU usage in a current window can be calculated based on duty cycles or CPU usage in N historical non-empty windows of a task by using a defined statistics policy, and the frequency can be scaled level by level. However, in the prior art, frequency scaling performed level by level based on predicted CPU usage by using a window size as a period cannot timely respond to a change of the performance requirement. Other similar components also have a frequency scaling problem similar to the problem in the CPU.

Therefore, in a frequency scaling process, how to timely respond to a performance change of the task and reduce power consumption has become an urgent problem to be resolved.

SUMMARY

This application provides a frequency scaling method and apparatus, so that a load change requirement can be responded to in time in a frequency scaling process.

According to a first aspect, a frequency scaling method is provided. The method includes: predicting an energy efficiency parameter for processing a current frame of an image by at least one module, selecting a first frequency set from a plurality of frequency sets based on the predicted energy efficiency parameter, and scaling a working frequency of each of the at least one module for processing the current frame to a preset frequency corresponding to each of the at least one module.

It should be understood that the at least one module for processing the image includes at least one of a central processing unit (CPU), a graphics processing unit (GPU), an internal memory (which may be, for example, a DDR memory) configured to store the current frame, or a neural network processing unit (NPU). It should be further understood that the first frequency set includes the preset frequency corresponding to each of the at least one module.

In this embodiment of this application, there are a plurality of implementations for predicting the energy efficiency parameter for processing the current frame by the at least one module. This is not specifically limited in this application. The energy efficiency parameter for processing the current frame may be predicted based on a historical energy efficiency parameter (which may be obtained based on an energy efficiency parameter of at least one frame before the current frame). For example, the energy efficiency parameter for processing the current frame may be predicted based on an average value of the historical energy efficiency parameters. For another example, a load prediction table may be constructed and searched based on the historical energy efficiency parameter, so that the energy efficiency parameter for processing the current frame may be predicted based on the load prediction table.

In this embodiment of this application, a load change requirement can be responded to in time in a frequency scaling process, and a good performance gain and/or a power consumption reduction gain can be obtained.

With reference to the first aspect, in some implementations of the first aspect, the energy efficiency parameter includes at least one of the following: a quantity of instructions for processing the current frame by the CPU, a cache miss generated when the CPU processes the current frame, a quantity of draw calls for processing the current frame by the CPU, a bandwidth for reading or storing the current frame by the memory, or a calculation amount for processing the current frame by the NPU.

Optionally, in some embodiments, if the CPU processes the current frame of the image, the energy efficiency parameter that is of the CPU and that is predicted in this embodiment of this application may include but is not limited to at least one of the following parameters: a quantity of instructions for processing the current frame by the CPU, a cache miss (for example, one or all of the following: times of level-1 data cache misses (L1 data cache misses) or times of level-2 cache misses (L2 data cache misses)) generated when the CPU processes the current frame, times of no operation issued due to frontend for the CPU (which may also be referred to as FE bound), and times of no operation issued due to backend for the CPU (which may also be referred to as BE bound).

Optionally, in some embodiments, if the CPU processes the current frame of the image, the energy efficiency parameter that is of the CPU and that is predicted in this embodiment of this application may include but is not limited to at least one of the following parameters: a quantity of draw calls for processing the current frame by the CPU, a quantity of drawn triangles, times of total-fragment (total-FRAG) of a pixel, and times of texture-operation (TEX-operation).

Optionally, in some embodiments, if a memory (for example, a DDR memory) that stores the current frame is configured, the energy efficiency parameter that is of the memory and that is predicted in this embodiment of this application may include but is not limited to a bandwidth for reading or storing the current frame by the memory.

Optionally, in some embodiments, if the NPU processes the current frame of the image, the energy efficiency parameter that is of the NPU and that is predicted in this embodiment of this application may include but is not limited to at least one of the following parameters: a calculation amount (tasks) for processing the current frame by the NPU, the total of instructions needed to execute the current frame (total-INSTR-EXEC), and the total of memory requests (total-MEM-request) of the NPU.

With reference to the first aspect, in some implementations of the first aspect, the first frequency set meets an energy efficiency requirement, and the energy efficiency requirement includes at least one of the following: a power consumption requirement or a performance requirement.

In this embodiment of this application, the energy efficiency requirement may be used to indicate that a preset frequency of the current frame meets the performance requirement, or may be used to indicate that a preset frequency of the current frame meets the power consumption requirement. This is not specifically limited in this application. In an example, the performance characteristic (for example, a running time period corresponding to the at least one module) corresponding to each of the plurality of frequency sets may be predicted based on the predicted energy efficiency parameter. In another example, power consumption (for example, power consumption for processing the current frame by the at least one module) corresponding to a plurality of frequency sets in the first frequency set may be further predicted based on the predicted energy efficiency parameter, and a frequency set corresponding to lowest power consumption may be selected from the first frequency set according to a power consumption formula corresponding to the at least one module.

With reference to the first aspect, in some implementations of the first aspect, the power consumption requirement is a minimum power consumption requirement, and the performance requirement is that performance characteristic meets a preset threshold.

It should be understood that the preset threshold may be less than or equal to a time threshold. In an example, the time threshold may be duration that is required by each frame and that is obtained through calculation based on a target frame rate. A 60-frame game is used as an example, and duration required by each frame is 16.6 ms (1000/60).

With reference to the first aspect, in some implementations of the first aspect, a performance characteristic corresponding to each frequency set is predicted based on the predicted energy efficiency parameter; and the first frequency set corresponding to the performance characteristic meeting the preset threshold is selected from the plurality of frequency sets.

Specifically, the first frequency set corresponding to the performance characteristic meeting the preset threshold may be selected from the plurality of frequency sets based on the predicted energy efficiency parameter and a performance formula.

It should be understood that a running time period corresponding to a preset frequency that is of the at least one module and that is in the first frequency set meets the prediction threshold, and the performance formula is used to indicate a function relationship between a running time period and the energy efficiency parameter that are of the at least one module.

In this embodiment of this application, the performance formula y=f(x) of the at least one module may be deduced based on a running parameter (for example, the running time period) and the energy efficiency parameter that are of the at least one module.

It should be understood that the performance formula y=f(x) may be used to indicate a function relationship between the running parameter (for example, the running time period) and the energy efficiency parameter that are of the at least one module, where x may be an independent variable (for example, the energy efficiency parameter of the at least one module), and y may be a dependent variable (for example, a running time period for processing any frame by the at least one module).

The performance formula y=f(x) is not specifically limited in this embodiment of this application. The function relationship between x and y may be linear, or may be non-linear.

With reference to the first aspect, in some implementations of the first aspect, power consumption corresponding to each frequency set is predicted based on the predicted energy efficiency parameter; a plurality of second frequency sets corresponding to a plurality of performance characteristics meeting the preset threshold are selected front the plurality of frequency sets; and the first frequency set corresponding to lowest power consumption is selected from the plurality of second frequency sets.

Specifically, the plurality of second frequency sets corresponding to the plurality of performance characteristics meeting the preset threshold may be selected from the plurality of frequency sets based on the predicted energy efficiency parameter and a power consumption formula. The first frequency set corresponding to the lowest power consumption is selected from the plurality of second frequency sets.

It should be understood that the plurality of second frequency sets meeting the performance requirement may be selected from the plurality of frequency sets based on the predicted energy efficiency parameter and the performance formula. The first frequency set corresponding to the lowest power consumption may also be selected from the plurality of second frequency sets based on the predicted energy efficiency parameter and the power consumption formula.

The power consumption formula is used to indicate a functional relationship between the power consumption currently for processing the current frame by the at least one module and the energy efficiency parameter of the at least one module.

In this embodiment of this application, a power consumption formula p=f(y) of the at least one module may be deduced based on a power consumption parameter and the energy efficiency parameter that are of the at least one module.

It should be understood that the power consumption formula p=f(y) may be used to indicate a function relationship between the power consumption parameter and the energy efficiency parameter that are of the at least one module, where y may be an independent variable, and y may be an output value of the performance formula, for example, the running time period for processing any frame by the at least one module; and p may be a dependent variable, for example, power consumption for processing the current frame of the image by the at least one module.

The power consumption formula p=f(y) is not specifically limited in this embodiment of this application. The function relationship between y and p may be linear, or may be non-linear.

With reference to the first aspect, in some implementations of the first aspect, the energy efficiency parameter for processing the current frame of the image by the at least one module is predicted based on a historical energy efficiency parameter. The historical energy efficiency parameter is obtained based on an energy efficiency parameter of at least one frame before the current frame.

With reference to the first aspect, in some implementations of the first aspect, a load prediction table is searched based on the historical energy efficiency parameter, to predict the energy efficiency parameter for processing the current frame of the image by the at least one module.

With reference to the first aspect, in some implementations of the first aspect, the load prediction table indicates at least a change trend of the plurality of historical energy efficiency parameters or directly indicates a correspondence between the plurality of historical energy efficiency parameters and the predicted energy efficiency parameter.

According to a second aspect, a frequency scaling apparatus is provided. The apparatus includes a prediction module, a determining module, and a processing module. The prediction module is configured to predict an energy efficiency parameter for processing a current frame of an image by at least one module, where the at least one module includes at least one of a central processing unit (CPU), a graphics processing unit (GPU), a memory configured to store the current frame, or a neural network processing unit (NPU). The determining module is configured to select a first frequency set from a plurality of frequency sets based on the predicted energy efficiency parameter, where the first frequency set includes a preset frequency corresponding to each of the at least one module. The processing module is configured to scale a working frequency of each of the at least one module for processing the current frame to the preset frequency corresponding to each of the at least one module.

With reference to the second aspect, in some implementations of the second aspect, the energy efficiency parameter includes at least one of the following: a quantity of instructions for processing the current frame by the CPU, a cache miss generated when the CPU processes the current frame, a quantity of draw calls for processing the current frame by the GPU, a bandwidth for reading or storing the current frame by the memory, or a calculation amount for processing the current frame by the NPU.

With reference to the second aspect, in some implementations of the second aspect, the first frequency set meets an energy efficiency requirement, and the energy efficiency requirement includes at least one of the following: a power consumption requirement or a performance requirement.

With reference to the second aspect, in some implementations of the second aspect, the power consumption requirement is a minimum power consumption requirement, and the performance requirement is that a performance characteristic meets a preset threshold.

With reference to the second aspect, in some implementations of the second aspect, the determining module is specifically configured to: predict, based on the predicted energy efficiency parameter, a performance characteristic corresponding to each frequency set; and select, from the plurality of frequency sets, the first frequency set corresponding to the performance characteristic meeting the preset threshold.

With reference to the second aspect, in some implementations of the second aspect, the determining module is further specifically configured to: predict, based on the predicted energy efficiency parameter, power consumption corresponding to each frequency set; select, from the plurality of frequency sets, a plurality of second frequency sets corresponding to a plurality of performance characteristics meeting the preset threshold; and select, from the plurality of second frequency sets, the first frequency set corresponding to lowest power consumption.

With reference to the second aspect, in some implementations of the second aspect, the prediction module is specifically configured to: predict, based on a historical energy efficiency parameter, the energy efficiency parameter for processing the current frame of the image by the at least one module, where the historical energy efficiency parameter is obtained based on an energy efficiency parameter of at least one frame before the current frame.

With reference to the second aspect, in some implementations of the second aspect, the prediction module is specifically configured to: search a load prediction table based on the historical energy efficiency parameter, to predict the energy efficiency parameter for processing the current frame of the image by the at least one module.

According to a third aspect, a frequency scaling system is provided. The apparatus includes a memory and a processor. The memory is configured to store a program. The processor is configured to execute the program stored in the memory, and when the program is executed, the processor performs the method according to any one of the first aspect or the possible implementations of the first aspect. For example, the processor may further be in communication connection with a transceiver. For example, the memory may be configured to store program code and data of the device. Therefore, the memory may be a storage unit in the processor, an external storage unit independent of the processor, or a component including a storage unit in the processor and an external storage unit independent of the processor.

Optionally, the processor may be a general-purpose processor, and may implement the method procedure by using hardware, or may implement the procedure by executing software. When the method procedure is implemented by the hardware, the processor may include a microprocessor, a digital signal processor, a microcontroller, the CPU, or the like that has a logic circuit, an integrated circuit, or the like. A function is implemented by reading software code stored in the memory. The memory may be integrated into the processor, or may be located outside the processor independently. Further, the processor may include a necessary hardware accelerator, for example, a hardware algorithm circuit, a logical operation circuit, or an analog circuit that does not depend on software to perform an operation.

When the program is executed, the processor is configured to predict an energy efficiency parameter for processing a current frame of an image by at least one module. The at least one module includes at least one of a central processing unit (CPU), a graphics processing unit (GPU), a memory configured to store the current frame, or a neural network processing unit (NPU). The processor is further configured to select a first frequency set front a plurality of frequency sets based on the predicted energy efficiency parameter, where the first frequency set includes a preset frequency corresponding to each of the at least one module. The processor is further configured to scale a working frequency of each of the at least one module for processing the current frame to the preset frequency corresponding to each of the at least one module.

With reference to the third aspect, in some implementations of the third aspect, the energy efficiency parameter includes at least one of the following: a quantity of instructions for processing the current frame by the CPU, a cache miss generated when the CPU processes the current frame, a quantity of draw calls for processing the current frame by the GPU, a bandwidth for reading or storing the current frame by the memory, or a calculation amount for processing the current frame by the NPU.

With reference to the third aspect, in some implementations of the third aspect, the first frequency set meets an energy efficiency requirement, and the energy efficiency requirement includes at least one of the following: a power consumption requirement or a performance requirement.

With reference to the third aspect, in some implementations of the third aspect, the power consumption requirement is a minimum power consumption requirement, and the performance requirement is that a performance characteristic meets a preset threshold.

With reference to the third aspect, in some implementations of the third aspect, the processor is specifically configured to: predict, based on the predicted energy efficiency parameter, a performance characteristic corresponding to each frequency set; and select, from the plurality of frequency sets, the first frequency set corresponding to the performance characteristic meeting the preset threshold.

With reference to the third aspect, in some implementations of the third aspect, the processor is further specifically configured to: predict, based on the predicted energy efficiency parameter, power consumption corresponding to each frequency set; select, from the plurality of frequency sets, a plurality of second frequency sets corresponding to a plurality of performance characteristics meeting the preset threshold; and select, from the plurality of second frequency sets, the first frequency set corresponding to lowest power consumption.

With reference to the third aspect, in some implementations of the third aspect, the processor is specifically configured to: predict, based on a historical energy efficiency parameter, the energy efficiency parameter for processing the current frame of the image by the at least one module, where the historical energy efficiency parameter is obtained based on an energy efficiency parameter of at least one frame before the current frame.

With reference to the third aspect, in some implementations of the third aspect, the processor is specifically configured to: search a load prediction table based on the historical energy efficiency parameter, to predict the energy efficiency parameter for processing the current frame of the image by the at least one module.

According to a fourth aspect, a chip is provided, including a processor and an interface that couples the processor to an outer part of the chip. For example, the interface may be coupled to a memory outside the chip, and the memory may be configured to store program code and data of the device. For specific descriptions of the memory and the processor, refer to the descriptions of the third aspect or any implementation of the third aspect. The processor may read program code from the memory by using the interface, to perform the operation.

When the program is executed, the processor is configured to predict an energy efficiency parameter for processing a current frame of an image by at least one module. The at least one module includes at least one of a central processing unit (CPU), a graphics processing unit (GPU), a memory configured to store the current frame, or a neural network processing unit (NPU). The processor is further configured to select a first frequency set from a plurality of frequency sets based on the predicted energy efficiency parameter, where the first frequency set includes a preset frequency corresponding to each of the at least one module. The processor is further configured to scale a working frequency of each of the at least one module for processing the current frame to the preset frequency corresponding to each of the at least one module.

With reference to the fourth aspect, in some implementations of the fourth aspect, the energy efficiency parameter includes at least one of the following: a quantity of instructions for processing the current frame by the CPU, a cache miss generated when the CPU processes the current frame, a quantity of draw calls for processing the current frame by the GPU, a bandwidth for reading or storing the current frame by the memory, or a calculation amount for processing the current frame by the NPU.

With reference to the fourth aspect, in some implementations of the fourth aspect, the first frequency set meets an energy efficiency requirement, and the energy efficiency requirement includes at least one of the following: a power consumption requirement or a performance requirement.

With reference to the fourth aspect, in some implementations of the fourth aspect, the power consumption requirement is a minimum power consumption requirement, and the performance requirement is that a performance characteristic meets a preset threshold.

With reference to the fourth aspect, in some implementations of the fourth aspect, the processor is specifically configured to: predict, based on the predicted energy efficiency parameter, a performance characteristic corresponding to each frequency set; and select, from the plurality of frequency sets, the first frequency set corresponding to the performance characteristic meeting the preset threshold.

With reference to the fourth aspect, in some implementations of the fourth aspect, the processor is further specifically configured to: predict, based on the predicted energy efficiency parameter, power consumption corresponding to each frequency set; select, from the plurality of frequency sets, a plurality of second frequency sets corresponding to a plurality of performance characteristics meeting the preset threshold; and select, from the plurality of second frequency sets, the first frequency set corresponding to lowest power consumption.

With reference to the fourth aspect, in some implementations of the fourth aspect, the processor is specifically configured to: predict, based on a historical energy efficiency parameter, the energy efficiency parameter for processing the current frame of the image by the at least one module, where the historical energy efficiency parameter is obtained based on an energy efficiency parameter of at least one frame before the current frame.

With reference to the fourth aspect, in some implementations of the fourth aspect, the processor is specifically configured to: search a load prediction table based on the historical energy efficiency parameter, to predict the energy efficiency parameter for processing the current frame of the image by the at least one module.

According to a fifth aspect, a computer-readable storage medium is provided, including a computer program. When the computer program is run on a computer or a processor, the computer or the processor is enabled to perform the method according to any one of the first aspect or the implementations of the first aspect.

According to a sixth aspect, a computer program product is provided. When the computer program product is run on a computer or a processor, the computer or the processor is enabled to perform the method according to any one of the first aspect or the implementations of the first aspect.

