CN115878409A - Power consumption query method and related equipment thereof - Google Patents
Power consumption query method and related equipment thereof Download PDFInfo
- Publication number
- CN115878409A CN115878409A CN202111136879.9A CN202111136879A CN115878409A CN 115878409 A CN115878409 A CN 115878409A CN 202111136879 A CN202111136879 A CN 202111136879A CN 115878409 A CN115878409 A CN 115878409A
- Authority
- CN
- China
- Prior art keywords
- time
- task
- sub
- target
- period
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 61
- 238000012545 processing Methods 0.000 claims description 27
- 238000004590 computer program Methods 0.000 claims description 9
- 238000010586 diagram Methods 0.000 description 16
- 230000006870 function Effects 0.000 description 11
- 238000004891 communication Methods 0.000 description 10
- 238000005516 engineering process Methods 0.000 description 5
- 230000008878 coupling Effects 0.000 description 3
- 238000010168 coupling process Methods 0.000 description 3
- 238000005859 coupling reaction Methods 0.000 description 3
- 230000003287 optical effect Effects 0.000 description 3
- 238000011161 development Methods 0.000 description 2
- 230000005236 sound signal Effects 0.000 description 2
- 238000012360 testing method Methods 0.000 description 2
- 230000001133 acceleration Effects 0.000 description 1
- 238000004364 calculation method Methods 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 238000007667 floating Methods 0.000 description 1
- 230000005484 gravity Effects 0.000 description 1
- 230000003993 interaction Effects 0.000 description 1
- 239000004973 liquid crystal related substance Substances 0.000 description 1
- 230000002093 peripheral effect Effects 0.000 description 1
- 238000003672 processing method Methods 0.000 description 1
- 239000007787 solid Substances 0.000 description 1
- 238000000638 solvent extraction Methods 0.000 description 1
- 238000010897 surface acoustic wave method Methods 0.000 description 1
- 230000000007 visual effect Effects 0.000 description 1
Images
Classifications
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Power Sources (AREA)
Abstract
The application provides a power consumption query method and related equipment thereof, which can accurately calculate the energy consumed by a CPU to operate tasks by using each frequency in a target time period, thereby accurately reflecting the total energy consumed by the CPU to operate the tasks in the target time period to a user. The method of the present application comprises: acquiring a query instruction, wherein the query instruction is used for indicating energy consumed by running a task in a target time period; dividing the target time period into a plurality of sub-time periods according to the time of frequency switching in the target time period, wherein one frequency is used for running a task in one sub-time period; acquiring energy consumed by running the task in each sub-time period of the plurality of sub-time periods; and acquiring a query result corresponding to the query instruction according to the energy consumed by running the task in each sub-time period.
Description
Technical Field
The present application relates to the field of terminal technologies, and in particular, to a power consumption query method and related devices.
Background
With the development of technology, the requirements of users on terminal equipment are increasing day by day. In order to meet various demands of users, different types of applications, such as game applications, music applications, and video applications, are generally installed on terminal devices. In order to enable the power consumption of the application to meet the relevant requirements, an application developer can run the developed application on the terminal device and perform power consumption test on the application through the terminal device.
When a Central Processing Unit (CPU) of a terminal device runs a task of an application, a situation that an operating frequency changes may occur, that is, the CPU may run the task using multiple frequencies. When the user needs to determine the energy consumed by the CPU to run the task in the target time period, a query instruction can be sent to the CPU. After the query instruction is obtained, for any frequency, the CPU can calculate the product between the length of the target time period and the time length of the CPU in the frequency, divide the product by the total time length of the CPU in all the frequencies to estimate the time length of the CPU using the frequency to run the task, and can determine the energy consumed by the CPU using the frequency to run the task based on the time length. Therefore, the CPU can obtain the energy consumed by the CPU to run the task by using each frequency in the target time period, and further obtain the total energy consumed by the CPU to run the task in the target time period.
Because the time length of the CPU using the frequency to run the task in the target time period is obtained by estimation, the energy consumed by the CPU using each frequency to run the task in the target time period is often not accurate enough, and the total energy consumed by the CPU to run the task in the target time period cannot be accurately reflected to a user.
Disclosure of Invention
The embodiment of the application provides a power consumption query method and related equipment, which can accurately calculate the energy consumed by a CPU to operate tasks by using various frequencies in a target time period, so that the total energy consumed by the CPU to operate the tasks in the target time period is accurately reflected to a user.
A first aspect of an embodiment of the present application provides a power consumption query method, where the method includes:
when a user needs to determine the power consumption of the started application within a certain period of time, that is, the energy consumed by the CPU to run the task of the application within the target period of time needs to be determined, a query instruction may be sent to the CPU, where the query instruction is used to instruct the CPU to run the energy consumed by the task of the application within the target period of time.
After the query instruction is acquired, the CPU divides the target time period into a plurality of sub-time periods according to the frequency switching time in the target time period. In the plurality of sub-periods, the CPU runs the task using one frequency in one sub-period. For example, three times of frequency switching, i.e., switching of frequency 1 to frequency 2, switching of frequency 2 to frequency 3, and switching of frequency 3 to frequency 1, occur within the target time period T, and the CPU can divide T into four sub-time periods, i.e., T1, T2, T3, and T4, using the time of the three times of frequency switching. In these four sub-periods, the CPU runs the task at T1 using frequency 1, at T2 using frequency 2, at T3 using frequency 3, and at T4 using frequency 1.
After obtaining the plurality of sub-time periods, the CPU can calculate the energy consumed by the CPU to operate the task in each sub-time period, then obtain the query result corresponding to the query instruction according to the energy consumed by the operation of the task in each sub-time period, and feed the query result back to the user for use.
From the above method, it can be seen that: after the CPU obtains the query instruction, the energy consumed by the CPU to run the task in the target time period can be determined. Then, the CPU may divide the target period into a plurality of sub-periods according to the timing at which the frequency switching occurs within the target period. After the energy consumed by running the task in each sub-time period of the plurality of sub-time periods is obtained, the CPU can obtain the query result corresponding to the query instruction according to the energy consumed by running the task in each sub-time period. Because the CPU uses one frequency to run the task in one sub-time period, the CPU can accurately count the time length of the CPU using each frequency to run the task in the target time period, so the CPU can accurately calculate the energy consumed by the CPU using each frequency to run the task in the target time period, and the total energy consumed by the CPU to run the task in the target time period is accurately reflected to a user.
In a possible implementation manner, the dividing the target time period into a plurality of sub-time periods according to the time of the frequency switching occurring in the target time period includes: and dividing the target time period into a plurality of sub time periods according to the time of starting the running task in the target time period, the time of frequency switching in the target time period and the time of acquiring the query instruction. In the foregoing implementation, when the CPU obtains the query instruction, the task is still running, that is, the CPU runs the task all the time in the target time period, and the target time period does not include a time at which the task is completed (i.e., a time at which the task is stopped), but includes a time at which the task is started to run, a time at which the frequency is switched, and a time at which the query instruction is obtained, so that in the target time period, the CPU can divide the target time period into a plurality of sub-time periods according to the time at which the total task is started to run, the time at which the frequency is switched, and the time at which the query instruction is obtained. Still as in the above example, the target time period T is set to the time period between the time T1 when the overall task starts to be executed and the time T2 when the query instruction is acquired. In T, the CPU can divide T into T1, T2, T3, and T4 according to T1, time T3 to switch from frequency 1 to frequency 2, time T4 to switch from frequency 2 to frequency 3, and time T5 and T2 to switch from frequency 3 to frequency 2, where the CPU runs the task using frequency 1 in T1, runs the task using frequency 2 in T2, runs the task using frequency 3 in T3, and runs the task using frequency 2 in T4.
In a possible implementation manner, the dividing the target time period into a plurality of sub-time periods according to the time of the frequency switching occurring in the target time period includes: and dividing the target time period into a plurality of sub-time periods according to the moment when the task starts to run in the target time period, the moment when the frequency switching occurs in the target time period and the moment when the task stops running in the target time period. In the foregoing implementation, when the CPU obtains the query instruction, the task is completed, that is, the CPU completes the operation of the task in the target time period, the target time period includes a time point at which the task starts to be operated, a time point at which the frequency is switched, a time point at which the task stops to be operated, and a time point at which the query instruction is obtained (the time point is after the time point at which the task stops to be operated), so that in the target time period, the CPU can divide the target time period into a plurality of sub-time periods according to the time point at which the total task starts to be operated, the time point at which the frequency is switched, and the time point at which the task stops to be operated. Still as in the above example, the target time period T is the time period between the time T1 when the overall task starts to run and the time T2 when the query instruction is obtained. In T, the CPU can divide T into T1, T2, T3, and T4 according to T1, a time T3 of switching from frequency 1 to frequency 2, a time T4 of switching from frequency 2 to frequency 3, a time T5 of switching from frequency 3 to frequency 2, and a time T6 of stopping the operation of the task (T6 is before T2), wherein the CPU operates the task using frequency 1 in T1, operates the task using frequency 2 in T2, operates the task using frequency 3 in T3, and operates the task using frequency 2 in T4.
In a possible implementation manner, the target sub-period is set to be any one of the sub-periods, a starting time of the target sub-period may be a time when the running task starts, and an ending time of the target sub-period may be a time when the frequency switching occurs. In this case, the target sub-period is the period from the time the task is started to the time the frequency switch occurs for the first time.
In a possible implementation manner, the target sub-time period is set as any one of the sub-time periods, and both the starting time of the target sub-time period and the ending time of the target sub-time period may be the time when the frequency switching occurs. In this case, the target sub-period is such a period between the time when two adjacent frequency switching occurs.
In a possible implementation manner, the target sub-time period is set as any one of the multiple sub-time periods, the starting time of the target sub-time period may be the time when the frequency switching occurs, and the ending time of the target sub-time period may be the time when the query instruction is obtained. In this case, the target sub-period is a period from the time when the frequency switching occurs last in the target period to the time when the query instruction is acquired.
In a possible implementation manner, the target sub-period is set to be any one of the sub-periods, a starting time of the target sub-period may be a time when the frequency switching occurs, and an ending time of the target sub-period may be a time when the task stops running. In this case, the target sub-period is a period between the time when the frequency switching occurs last in the target period and the time when the task is completed.
In one possible implementation, the obtaining the energy consumed by running the task in each of the plurality of sub-periods comprises: and determining the energy consumed by running the task in the target sub-time period according to the length of the target sub-time period, the length of the time period used for processing the interrupt event in the target sub-time period and the power corresponding to the frequency used by running the task in the target sub-time period, wherein the interrupt event is the event for interrupting the running of the task. In the foregoing implementation manner, if an event that interrupts the task operation occurs during the process of operating the task within the target sub-time period, the CPU obtains the length of the target sub-time period, the length of the time period that the CPU is used for processing the interrupt event within the target sub-time period, and the power corresponding to the frequency used by the CPU to operate the task within the target sub-time period. Then, the CPU subtracts the length of the time period used by the CPU for processing the interrupt event from the length of the target sub-time period to obtain the length of the time period used by the CPU for running the task in the target time period, and then multiplies the length of the time period used by the CPU for running the task in the target time period by the power corresponding to the frequency used by the CPU for running the task in the target sub-time period to obtain the energy consumed by the CPU for running the task in the target sub-time period. Therefore, the CPU can judge whether an interrupt event occurs in the sub-time period or not in calculating the energy consumed by the CPU to run the task in the certain sub-time period, thereby removing the influence of the time occupied by processing the interrupt event on the time occupied by the task running and further improving the accuracy of energy statistics.
In a possible implementation manner, obtaining a query result corresponding to the query instruction according to energy consumed by running the task in each sub-time period includes: the CPU can accumulate the energy consumed by running the task in each sub-time period, count the total energy consumed by running the task in the target time period, and feed back the total energy to the user for use as a query result corresponding to the query instruction.
A second aspect of an embodiment of the present application provides a power consumption query apparatus, including: the first acquisition module is used for acquiring a query instruction, and the query instruction is used for indicating to acquire energy consumed by running the task in a target time period; the dividing module is used for dividing the target time period into a plurality of sub-time periods according to the time when the frequency switching occurs in the target time period, and one frequency is used for running a task in one sub-time period; the second acquisition module is used for acquiring energy consumed by running the task in each sub-time period of the plurality of sub-time periods; and the third acquisition module is used for acquiring the query result corresponding to the query instruction according to the energy consumed by running the task in each sub-time period.
From the above device it can be seen that: after the CPU obtains the query instruction, the energy consumed by the CPU to run the task in the target time period can be determined. Then, the CPU may divide the target period into a plurality of sub-periods according to the timing at which the frequency switching occurs within the target period. After the energy consumed by running the task in each sub-time period of the plurality of sub-time periods is obtained, the CPU can obtain the query result corresponding to the query instruction according to the energy consumed by running the task in each sub-time period. Because the CPU uses one frequency to run the task in one sub-time period, the CPU can accurately count the time length of the CPU using each frequency to run the task in the target time period, so the CPU can accurately calculate the energy consumed by the CPU using each frequency to run the task in the target time period, and the total energy consumed by the CPU to run the task in the target time period is accurately reflected to a user.
In a possible implementation manner, the target time period does not include a time when the task stops running, and the dividing module is configured to divide the target time period into a plurality of sub-time periods according to a time when the task starts running within the target time period, a time when the frequency switching occurs within the target time period, and a time when the query instruction is acquired.
In a possible implementation manner, the target time period includes a time at which the task stops operating, and the dividing module is configured to divide the target time period into a plurality of sub-time periods according to a time at which the task starts to operate within the target time period, a time at which the frequency switching occurs within the target time period, and a time at which the task stops operating within the target time period.
In a possible implementation manner, the starting time of the target sub-period is the time when the running task starts, the ending time of the target sub-period is the time when the frequency switching occurs, and the target sub-period is any one of the plurality of sub-periods.
In a possible implementation manner, both the starting time of the target sub-period and the ending time of the target sub-period are times at which frequency switching occurs, and the target sub-period is any one of the plurality of sub-periods.
In a possible implementation manner, the starting time of the target sub-period is the time of occurrence of frequency switching, the ending time of the target sub-period is the time of obtaining the query instruction, and the target sub-period is any one of the plurality of sub-periods.
In a possible implementation manner, the starting time of the target sub-period is the time when the frequency switching occurs, the ending time of the target sub-period is the time when the running task is stopped, and the target sub-period is any one of the plurality of sub-periods.
In a possible implementation manner, the second obtaining module is configured to determine, according to the length of the target sub-time period, the length of the time period used for processing the interrupt event in the target sub-time period, and the power corresponding to the frequency used by the running task in the target sub-time period, the energy consumed by the running task in the target sub-time period, where the interrupt event is an event that interrupts the running of the task.
In a possible implementation manner, the third obtaining module is configured to accumulate energy consumed by running the task in each sub-time period to obtain total energy consumed by running the task in a target time period, where the total energy is used as a query result corresponding to the query instruction.
A third aspect of an embodiment of the present application provides a terminal device, including a memory and a processor; the memory stores code and the processor is configured to execute the code, when executed, the terminal device performs the method according to the first aspect or any one of the possible implementations of the first aspect.
A fourth aspect of embodiments of the present application provides a computer storage medium storing one or more instructions that, when executed by one or more computers, cause the one or more computers to perform the method according to the first aspect or any one of the possible implementations of the first aspect.
A fifth aspect of embodiments of the present application provides a computer program product storing instructions that, when executed by a computer, cause the computer to perform the method according to the first aspect or any one of the possible implementations of the first aspect.
From the above method, it can be seen that: after the CPU obtains the query instruction, the energy consumed by the CPU to run the task in the target time period can be determined. Then, the CPU may divide the target period into a plurality of sub-periods according to the timing at which the frequency switching occurs within the target period. After the energy consumed by running the task in each sub-time period of the plurality of sub-time periods is obtained, the CPU can obtain the query result corresponding to the query instruction according to the energy consumed by running the task in each sub-time period. Because the CPU uses one frequency to run the task in one sub-time period, the CPU can accurately count the time length of the CPU using each frequency to run the task in the target time period, so the CPU can accurately calculate the energy consumed by the CPU using each frequency to run the task in the target time period, and the total energy consumed by the CPU to run the task in the target time period is accurately reflected to a user.
Drawings
Fig. 1 is a schematic structural diagram of a terminal device according to an embodiment of the present application;
fig. 2 is another schematic structural diagram of a terminal device according to an embodiment of the present application;
fig. 3 is a schematic flowchart of a power consumption query method according to an embodiment of the present application;
fig. 4 is a schematic diagram of frequency switching according to an embodiment of the present application;
fig. 5 is another schematic diagram of frequency switching provided in the present application;
fig. 6 is another schematic diagram of frequency switching according to an embodiment of the present application;
fig. 7 is another schematic diagram of frequency switching according to an embodiment of the present application;
fig. 8 is another schematic diagram of frequency switching provided in the present application;
fig. 9 is a schematic structural diagram of a power consumption query device according to an embodiment of the present application.
Detailed Description
The embodiment of the application provides a power consumption query method and related equipment, which can accurately calculate the energy consumed by a CPU to operate tasks by using various frequencies in a target time period, so that the total energy consumed by the CPU to operate the tasks in the target time period is accurately reflected to a user.
The terms "first," "second," and the like in the description and in the claims of the present application and in the above-described drawings are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the terms so used are interchangeable under appropriate circumstances and are merely descriptive of the various embodiments of the application and how objects of the same nature can be distinguished. Furthermore, the terms "comprises," "comprising," and any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of elements is not necessarily limited to those elements, but may include other elements not expressly listed or inherent to such process, method, article, or apparatus.
With the development of technology, the requirements of users on terminal equipment are increasing day by day. In order to meet various demands of users, different types of applications, such as game applications, music applications, and video applications, etc., are generally installed on terminal devices. In order to enable the power consumption of the application to meet the relevant requirements, the application developer can run the application developed by the application developer on the terminal device and perform power consumption testing on the application through the terminal device.
When a CPU of a terminal device runs a task of an application, it may encounter a situation that a working frequency changes, that is, the CPU may run the task using multiple frequencies. When the user needs to determine the energy consumed by the CPU to run the task in the target time period, a query instruction can be sent to the CPU. After the query instruction is obtained, for any frequency Fi, the CPU can estimate the time length of a task operated by the CPU by using the frequency according to the length T (app) of a target time period, the time length T (Fi) of the CPU at the frequency and the total time length T (F1-FN) of the CPU at all frequencies, and the estimated time length formula is as follows: t (app, fi) = T (app) × T (Fi)/T (F1-FN). Then, the CPU may determine, according to the duration T (app, fi) and the power P (Fi) corresponding to the frequency, an energy W (i) consumed by the CPU to run the task using the frequency, where a formula for determining the energy W (i) is as follows: w (i) = T (app, fi) × P (Fi). Therefore, the CPU can obtain the energy consumed by the CPU to run the task by using each frequency in the target time period, and further obtain the total energy consumed by the CPU to run the task in the target time period.
Because the time length of the CPU using the frequency to run the task in the target time period is obtained by estimation, the energy consumed by the CPU using each frequency to run the task in the target time period is often not accurate enough, and the total energy consumed by the CPU to run the task in the target time period cannot be accurately reflected to a user.
In order to solve the above problem, an embodiment of the present application provides an energy determining method, which may be implemented by a terminal device, and the following first introduces the terminal device provided in the embodiment of the present application. Fig. 1 is a schematic structural diagram of a terminal device provided in an embodiment of the present application, and as shown in fig. 1, the terminal device includes: a processor 101, a microcontroller unit (MCU) 103, a memory 105, a modem (modem) 107, a Radio Frequency (RF) module 109, a Wi-Fi module 111, a bluetooth module 113, a sensor 114, a positioning module 150, an input/output (I/O) device 115, and the like. These components may communicate over one or more communication buses or signal lines. Those skilled in the art will appreciate that the hardware configuration shown in fig. 1 is not intended to be limiting, and that the handset 100 may include more or fewer components than those shown, or some components may be combined, or a different arrangement of components.
The following describes each component of the terminal device 100 in detail with reference to fig. 1:
the processor 101 is the control center of the handset 100 and connects the various components of the terminal device 100 using various interfaces and buses. In some embodiments, processor 101 may include one or more processing units.
The memory 105 has stored therein computer programs, such as an operating system 161 and application programs 163 shown in FIG. 1. The processor 101 is configured to execute the computer program in the memory 105, so as to implement the functions defined by the computer program, for example, the processor 101 executes the operating system 161, so as to implement various functions of the operating system 161 on the terminal device 100 (for example, the operating system 161 can be used to implement the application preloading method provided by the embodiment of the present application). The memory 105 also stores data other than computer programs, such as data generated during operation of the operating system 161 and application programs 163. The storage 105 is a non-volatile storage medium, and typically includes both internal and external memory. Memory includes, but is not limited to, random Access Memory (RAM), cache, and the like. The external memory includes, but is not limited to, flash memory (flash memory), hard disk, optical disc, universal Serial Bus (USB) disk, etc., wherein the hard disk may include Hard Disk Drive (HDD) and Solid State Disk (SSD). The computer program is typically stored on an external memory, from which the processor loads the program into the internal memory before executing the computer program.
The memory 105 may be independent and connected to the processor 101 through a bus; memory 105 may also be integrated with processor 101 into a chip subsystem.
The MCU103 is a co-processor for acquiring and processing data from the sensor 114, the processing power and power consumption of the MCU103 are smaller than those of the processor 101, but the MCU103 has a feature of "always on", which can continuously collect and process sensor data when the processor 101 is in sleep mode, and thus, the normal operation of the sensor can be guaranteed with extremely low power consumption. In one embodiment, the MCU103 may be a sensor hub chip. The sensor 114 may include a light sensor, a motion sensor. Specifically, the light sensor may include an ambient light sensor that adjusts the brightness of the display 151 according to the brightness of ambient light, and a proximity sensor that turns off the power of the display when the terminal device 100 is moved to the ear. As one type of motion sensor, an accelerometer sensor can detect the magnitude of acceleration in various directions (generally, three axes), and can detect the magnitude and direction of gravity when the accelerometer sensor is stationary; the sensor 114 may also include other sensors such as a gyroscope, a barometer, a hygrometer, a thermometer, an infrared sensor, etc., which are not described in detail herein. The MCU103 and the sensor 114 may be integrated on the same chip or may be separate components connected by a bus.
The Modem 107 and the rf module 109 constitute a communication subsystem of the terminal device 100, and are used for implementing main functions of wireless communication standard protocols such as 3GPP and ETSI. The Modem 107 is used for encoding and decoding, signal modulation and demodulation, equalization, and the like. The rf module 109 is used for receiving and transmitting wireless signals, and the rf module 109 includes, but is not limited to, an antenna, at least one amplifier, a coupler, a duplexer, and the like. The radio frequency module 109 is matched with the Modem 107 to realize a wireless communication function. The Modem 107 can be a separate chip, or can be integrated with other chips or circuits to form a system-on-chip or integrated circuit. These chips or integrated circuits are applicable to all terminal devices implementing wireless communication functions, including: mobile phones, computers, notebooks, tablets, routers, wearable devices, automobiles, home appliances, and the like.
The terminal device 100 may also perform wireless communication using the Wi-Fi module 111, the bluetooth module 113, and the like. The Wi-Fi module 111 is configured to provide network access complying with a Wi-Fi related standard protocol for the terminal device 100, and the terminal device 100 may access a Wi-Fi access point through the Wi-Fi module 111 to further access the internet. In some other embodiments, the Wi-Fi module 111 may also serve as a Wi-Fi wireless access point, which may provide Wi-Fi network access for other terminal devices. The bluetooth module 113 is used to implement short-range communication between the terminal device 100 and other terminal devices (e.g., a mobile phone, a smart watch, etc.). The Wi-Fi module 111 in the embodiment of the present application may be an integrated circuit or a Wi-Fi chip, and the bluetooth module 113 may be an integrated circuit or a bluetooth chip.
The location module 150 is used to determine the geographical location of the terminal device 100. It is understood that the positioning module 150 may specifically be a receiver of a Global Positioning System (GPS) or a Beidou satellite navigation system, russian GLONASS, or other positioning systems.
Wi-Fi module 111, bluetooth module 113, and location module 150 may each be separate chips or integrated circuits, or may be integrated together. For example, in one embodiment, wi-Fi module 111, bluetooth module 113, and location module 150 may be integrated onto the same chip. In another embodiment, the Wi-Fi module 111, the Bluetooth module 113, the positioning module 150 and the MCU103 can also be integrated into the same chip.
Input/output devices 115 include, but are not limited to: a display 151, a touch screen 153, and an audio circuit 155, among others.
Among other things, the touch screen 153 can capture touch events of a user of the terminal device 100 on or near the touch screen 153 (e.g., operations of the user on the touch screen 153 or near the touch screen 153 using any suitable object such as a finger, a stylus, etc.) and transmit the captured touch events to other devices (e.g., the processor 101). The operation of the user near the touch screen 153 may be referred to as floating touch; by the hover touch, the user may select, move, or drag a target (e.g., an icon, etc.) without directly contacting the touch screen 153. In addition, the touch screen 153 may be implemented using various types of resistive, capacitive, infrared, and surface acoustic waves.
The display 151 (also referred to as a display screen) is used to display information input by a user or information presented to the user. The display may be configured in the form of a liquid crystal display, an organic light emitting diode, or the like. The touch screen 153 may be overlaid on the display 151, and when the touch screen 153 detects a touch event, the touch event is transmitted to the processor 101 to determine the type of the touch event, and then the processor 101 may provide a corresponding visual output on the display 151 according to the type of the touch event. Although in fig. 1 the touch screen 153 and the display 151 are two separate components to implement the input and output functions of the terminal device 100, in some embodiments, the touch screen 153 and the display 151 may be integrated to implement the input and output functions of the mobile phone 100. In addition, the touch screen 153 and the display 151 may be disposed in a full panel form on the front surface of the terminal device 100 to realize a frameless structure.
The audio circuitry 1155, speaker 116, microphone 117 may provide an audio interface between the user and the terminal device 100. The audio circuit 109 may transmit the electrical signal converted from the received audio data to the speaker 113, and convert the electrical signal into a sound signal for output by the speaker 113; on the other hand, the microphone 114 converts the collected sound signal into an electric signal, and the electric signal is received by the audio circuit 109 and then converted into audio data, and the audio data is transmitted to, for example, another terminal device through the Modem 107 and the radio frequency module 109, or the audio data is output to the memory 105 for further processing.
In addition, the terminal device 100 may also have a fingerprint recognition function. For example, the fingerprint acquisition device may be disposed on the back side of the terminal device 100 (e.g., below the rear camera), or disposed on the front side of the terminal device 100 (e.g., below the touch screen 153). For another example, a fingerprint acquisition device may be configured in the touch screen 153 to realize the fingerprint identification function, that is, the fingerprint acquisition device may be integrated with the touch screen 153 to realize the fingerprint identification function of the terminal device 100. In this case, the fingerprint acquisition device is disposed in the touch screen 153, may be a part of the touch screen 153, and may be disposed in the touch screen 153 in other manners. The main component of the fingerprint acquisition device in the embodiments of the present application is a fingerprint sensor, which may employ any type of sensing technology, including but not limited to optical, capacitive, piezoelectric, or ultrasonic sensing technologies, etc.
Further, the operating system 161 carried by the terminal device 100 may be an iOS, android, microsoft, or other operating systems, which is not limited in this embodiment of the present application.
The operating system 161 may perform the steps of the instruction processing method shown in fig. 3, and may be specifically implemented by the application processor 101 executing a program stored in the memory 105.
To further understand the relationship between the terminal device and the operating system, the relationship will be further described with reference to fig. 2. Fig. 2 is another schematic structural diagram of a terminal device according to an embodiment of the present application, as shown in fig. 2, the terminal device may be logically divided into a hardware layer, an operating system layer, and an application layer, and the following layers are respectively introduced:
the hardware layer may include processing devices (corresponding to an implementation of the processor 101 in fig. 1) including a CPU and a Graphics Processing Unit (GPU), storage devices (corresponding to an implementation of the storage 105 in fig. 1) including a memory and a peripheral memory, and input and output devices (corresponding to an implementation of the I/O device 115 in fig. 1) including a speaker, a microphone, and a screen. Of course, the hardware layer 450 may further include the power supply, the camera, the radio frequency module, the positioning module, and the WiFi module shown in fig. 1, and may further include other hardware modules not shown in fig. 1, such as a memory controller, a display controller, and the like.
The operating system layer may include a kernel layer and a system framework layer. The kernel layer is used to provide the underlying system components and services, such as the system kernel and hardware drivers. The hardware drivers include drivers for devices such as a GPU, a camera, a speaker, a microphone, and a positioning module, and the system kernel can be used to implement the following functions: processing of the tasks of the application, switching of the frequency used for running the tasks (i.e. frequency modulation), processing of interrupt events, calculation of the energy consumed for running the tasks, switching of different tasks, etc., where not expanded at first.
The system framework layer is used for providing various basic common components and services for each application in the application layer, such as an Application Programming Interface (API) and the like.
The application layer contains one or more applications, such as camera software, communication software, office software, query software, and the like. For convenience of explanation, the following description will be made with respect to communication software. When the communication application is started, at least one task can be generated for processing by the system kernel, and the system kernel can continuously run the tasks according to a certain frequency or certain frequencies. In this process, the system kernel may count the energy consumed by running the tasks (i.e., the power consumption for running the tasks) for querying (for example, after the query software issues the query instruction to the system kernel through the power consumption management API, the system kernel may take the power consumption for running the tasks as a query result based on the query instruction, and return the query result to the query software through the power consumption management API).
It can be understood that, since the system kernel is disposed in the operating system layer of the terminal device, and the operating system is run by the CPU of the terminal device, the steps executed by the system kernel may also be regarded as steps executed by the CPU, and are not described in detail later.
To further understand the process of the CPU performing power consumption statistics, the process is described in detail below in conjunction with fig. 3. Fig. 3 is a schematic flowchart of a power consumption query method according to an embodiment of the present application, and as shown in fig. 3, the method includes:
301. the CPU obtains a query instruction, and the query instruction is used for indicating the energy consumed by the CPU for running the task in the target time period.
In this embodiment, after a user starts an application on the terminal device, the application may generate at least one task and hand the task to the CPU of the terminal device for processing. For example, after a user starts the communication software on the mobile phone, multiple tasks such as an audio playing task, a video playing task and the like can be generated in the loading process of the communication software for processing by the CPU, so that the loading interface of the communication software presents a section of animation for the user to watch.
Because the CPU can generally run only one task at the same time, in order to ensure that the application can work normally, the CPU can switch and run a plurality of task cycles generated by the application. As shown in fig. 4 (fig. 4 is a schematic diagram of frequency switching provided by the embodiment of the present application), after the CPU obtains task 1, task 2, and task 3 generated by a certain application, the tasks may be placed in a task queue. At time 1, the CPU pulls task 1 out of the task queue (i.e., performs a swap-in operation on task 1), and then runs task 1 (i.e., performs the 1 st run on task 1). At time 2, the CPU puts task 1 into the task queue (i.e., swap out task 1), and pulls task 2 out of the task queue (i.e., swap in task 2), followed by running task 2 (i.e., run task 2 for the 1 st time). At time 3, the CPU puts task 2 into the task queue while pulling task 3 out of the task queue, and then runs task 3 (i.e., runs task 3 for the 1 st time). At time 4, the CPU puts task 3 into the task queue while pulling task 1 out of the task queue, and then runs task 1 (i.e., runs task 1 for the 2 nd time) \ 8230. And repeating the steps until all the tasks are completed, so that the CPU performs multiple operations on each task in multiple tasks, and each operation occupies a time period. Then, when the CPU performs a certain operation on a certain task, the start time of the time period occupied by the operation is the time when the task is switched in (for example, the aforementioned time 1 is the time when the task 1 is switched in) and the end time of the time period occupied by the operation is the time when the task is switched out (for example, the aforementioned time 2 is the time when the task 1 is switched out 1). For any task, the time when the task is switched in for the first time can be understood as the time when the CPU starts the task, and the time when the task is switched out for the last time can be understood as the time when the CPU completes the task (i.e., the time when the CPU completes the task).
It should be noted that, for any task, a time when the task is started may be referred to as a time when the task starts to run, and a time when the task is completed may also be referred to as a time when the task stops running, which will not be described in detail later.
It is worth noting that the CPU can continuously adjust its own state, that is, the CPU can implement state switching, and since different states correspond to different frequencies, when the CPU switches states, it is equivalent to switching its own operating frequency. Specifically, the CPU can switch between a performance state (P-state) and an idle state (C-state), can also switch between different P states (performance states), and can also switch between different C states (idle states). The P state includes P1 state, P2 state, P3 state, \8230;, PN state, etc., and the C state includes C1 state, C2 state, C3 state, \8230;, CN state, etc., different P states correspond to different frequencies, different C states correspond to different frequencies, and different frequencies correspond to different powers (corresponding to different states corresponding to different powers). It should be noted that the frequency corresponding to the P state is generally higher than the frequency corresponding to the C state, and therefore the power corresponding to the P state is generally higher than the power corresponding to the C state.
As can be seen, if the CPU performs frequency switching (frequency modulation) during the task operation, the task operation can be performed using (according to) a different frequency. Still referring to the example shown in fig. 4, in the 1 st round of the task 1, after the task 1 is switched in for the first time (it can be understood that the task 1 is started by the CPU), the CPU can use the frequency 1 to run the task 1 for a period of time, after switching from the frequency 1 to the frequency 2, then use the frequency 2 to run the task 1 for a period of time, and after switching from the frequency 2 to the frequency 3, use the frequency 3 to run the task 1 again for a period of time until the task 1 is switched out. In the 2 nd round of the task 1, after the task 1 is switched in again, the CPU continues to run the task 1 at the frequency 2 (before the task 3 is switched out, the CPU runs the task 3 at the frequency 2), after switching from the frequency 2 to the frequency 3, the CPU again runs the task 1 at the frequency 3 until the task 1 is switched out again, and so on.
When the frequency switching occurs, the CPU records the time of the frequency switching, and the CPU can accurately calculate the energy consumed by the CPU to run tasks by using each frequency based on the time, and does not perform expansion at first.
When a user needs to determine the power consumption of the started application in a certain time period, that is, the energy consumed by the CPU to run the task of the application in the target time period needs to be determined, a query instruction may be sent to the CPU, where the query instruction is used to indicate the energy consumed by the CPU to run the task of the application in the target time period.
Specifically, the query instruction may be used to indicate energy consumed by the CPU to run a certain task in the target time period, that is, the user needs to determine energy consumed by the CPU to run a certain task of the application in the target time period, for example, after the CPU of the mobile phone runs communication software started by the user for a certain time period, the user needs to query energy consumed by the CPU to run a video playing task of the software, so that the query instruction may be sent to the CPU, and the query instruction is used to indicate energy consumed by the CPU to run the video playing task of the software in the time period from the starting time to the current time of the video playing task of the software.
The query instruction may also be used to indicate energy consumed by the CPU to run multiple tasks in the target time period, that is, the user needs to determine energy consumed by the CPU to run the application (which may also be understood as all tasks of the application) in the target time period, for example, after the CPU of the mobile phone runs the communication software started by the user for a certain time period, the user needs to query energy consumed by the CPU to run the software, so that the query instruction may be sent to the CPU, where the query instruction is used to indicate energy consumed by the CPU to run all tasks of the software, such as a video playing task and an audio playing task, in the time period from the starting time to the current time of the software.
It should be understood that the terminal device is usually installed with query software, and the user can issue a query instruction to the CPU through the query software. In addition, the inquiry software can also trigger by itself to send an inquiry instruction to the CPU. The foregoing embodiments are only schematically described in terms of sending a query instruction to a CPU by a user, and do not limit the triggering manner of the query instruction in the present application.
302. The CPU divides the target time period into a plurality of sub-time periods according to the time of frequency switching in the target time period, and the CPU uses one frequency to run a task in one sub-time period.
Since different query instructions can indicate different contents, the CPU can perform different processing on the target time period indicated by the query instruction for the query instruction indicating different contents, which will be described below:
(1) Assuming that the query instruction is used to indicate the energy consumed by the CPU to run a plurality of tasks in the target time period, the CPU may regard the plurality of tasks as a whole, and for convenience of description, the plurality of tasks are hereinafter referred to as a total task. The starting time of the target time period is usually the time when the CPU starts the total task, and the ending time of the target time period is usually the time when the CPU acquires the query instruction, and since the total task may be completed or may still be in operation when the CPU acquires the query instruction, the following two cases will be described separately:
(1.1) when the CPU obtains the query instruction, the total task is still in operation, that is, the CPU always operates the total task in the target time period, and the target time period does not contain the time for completing the total task, so that in the target time period, the CPU can divide the target time period into a plurality of sub-time periods according to the time for starting the total task (namely the time for starting to operate the total task), the time for switching the frequency and the time for obtaining the query instruction, and the CPU operates the total task at a frequency in each sub-time period. As shown in fig. 5 (fig. 5 is another schematic diagram of frequency switching provided in the embodiment of the present application), it is assumed that task 1, task 2, and task 3 of a certain software all perform 1 operation, and during the process of performing task 1 for the 2 nd operation by the CPU, the CPU receives an inquiry instruction, and based on the inquiry instruction, the CPU can determine that it is necessary to count the energy consumed by the CPU to operate all tasks of the software in the time period T from the time T1 when the task of the software is started to the time T2 when the inquiry instruction is obtained. Then, the CPU can divide T into T1, T2, T3, and T4 according to T1, a time T3 to switch from the frequency 1 to the frequency 2, a time T4 to switch from the frequency 2 to the frequency 3, and times T5 and T2 to switch from the frequency 3 to the frequency 2, wherein the CPU runs task 1 using the frequency 1 in T1, runs task 1 using the frequency 2 in T2, runs task 1, task 2, and task 3 using the frequency 3 in T3, and runs task 3 and task 1 using the frequency 2 in T4. In this way, the CPU can count the energy consumed by running all tasks by using the four sub-periods T1, T2, T3, and T4.
In the plurality of sub-periods, for any one sub-period, which is referred to as a target sub-period, there may be the following cases in the starting time and the ending time of the target sub-period: (a) The starting time of the target sub-time period is the time for starting the operation of the total task, and the ending time of the target sub-time period is the time for switching the frequency. In this case, the target sub-period is a period (for example, T1 in the example shown in fig. 5) from the time when the overall task is started to the time when the frequency switching occurs for the first time. (b) The starting time of the target sub-period and the ending time of the target sub-period are both the time when the frequency switching occurs. In this case, the target sub-period is such a period between the timings at which the frequency switching occurs two adjacent times (for example, T2 and T3 in the example shown in fig. 5). (c) The starting time of the target sub-time period is the time of frequency switching, and the ending time of the target sub-time period is the time of acquiring the query instruction. In this case, the target sub-period is a period (for example, T4 in the example shown in fig. 5) from the time when the frequency switching occurs last in the target period to the time when the inquiry instruction is acquired.
(1.2) when the CPU acquires the query instruction, the total task is completed, that is, the CPU completes the operation of the total task in a target time period, wherein the target time period comprises the time for completing the total task (namely the time for stopping operating the total task), so that in the target time period, the CPU can divide the target time period into a plurality of sub-time periods according to the time for starting the total task, the time for generating frequency switching and the time for completing the total task, and the CPU operates the total task at a frequency in each sub-time period. As shown in fig. 6 (fig. 6 is another schematic diagram of frequency switching provided in the embodiment of the present application), it is assumed that task 1, task 2, and task 3 of a certain software all have performed the 1 st operation, and after task 1 has performed the 2 nd operation, all tasks of the software are completed (i.e., the CPU finishes operating the software). After that, the CPU receives the query instruction, and based on the query instruction, the CPU may determine that the energy consumed by the CPU to run all tasks of the software needs to be counted in the time period T from the time T1 when the task of the software is started to the time T2 when the query instruction is obtained. Then, the CPU can divide T into T1, T2, T3, and T4 according to T1, time T3 to switch from frequency 1 to frequency 2, time T4 to switch from frequency 2 to frequency 3, time T5 to switch from frequency 3 to frequency 2, and time T6 to complete the task of the software (T6 is before T2), where the CPU runs task 1 using frequency 1 in T1, runs task 1 using frequency 2 in T2, runs task 1, task 2, and task 3 using frequency 3 in T3, and runs task 3 and task 1 using frequency 2 in T4 until task 1 is completed, which is equivalent to completing the total task. In this way, the CPU can count the energy consumed by running all tasks by using the four sub-periods T1, T2, T3, and T4.
In the plurality of sub-periods, for any one sub-period, which is referred to as a target sub-period, the starting time and the ending time of the target sub-period may be as follows: (a) The starting time of the target sub-time period is the time for starting the operation of the total task, and the ending time of the target sub-time period is the time for switching the frequency. In this case, the target sub-period is a period from the time when the overall task is started to the time when the frequency switching occurs for the first time (for example, T1 in the example shown in fig. 6). (b) The starting time of the target sub-period and the ending time of the target sub-period are both the time when the frequency switching occurs. In this case, the target sub-period is such a period between the timings at which the frequency switching occurs two adjacent times (for example, T2 and T3 in the example shown in fig. 6). (c) The starting time of the target sub-time period is the time of frequency switching, and the ending time of the target sub-time period is the time of stopping running the total task. In this case, the target sub-period is a period (e.g., T4 in the example shown in fig. 6) between the time when the frequency switching occurs last in the target period and the time when the overall task is completed.
(2) The query instruction is set to indicate energy consumed by the CPU to run a task in a target time period, where a starting time of the target time period is usually a time when the CPU starts the task, and an ending time of the target time period is usually a time when the CPU obtains the query instruction, and since the CPU obtains the query instruction, the task may be completed, or the task may still be running, which will be described below:
(2.1) when the CPU obtains the query instruction, the task is still running, that is, the CPU runs the task all the time in the target time period, the target time period does not contain the time for completing the task, so in the target time period, the CPU can divide the target time period into a plurality of sub-time periods according to the time for switching in the task (including the time for starting the task, namely the time for starting running the task), the time for switching out the task, the time for generating frequency switching and the time for obtaining the query instruction, and the CPU runs the task at one frequency in each sub-time period. As shown in fig. 7 (fig. 7 is another schematic diagram of frequency switching provided in this embodiment of the present application), it is assumed that task 1, task 2, and task 3 of a certain software all perform 1 operation, and during the process of performing the 2 nd operation of task 1 by the CPU, the CPU receives a query instruction, and based on the query instruction, the CPU may determine that it is necessary to count the energy consumed by the CPU to operate task 1 of the software during a time period T from a time T1 when task 1 of the software is started to a time T2 when the query instruction is obtained. Then, the CPU can divide T into T1, T2, T3, T4, T5, T6, T7, T8, T9 and T2, based on time T1 of swapping in task 1 for the 1 st time, time T3 of switching from frequency 1 to frequency 3, time T4 of swapping in task 2 for the 1 st time (i.e., time T1 of swapping out task 1 for the 1 st time), time T5 of swapping in task 2 for the 1 st time, time T6 of swapping in task 3 for the 1 st time, time T7 of swapping in task 3 for the 2 nd time, and time T9 and T2 of switching from frequency 2 to frequency 3, where the CPU runs task 1 using frequency 1 in T1, runs task 1 using frequency 2 in T2, runs task 1 using frequency 3 in T3, runs task 2 using frequency 3 in T4, runs task 3 using frequency 3 in T5, runs task 3 using frequency 3 in T6, runs task 3 using frequency in T7, and runs task 1 using frequency 8 in T1. In this way, the CPU may select five sub-periods T1, T2, T3, T7, and T8 for counting the energy consumed to run task 1.
In the plurality of sub-periods, for any one sub-period, which is referred to as a target sub-period, there may be the following cases in the starting time and the ending time of the target sub-period: (a) The starting time of the target sub-time period is the time for switching in the task, and the ending time of the target sub-time period is the time for switching the frequency. In this case, the target sub-period may be a period from the time when the task is switched in to the time when the frequency switching has occurred last time (for example, T1 and T7 in the example shown in fig. 7). (b) The starting time of the target sub-period and the ending time of the target sub-period are both the time when the frequency switching occurs. In this case, the target sub-period may be such a period (for example, T2 in the example shown in fig. 7) between the timings at which the frequency switching occurs twice adjacently. (c) The starting time of the target sub-time period is the time of frequency switching, and the ending time of the target sub-time period is the time of acquiring the query instruction. In this case, the target sub-period may be a period (e.g., T8 in the example shown in fig. 7) from the time when the frequency switching occurs last in the target period to the time when the query instruction is acquired. (d) The starting time of the target sub-period is the time when the frequency switching occurs, and the ending time of the target sub-period is the time when the task is switched out. In this case, the target sub-period is a period from the time when a certain frequency switching occurs to the time when the task has been switched out last time (for example, T3 in the example shown in fig. 7). (e) The starting time of the target sub-period is the time for switching in the task, and the ending time of the target sub-period is the time for switching out the task. In this case, the target sub-period is the period from the time of swapping in the task to the time of swapping out the task (i.e. the frequency switching does not occur in the running of the task, which is not shown in fig. 7 for task 1, but it is possible to refer to T4 for running task 2). (f) The starting time of the target sub-time period is the time for switching in the task, and the ending time of the target sub-time period is the time for acquiring the query instruction. In this case, the target sub-period is a period from the time when the task is switched in for the last time in the target period to the time when the query instruction is acquired (this is not shown in fig. 7 for task 1).
(2.2) when the CPU obtains the query instruction, the task is completed, that is, the CPU completes the task in a target time period, the target time period comprises the time for completing the task, so in the target time period, the CPU can divide the target time period into a plurality of sub-time periods according to the time for switching in the task (comprising the time for starting the task, namely the time for starting running the task), the time for switching out the task (comprising the time for completing the task, namely the time for stopping running the task) and the time for switching the frequency, and the CPU runs the task at one frequency in each sub-time period. As shown in fig. 8 (fig. 8 is another schematic diagram of frequency switching provided in the embodiment of the present application), it is assumed that task 1, task 2, and task 3 of a certain software all have performed the 1 st operation, and after task 1 has performed the 2 nd operation, all tasks of the software are completed (i.e., the CPU finishes operating the software). After that, the CPU receives the query instruction, and based on the query instruction, the CPU may determine that the energy consumed by the CPU to run task 1 of the software in the time period T from the time T1 when task 1 of the software is started to the time T2 when the query instruction is obtained needs to be counted. Then, the CPU can divide T into T1, T2, T3, T4, T5, T6 and T6 (T10 is located before T2) according to time T1 of swapping in task 1 for the 1 st time, time T3 of switching from frequency 1 to frequency 2, time T4 of swapping in task 2 for the 1 st time (i.e., time T1 of swapping out task 1 for the 1 st time), time T5 of swapping in task 2 for the 1 st time, time T7 of swapping in task 3 for the 1 st time, time T8 of swapping in task 1 for the 2 nd time, T9 of switching from frequency 2 to frequency 3, and time T10 of swapping out task 1 for the 2 nd time (T10 is located before T2), where the CPU runs task 1 using frequency 1 in T1, runs task 1 using frequency 2 in T2, runs task 1 using frequency 3 in T3, runs task 2 using frequency 3 in T4, runs task 2 using frequency 3 in T5, runs task 3 using frequency 3 in T6, runs task 1 using frequency 2 in T3, runs task 1 using frequency 3 in T2, and finishes the task 1 using frequency 3. In this way, the CPU can select five sub-periods T1, T2, T3, T7, and T8 for counting the energy consumed to run task 1.
In the plurality of sub-periods, for any one sub-period, which is referred to as a target sub-period, the starting time and the ending time of the target sub-period may be as follows: (a) The starting time of the target sub-time period is the time for switching in the task, and the ending time of the target sub-time period is the time for switching the frequency. In this case, the target sub-period may be such a period from the time when the task is switched in to the time when the frequency switching has occurred last (for example, T1 and T7 in the example shown in fig. 8). (b) The starting time of the target sub-period and the ending time of the target sub-period are both the time when the frequency switching occurs. In this case, the target sub-period may be such a period (for example, T2 in the example shown in fig. 8) between the timings at which the frequency switching occurs twice adjacently. (c) The starting time of the target sub-period is the time of frequency switching, and the ending time of the target sub-period is the time of switching out the task. In this case, the target sub-period is a period from the time when a certain frequency switching occurs to the time when the task has been switched out last time (for example, T3 and T8 in the example shown in fig. 8). (d) The starting time of the target sub-period is the time for switching in the task, and the ending time of the target sub-period is the time for switching out the task. In this case, the target sub-period is the period from the time when the task is switched in to the time when the task is switched out (i.e. the frequency switching does not occur in the operation of the task, which is not shown in fig. 8 for task 1, but reference may be made to T4 for task 2).
It is noted that the CPU may divide the target time period into a plurality of sub-time periods in real time. For example, in the aforementioned case (1.1), the CPU takes the time at which the frequency switching occurs as a division point of the target time period, and upon occurrence of one frequency switching, the CPU records the time at which the frequency switching occurs and divides one sub-time period by the time. Therefore, when the CPU acquires the query instruction, the CPU finishes dividing the rest sub-time periods except the last sub-time period in the plurality of sub-time periods, so that the CPU can successfully divide the last sub-time period based on the time of acquiring the query instruction, and the target time period is divided into the plurality of sub-time periods. As another example, in the aforementioned case (1.2), the CPU uses the time at which the frequency switching occurs as a division point of the target time period, and once the frequency switching occurs once, the CPU records the time at which the frequency switching occurs and divides one sub-time period by the time until the total task is completed, and then successfully divides the target time period into a plurality of sub-time periods. It can be seen that the CPU has completed the partitioning among the plurality of sub-periods when the CPU acquires the query instruction. As another example, in the aforementioned case (2.1), the CPU takes the time at which the task switching occurs and the time at which the frequency switching occurs as the division points of the target time period, and upon occurrence of one frequency switching or one task switching, the CPU records the time at which the frequency switching or task switching occurs and divides one sub-time period by that time. Therefore, when the CPU acquires the query instruction, the CPU finishes dividing the rest sub-time periods except the last sub-time period in the plurality of sub-time periods, so that the CPU can successfully divide the last sub-time period based on the time of acquiring the query instruction, and the target time period is divided into the plurality of sub-time periods. Also, as in the foregoing case (2.2), the CPU takes the time at which the task switching occurs and the time at which the frequency switching occurs as the division points of the target time period, and upon occurrence of one frequency switching or one task switching, the CPU records the time at which the frequency switching or task switching occurs and divides one sub-time period by that time until the completion of the total task, successfully divides the target time period into a plurality of sub-time periods. It can be seen that the CPU has completed the division into these multiple sub-periods when the CPU obtains the query instruction.
The CPU can also divide the target time period into a plurality of sub-time periods after receiving the query instruction. For example, in the aforementioned case (1.1) and case (1.2), once frequency switching occurs, the CPU records the time at which the frequency switching occurs. After the CPU obtains the query instruction, the CPU obtains the time of each occurrence frequency switching in the target time period, and then divides the target time period into a plurality of sub-time periods based on the time uniformly. For another example, in the case (2.1) and the case (2.2), once the frequency switching or the task switching occurs, the CPU records the time when the frequency switching or the task switching occurs. After the CPU obtains the query instruction, the CPU obtains the time of each occurrence frequency switching and the time of each occurrence task switching (i.e., the time of swapping out the task and the time of swapping in the task) in the target time period, and then uniformly divides the target time period into a plurality of sub-time periods based on these times.
It should be understood that, in the examples shown in fig. 4 to 8, only 2 operations are performed for task 1, and 1 operation is performed for task 2 and task 3, which are schematically described, and do not limit the number of actual operations of each task in the present application.
It should also be understood that, in the examples shown in fig. 4 to 8, only the starting time of the target time period is taken as the time when the CPU starts the task for the schematic description, and the starting time of the target time period may also be before the time when the CPU starts the task, that is, the target time period includes the time when the CPU starts the task (the time when the running task is started).
303. The CPU obtains energy consumed by the CPU for running the task in each sub-time period of the plurality of sub-time periods.
In a plurality of sub-periods, since the CPU runs the task using one frequency in one sub-period, the CPU can calculate the energy consumed by the CPU to run the task in each sub-period.
Specifically, among the plurality of sub-periods, for any one sub-period, it is referred to as a target sub-period. And if the event for interrupting the task operation does not occur in the process of operating the task in the target sub-time period, the CPU acquires the length of the target sub-time period and the power corresponding to the frequency used by the CPU to operate the task in the target sub-time period. And then, the CPU multiplies the length of the target sub-time period by the power corresponding to the frequency used by the CPU to run the task in the target sub-time period to obtain the energy consumed by the CPU to run the task in the target sub-time period.
If an event for interrupting the task operation occurs in the process of operating the task in the target sub-time period (the CPU processes the interrupt event, so that the CPU processes the interrupt event and occupies a part of the time of the target sub-time period), the CPU obtains the length of the target sub-time period, the length of the time period for processing the interrupt event by the CPU in the target sub-time period, and the power corresponding to the frequency used by the CPU to operate the task in the target sub-time period. Then, the CPU subtracts the length of the time period used by the CPU for processing the interrupt event from the length of the target sub-time period to obtain the length of the time period used by the CPU for running the task in the target time period, and then multiplies the length of the time period used by the CPU for running the task in the target time period by the power corresponding to the frequency used by the CPU for running the task in the target sub-time period to obtain the energy consumed by the CPU for running the task in the target sub-time period.
In this way, the CPU can obtain the energy consumed by the CPU to run the task in each sub-period.
It should be understood that the CPU may calculate the energy consumed by the CPU to execute the task in each sub-period after dividing the sub-period. The CPU may also calculate the energy consumed by the CPU to run the task in each sub-time period in a unified manner after dividing the sub-time periods, which is not limited herein.
304. And the CPU acquires a query result corresponding to the query instruction according to the energy consumed by running the task in each sub-time period.
After the energy consumed by the CPU for running the task in each sub-time period is obtained, the CPU can accumulate the energy consumed by running the task in each sub-time period, and count the total energy consumed by running the task in the target time period. In the example shown in (1.1), after the CPU divides T1 in T, the energy W1 consumed by the CPU to run task 1 in T1 is calculated and added to the total energy consumed by the CPU to run the total task. And then, after the CPU divides T2, calculating the energy W2 consumed by the CPU to run the task 1 in the T2, and accumulating the W2 to the total energy consumed by the CPU to run the total task. And then, after the CPU divides T3, calculating the energy W3 consumed by the CPU to run the task 1, the task 2 and the task 3 in the T3, and accumulating the W3 to the total energy consumed by the CPU to run the total task. And finally, after the CPU divides T4, calculating the energy W4 consumed by the CPU in the T4 for running the task 1 and the task 3, and accumulating the W4 to the total energy consumed by the CPU for running the total task. Thus, the total energy consumed by the CPU to run the total task in T is obtained (in this case, the total energy at least includes W1+ W2+ W3+ W4). In the example shown in (2.1), after the CPU divides T1 into T1, the energy W1 consumed by the CPU to run task 1 in T1 is calculated and added to the total energy consumed by the CPU to run task 1. And then, after the CPU divides T2, calculating the energy W2 consumed by the CPU to run the task 1 in the T2, and accumulating the W2 to the total energy consumed by the CPU to run the task 1. And then, after the CPU divides T3, calculating the energy W3 consumed by the CPU to run the task 1 in the T3, and accumulating the W3 to the total energy consumed by the CPU to run the task 1. And then, after the CPU divides T7, calculating the energy W4 consumed by the CPU to run the task 1 in the T7, and accumulating the W4 to the total energy consumed by the CPU to run the task 1. And finally, after the CPU divides T8, calculating the energy W5 consumed by the CPU in the T8 for running the task 1, and accumulating the W5 to the total energy consumed by the CPU for running the task 1. Thus, the total energy consumed by the CPU to run task 1 in T is obtained (in this case, the total energy at least includes W1+ W2+ W3+ W4+ W5).
After the total energy consumed by running the task in the target time period is obtained, the CPU can feed back the total energy to the user for use as a query result corresponding to the query instruction.
It should be noted that, when the CPU acquires the query instruction, if the task executed by the query instruction is still running (for example, the foregoing case (1.1) and case (2.1)), the CPU may reset the time of acquiring the query instruction to the time of starting the task after completing the power consumption statistics (for example, in the foregoing case (1.1), after completing the energy statistics, the CPU may reset the time of acquiring the query instruction to the time of starting the total task, in the foregoing case (2.1), after completing the energy statistics, the CPU may reset the time of acquiring the query instruction to the time of starting the task, and so on). Then, in the process of running the task by the CPU, if a new query instruction is obtained again (the tasks indicated by the two query instructions are the same), the CPU performs power consumption statistics based on the reset time for starting the task (re-executes steps 302 to 304), so as to obtain a query result corresponding to the new query instruction.
In the embodiment of the application, after the CPU acquires the query instruction, the energy consumed by the CPU to operate the task in the target time period can be determined to be acquired. Then, the CPU may divide the target period into a plurality of sub-periods according to the timing at which the frequency switching occurs within the target period. After the energy consumed by running the task in each sub-time period of the plurality of sub-time periods is obtained, the CPU can obtain the query result corresponding to the query instruction according to the energy consumed by running the task in each sub-time period. Because the CPU in one sub-time period uses one frequency to run the task, the CPU can accurately count the time length of the CPU in the target time period when the CPU uses each frequency to run the task, so that the CPU can accurately calculate the energy consumed by the CPU in the target time period when the CPU uses each frequency to run the task, and the total energy consumed by the CPU in the target time period when the CPU runs the task is accurately reflected to a user.
Furthermore, the CPU calculates the energy consumed by the CPU to run the task in a certain sub-time period, and also judges whether an interrupt event occurs in the sub-time period, so that the influence of the time occupied by processing the interrupt event on the time occupied by the task running is eliminated, and the accuracy of energy statistics is further improved.
The above is a detailed description of the power consumption query method provided in the embodiment of the present application, and the following describes a power consumption query device provided in the embodiment of the present application. Fig. 9 is a schematic structural diagram of a power consumption query apparatus according to an embodiment of the present application, and as shown in fig. 9, the apparatus includes:
a first obtaining module 901, configured to obtain a query instruction, where the query instruction is used to instruct to obtain energy consumed by running a task in a target time period;
a dividing module 902, configured to divide a target time period into multiple sub-time periods according to a time at which frequency switching occurs in the target time period, where one frequency is used to run a task in one sub-time period;
a second obtaining module 903, configured to obtain energy consumed by running a task in each of the multiple sub-time periods;
and a third obtaining module 904, configured to obtain a query result corresponding to the query instruction according to energy consumed by running the task in each sub-time period.
In a possible implementation manner, the target time period does not include a time when the task stops running, and the dividing module 902 is configured to divide the target time period into a plurality of sub-time periods according to a time when the task starts running within the target time period, a time when the frequency switching occurs within the target time period, and a time when the query instruction is acquired.
In a possible implementation manner, the target time period includes a time when the task is stopped, and the dividing module 902 is configured to divide the target time period into a plurality of sub-time periods according to a time when the task starts to run in the target time period, a time when the frequency switching occurs in the target time period, and a time when the task is stopped in the target time period.
In a possible implementation manner, the starting time of the target sub-period is the time when the running task starts, the ending time of the target sub-period is the time when the frequency switching occurs, and the target sub-period is any one of the plurality of sub-periods.
In a possible implementation manner, both the starting time of the target sub-period and the ending time of the target sub-period are the time when the frequency switching occurs, and the target sub-period is any one of the sub-periods.
In a possible implementation manner, the starting time of the target sub-period is the time of occurrence of frequency switching, the ending time of the target sub-period is the time of obtaining the query instruction, and the target sub-period is any one of the plurality of sub-periods.
In a possible implementation manner, the starting time of the target sub-period is the time when the frequency switching occurs, the ending time of the target sub-period is the time when the running task is stopped, and the target sub-period is any one of the plurality of sub-periods.
In a possible implementation manner, the second obtaining module 903 is configured to determine, according to a length of the target sub-time period, a length of a time period used for processing an interrupt event in the target sub-time period, and a power corresponding to a frequency used by a task running in the target sub-time period, energy consumed by the task running in the target sub-time period, where the interrupt event is an event that interrupts the task running.
In a possible implementation manner, the third obtaining module 904 is configured to accumulate energy consumed by running the task in each sub-time period to obtain total energy consumed by running the task in a target time period, where the total energy is used as a query result corresponding to the query instruction.
It should be noted that, because the contents of information interaction, execution process, and the like between the modules/units of the apparatus are based on the same concept as the method embodiment of the present application, the technical effect brought by the contents is the same as the method embodiment of the present application, and specific contents may refer to the description in the foregoing method embodiment of the present application, and are not repeated herein.
Embodiments of the present application also relate to a computer storage medium storing one or more instructions that when executed by one or more computers cause the one or more computers to implement a method as described in fig. 3.
The embodiment of the present application also relates to a computer program product, which stores instructions that, when executed by a computer, cause the computer to implement the method as described in fig. 3.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the several embodiments provided in the present application, it should be understood that the disclosed system, apparatus and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the units is only one type of logical functional division, and other divisions may be realized in practice, for example, multiple units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present application, which are essential or part of the technical solutions contributing to the prior art, or all or part of the technical solutions, may be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
Claims (21)
1. A power consumption query method, the method comprising:
acquiring a query instruction, wherein the query instruction is used for indicating energy consumed by running a task in a target time period;
dividing the target time period into a plurality of sub-time periods according to the time of frequency switching in the target time period, wherein one frequency is used in one sub-time period to run the task;
acquiring energy consumed by running the task in each sub-time period of the plurality of sub-time periods;
and acquiring a query result corresponding to the query instruction according to the energy consumed by running the task in each sub-time period.
2. The method of claim 1, wherein the target time period does not include a time at which the task is stopped, and wherein dividing the target time period into a plurality of sub-time periods according to a time at which a frequency switch occurs within the target time period comprises:
and dividing the target time period into a plurality of sub time periods according to the time of starting to run the task in the target time period, the time of frequency switching in the target time period and the time of acquiring the query instruction.
3. The method of claim 1, wherein the target time period comprises a time when the task stops running, and wherein dividing the target time period into a plurality of sub-time periods according to a time when the frequency switching occurs in the target time period comprises:
and dividing the target time period into a plurality of sub time periods according to the time of starting to run the task in the target time period, the time of frequency switching in the target time period and the time of stopping running the task in the target time period.
4. The method according to claim 2 or 3, wherein a starting time of a target sub-period is a time when the task starts to run, an ending time of the target sub-period is a time when the frequency switching occurs, and the target sub-period is any one of the plurality of sub-periods.
5. The method according to claim 2 or 3, wherein the starting time of a target sub-period and the ending time of the target sub-period are both the times when frequency switching occurs, and the target sub-period is any one of the plurality of sub-periods.
6. The method according to claim 2, wherein a starting time of a target sub-period is a time when the frequency switching occurs, an ending time of the target sub-period is a time when the query instruction is acquired, and the target sub-period is any one of the plurality of sub-periods.
7. The method according to claim 3, wherein a starting time of a target sub-period is a time when the frequency switching occurs, an ending time of the target sub-period is a time when the task stops running, and the target sub-period is any one of the plurality of sub-periods.
8. The method of any one of claims 4 to 7, wherein the obtaining the energy consumed for running the task in each of the plurality of sub-periods comprises:
determining energy consumed by running the task in the target sub-time period according to the length of the target sub-time period, the length of a time period used for processing an interrupt event in the target sub-time period, and power corresponding to the frequency used by running the task in the target sub-time period, wherein the interrupt event is an event for interrupting the running of the task.
9. The method according to any one of claims 1 to 8, wherein the obtaining the query result corresponding to the query instruction according to the energy consumed by running the task in each sub-time period comprises:
and accumulating the energy consumed by running the task in each sub-time period to obtain the total energy consumed by running the task in the target time period, wherein the total energy is used as a query result corresponding to the query instruction.
10. A power consumption inquiry apparatus, characterized in that the apparatus comprises:
the system comprises a first acquisition module, a first processing module and a second processing module, wherein the first acquisition module is used for acquiring a query instruction, and the query instruction is used for indicating to acquire energy consumed by running a task in a target time period;
the dividing module is used for dividing the target time period into a plurality of sub-time periods according to the time when the frequency switching occurs in the target time period, and one frequency is used for running the task in one sub-time period;
a second obtaining module, configured to obtain energy consumed by running the task in each of the multiple sub-time periods;
and the third acquisition module is used for acquiring the query result corresponding to the query instruction according to the energy consumed by running the task in each sub-time period.
11. The apparatus according to claim 10, wherein the target time period does not include a time when the task stops running, and the dividing module is configured to divide the target time period into a plurality of sub-time periods according to a time when the task starts running within the target time period, a time when the frequency switching occurs within the target time period, and a time when the query instruction is obtained.
12. The apparatus according to claim 10, wherein the target time period comprises a time point at which the task stops running, and the dividing module is configured to divide the target time period into a plurality of sub-time periods according to a time point at which the task starts running within the target time period, a time point at which the frequency switching occurs within the target time period, and a time point at which the task stops running within the target time period.
13. The apparatus according to claim 11 or 12, wherein a starting time of a target sub-period is a time when the task starts to run, an ending time of the target sub-period is a time when the frequency switching occurs, and the target sub-period is any one of the plurality of sub-periods.
14. The apparatus according to claim 11 or 12, wherein a starting time of a target sub-period and an ending time of the target sub-period are both times when frequency switching occurs, and the target sub-period is any one of the sub-periods.
15. The apparatus according to claim 11, wherein a starting time of a target sub-period is a time when the frequency switching occurs, an ending time of the target sub-period is a time when the query instruction is obtained, and the target sub-period is any one of the plurality of sub-periods.
16. The apparatus according to claim 12, wherein a starting time of a target sub-period is a time when the frequency switching occurs, an ending time of the target sub-period is a time when the task stops running, and the target sub-period is any one of the plurality of sub-periods.
17. The apparatus according to any one of claims 13 to 16, wherein the second obtaining module is configured to determine, according to a length of a target sub-time period, a length of a time period used for processing an interrupt event in the target sub-time period, and a power corresponding to a frequency used by running the task in the target sub-time period, an energy consumed by running the task in the target sub-time period, where the interrupt event is an event that interrupts running of the task.
18. The apparatus according to any one of claims 10 to 17, wherein the third obtaining module is configured to accumulate energy consumed for running the task in each sub-time period to obtain total energy consumed for running the task in the target time period, where the total energy is used as a query result corresponding to the query instruction.
19. A terminal device, characterized in that the terminal device comprises a memory and a processor; the memory stores code, the processor is configured to execute the code, and when executed, the terminal device performs the method of any of claims 1 to 9.
20. A computer storage medium, characterized in that the computer storage medium stores one or more instructions that, when executed by one or more computers, cause the one or more computers to implement the method of any one of claims 1 to 9.
21. A computer program product having stored thereon instructions which, when executed by a computer, cause the computer to carry out the method of any one of claims 1 to 9.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111136879.9A CN115878409A (en) | 2021-09-27 | 2021-09-27 | Power consumption query method and related equipment thereof |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111136879.9A CN115878409A (en) | 2021-09-27 | 2021-09-27 | Power consumption query method and related equipment thereof |
Publications (1)
Publication Number | Publication Date |
---|---|
CN115878409A true CN115878409A (en) | 2023-03-31 |
Family
ID=85763007
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202111136879.9A Pending CN115878409A (en) | 2021-09-27 | 2021-09-27 | Power consumption query method and related equipment thereof |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN115878409A (en) |
-
2021
- 2021-09-27 CN CN202111136879.9A patent/CN115878409A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US11442747B2 (en) | Method for establishing applications-to-be preloaded prediction model based on preorder usage sequence of foreground application, storage medium, and terminal | |
CN107407980B (en) | Stylus pen having multiple operating portions configured to transmit synchronized signals | |
AU2022200464B2 (en) | Method for reducing power consumption of terminal, and terminal | |
US9170912B1 (en) | System and methods for power and energy modeling in computing devices using system call tracing | |
US20140160045A1 (en) | Terminal and method for providing user interface using a pen | |
JP6487044B2 (en) | Power management method and power management apparatus for user equipment | |
CN110888821B (en) | Memory management method and device | |
US10558840B2 (en) | Fingerprint recognition method and electronic device | |
WO2017206902A1 (en) | Application control method and related device | |
CN107545067B (en) | Log information reporting method and device, storage medium, ADSP and terminal | |
CN110109759B (en) | Catton optimization method, server, electronic device and computer-readable storage medium | |
WO2015062372A1 (en) | Method and apparatus for selecting objects | |
CN110865884A (en) | Memory management method and device | |
CN108983944B (en) | State-based location monitoring | |
US20230400937A1 (en) | Stylus haptic component arming and power consumption | |
WO2014146612A1 (en) | Startup item consumed time acquisition method and device | |
JP7272694B2 (en) | Method and terminal for reducing power consumption of terminal | |
CN107609114B (en) | Log information reporting method and device, storage medium, ADSP and terminal | |
CN115878409A (en) | Power consumption query method and related equipment thereof | |
CN113434336B (en) | Startup method and device, electronic equipment and readable storage medium | |
EP4354293A1 (en) | Detection method and apparatus, and electronic device | |
WO2019071611A1 (en) | Fault processing method for terminal device and terminal device | |
US10210111B2 (en) | Systems and methods for minimizing audio glitches when incurring system management interrupt latency | |
CN106407805B (en) | Trojan horse detection method and device based on Linux system | |
CN115546005A (en) | Instruction processing method and related equipment thereof |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |