aboutsummaryrefslogtreecommitdiffstats
path: root/config/hypr/scripts/disable.cpu.turbo.sh
blob: dafee76b781b1d11beddd322e4471abbda496b5b (plain) (blame)
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
#!/usr/bin/env bash
set -euo pipefail

require_root() {
  if [[ ${EUID} -ne 0 ]]; then
    exec sudo -- "$0" "$@"
  fi
}

write_sysfs() {
  local path="$1"
  local value="$2"
  if [[ -w "$path" ]]; then
    printf '%s' "$value" >"$path"
    return 0
  fi
  return 1
}

require_root "$@"

changed=0

# Intel P-State turbo control
if [[ -e /sys/devices/system/cpu/intel_pstate/no_turbo ]]; then
  if write_sysfs /sys/devices/system/cpu/intel_pstate/no_turbo 1; then
    changed=1
  fi
fi

# Generic cpufreq boost control (AMD/Intel)
if [[ -e /sys/devices/system/cpu/cpufreq/boost ]]; then
  if write_sysfs /sys/devices/system/cpu/cpufreq/boost 0; then
    changed=1
  fi
fi

# Prefer a quieter governor if available
for gov in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do
  if [[ -w "$gov" ]]; then
    current=$(cat "$gov")
    if [[ "$current" != "powersave" ]] && grep -q powersave "${gov%/*}/scaling_available_governors"; then
      printf '%s' powersave >"$gov"
      changed=1
    fi
  fi
done

# Lower energy/performance preference if supported
for epp in /sys/devices/system/cpu/cpu*/cpufreq/energy_performance_preference; do
  if [[ -w "$epp" ]]; then
    printf '%s' power >"$epp" 2>/dev/null || true
    changed=1
  fi
done

if [[ $changed -eq 1 ]]; then
  echo "CPU turbo/boost disabled and power-saving preferences applied."
  exit 0
fi

echo "No writable turbo/boost controls found. Check kernel driver support."
exit 1
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage