Os fine-grained power control method and device based on eBPF

CN117785601BActive Publication Date: 2026-09-08KYLIN CORP
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311565527.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-11-22
Publication Date
2026-09-08
Estimated Expiration
2043-11-22

AI Technical Summary

Technical Problem

[0003]现在大部分操作系统只能估算出硬件模块的总耗电量或者进程总的耗电量,得到的数据往往不够准确,也不够精细,无法针对进程功耗作出进一步更精确的控制

Benefits of technology

[0010] This invention can more accurately calculate the power consumption of each hardware module, and can also perform process-level power consumption control to improve battery life.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117785601B_ABST
    Figure CN117785601B_ABST
Patent Text Reader

Abstract

An eBPF-based operating system fine-grained power consumption control device and method, the device comprising: an application layer, on which a background application and a configuration file are running, the configuration file storing power consumption limit values of various background applications with respect to various hardware modules; a hardware module layer, providing hardware operation interfaces for the background application; an eBPF program, provided with a hook to monitor and capture the calls of the background application to the corresponding hardware operation interfaces in the hardware module layer, to obtain power consumption data of the background application; a support layer, receiving, processing and counting the power consumption data monitored by the eBPF program, and taking corresponding measures on the background application of the application layer based on the processing and counting results. The application can more accurately calculate the power consumption values of various hardware modules, and can also perform process-level power consumption control, thereby improving the battery life.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of operating system power consumption control technology, and specifically to a method and apparatus for fine-grained power consumption control of operating systems based on eBPF. Background Technology

[0002] eBPF is a mechanism provided by the Linux kernel for users to execute custom bytecode without modifying the kernel source code. The kernel performs a series of checks on the eBPF program. If the checks pass, the eBPF program is loaded into the kernel and listens for specific events. Once an event is triggered, the bytecode is executed and information is collected.

[0003] Most operating systems can only estimate the total power consumption of hardware modules or the total power consumption of processes. The data obtained is often inaccurate and not precise enough, making it impossible to make further and more precise control over process power consumption. Summary of the Invention

[0004] To address the shortcomings of existing technologies, this invention provides a fine-grained power consumption control device for operating systems based on eBPF, comprising: The application layer runs background applications and configuration files, which store power consumption limits for various background applications relative to each hardware module. The hardware module layer provides hardware operation interfaces for backend applications. The eBPF program connects to the hardware module layer. The eBPF program is equipped with hooks to monitor and capture the calls of each background application to the corresponding hardware operation interface in the hardware module layer, so as to obtain the power consumption data of each background application. The support layer connects to the eBPF program and the application layer to receive, process, and statistically analyze the power consumption data monitored by the eBPF program, and to take corresponding measures for the background applications in the application layer based on the processing and statistical results. The application layer indirectly calls the hardware operation interface of the hardware module layer through the interface provided by the support layer, so that the background application can run.

[0005] The support layer includes a data receiving module, a data statistics module, and a data processing module connected in sequence. The data receiving module holds a hardware module power consumption data event queue. It receives power consumption data sent by the eBPF program through a socket. The power consumption data includes the process ID of the background application, the hardware module name, and the power consumption value. The data statistics module holds nested map containers to collect data from the data receiving module and categorize it according to process ID; The data processing module holds a power consumption anomaly event queue. It receives data from the data statistics module and compares the actual power consumption value of each process ID with the relevant power consumption limit value in the configuration file. When the actual power consumption value exceeds the power consumption limit value, it transmits a power consumption anomaly event.

[0006] The data receiving module and the data processing module are both queue modules implemented based on the std::queue class provided by C++STL, and the data processing and statistics module is a queue module implemented based on the std::map class provided by C++STL.

[0007] The eBPF program is implemented in C language and internally holds a circular buffer for transmitting hardware module power consumption data generation events. The eBPF program asynchronously retrieves events from the circular buffer and then sends them to the support layer via a socket.

[0008] The present invention also provides a refined power consumption control method for an operating system based on eBPF, which is based on the above-mentioned control device and includes the following steps: Step S1: Configure the power consumption limit values ​​for various background applications relative to each hardware module in the configuration file; Step S2: The background application starts running and indirectly calls the hardware operation interface of the hardware module layer through the interface provided by the support layer. Step S3: The eBPF program captures events through hooks, monitors the corresponding hardware operation interface in the hardware module layer being called, and obtains the corresponding power consumption data, which includes the process ID, hardware module name, and power consumption value. Step S4: The eBPF program sends the acquired power consumption data to the support layer via a socket. Step S5: The support layer receives, processes, and statistically analyzes the power consumption data monitored by the eBPF program, and takes corresponding measures for the background application of the application layer based on the processing and statistical results.

