Skip to content

tools/power-ab: a systemd suspend mode, and a gauge without charge_counter - #157

Merged
derekross merged 2 commits into
derekross:mainfrom
W4HO-ham:power-ab-systemd-suspend
Oct 29, 2026
Merged

derekross merged 2 commits into
derekross:mainfrom
W4HO-ham:power-ab-systemd-suspend

Conversation

@W4HO-ham

Copy link
Copy Markdown
Contributor

Two small things the sleep-drain audit on the 9a (#144) needed from this tool:

  • --suspend systemd: the s2idle phase arms the RTC alarm with rtcwake -m no and runs systemctl suspend, so the system-sleep hooks run (on the 9a the NFC stop-poll hook has to), and waits for /sys/power/suspend_stats/success to move. The default stays rtcwake, the old behaviour, so cheetah's runs don't change.
  • A gauge with charge_now but no charge_counter (the 9a's max77779) is accepted; the summary already read charge_now as its cross-check column, so for such a gauge that is the sleep-phase figure.

Tried on the palmtop: a 40 s awake / 40 s sleep cycle through systemd, woken by the RTC, SSH and NFC polling back afterwards; the two-hour run with the cable out is in progress for #144. Nothing else runs on a phone; tools/pr-check passes.

…unter

The s2idle test froze through rtcwake -m freeze, which skips the system-sleep hooks; on the palmtop (Pixel 9a) the NFC hook must run, since polling through s2idle has reset it. --suspend systemd arms the RTC alarm and runs systemctl suspend, waiting for the suspend success count to move. The 9a's gauge has charge_now but no charge_counter, so the test now accepts either; the summary already used charge_now as its cross-check. Tried on the palmtop: one 40 s cycle with the hooks, woken by the RTC, NFC polling again afterwards.
@derekross

Copy link
Copy Markdown
Owner

Thank you, this is a tidy change and the default is handled well. With no --suspend, power-ab runs exactly the old rtcwake -m freeze line. --detach passes the mode through. The charge_now fallback only loosens the s2idle precondition, and the summary's charge-counter pass already prints nothing for an empty column. So on the Pixel 7 Pro the only change is "suspend rtcwake" at the end of the CSV's first comment line, which nothing parses. Nothing new assumes USB comes back. It's also good that the systemd path respects logind's inhibitors. On the 9a the modem's inhibitor is there for a reason, and the old path went around it.

One thing before it merges:

systemctl suspend doesn't necessarily mean s2idle. rtcwake -m freeze always enters s2idle. systemctl suspend enters whatever systemd and /sys/power/mem_sleep resolve to. On a phone with neither mem_sleep_default=s2idle in its bootargs nor a MemorySleepMode=s2idle drop-in, that's deep, which never wakes on gs201. Today that's the Pixel Fold, for example. With the cable out and the tool detached, that's a phone asleep until someone holds the power key, and the precondition (grep -qw s2idle) only checks that s2idle is offered. The 9a is fine (its board DT has the boot argument). Could the systemd mode refuse unless s2idle is what will actually run? Something like:

if [[ $suspend == systemd ]]; then
  msm=$(systemd-analyze cat-config systemd/sleep.conf 2>/dev/null |
        sed -n 's/^MemorySleepMode=//p' | tail -n1)
  if [[ -n $msm ]]; then [[ ${msm%% *} == s2idle ]]
  else grep -q '\[s2idle\]' /sys/power/mem_sleep; fi ||
    { echo "power-ab: systemctl suspend would not enter s2idle here" >&2; exit 1; }
fi

Please also reject an unknown --suspend value. Right now a typo quietly runs the rtcwake path.

Not blocking:

  • After an early wake near the end of a phase, the loop suspends again with as little as 6 s on the alarm. rtcwake -m no sets an absolute time, and systemd's sleep hooks run before the kernel freezes, so if the hooks take longer than that, the alarm fires while the phone is still awake and the freeze has no RTC wake. A larger floor for the systemd mode (say 30 s, staying awake for the remainder) avoids it.
  • The usage text for s2idle still says "(rtcwake -m freeze, …)". Worth a word about the systemd mode there.
  • For the 9a, charge_now is the gauge's model-corrected remaining charge, so it's a coarser sleep figure than a coulomb counter. That's fine for device/tegu: SLEEP-PLAN, an audit of the s2idle drain #144, but worth saying next to the result.

The policy check and both CI jobs pass, and the script parses.

…ects a typo

systemctl suspend enters what sleep.conf and mem_sleep resolve to, and deep never wakes on these phones, so the systemd mode checks MemorySleepMode from the merged sleep.conf (or the selected mem_sleep) and refuses otherwise; an unknown --suspend value is an error instead of the rtcwake path. With less than 30 s left in a phase the systemd mode stays awake for the remainder, since the hooks run before the freeze and a short alarm could fire first. The usage names the mode, and the summary says what the reported-charge column is.
W4HO-ham added a commit to W4HO-ham/omarchy-mobile that referenced this pull request Oct 29, 2026
…oot, S1's command and column

S2 says it turns LDO15S off on purpose for one boot against FINGERPRINT-PLAN's rule (that plan gets the matching note once derekross#138 is on main), and step 3 keeps omamobile-fp, the trusted app and storageproxyd stopped before the push and until the rollback, since F6c still writes secure objects. S1 names its command, power-ab with derekross#157's systemd suspend mode (rtcwake -m no plus systemctl suspend, so the NFC hook runs), reads charge_now, column 7, because the 9a's gauge has no charge_counter, and waits for derekross#157. Also: derekross#125's rules are being settled; the four rails read disabled with or without the unused-rail cleanup; stock's source grepped for the four rail names (DT sources and the register header only, no module asks by name); a Polling read before each run; nothing starts the modem at boot, so nothing to mask.
@W4HO-ham

Copy link
Copy Markdown
Contributor Author

All in at 3dabf3a: the systemd mode now checks MemorySleepMode from the merged sleep.conf, or the selected entry of mem_sleep when there's none, and refuses unless that's s2idle (your snippet, as written); an unknown --suspend value is an error; with less than 30 s left in a phase the systemd mode stays awake for the remainder rather than arm a short alarm under the hooks; the usage names the mode; and the summary says the reported-charge column is the gauge's model-corrected figure, coarser than a coulomb counter. bash -n and pr-check pass. The 9a's board DT has mem_sleep_default=s2idle, so the check passes there, and I'll re-run the short cycle with this version before the cable-out run for #144.

@W4HO-ham

Copy link
Copy Markdown
Contributor Author

Re-ran the short cycle on the palmtop with 3dabf3a: the s2idle check passed (the 9a's sleep.conf drop-in names s2idle), one 40 s awake / 40 s sleep cycle through systemctl suspend, woken by the RTC, suspend_stats 1 success 0 fail, NFC polling back afterwards.

@derekross
derekross merged commit b552c67 into derekross:main Oct 29, 2026
2 checks passed
derekross pushed a commit that referenced this pull request Oct 29, 2026
* device/tegu: SLEEP-PLAN, an audit of the s2idle drain

The 9a sleeps and wakes, but its drain is high. This audits why from stock's device tree and a snapshot of the palmtop: no cluster or SICD idle states, the GNSS and fingerprint rails always on in the bring-up DTB, and MIF, with a measurement runbook.

* device/tegu SLEEP-PLAN: the firmware's PSCI has no OS-initiated mode

So cluster states on zumapro would be platform-coordinated, with a composite StateID; and the core state's rejection rate, read from cpuidle.

* device/tegu SLEEP-PLAN: start from what's measured

The cable-out s2idle figure (about 140 mA), MIF in sleep (about 57 mA saved), and the cluster power-down tries of 10-28 (cluster 0 hangs; clusters 1-2 save nothing measurable) were already measured; the candidates are re-ranked on them.

* device/tegu SLEEP-PLAN: S2's image, its expectation and rollback

* device/tegu SLEEP-PLAN: the review's preconditions, S2's before and after, the code by commit

The runbook stops if slot B isn't marked successful and doesn't mark it (a devinfo write on the 9a, #125). S1 needs the NFC stop-poll hook active or polling stopped by hand, with the kernel's #131 state and the rule that stays, a Rollback line and pstore after a cycle that doesn't come back. S2 snapshots regulator_summary before and diffs it after, stops if more than the four rails changed, records stock's consumers of them (none in its DT: no phandle on any of the four, the GNSS three on the PMIC's channel mux, LDO15S a spare), keeps the modem off in that boot and stays away from a G3 session. The push wording says what bin/omamobile push writes and that only vendor_kernel_boot differs. The module, the bring-up DT and the S2 change are linked by commit on the fork's tegu-sleep-bringup branch, and the CPU_INFORM hints of 10-28 are credited to the bring-up module that wrote them over the PMU SMC. The measurements link #100's NOTES entry.

* device/tegu SLEEP-PLAN: the fingerprint stack stays stopped in S2's boot, S1's command and column

S2 says it turns LDO15S off on purpose for one boot against FINGERPRINT-PLAN's rule (that plan gets the matching note once #138 is on main), and step 3 keeps omamobile-fp, the trusted app and storageproxyd stopped before the push and until the rollback, since F6c still writes secure objects. S1 names its command, power-ab with #157's systemd suspend mode (rtcwake -m no plus systemctl suspend, so the NFC hook runs), reads charge_now, column 7, because the 9a's gauge has no charge_counter, and waits for #157. Also: #125's rules are being settled; the four rails read disabled with or without the unused-rail cleanup; stock's source grepped for the four rail names (DT sources and the register header only, no module asks by name); a Polling read before each run; nothing starts the modem at boot, so nothing to mask.
derekross added a commit that referenced this pull request Oct 31, 2026
… rounds

L-348 to L-361: shared drivers judged against every int-line user (#150),
board pins against every stock user (#151), ownership flags under the
consumer's lock (#152), /chosen children and Google's panel constants
(#154), same-day notes PRs on one device (#208/#209), merge simulations for
DEVICES rows, ours included (#165), stacked PRs that merged main (#115/#117),
titles behind renumbered versions, a contributor merge that dropped the PR
(#99), smoke package lists as provenance and "owner-authorized" writes
(#200), promised fixes and named tags checked on the remote (#153/#157/#158),
and file swaps into old packages (#193). C-23 (usbc-deadman's device scope,
kernel #107) and C-24 (BNEP in a lynx-only fragment, #98).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
derekross pushed a commit that referenced this pull request Nov 1, 2026
options clk_acpm zuma_gpu_max_khz=890000, as tegu's zumapro_gpu_max_khz: the cap kernel #157 adds, with OPPs to 890 MHz and a gpu-thermal passive trip at 85 °C. Without #157 the option is ignored.
robertzas pushed a commit to robertzas/omarchy-mobile that referenced this pull request Nov 14, 2026
…unter (derekross#157)

--suspend systemd runs the A/B drain cycles through systemctl suspend, so
sleep hooks (the 9a's NFC stop-poll) run; it refuses unless s2idle is the
mode that will actually run, and rejects unknown --suspend values, so a
phone without mem_sleep_default=s2idle can't enter deep with the cable out.
A gauge without charge_counter (the 9a's) is read through charge_now. The
default rtcwake mode is unchanged.

Co-authored-by: W4HO-ham <87742609+W4HO-ham@users.noreply.github.com>
robertzas pushed a commit to robertzas/omarchy-mobile that referenced this pull request Nov 14, 2026
* device/tegu: SLEEP-PLAN, an audit of the s2idle drain

The 9a sleeps and wakes, but its drain is high. This audits why from stock's device tree and a snapshot of the palmtop: no cluster or SICD idle states, the GNSS and fingerprint rails always on in the bring-up DTB, and MIF, with a measurement runbook.

* device/tegu SLEEP-PLAN: the firmware's PSCI has no OS-initiated mode

So cluster states on zumapro would be platform-coordinated, with a composite StateID; and the core state's rejection rate, read from cpuidle.

* device/tegu SLEEP-PLAN: start from what's measured

The cable-out s2idle figure (about 140 mA), MIF in sleep (about 57 mA saved), and the cluster power-down tries of 10-28 (cluster 0 hangs; clusters 1-2 save nothing measurable) were already measured; the candidates are re-ranked on them.

* device/tegu SLEEP-PLAN: S2's image, its expectation and rollback

* device/tegu SLEEP-PLAN: the review's preconditions, S2's before and after, the code by commit

The runbook stops if slot B isn't marked successful and doesn't mark it (a devinfo write on the 9a, derekross#125). S1 needs the NFC stop-poll hook active or polling stopped by hand, with the kernel's derekross#131 state and the rule that stays, a Rollback line and pstore after a cycle that doesn't come back. S2 snapshots regulator_summary before and diffs it after, stops if more than the four rails changed, records stock's consumers of them (none in its DT: no phandle on any of the four, the GNSS three on the PMIC's channel mux, LDO15S a spare), keeps the modem off in that boot and stays away from a G3 session. The push wording says what bin/omamobile push writes and that only vendor_kernel_boot differs. The module, the bring-up DT and the S2 change are linked by commit on the fork's tegu-sleep-bringup branch, and the CPU_INFORM hints of 10-28 are credited to the bring-up module that wrote them over the PMU SMC. The measurements link derekross#100's NOTES entry.

* device/tegu SLEEP-PLAN: the fingerprint stack stays stopped in S2's boot, S1's command and column

S2 says it turns LDO15S off on purpose for one boot against FINGERPRINT-PLAN's rule (that plan gets the matching note once derekross#138 is on main), and step 3 keeps omamobile-fp, the trusted app and storageproxyd stopped before the push and until the rollback, since F6c still writes secure objects. S1 names its command, power-ab with derekross#157's systemd suspend mode (rtcwake -m no plus systemctl suspend, so the NFC hook runs), reads charge_now, column 7, because the 9a's gauge has no charge_counter, and waits for derekross#157. Also: derekross#125's rules are being settled; the four rails read disabled with or without the unused-rail cleanup; stock's source grepped for the four rail names (DT sources and the register header only, no module asks by name); a Polling read before each run; nothing starts the modem at boot, so nothing to mask.
robertzas pushed a commit to robertzas/omarchy-mobile that referenced this pull request Nov 14, 2026
… rounds

L-348 to L-361: shared drivers judged against every int-line user (derekross#150),
board pins against every stock user (derekross#151), ownership flags under the
consumer's lock (derekross#152), /chosen children and Google's panel constants
(derekross#154), same-day notes PRs on one device (derekross#208/derekross#209), merge simulations for
DEVICES rows, ours included (derekross#165), stacked PRs that merged main (derekross#115/derekross#117),
titles behind renumbered versions, a contributor merge that dropped the PR
(derekross#99), smoke package lists as provenance and "owner-authorized" writes
(derekross#200), promised fixes and named tags checked on the remote (derekross#153/derekross#157/derekross#158),
and file swaps into old packages (derekross#193). C-23 (usbc-deadman's device scope,
kernel derekross#107) and C-24 (BNEP in a lynx-only fragment, derekross#98).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
robertzas pushed a commit to robertzas/omarchy-mobile that referenced this pull request Nov 14, 2026
…ekross#221)

options clk_acpm zuma_gpu_max_khz=890000, as tegu's zumapro_gpu_max_khz: the cap kernel derekross#157 adds, with OPPs to 890 MHz and a gpu-thermal passive trip at 85 °C. Without derekross#157 the option is ignored.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants