scx_bpfland: Introduce --throttle-us #2004
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Introduce an option to throttle the CPUs, forcing them to periodically stay idle for a certain amount of time every time slice period.
This option can help extend battery life on portable devices, reduce heating, fan noise and overall energy consumption (disabled by default).
The mechanism is implemented using a BPF timer configured with a duty cycle that defines alternating execution and idle intervals. The timer regularly preempts all the CPUs (SCX_KICK_PREEMPT), allowing them to enter the idle state. After the idle period, it wakes them up using SCX_KICK_IDLE to resume execution for the next runtime interval.
This allows to inject idle phases interleaved with active runtime across all CPUs, effectively throttling their activity.
Test results
Hardware:
CPU: AMD Ryzen AI 9 HX 370 w/ Radeon 890M
Test: WebGL acquarium / 15K fishes (https://webglsamples.org/aquarium/aquarium.html)
Power consumption (measured using turbostat):
$ turbostat --header_iterations 5 -S -s PkgWatt,CorWattResult (fps / W):
In this scenario, injecting 10ms idle cycles resulted in ~74.5% power savings (theoretically extending battery life by nearly 4x), while maintaining reasonable system responsiveness (25–30 fps in the WebGL aquarium benchmark).
[ fixed "devices" spelling mistake noticed by @1Naim ]