Repository navigation
drm/amd/pm: defer UCLK DPM on selected Apple Navi GPUs - #61
edschofield wants to merge 5 commits into
Conversation
Add the board-specific initialization workaround for the tested 0218/41 iMac. Keep the existing 0219 patch unchanged. Assisted-by: LLM
Defer UCLK DPM enablement to avoid timeouts on Apple iMac 1002:7340/106b:0218. Update firmware bit and memory DPM table accordingly.
Include the 0218 fix from PR 60 and add the experimental board matches and T2 0219 memory-policy handling. Hardware validation of the broader scope remains pending. Assisted-by: LLM Signed-off-by: Ed Schofield <ed@charmersgroup.com>
|
My Linux distribution is 7.2.4-1-t2-resolute. It's a clean install and I haven't changed memory DPM. No workarounds other than trying multiple restarts until it gets to a login prompt. Symptom is that on boot, the system will hang...usually at roughly the same point but not exactly. Latest hang point shown in attached. (That red dotted line about half way down the image, 2/3 of the way down the screen seems to always feature). Once booted successfully, I'm not sure graphics performance matches the MacOS but that's subjective. Any suggestions for the graphics test you'd like me to run after the two warm boots? |
|
@olneyMatt : Thanks for offering to test this on your machine. You'll need ~30 GB of disk space and about 2 hours (mostly waiting for the kernel to compile). Your card is a Navi 10, General approachI suggest you build the kernel yourself using T2Linux's [T2-Debian-and-Ubuntu-Kernel] scripts. It has a file To get the patch in, you need to edit 3 lines in To test: I think you said your kernel is hanging intermittently, so please start testing by restarting your current kernel 5 times as a baseline, so we can estimate how often it fails without the patch. Then try 3 boots on the test kernel, running More detailed steps below. Step 0: a baseline on your current kernel (10 minutes)Before changing anything, I'd like to know how bad the problem is right now, so we have something to compare against. So please restart your iMac five times. Each time, note whether it reaches the login screen or hangs. If it hangs, hold the power button, start it again, and count that as a failure. Write down something like "3 out of 5 hung". Then, whenever you can boot successfully, run this to save a report on your current kernel: mkdir -p ~/t2-uclk-test
cat > ~/t2-uclk-test/collect.sh <<'EOF'
#!/bin/bash
# Saves a short report about the graphics card after a boot.
# It only reads information. It changes nothing.
sudo -v || exit 1
out=~/t2-uclk-test/report-$(date +%Y%m%d-%H%M%S).txt
gpu=/sys/bus/pci/devices/0000:03:00.0
[ -d "$gpu" ] || gpu=$(readlink -f /sys/class/drm/card0/device)
{
echo "== date =="; date
echo; echo "== kernel =="; uname -r
echo; echo "== distro =="; grep PRETTY_NAME /etc/os-release
echo; echo "== boot command line =="; cat /proc/cmdline
echo; echo "== graphics card =="; lspci -nnk -s 03:00.0
echo; echo "== sysfs path =="; echo "$gpu"
echo; echo "== displays =="
for c in /sys/class/drm/card*-*; do
[ -e "$c/status" ] || continue
echo "$(basename "$c"): $(cat "$c/status") $(head -n1 "$c/modes" 2>/dev/null)"
done
echo; echo "== memory clock levels =="; cat "$gpu/pp_dpm_mclk"
echo; echo "== core clock levels =="; cat "$gpu/pp_dpm_sclk"
echo; echo "== power features =="; sudo cat "$gpu/pp_features"
echo; echo "== amdgpu messages this boot =="
sudo journalctl -k -b --no-pager | grep -iE 'amdgpu|smu|\[drm\]' | tail -n 150
echo; echo "== possible GPU errors this boot =="
sudo journalctl -k -b --no-pager | grep -iE 'ring .*timeout|GPU reset|page fault|VM_L2|SMU.*fail|amdgpu.*(error|failed)' | tail -n 60
} > "$out" 2>&1
echo "Saved: $out"
EOF
chmod +x ~/t2-uclk-test/collect.shNow run it: bash ~/t2-uclk-test/collect.shIt will ask for your password first, because reading the kernel log needs root, then it should print the name of the file it saved. Keep that file; send it to me with the rest at the end. Step 1: make the boot menu appear (2 minutes)You'll need to choose between kernels, so make GRUB stop and ask. sudo cp /etc/default/grub /etc/default/grub.backup
sudo sed -i '/^GRUB_TIMEOUT_STYLE=/d; /^GRUB_TIMEOUT=/d' /etc/default/grub
printf 'GRUB_TIMEOUT_STYLE=menu\nGRUB_TIMEOUT=10\n' | sudo tee -a /etc/default/grub
grep -E '^GRUB_TIMEOUT' /etc/default/grub
sudo update-grubThe Restart once to check that you now get a menu with a ten-second countdown. You can use this to get back to your current kernel later. Step 2: get the official t2linux build scripts (5 minutes)We're using the same scripts the t2linux project uses for its own Ubuntu kernels. Run this: sudo apt update
sudo apt install -y git
cd ~
git clone https://github.com/t2linux/T2-Debian-and-Ubuntu-Kernel
cd ~/T2-Debian-and-Ubuntu-Kernel
grep -n '^KERNEL_VERSION' build.shThat should print Step 3: point the scripts at my patch (2 minutes)Edit two files using these commands: cd ~/T2-Debian-and-Ubuntu-Kernel
sed -i 's|^T2_PATCHES_GIT_URL=.*|T2_PATCHES_GIT_URL=https://github.com/edschofield/linux-t2-patches.git|' patch_driver.sh
sed -i 's|^T2_PATCHES_BRANCH_NAME=.*|T2_PATCHES_BRANCH_NAME=draft/apple-navi-generalized-uclk|' patch_driver.sh
sed -i 's|^T2_PATCHES_COMMIT_HASH=.*|T2_PATCHES_COMMIT_HASH=a4c0276293822712b97d5ea936f68629e6b03b65|' patch_driver.sh
sed -i 's|^PKGREL=.*|PKGREL=1uclk|' build.sh
grep -nE '^T2_PATCHES|^PKGREL' patch_driver.sh build.shThe last command should print this: The line numbers might differ, but the text after the The first three lines take the patches from my branch, which is the full t2linux patch set plus the one file under test, Step 4: build it (about an hour of waiting)df -h /
sudo mkdir -p /tmp/artifacts
cd ~/T2-Debian-and-Ubuntu-Kernel
sudo ./build.sh 2>&1 | tee ~/t2-uclk-test/build.logCheck The build downloads the kernel source, installs compilers, applies the patches, and compiles. Expect a lot of scrolling output and somewhere between 40 and 90 minutes. You can use the machine meanwhile, though it'll be slow and the fans will be loud. When it finishes, confirm that my patch actually went in: grep -c '6002-drm-amd-pm-defer-UCLK-DPM-on-Apple-Navi' ~/t2-uclk-test/build.log
ls -la /tmp/artifacts/The If the build stops with an error, send me the last 30 lines of Step 5: install the test kernel (5 minutes)
sudo apt install /tmp/artifacts/linux-image-7.2.4-1uclk-t2-resolute_*.deb \
/tmp/artifacts/linux-headers-7.2.4-1uclk-t2-resolute_*.debDon't install the Now check both kernels are present and both are in the boot menu: ls /boot/vmlinuz-*
grep -c '1uclk' /boot/grub/grub.cfgYou should see your original kernel still there, the new Step 6: boot the test kernelRestart. At the GRUB menu, choose "Advanced options for Ubuntu", then the entry containing If the screen hangs the way it does now, we need to know that. Hold the power button, start again, and pick the same test entry. Please note how many attempts you need for a successful boot. Once you're at the login screen, confirm you're on the right kernel: uname -rIt must print Now check that the patched code recognised your card and ran by typing: sudo dmesg | grep -i 'late UCLK'On a good boot that should print one line ending in something like If you see one of these things, tell me about it too please:
Then save a report with: bash ~/t2-uclk-test/collect.shStep 7: graphics testYou asked about this, but I'm curious too. On my iMac the memory clock does change level, but only with the screens: 875 MHz while a display is on, 98 MHz once they blank. What I haven't seen is it change under load with the displays left on, which is the case that seems to hang other people's machines, so we can perhaps see that on your machine. Install the test tools: sudo apt install -y mesa-utils glmark2 vulkan-toolsOpen two terminal windows side by side. In the first, watch the memory clock. The watch -n 1 'cat /sys/bus/pci/devices/0000:03:00.0/pp_dpm_mclk'If that file doesn't exist, take the right path from the "sysfs path" line in one of your report files and use that instead. In the second, run the benchmark. It takes a few minutes and prints a score at the end: glmark2If While it runs, watch which line carries the Then a couple of shorter things: run Finally, save another report and note your glmark2 score: bash ~/t2-uclk-test/collect.shStep 8: two more restartsRestart twice more into the test kernel, running Step 9: send me the resultsBundle the reports and the build log: cd ~ && tar czf t2-uclk-results.tar.gz t2-uclk-test/
ls -lh ~/t2-uclk-results.tar.gzAttach
Cleaning upTo remove the test kernel completely: sudo apt remove --purge 'linux-image-7.2.4-1uclk-t2-resolute' \
'linux-headers-7.2.4-1uclk-t2-resolute'
sudo update-grubTo put the boot menu back to how it was: sudo cp /etc/default/grub.backup /etc/default/grub
sudo update-grubAnd to reclaim the disk space the build used: sudo rm -rf /root/work /tmp/artifacts ~/T2-Debian-and-Ubuntu-KernelPhew! |
The deferred path was silent on success, so a tester could only infer it from the kernel release name and the build log. Print one info line once the firmware has confirmed UCLK and the memory-clock table has been rebuilt, and report the number of levels found.
a22effd to
a4c0276
Compare
|
Quick question please @edschofield - I'm obviously using the built-in iMac screen (running 3840x2160 sadly!), but I also have two USB-C external displays running over Thunderbolt. Would you rather I disconnected them for testing? Thanks. |
|
As a baseline (before patching your kernel), you could try 5 restarts with your two displays connected and then 5 more with them disconnected. It would be worth seeing whether your computer hangs more one way or the other, or whether it makes no difference. After patching the kernel, please try booting it without the displays connected first. If that boots fine, you could try connecting them too, since that should work the display initialization harder... |
|
You can just use the CI instead of torturing your Mac tbh |
|
@AdityaGarg8 : Oh yes, good idea. So, I guess the flow is ... fork the t2linux kernel repo, make the same three-line change with |
Yes. Also, instead of forking linux t2 patches, you can just add extra patches in the patches folder of this repo. |
|
@olneyMatt: thanks for your patience! @AdityaGarg8 pointed out a much easier route: let GitHub compile the kernel. Here's how to do the build on GitHub:
Also edit Extract the ZIP, open a terminal in that folder, and install just these two packages: sudo apt install ./linux-image-7.2.4-1uclk-t2-resolute_*.deb \
./linux-headers-7.2.4-1uclk-t2-resolute_*.debKeep your old kernel. Check that both appear in GRUB, then restart and choose 7.2.4-1uclk-t2-resolute under Advanced options. Installation can change the default, so choose the entry explicitly. Once booted, check: uname -r
sudo dmesg | grep -i 'late UCLK'
cat /sys/bus/pci/devices/0000:03:00.0/pp_dpm_mclkPlease paste those results here, try For anyone using Noble who wants to test this, use the same workflow as above but substitute |
|
Thanks for these @edschofield - have started the process. Will revert when complete. |
FYI, don't think it's a problem, but this command came back with:
The uclk kernel is showing up in grub so I think all's ok? |
|
Hi @edschofield, Finished testing. If you look in Testing_diary.txt, you'll get an explanation of what I did, what config each report relates to, screenshots etc. TL;DR After patching: glmark2 scores were consistent between kernels. No glitching at any point with either. Curiously, unplugging the external monitors reduces clock from 750MHz to 98MHz . Replugging, clocks go back up to 750MHz. (glmark2 scores were lower for built-in screen only, maybe because of this?) Let me know what questions you have.... P.S. glmark2 scores of <4,000 for a Radeon Pro 5700 seem to support my perception that it's not running at full speed? Interested to know your view. |
|
Hi @edschofield, Thanks for your effort so far in trying to resolve this issue which users on iMac 2020 and others are facing 🫡 I applied your patch on the kernel used by Omarchy (4.0.3) and now with patched kernel I have not faced screen hangs yet (3 successful attempts 💯 so far which never happened earlier) Tested this on Omarchy / Arch Linux on a 2020 27-inch iMac. Hardware
KernelsStock:
Experimental:
The experimental Arch kernel was built from
Build run: https://github.com/vivekchauhan/linux-t2-arch/actions/runs/34678345378 Baseline — stock 7.2.4Five warm boots:
Total hangs: A failing stock boot shows: Experimental delayed-UCLK kernelBoot attempts: All are success
I've attached t2-uclk-results-omarchy.tar.gz Happy to help with any further details. |
|
@edschofield — Test build: Setup for the test: my two userspace workarounds skip themselves when Result: hang on the first boot, ~40 s after the greeter appeared. Black screen right after entering the password, What the log shows (kern.log of that boot, 15:04:09–15:04:15): So the patch did fire ( Side notes, both unrelated to the patch: Xorg aborted twice (SIGABRT) while lightdm started before amdgpu finished I'm back on |
|
@edschofield — a follow-up that may help: Following up on my negative result above, I tried the opposite of "let UCLK switch freely": enable UCLK DPM as usual, echo low > /sys/bus/pci/devices/0000:03:00.0/power_dpm_force_performance_level # everything at minimum, X still without acceleration
echo manual > /sys/bus/pci/devices/0000:03:00.0/power_dpm_force_performance_level
echo 3 > /sys/bus/pci/devices/0000:03:00.0/pp_dpm_mclk # allow only the top UCLK level (750 MHz)
# then restart X with acceleration; pp_features left untouched, DPM_UCLK stays enabledThe transition 95 → 736/750 MHz happened at idle within a second, and after that
Sampled once per second from sysfs ( So on this board the SMU survives a UCLK transition at idle and is perfectly happy running at the top level under sustained 3D For the kernel side this suggests a much smaller change for If you'd like to try that as a patch variant, I'm happy to test it on this board — just ping me here. Meanwhile I'll keep the |
|
Two more data points on the UCLK pin, same board (MacBookPro16,1 / Navi 14 1. Every fixed UCLK level is stable — only the transition matters. I switched
So the SMU is fine at any single level under sustained 3D load; what wedges it is a UCLK transition while the GPU is busy. I've made level 1 my default now (less idle heat, 75 % of the bandwidth). One thing I noticed in the 1 Hz sysfs log: when X restarts with acceleration (modeset), 2. Warning for anyone using the userspace pin: TLP silently undoes it. Two hard hangs today (screen black, machine gone from the network) turned out not to be the new level at all. TLP's defaults are (empty = TLP doesn't touch the GPU). After that Kernel-wise this still points the same way as before: on this panel/board combination, disallowing UCLK switching once the eDP is up (hard-min = whatever level) would avoid the hang, and the level itself can be chosen for power rather than forced to max. Still happy to test a patch variant here. |
|
Follow-up on the UCLK pin, same board (MacBookPro16,1 / Navi 14 A forced UCLK level change does not wedge the SMU — even under full 3D load. Yesterday I concluded "every fixed level is fine, what wedges the SMU is a UCLK transition while the GPU is busy". That was too broad. Today I switched
So the distinction seems to be: a UCLK change ordered from userspace via Workaround I'm now running: a tiny userspace governor. It polls Caveats, clearly: ~40 switches in total so far, a few hours of uptime, a single machine. Whether hundreds of switches per day over weeks stay clean is exactly what I don't know yet; the governor counts every switch in its log so a first amdgpu error can be tied to it. If anyone with a Navi 10/14 Apple board wants to try, the boot-time pin from the wiki workaround (perf level governor script (systemd service, After=your pin unit)#!/bin/bash
# Radeon memory-clock governor: level 0 (95 MHz) idle/video, level 1 (496 MHz) under 3D load.
# Writes ONLY pp_dpm_mclk 0/1, never power_dpm_force_performance_level.
D=/sys/bus/pci/devices/0000:03:00.0; LOG=/var/log/amdgpu-stage-governor.log
UP=40; UPN=2 # up: busy >= 40 % in 2 samples (4 s)
DOWN=15; DOWNN=15 # down: busy < 15 % for 15 consecutive samples (30 s)
MINGAP=10; T=2 # >= 10 s between switches, sample every 2 s
log(){ echo "$(date '+%F %T') $*" >> "$LOG"; }
for i in $(seq 1 60); do [ "$(cat $D/power_dpm_force_performance_level)" = manual ] && break; sleep 5; done
[ "$(cat $D/power_dpm_force_performance_level)" = manual ] || { log "perf level not manual, not starting"; exit 1; }
hi=0; lo=0; last=0; n=0
while :; do
[ "$(cat $D/power_dpm_force_performance_level)" = manual ] || { log "perf level not manual, paused"; sleep 30; continue; }
cur=$(grep '\*' $D/pp_dpm_mclk | cut -d: -f1); b=$(cat $D/gpu_busy_percent); want=""
if [ "$b" -ge $UP ]; then hi=$((hi+1)); lo=0; elif [ "$b" -lt $DOWN ]; then lo=$((lo+1)); hi=0; else hi=0; fi
[ $hi -ge $UPN ] && want=1
[ $lo -ge $DOWNN ] && want=0
now=$(date +%s)
if [ -n "$want" ] && [ "$want" != "$cur" ] && [ $((now-last)) -ge $MINGAP ]; then
echo "$want" > $D/pp_dpm_mclk && { last=$now; n=$((n+1)); hi=0; lo=0; log "level $cur -> $want (busy=$b %, switch #$n)"; }
fi
sleep $T
donehow I tested the switching (detached, hang-proof log)Run from a transient systemd unit so it survives the SSH session, with For the kernel side this may narrow the search: it's not the memory-clock switch itself (PMFW handles the forced change fine at 99 % busy), it's something in the SMU's own UCLK DPM decision path on this panel/board combination. |
|
Thanks for your testing, @olneyMatt , @vivekchauhan , and @3v3nFloW . I posted this patch last week to AMD. I'll let you know if there's any news... |
|
No problem - thanks for the work. It's testament to your instructions that I managed to fork and patch despite having never done it before! Patch is still working well. Only issue is if I reboot and forget to select the patched kernel within 10 secs (which is what I suspect happened in my one failed boot). |
|
@iurjscsi1101500 : This issue is still ongoing. Here's the latest version of the AMD patch, which is the closest to this PR: https://lore.kernel.org/all/20260916144014.879355-1-ed@aicharmers.com/ The patch is needed and does solve the boot problem. Without it, several Apple devices refuse to boot. With the patch, they boot reliably. So could you please open this PR again pending AMD's upstream decision? |

Some Apple Navi GPUs intermittently fail during startup when UCLK DPM is enabled too early. This draft extends the delayed-UCLK fix from PR #60 to the same three board matches as my AMD v4 patch.
7340/0218417340/0219731b/021a40All matches also require AMD vendor
1002and Apple subsystem vendor106b. The patch enables UCLK after display hardware initialization, checks that the firmware accepted it, and refreshes the memory-clock table. It still respects the user's memory-DPM setting and the existing secure Navi 10 exclusion.This PR includes PR #60, so it can be reviewed against
mainon its own. If PR #60 merges first, I will rebase this PR. The T2 patch also needs one change that clean AMD does not: patch 6001 uses a fixed feature mask on0219, so patch 6002 makes its memory-feature bits follow the allowed list. That keeps 6001 from turning UCLK back on too early.Why the board list is smaller now
The earlier draft also matched
020fand021b. On020f, a tester booted the patched kernel and saw the delayed UCLK enable succeed, but the machine then hung after login. Their newer tests suggest that automatic memory-clock policy, rather than every clock change, is involved. That needs a separate investigation; this delayed-enable patch does not fix their board. We have no UCLK-only test for021b. Neither board receives the workaround in this version.Testing so far
The earlier T2 candidate improved reported boot results on
0219from 1/5 to 3/3, and on021awith the internal display from 2/10 to 10/10. The0219and021aresults are for the earlier T2 candidate, not the separate AMD v4 build. My earlier0218implementation also passed warm-boot testing. None of these results establishes reliability on every display setup.The latest edit only removes the
020fand021bmatches; I have checked that the remaining board predicate matches AMD v4. There has been no new hardware boot of this narrowed version yet.If you test one of the three listed boards, please include the exact GPU and subsystem IDs, PCI revision, kernel version, boot results, and any
amdgpuerrors. This PR will stay a draft while we collect more results.This work builds on Atharva Tiwari's delayed-UCLK proposal and Guna's testing. I used Codex / GPT-6 to help prepare the patch and checks.