-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathaffinity-setup.sh
More file actions
executable file
·69 lines (56 loc) · 1.69 KB
/
Copy pathaffinity-setup.sh
File metadata and controls
executable file
·69 lines (56 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/sh
# Minimal display affinity helper:
# - optionally set CPU governor to performance
# - de-prioritize display.service so UI work is less likely to interfere
# with Klipper/Moonraker on low-power SBCs
set -eu
TAG="display-affinity-minimal"
ENABLE_PERFORMANCE_GOVERNOR="${ENABLE_PERFORMANCE_GOVERNOR:-yes}"
log() {
logger -t "$TAG" -- "$@" 2>/dev/null || true
printf '%s: %s\n' "$TAG" "$*"
}
have() { command -v "$1" >/dev/null 2>&1; }
# Re-exec as root because systemd may call this via affinity.service.
if [ "$(id -u)" != 0 ]; then
exec sudo -E -- "$0" "$@"
fi
mainpid() {
unit="$1"
systemctl show -p MainPID --value "$unit" 2>/dev/null || echo 0
}
renice_unit() {
unit="$1"
nice_val="$2"
pid="$(mainpid "$unit")"
[ "$pid" -gt 0 ] || return 0
renice "$nice_val" -p "$pid" >/dev/null 2>&1 || true
}
ionice_idle_unit() {
unit="$1"
pid="$(mainpid "$unit")"
[ "$pid" -gt 0 ] || return 0
have ionice || return 0
ionice -c3 -p "$pid" >/dev/null 2>&1 || true
}
set_performance_governor() {
[ "$ENABLE_PERFORMANCE_GOVERNOR" = "yes" ] || {
log "Skipping CPU governor change"
return 0
}
if have cpupower; then
cpupower frequency-set -g performance >/dev/null 2>&1 || true
else
for g in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do
[ -w "$g" ] && echo performance > "$g" 2>/dev/null || true
done
fi
log "CPU governor set to performance (best effort)"
}
set_performance_governor
# Keep the UI process gentle. Do not touch klipper/klipper-mcu scheduling,
# CPU affinity, IRQ affinity, or serial driver tuning here.
renice_unit display.service 19
ionice_idle_unit display.service
log "Applied gentle priority tuning to display.service"
exit 0