On 9/2/2025 12:36 AM, Rafael J. Wysocki wrote:
On Mon, Sep 1, 2025 at 3:56 PM Lin Yikai <yikai....@vivo.com> wrote:
Changes in v2:
- Optimized the logic in descriptions. (Song Liu)
- Created a new header file to declare kfuncs for future extensions included
by other files. (Christian Loehle)
- Fixed some logical issues in the code. (Christian Loehle)
Reference:
[1] https://lore.kernel.org/bpf/20250829101137.9507-1-yikai....@vivo.com/
Summary
----------
Hi, everyone,
This patch set introduces an extensible cpuidle governor framework
using BPF struct_ops, enabling dynamic implementation of idle-state selection
policies
via BPF programs.
Motivation
----------
As is well-known, CPUs support multiple idle states (e.g., C0, C1, C2, ...),
where deeper states reduce power consumption, but results in longer wakeup
latency,
potentially affecting performance.
Existing generic cpuidle governors operate effectively in common scenarios
but exhibit suboptimal behavior in specific Android phone's use cases.
Our testing reveals that during low-utilization scenarios
(e.g., screen-off background tasks like music playback with CPU utilization
<10%),
the C0 state occupies ~50% of idle time, causing significant energy
inefficiency.
I gather that this is based on measurements taken on ARM-based
platforms because for x86 it is demonstrably not true.
Yes, we conducted our tests on mobile phones based on Qualcomm SoCs, which use
the ARM64 platform.
There are only two cpuidle states in total on these CPUs (C0/C1).
Through tracing cpuidle and scheduling, we found that during screen-off music
playback,
although the task running time accounts for less than 10%, the C0 state's
proportion exceeds 50%.
Reducing C0 to ≤20% could yield ≥5% power savings on mobile phones.
To address this, we expect:
1.Dynamic governor switching to power-saved policies for low cpu utilization
scenarios (e.g., screen-off mode)
2.Dynamic switching to alternate governors for high-performance scenarios
(e.g., gaming)
All of this can be done without using BPF at all, so why use it here?
Thanks for your comments.
Conclusion first
------------------
Yes,it is possible to switch different governors using sysfs nodes,
but that lacks granularity and flexibility.
This approach aims to preserve the common logic of existing Linux governors
while adding flexibility for scenario-specific optimizations on certain SoC
platforms or by ODMs.
Details second
-----------------
Below is a comparison of traditional governor methods
with a BPF-based approach for dynamic optimization of the cpuidle governor:
1.Agile Iteration
-Traditional:
Governor policies require being predetermined and statically embedded before
kernel compilation.
-BPF:
Allows dynamic policy iteration based on real-time market user feedback
User-space components can be updated via cloud deployment,
eliminating the need for kernel modifications, recompilation, or reboots.
It is very convenient for mobile device updates.
2.Dynamic Fine-Tuning
-Traditional:
Involves replacing the entire governor, which is less granular.
-BPF:
Allows granular tuning of governor parameters.
-Examples:
--Screen-off music playback: dynamically enable "expect_deeper" or other flags
add by BPF progs for deeper idle states.
--Gaming scenarios: Allows idle strategy parameters adjustments via user-space
signals
(e.g., FPS, charging state) – metrics often opaque to the kernel.
So, by exposing tunable parameters through BPF maps,
user-space applications could make more run-time parameters adjustments,
enhancing precision for specific scenarios.
Wish more additional insights you might have on this.
Thanks,
[yikai]