Systemd job to set card power limit

This commit is contained in:
Andreas
2025-11-01 18:39:16 +01:00
parent 14b9edf59c
commit 0dba2464b2
3 changed files with 63 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
# Vibe coded script to override thermal limit at bootup
## Setup
- put throttle_instinct.sh into /usr/local/bin
- put throttle_instinct.service into /etc/systemd/system
- enable with `systemctl enable throttle_instinct.service`
- if required, adjust the desired power limit in the shell script

View File

@@ -0,0 +1,11 @@
[Unit]
Description=Throttle Instinct MI50 GPU to a desired power cap
After=sysinit.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/throttle_instinct.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,45 @@
#!/bin/bash
watt_limit=120
for i in {0..10}; do
card="/sys/class/drm/card$i"
# Skip non-existing, virtual or non-GPU devices
if [ ! -d "$card" ] || [ ! -e "$card/device" ]; then
continue
fi
# Resolve the PCI device path
device_path=$(readlink -f "$card/device")
# Read vendor and device IDs from sysfs
vendor_id=$(cat "$device_path/vendor")
device_id=$(cat "$device_path/device")
if [ "$vendor_id" == "0x1002" ] && [ "$device_id" == "0x66a0" ]; then
echo "Vega detected, limiting to $watt_limit W."
# TODO check if the hwmon / power indices are stable with multiple cards or
# make the script robust to always set the correct power cap
found=0
for hwmon in /sys/class/hwmon/hwmon*; do
if [ -e "$hwmon/device" ]; then
hwmon_dev=$(readlink -f "$hwmon/device")
if [ "$hwmon_dev" = "$device_path" ]; then
power_cap_file="$hwmon/power1_cap"
if [ -e "$power_cap_file" ]; then
echo ${watt_limit}000000 > $power_cap_file
found=1
break
fi
fi
fi
done
if [ $found -eq 0 ]; then
echo "Warning: Could not find power1_cap for this GPU."
fi
fi
echo
done