Optimize: apply a server-provided power setting and send clock measurements
Description
Client mechanics for a new Optimize lever type, power_cap, and the measurements that go with it.
- Lever:
power_capcarries, per domain (efficiency, performance, prime, gpu), how many operating points below the top of this device's own table the clock cap sits. No absolute clocks on the wire. Applying the step stores it on the container (optimizePowerCapextra); undo puts the previous value back. - Session start: when the container has a power setting and the power-control driver can cap each cluster, PowerManager writes each domain's cap as a ceiling. The ceiling never goes above the user's power profile, and the kernel keeps any thermal cap below it. Every later max-clock write (profile, tuners) is clamped to the ceiling. If the user's power control is off, the driver is started for the setting alone, so the session baseline restores the clocks at exit. The setting is reapplied on resume.
- App start: an apply or request that comes in before power control has finished starting waits for it (bounded) instead of treating the device as having no power control.
- No driver: the lever is skipped as not applicable. A step that has only this lever comes back as a no-op, and other levers still apply.
- Request: the device block gains
power_control: per domain its cores, operating points in MHz, the cap in force and how far below the top it sits, plus whether the user's power control is on. - Measurements: the session series now carries per-sample
cluster_cur_mhzandthermal_headroom, pluscluster_coresand thepower_capthe session ran with. On kgsl the GPU max clock sample readsmax_gpuclk, where a thermal cap shows. - Busiest thread per cluster: each sample also carries
cluster_busiest_pct, one entry per cluster in the order ofcluster_cores: the busy percent of the busiest game thread whose last-run core is in that cluster since the previous sample, -1 where no game thread ran there. Wine helper threads are left out by the same name filter as the hot thread. It comes from one pass a second over/proc/<pid>/task/*/statof the game process (utime + stime deltas and the last-run CPU), read into a reused buffer; the tracked hot thread's stat is taken from the same pass instead of a read of its own. - Card: a kept step whose outcome is
coolerreads "That change helped: less heat and longer battery life", in every shipped language.
Unit tests: OptimizePowerCapTest, SessionSeriesTest, TaskWalkTest (fixture task folders: attribution per cluster, the name filter, a game restart, the tracked thread's stat, and the cost of a 100-thread pass). Device test (RP6, Witcher 3 GOG): the setting was applied at session start, held for the whole session, and restored at exit.
Recording
Not applicable (no new screen); the card title is the only visible change.
Type of Change
- Bug fix
- Performance / stability improvement
- Compatibility improvements
- Other (requires prior approval)
Checklist
- If I have access to
#code-changes, I have discussed this change there and it has been green-lighted. If I do not have access, I have still provided clear context in this PR. If I skip both, I accept that this change may face delays in review, may not be reviewed at all, or may be closed. - This change aligns with the current project scope (core functionality, stability, or performance). If not, it has been explicitly approved beforehand.
- I have attached a recording of the change.
- I have read and agree to the contribution guidelines in
CONTRIBUTING.md.
Summary by cubic
Adds a server-provided power setting lever to Optimize that caps CPU and GPU clocks, plus the measurements that go with it.
power_cap carries, per domain (efficiency, performance, prime, gpu), how many operating points below the top of the device's own table the clock cap sits. At session start the setting is applied as a ceiling that every later max-clock write is clamped to; it never exceeds the user's power profile, and the session baseline restores clocks at exit. The setting is stored on the container, reapplied on resume, and skipped on devices without a driver that caps clusters. Apply and request now wait, with a bound, for the power-control driver to finish starting so the setting is not skipped when read right after app start.
Session data
- The series now includes per-sample current cluster clocks, thermal headroom, and the busiest game thread per cluster, plus cluster cores and the power cap the session ran with. The per-cluster busy percent comes from one pass over the game's
/proctask stats every fifth tick, which also supplies the tracked hot thread's stat. - The device request gains a
power_controlblock describing each domain's cores, operating points, and cap in force. - On kgsl the GPU max clock sample reads
max_gpuclk, where a thermal cap shows. - A kept step with a cooler outcome reads "That change helped: less heat and longer battery life" in every shipped language.
Summary by CodeRabbit
- New Features
- Added per-container CPU and GPU power caps on supported devices, with prior settings restored when optimizations are reverted.
- Optimization results can report reduced heat and longer battery life, with translated messaging.
- Session performance data now includes per-cluster activity and power-cap details.
- Bug Fixes
- Improved GPU clock detection and handling of missing or invalid performance readings.