[0009] Step S5 includes: The data receiving module detects receivable data, begins receiving it, and places it into the hardware module power consumption data event queue it holds; If the power consumption data event queue of the hardware module of the data receiving module is not empty, the data statistics module starts to obtain power consumption data from the event queue, identifies the corresponding process ID and hardware module name, and checks whether there is power consumption data in the map container for the corresponding process ID and hardware module name. If there is, the new power consumption data is added to the map element; otherwise, the power consumption data is inserted into the map container. The data processing module compares the total power consumption corresponding to the power consumption data with the relevant power consumption limit value in the configuration file. If the power consumption limit value is exceeded, the power consumption abnormal event is pushed into the power consumption abnormal event queue. The module also obtains the process ID and corresponding hardware module name of the power consumption abnormal process in the power consumption abnormal event queue and judges the power consumption abnormal process: if the process is a foreground application or the power consumption abnormal hardware module of the process is in the user-configured whitelist, no action is taken; otherwise, the user is prompted whether to freeze or kill the process and whether to add the corresponding hardware module to the whitelist.

[0010] This invention can more accurately calculate the power consumption of each hardware module, and can also perform process-level power consumption control to improve battery life. Attached Figure Description

[0011] Figure 1 This invention relates to an eBPF-based operating system-based refined power consumption control device. Detailed Implementation

[0012] To gain a better understanding of the technical solution and beneficial effects of the present invention, the technical solution of the present invention and its beneficial effects are described in detail below with reference to the accompanying drawings.

[0013] Figure 1 The eBPF-based operating system fine-grained power consumption control device of the present invention includes: The application layer runs background applications and configuration files. The configuration files store the power consumption limits of various background applications relative to each hardware module. The hardware modules configured in the configuration files include, but are not limited to, WIFI, Bluetooth, communication, audio, video, GPS, CPU, memory, screen, camera, etc. The hardware module layer provides hardware operation interfaces for backend applications. The eBPF program is loaded and connected to the hardware module layer. The eBPF program has hooks to capture events and monitor background applications' calls to corresponding hardware operation interfaces in the hardware module layer. When a target system call node of the hardware module is invoked, the eBPF program runs to obtain power consumption data from each background application. This power consumption data includes the process ID, hardware module name, and power consumption value. The eBPF program is implemented in C and internally maintains a circular buffer for transmitting events generated by the hardware module's power consumption data. The eBPF program asynchronously retrieves events from the circular buffer and then sends them to the support layer via sockets. Target system nodes invoked by the hardware module include, but are not limited to, functions for scanning Wi-Fi, scanning Bluetooth, making calls, playing audio, playing video, GPS positioning and navigation, requesting CPU time slices, reading memory, rendering UI, and taking photos. Data is transferred between the eBPF program and the hardware module layer via sockets. The support layer connects with the eBPF program and the application layer to implement business logic and process power consumption data. Specifically, it receives, processes, and statistically analyzes the power consumption data monitored by the eBPF program, and takes corresponding measures for the background application of the application layer based on the processing and statistical results. The application layer indirectly calls the hardware operation interface of the hardware module layer through the interface provided by the support layer, so that the background application can run.

[0014] The support layer includes a data receiving module, a data statistics module, and a data processing module connected in sequence: the data receiving module and the data processing module are both queue modules implemented based on the std::queue class provided by C++STL, and the data processing and statistics module is a queue module implemented based on the std::map class provided by C++STL.

[0015] The data receiving module holds a hardware module power consumption data event queue. It receives power consumption data sent by the eBPF program through a socket. The data statistics module holds a nested map container to collect data from the data receiving module, classify it according to process ID, and calculate the total power consumption of the same process and the same hardware module. The data processing module holds a power consumption anomaly event queue. It receives data from the data statistics module and compares the actual power consumption value (also known as the total power consumption value) of each process ID relative to each hardware module with the relevant power consumption limit value in the configuration file. When the actual power consumption value exceeds the power consumption limit value, a power consumption anomaly event is transmitted.

[0016] In practice, the data receiving module uses the epoll model to monitor the corresponding socket. When it detects that data can be received, it starts receiving data and puts it into the hardware module power consumption data event queue. The data receiving module's hardware module power consumption data event queue is not empty. The data statistics module starts to obtain power consumption data from this event queue and identifies the corresponding process ID and hardware module name. It checks whether there is power consumption data for the corresponding process ID and hardware module name in the map container. If there is, the new power consumption data is added to the map element. If not, the power consumption data is inserted into the map container. The data processing module compares the total power consumption value corresponding to the power consumption data with the relevant power consumption limit value in the configuration file. If the power consumption limit value is exceeded, the power consumption abnormal event is pushed into the power consumption abnormal event queue. The module obtains the process ID and corresponding hardware module name of the power consumption abnormal process in the power consumption abnormal event queue and judges the power consumption abnormal process: if the process is a foreground application or the power consumption abnormal hardware module of the process is in the user-configured whitelist, no action is taken. Otherwise, the user is prompted whether to freeze or kill the process and whether to add the corresponding hardware module to the whitelist. After being added to the whitelist, the power consumption of the corresponding hardware module will not be limited.

