Skip to content

scsi: ufs: exynos: zumapro: Gate the host clocks when idle - #99

Merged
derekross merged 4 commits into
derekross:omamobilefrom
W4HO-ham:tegu-ufs-clkgate
Nov 1, 2026
Merged

derekross merged 4 commits into
derekross:omamobilefrom
W4HO-ham:tegu-ufs-clkgate

Conversation

@W4HO-ham

Copy link
Copy Markdown
Contributor

zumapro's UFS host never gated its clocks at idle: it set neither UFSHCD_CAP_CLK_GATING nor UFSHCD_CAP_HIBERN8_WITH_CLK_GATING. On a host without clock scaling the core also holds its CPU latency request at 0 while the clocks are on, so no core on the 9a reached C2 (this is what #69 worked around at probe). This turns on gating with the link in Hibern8 after the core's idle delay, as gs101 and gs201 do.

Tested on the 9a (7.3.0-rc6-omamobile-tegu-s2mpg15-m1-g991042e2eff3-dirty, ufs-exynos.c blob 5fdf7d01be6a, the file in this patch):

  • clkgate_enable 1 with the default 150 ms delay;
  • with pm_qos_enable left on, /dev/cpu_dma_latency sits at the default when idle;
  • in an idle minute cpu0 spent 36 s in C2, cpu4 39 s and cpu7 41 s, against 0 s with the clocks held on;
  • a cold read of 20000 files under /usr, then 30 fsync'd 8 MiB writes with idle gaps between them, all with no UFS errors.

The root file system has been on it since boot. With this in, #69 is no longer needed for the 9a. I'll close #69 if you agree.

@derekross

Copy link
Copy Markdown
Owner

