Skip to content

Commit 0cc40d7

Browse files
committed
Add Arch performance tuning profile
1 parent 700417f commit 0cc40d7

File tree

2 files changed

+248
-2
lines changed

2 files changed

+248
-2
lines changed

script/install.d/07-arch-perf.sh

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
#!/usr/bin/env bash
2+
3+
# -----------------------------------------------------------------------------
4+
# Description:
5+
# Apply Arch/CachyOS performance tuning when NVIDIA hardware is present.
6+
#
7+
8+
enable_unit_if_available() {
9+
local unit=$1
10+
if systemctl list-unit-files --no-legend 2>/dev/null | awk '{print $1}' | grep -Fxq "$unit"; then
11+
if sudo systemctl enable --now "$unit" >/dev/null 2>&1; then
12+
log_info "Enabled systemd unit: $unit"
13+
else
14+
log_warn "Unable to enable $unit"
15+
fi
16+
else
17+
log_warn "Unit $unit not found; skipping"
18+
fi
19+
}
20+
21+
skip_with_reason() {
22+
log_warn "$1"
23+
return 0
24+
}
25+
26+
main() {
27+
if [[ "${OSTYPE:-}" != linux-gnu* ]]; then
28+
skip_with_reason "Skipping Arch performance tuning: requires Linux"
29+
return
30+
fi
31+
32+
if [[ ! -r /etc/os-release ]]; then
33+
skip_with_reason "Skipping Arch performance tuning: /etc/os-release not found"
34+
return
35+
fi
36+
37+
# shellcheck disable=SC1091
38+
. /etc/os-release
39+
40+
local id_lower id_like_lower
41+
id_lower=$(echo "${ID:-}" | tr '[:upper:]' '[:lower:]')
42+
id_like_lower=$(echo "${ID_LIKE:-}" | tr '[:upper:]' '[:lower:]')
43+
44+
if [[ "$id_lower" != "arch" && "$id_lower" != "cachyos" && "$id_like_lower" != *"arch"* ]]; then
45+
skip_with_reason "Skipping Arch performance tuning: ${NAME:-unknown} is not Arch based"
46+
return
47+
fi
48+
49+
if ! command -v pacman >/dev/null 2>&1; then
50+
skip_with_reason "Skipping Arch performance tuning: pacman not available"
51+
return
52+
fi
53+
54+
if ! command -v nvidia-smi >/dev/null 2>&1; then
55+
skip_with_reason "Skipping Arch performance tuning: NVIDIA utilities not detected"
56+
return
57+
fi
58+
59+
log_info "Applying performance profile for ${NAME:-Arch Linux}"
60+
61+
local -a packages=(
62+
cpupower
63+
fastfetch
64+
gamemode
65+
lib32-gamemode
66+
lib32-nvidia-utils
67+
nvidia-settings
68+
nvidia-utils
69+
nvtop
70+
vulkan-tools
71+
)
72+
73+
log_info "Ensuring required packages are installed"
74+
sudo pacman -S --noconfirm --needed "${packages[@]}"
75+
76+
log_info "Configuring cpupower defaults"
77+
sudo tee /etc/default/cpupower >/dev/null <<'EOF'
78+
# Managed by dotfiles performance install
79+
governor='schedutil'
80+
min_freq='0'
81+
max_freq='0'
82+
EOF
83+
enable_unit_if_available "cpupower.service"
84+
85+
log_info "Writing sysctl overrides"
86+
sudo tee /etc/sysctl.d/99-dots-performance.conf >/dev/null <<'EOF'
87+
# Managed by dotfiles performance install
88+
vm.swappiness = 10
89+
vm.vfs_cache_pressure = 50
90+
kernel.unprivileged_userns_clone = 1
91+
EOF
92+
sudo sysctl -p /etc/sysctl.d/99-dots-performance.conf >/dev/null
93+
94+
log_info "Setting transparent huge page policy"
95+
sudo tee /etc/tmpfiles.d/dots-performance-thp.conf >/dev/null <<'EOF'
96+
# Managed by dotfiles performance install
97+
w /sys/kernel/mm/transparent_hugepage/enabled - - - - madvise
98+
w /sys/kernel/mm/transparent_hugepage/defrag - - - - madvise
99+
EOF
100+
sudo systemd-tmpfiles --create /etc/tmpfiles.d/dots-performance-thp.conf
101+
102+
log_info "Configuring NVMe scheduler"
103+
sudo tee /etc/udev/rules.d/60-dots-nvme-scheduler.rules >/dev/null <<'EOF'
104+
# Managed by dotfiles performance install
105+
ACTION=="add|change", KERNEL=="nvme[0-9]n[0-9]", ATTR{queue/scheduler}="none"
106+
EOF
107+
sudo udevadm control --reload-rules
108+
sudo udevadm trigger --subsystem-match=block --action=change
109+
110+
log_info "Applying NVIDIA module defaults"
111+
sudo tee /etc/modprobe.d/dots-nvidia-performance.conf >/dev/null <<'EOF'
112+
# Managed by dotfiles performance install
113+
options nvidia NVreg_UsePageAttributeTable=1
114+
options nvidia NVreg_InitializeSystemMemoryAllocations=0
115+
options nvidia NVreg_EnableGpuFirmware=1
116+
options nvidia_drm modeset=1 fbdev=1
117+
EOF
118+
119+
if command -v mkinitcpio >/dev/null 2>&1; then
120+
log_info "Rebuilding initramfs for NVIDIA modules"
121+
sudo mkinitcpio -P >/dev/null
122+
fi
123+
124+
enable_unit_if_available "nvidia-persistenced.service"
125+
enable_unit_if_available "fstrim.timer"
126+
127+
local config_home="${XDG_CONFIG_HOME:-$HOME/.config}"
128+
mkdir -p "$config_home"
129+
130+
log_info "Writing GameMode configuration"
131+
cat <<'EOF' > "$config_home/gamemode.ini"
132+
# Managed by dotfiles performance install
133+
[general]
134+
renice=10
135+
ioprio=0
136+
inhibit_screensaver=1
137+
138+
[cpu]
139+
desiredgov=schedutil
140+
141+
[gpu]
142+
apply_gpu_optimisations=accept
143+
gpu_device=0
144+
nv_powermizer_mode=1
145+
146+
[custom]
147+
start=logger -t dots-perf "GameMode activated"
148+
end=logger -t dots-perf "GameMode deactivated"
149+
EOF
150+
151+
log_info "Configuring Proton/DXVK defaults"
152+
local env_dir="$config_home/environment.d"
153+
mkdir -p "$env_dir"
154+
cat <<'EOF' > "$env_dir/99-dots-performance.conf"
155+
# Managed by dotfiles performance install
156+
PROTON_ENABLE_NVAPI=1
157+
PROTON_HIDE_NVIDIA_GPU=0
158+
DXVK_ASYNC=1
159+
__GL_THREADED_OPTIMIZATION=1
160+
EOF
161+
162+
log_pass "Arch performance tuning complete"
163+
}
164+
165+
main "$@"
166+
unset -f main
167+
unset -f enable_unit_if_available
168+
unset -f skip_with_reason