[0017] This invention can more accurately calculate the power consumption of each hardware module, and can also perform process-level power consumption control to improve battery life.

[0018] Although the present invention has been described using the above preferred embodiments, it is not intended to limit the scope of protection of the present invention. Any changes and modifications made by those skilled in the art to the above embodiments without departing from the spirit and scope of the present invention shall still fall within the scope of protection of the present invention. Therefore, the scope of protection of the present invention shall be defined by the claims.

Claims

1. A refined power consumption control device based on eBPF operating system, characterized in that... include: The application layer runs background applications and configuration files, which store power consumption limits for various background applications relative to each hardware module. The hardware module layer provides hardware operation interfaces for backend applications. The eBPF program connects to the hardware module layer. The eBPF program is equipped with hooks to monitor and capture the calls of each background application to the corresponding hardware operation interface in the hardware module layer, so as to obtain the power consumption data of each background application. The support layer connects to the eBPF program and the application layer to receive, process, and statistically analyze the power consumption data monitored by the eBPF program, and to take corresponding measures for the background applications in the application layer based on the processing and statistical results. The application layer indirectly calls the hardware operation interface of the hardware module layer through the interface provided by the support layer for the background application to run; The support layer includes a data receiving module, a data statistics module, and a data processing module connected in sequence. The data receiving module holds a hardware module power consumption data event queue. It receives power consumption data sent by the eBPF program through a socket. The power consumption data includes the process ID of the background application, the hardware module name, and the power consumption value. The data statistics module holds nested map containers to collect data from the data receiving module and categorize it according to process ID; The data processing module holds a power consumption anomaly event queue. It receives data from the data statistics module and compares the actual power consumption value of each process ID with the relevant power consumption limit value in the configuration file. When the actual power consumption value exceeds the power consumption limit value, it transmits a power consumption anomaly event.

2. The eBPF-based operating system fine-grained power consumption control device as described in claim 1, characterized in that: The data receiving module and the data processing module are both queue modules implemented based on the std::queue class provided by C++STL, and the data statistics module is a statistics module implemented based on the std::map class provided by C++STL.

3. The eBPF-based operating system fine-grained power consumption control device as described in claim 1, characterized in that: The eBPF program is implemented in C language and internally holds a circular buffer for transmitting hardware module power consumption data generation events. The eBPF program asynchronously retrieves events from the circular buffer and then sends them to the support layer via a socket.

4. A method for fine-grained power consumption control of an operating system based on eBPF, characterized in that, The process, based on the control device described in claim 1, includes the following steps: Step S1: Configure the power consumption limit values ​​for various background applications relative to each hardware module in the configuration file; Step S2: The background application starts running and indirectly calls the hardware operation interface of the hardware module layer through the interface provided by the support layer. Step S3: The eBPF program captures events through hooks, monitors the corresponding hardware operation interface in the hardware module layer being called, and obtains the corresponding power consumption data, which includes the process ID, hardware module name, and power consumption value. Step S4: The eBPF program sends the acquired power consumption data to the support layer via a socket. Step S5: The support layer receives, processes, and statistically analyzes the power consumption data monitored by the eBPF program, and takes corresponding measures for the background application of the application layer based on the processing and statistical results.

5. The operating system fine-grained power consumption control method based on eBPF as described in claim 4, characterized in that, Step S5 includes: The data receiving module detects receivable data, begins receiving it, and places it into the hardware module power consumption data event queue it holds; If the power consumption data event queue of the hardware module of the data receiving module is not empty, the data statistics module starts to obtain power consumption data from the event queue, identifies the corresponding process ID and hardware module name, and checks whether there is power consumption data in the map container for the corresponding process ID and hardware module name. If there is, the new power consumption data is added to the map element; otherwise, the power consumption data is inserted into the map container. The data processing module compares the total power consumption corresponding to the power consumption data with the relevant power consumption limit value in the configuration file. If the power consumption limit value is exceeded, the power consumption abnormal event is pushed into the power consumption abnormal event queue. The module also obtains the process ID and corresponding hardware module name of the power consumption abnormal process in the power consumption abnormal event queue and judges the power consumption abnormal process: if the process is a foreground application or the power consumption abnormal hardware module of the process is in the user-configured whitelist, no action is taken; otherwise, the user is prompted whether to freeze or kill the process and whether to add the corresponding hardware module to the whitelist.

Citation Information

Patent Citations

  • Method for reducing power consumption of device, mobile terminal and system

    CN105159816A

  • Power consumption calculation method based on Android system

    CN108415816A