Thank you for this, and for the numbers: C2 residency before and after, plus an I/O soak with the root on it, make the 9a side easy to follow. Stock zumapro does run software Hibern8 with clock gating (its zuma-ufs.dtsi has no samsung,support-ah8, so Google's driver sets both caps), so this is the right direction for the 9a.

The checks pass on today's omamobile (clean merge, sign-off, checkpatch, W=1), and on the Pixel 7 Pro's config only zumapro_ufs_drv_init changes in ufs-exynos.o, so cheetah is untouched.

Before I can merge it, two things:

  1. It also turns this on for the Pixel 8 Pro. husky's zuma.dtsi has compatible = "google,zuma-ufs", "google,zumapro-ufs", and the driver only matches google,zumapro-ufs, so husky runs zumapro_ufs_drv_init too. husky runs Arch from userdata on this host, and its UFS plan says Hibern8 hasn't run on Tensor G3 or G4 yet and that its first run (U5) should be attended, from an initramfs boot. With this patch husky would enter Hibern8 after every 150 ms of idle under Arch. Could you keep it to the 9a: for example a google,zuma-ufs entry with its own data that keeps today's behaviour, or a flag in the zumapro data that only tegu's compatible sets? The other route is husky's owner running U5 with this patch first, but keeping it to the 9a is simpler.

  2. Google runs PHY writes on every Hibern8 entry and exit that our zumapro PHY doesn't have. Google's ufs-exynos.c (exynos_ufs_hibern8_notify) calls ufs_cal_post_h8_enter after entering and ufs_cal_pre_h8_exit before leaving. In zuma/ufs-cal.h those are post_h8_enter (TRSV_SQ 0x9F4 = 0x08 and 0xA00 = 0x3A, COMN 0x000 = 0x51, TRSV 0xB64 0x30 then 0x33) and pre_h8_exit (the reverse). Mainline's gs101 PHY carries them as cfgs_hibern8, and gs201 uses that PHY data, so "as gs101 and gs201 do" holds for the caps but not for the PHY: phy-zumapro-ufs.c has no cfgs_hibern8, so phy_notify_state() returns without writing anything. Could you add the two tables to the zumapro PHY (the same CAL serves zuma and zumapro), or say in the message why they aren't needed? Your soak shows the link survives without them, but not what state the PHY is left in while in Hibern8.

Once it's 9a-only, with the PHY sequences or a reason, I'll merge it, and #69 can close then as you suggest.

The PHY tables can only describe register writes. Tensor G4's Hibern8
exit sequence in Google's zuma calibration tables waits 10 us
(COMMON_WAIT) between its write to the PMA common register 0x000 and
its writes to the lane registers.

Add a table entry for such a wait. Like a common block write, it runs
once, on the lane 0 pass. Existing tables are unchanged.

Link: https://android.googlesource.com/kernel/google-modules/soc/gs/+/204078758737776959ecc85c527a00fd2cabb62f/drivers/ufs/zuma/ufs-cal.h
Link: https://android.googlesource.com/kernel/google-modules/soc/gs/+/204078758737776959ecc85c527a00fd2cabb62f/drivers/ufs/zuma/ufs-cal-if.c
Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com>
Google's UFS driver runs a PMA sequence after every Hibern8 entry
(ufs_cal_post_h8_enter) and another before every exit
(ufs_cal_pre_h8_exit). The Tensor G4 PHY data has no cfgs_hibern8, so
phy_notify_state() writes nothing and the PMA stays in its active
setting while the link is in Hibern8.

Add both tables from Google's zuma calibration, which the zuma and
zumapro builds share (CONFIG_SOC_ZUMA). After entry: the TRSV_SQ
registers 0x9f4 = 0x08 and 0xa00 = 0x3a on each lane, the common
register 0x000 = 0x51, then 0xb64 = 0x30 and 0x33 on each lane. Before
exit: 0x000 = 0x11, a 10 us wait, 0x9f4 = 0x00 and 0xa00 = 0x30, then
0xb64 = 0x32 and 0x22. As in the existing table, Google's byte offsets
are converted to words and the lane stride is 0x800 bytes. The
sequences are the same for every power mode (PMD_ALL), and Google's
exit sequence has no CDR wait, so no wait_for_cdr is needed.

As on gs101, the host driver runs the entry sequence after it has
stopped the host clocks, where Google's runs it just before.

The Pixel 8 Pro binds this data through its google,zuma-ufs-phy
fallback. Its host has no idle clock gating, and runtime PM of its
LUNs stays off unless userspace allows it, so it enters Hibern8 only
on the way to turning the link off, at shutdown and system suspend.
Google's driver runs the same entry sequence there, from the same
tables.

Link: https://android.googlesource.com/kernel/google-modules/soc/gs/+/204078758737776959ecc85c527a00fd2cabb62f/drivers/ufs/zuma/ufs-cal.h
Link: https://android.googlesource.com/kernel/google-modules/soc/gs/+/204078758737776959ecc85c527a00fd2cabb62f/drivers/ufs/ufs-exynos.c
Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com>
The Pixel 8 Pro's UFS host is "google,zuma-ufs", "google,zumapro-ufs",
and the driver matches only the fallback, so Tensor G3 and Tensor G4
share one set of host data and anything enabled for G4 reaches G3 too.
Idle Hibern8 has not been tried on G3 yet, and the next patch turns on
idle clock gating with the link in Hibern8 on G4.

Match "google,zuma-ufs", which the binding already documents, with a
copy of today's data, and rename the shared drv_init to the SoC that
keeps it. No functional change.

Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com>
zumapro set neither UFSHCD_CAP_CLK_GATING nor
UFSHCD_CAP_HIBERN8_WITH_CLK_GATING, so the host clocks never went off at
idle. The core also holds its CPU latency request at 0 while the clocks
are on (on a host without clock scaling), so no core reached its C2
state. Gate them with the link in Hibern8 after the core's idle delay,
as gs101 and gs201 do, and as Google's driver does on zumapro: its
zuma-ufs.dtsi has no samsung,support-ah8, so it sets both caps.

Only Tensor G4 gets this. Tensor G3 keeps its own host data, with the
link active at idle, until Hibern8 has been tried there.

Tested on the Pixel 9a with
7.3.0-rc6-omamobile-tegu-s2mpg15-m1-g991042e2eff3-dirty, before the
PHY's Hibern8 sequences were added: clkgate_enable 1 with the 150 ms
default delay, pm_qos_enable left on, /dev/cpu_dma_latency idle at the
default, and in an idle minute cpu0 spent 36 s in C2, cpu4 39 s and
cpu7 41 s (0 s with the clocks held on). A cold read of 20000 files
under /usr and 30 fsync'd 8 MiB writes with idle gaps between them ran
with no UFS errors, and the root file system has been on it since boot.

Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com>
@W4HO-ham

W4HO-ham commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for catching both. Reworked as four commits (head 5894c52, rebased onto omamobile):

  1. phy: samsung-ufs: Allow a delay between calibration table entries. Google's exit sequence waits 10 us between its common write and its lane writes, and the tables could only describe writes. This adds a PHY_DELAY_BLK entry that samsung_ufs_phy_config() runs once, on the lane 0 pass. No existing table uses it, so gs101, gs201 and the rest don't change.
  2. phy: samsung-ufs: Add the Tensor G4 Hibern8 sequences. zumapro_post_h8_enter, zumapro_pre_h8_exit and .cfgs_hibern8 in phy-zumapro-ufs.c, as gs101 does it, with the values from zuma/ufs-cal.h at google-modules/soc/gs 204078758737 (android-gs-tegu-6.1-android16; the zuma CAL is built for both zuma and zumapro). post_h8_enter is what you wrote. One correction to the summary: pre_h8_exit isn't quite the reverse. It writes COMN 0x000 = 0x11, waits 10 us, then sets TRSV_SQ 0x9F4 = 0x00 and 0xA00 = 0x30, then TRSV 0xB64 = 0x32 and 0x22. As on gs101, mainline writes the entry sequence after the host clocks stop, where Google writes it just before; the message says so.
  3. scsi: ufs: exynos: Give Tensor G3 its own host data. A google,zuma-ufs match (already in the binding, as the fallback pair) with a copy of today's data, so husky keeps its link active at idle. No functional change.
  4. scsi: ufs: exynos: zumapro: Gate the host clocks when idle. Only google,zumapro-ufs sets the two clock-gating caps now.

husky shares the PHY data through its google,zuma-ufs-phy fallback. With no clock gating it enters Hibern8 only on the way to link-off at shutdown or suspend, and Google's driver runs the same entry sequence there from the same tables. checkpatch --strict is clean, and W=1 is clean on all the Samsung UFS PHY objects (the header change reaches them all) and on ufs-exynos.o.

A boot of this head on the palmtop today (7.3.0-rc6-omamobile-push1-g5894c5287770, built from omamobile with this series, root on UFS throughout): clkgate_enable 1 with the 150 ms delay, spm_lvl 5. A cold read of 20000 files under /usr (after drop_caches) took 4 s. Then 30 fsync'd 8 MiB writes with 2 s idle gaps, so the link went in and out of Hibern8 between them, and the files read back identical after another drop_caches. One s2idle: it entered at 14:51:13, and since this kernel has no RTC alarm wake (that's #55), it slept until the power key at 14:54:47. It resumed and thawed in 80 ms. Nothing in dmesg matched ufshcd errors, resets, link startup failed, Host init failed or I/O error, before or after the sleep.

What this boot can't show is the C2 residency. omamobile's zumapro.dtsi has no idle states yet, so there's no cpuidle C2 to measure on this kernel. The numbers in the last commit's message are still the earlier ones from my integration kernel, measured before the PHY sequences existed, and the message says that. I'll re-measure C2 on the integration kernel with these four commits if you want that before merging.

@derekross

Copy link
Copy Markdown
Owner

Thank you, @W4HO-ham. The four-commit split reads well, and thank you for correcting my summary of pre_h8_exit. You're right that it isn't the reverse.

What I checked on 5894c5287770:

  • The PHY tables against Google's. I compared both tables with zuma/ufs-cal.h and with the loop in zuma/ufs-cal-if.c. The byte offsets come out as your words (0x9F4 → 0x27d, 0xA00 → 0x280, 0xB64 → 0x2d9). PHY_PMA_TRSV_SQ and PHY_PMA_TRSV are both per lane with the 0x800 stride. Google's loop skips PHY_PMA_COMN and COMMON_WAIT on lanes above 0, which is exactly what PHY_DELAY_BLK does here, and COMMON_WAIT 0x0A is your 10 µs. Every value matches.
  • The new table entry. No existing table uses PHY_DELAY_BLK, so the gs101 and gs201 tables, which the Pixel 7 Pro runs, take the same writes as before. The only new code on their path is the id compare.
  • Host data. zuma_ufs_drvs is field for field what zumapro_ufs_drvs was, and only google,zumapro-ufs sets the two clock-gating caps now. So the Pixel 8 Pro's host keeps its link active at idle, as I asked.
  • Gate on today's omamobile: a clean merge, all four commits signed off, checkpatch --strict with nothing to read, and W=1 builds of the three touched C files. CI is green on this head, and it merges cleanly with the other open 9a PRs.

One thing for the record, which your PHY commit already says: the Pixel 8 Pro binds the zumapro PHY data through its fallback, so it now runs these two sequences when its link goes into Hibern8 on the way to link-off, at shutdown and system suspend. That's the same sequence Google's driver runs on zuma, and on that path only, so I'm fine with it. I'll let Brett know, so his next husky reboot covers it.

Optional, not a blocker: the last commit's "Tested" paragraph is from your integration kernel before the PHY sequences existed, and it says so. If you'd like to add today's boot of this head (7.3.0-rc6-omamobile-push1-g5894c5287770: the file read, the fsync'd writes across Hibern8 and the clean s2idle), push it and I'll merge that. Otherwise I'll rebase-merge it as it is, and #69 can close then. A C2 re-measure isn't needed for this.

@derekross
derekross merged commit 1c9b7ad into derekross:omamobile Nov 1, 2026
1 check passed
@derekross

Copy link
Copy Markdown
Owner

Merged. Thanks, @W4HO-ham.

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