script/install.d/99-screenfetch.sh

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,85 @@
22

33
# -----------------------------------------------------------------------------
44
# Description:
5-
# Print system information.
5+
# Print system information with optional telemetry details.
66
#
77

8-
neofetch
8+
trim() {
9+
local value="${1:-}"
10+
value="${value#${value%%[![:space:]]*}}"
11+
value="${value%${value##*[![:space:]]}}"
12+
printf '%s' "$value"
13+
}
14+
15+
print_fetch() {
16+
if command -v fastfetch >/dev/null 2>&1; then
17+
fastfetch
18+
return
19+
fi
20+
21+
if command -v neofetch >/dev/null 2>&1; then
22+
neofetch
23+
return
24+
fi
25+
26+
log_warn "Skipping fetch output: fastfetch/neofetch not installed"
27+
}
28+
29+
log_gpu_stats() {
30+
if ! command -v nvidia-smi >/dev/null 2>&1; then
31+
return
32+
fi
33+
34+
local line
35+
line=$(nvidia-smi --query-gpu=name,driver_version,memory.used,memory.total,clocks.gr,clocks.mem --format=csv,noheader,nounits 2>/dev/null | head -n 1)
36+
if [[ -z "$line" ]]; then
37+
return
38+
fi
39+
40+
IFS=',' read -r gpu_name driver mem_used mem_total clock_gr clock_mem <<< "$line"
41+
gpu_name=$(trim "$gpu_name")
42+
driver=$(trim "$driver")
43+
mem_used=$(trim "$mem_used")
44+
mem_total=$(trim "$mem_total")
45+
clock_gr=$(trim "$clock_gr")
46+
clock_mem=$(trim "$clock_mem")
47+
48+
[[ -n "$gpu_name" ]] && log_info "GPU: ${gpu_name} (driver ${driver})"
49+
if [[ -n "$clock_gr" || -n "$clock_mem" ]]; then
50+
log_info "GPU clocks: ${clock_gr:-?} MHz graphics | ${clock_mem:-?} MHz memory"
51+
fi
52+
if [[ -n "$mem_used" && -n "$mem_total" ]]; then
53+
log_info "GPU memory usage: ${mem_used}/${mem_total} MiB"
54+
fi
55+
}
56+
57+
log_cpu_stats() {
58+
if ! command -v lscpu >/dev/null 2>&1; then
59+
return
60+
fi
61+
62+
local cpu_model cpu_cur cpu_max
63+
cpu_model=$(lscpu | awk -F: '/Model name/ {gsub(/^[ \t]+/, "", $2); print $2; exit}')
64+
cpu_cur=$(lscpu | awk -F: '/CPU MHz/ {gsub(/^[ \t]+/, "", $2); print $2; exit}')
65+
cpu_max=$(lscpu | awk -F: '/CPU max MHz/ {gsub(/^[ \t]+/, "", $2); print $2; exit}')
66+
67+
[[ -n "$cpu_model" ]] && log_info "CPU: ${cpu_model}"
68+
if [[ -n "$cpu_cur" || -n "$cpu_max" ]]; then
69+
if [[ -n "$cpu_cur" && -n "$cpu_max" ]]; then
70+
log_info "CPU clock: current ${cpu_cur} MHz (max ${cpu_max} MHz)"
71+
elif [[ -n "$cpu_cur" ]]; then
72+
log_info "CPU clock: current ${cpu_cur} MHz"
73+
else
74+
log_info "CPU clock: max ${cpu_max} MHz"
75+
fi
76+
fi
77+
}
78+
79+
print_fetch
80+
log_gpu_stats
81+
log_cpu_stats
82+
83+
unset -f trim
84+
unset -f print_fetch
85+
unset -f log_gpu_stats
86+
unset -f log_cpu_stats

0 commit comments

Comments
 (0)