forked from ryan4yin/nix-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnitrosense
129 lines (118 loc) · 4.07 KB
/
nitrosense
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
set -Eeuo pipefail
if [ $# -le 0 ]; then
echo "ENA: [w]rite to ec"
echo "PWR: [q]uiet [d]efault [p]erformance"
echo "FAN: [a]uto [c]ustom [m]ax"
echo "DBG: [r]ead from ec"
echo "DBG: [e]nergy data from intel_rapl"
echo "DBG: [n]vidia-powerd restart"
exit
fi
echo on | sudo tee /sys/module/msr/parameters/allow_writes &>/dev/null
if [[ "$(lsmod | grep ec_sys | wc -c)" -gt 1 ]]; then
if [ -f ~/ec_sys.ko ]; then
sudo rmmod ec_sys
else
sudo modprobe -r ec_sys
fi
fi
if [ -f ~/ec_sys.ko ]; then
if ! sudo insmod ~/ec_sys.ko write_support=1; then
sudo dmesg | tail
exit
fi
else
if ! sudo modprobe ec_sys write_support=1; then
sudo dmesg | tail
exit
fi
fi
EC=/sys/kernel/debug/ec/ec0/io
if [[ $* =~ "r" ]]; then
if [[ $(sudo ls $EC 2>/dev/null) ]]; then
sudo xxd -g1 $EC
else
echo "EC interface not enabled"
fi
fi
if [[ $* =~ "e" ]]; then
find /sys/devices/virtual/powercap -type f -iname "energy_uj" -print | while read -r f; do
echo -e "$f\n$(cat "$f")"
done
fi
function ecw() {
# shellcheck disable=SC2059
printf "$2" | sudo dd of=$EC bs=1 seek="$1" count=1 conv=notrunc &>/dev/null
}
function set_power_limits() {
echo "$3" | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
MSR=/sys/devices/virtual/powercap/intel-rapl/intel-rapl:0
MCH=/sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0
for N in "$MSR" "$MCH"; do
echo "${1}000000" | sudo tee "$N/constraint_0_power_limit_uw" &>/dev/null
echo "${2}000000" | sudo tee "$N/constraint_1_power_limit_uw" &>/dev/null
echo "128000000" | sudo tee "$N/constraint_0_time_window_us" &>/dev/null
echo "128000000" | sudo tee "$N/constraint_1_time_window_us" &>/dev/null
[[ "$N" == "$MSR" ]] && NODE=MSR || NODE=MCH
echo "[$NODE] PL1 [$(cat "$N/constraint_0_power_limit_uw") $(cat "$N/constraint_0_time_window_us")] PL2 [$(cat "$N/constraint_1_power_limit_uw") $(cat "$N/constraint_1_time_window_us")]"
done
}
ecw $((0x03)) '\x11' # Write-Enable
if [[ $(sudo ls $EC 2>/dev/null) ]]; then
if [[ $* =~ "q" ]]; then
echo "PWR - Quiet"
ecw $((0x2c)) '\x00' # 00 01 04 PWR: quiet default perf
ecw $((0x2d)) '\x04' # 04 05 PWR
set_power_limits 10 10 "powersave"
echo powersupersave | sudo tee /sys/module/pcie_aspm/parameters/policy
echo power | sudo tee /sys/devices/system/cpu/cpufreq/policy*/energy_performance_preference
fi
if [[ $* =~ "d" ]]; then
echo "PWR - Default"
ecw $((0xab)) '\x0a' # 08 0a SDTM (Shutdown Therm Temp) temp=val*10, default 80*c
ecw $((0x2c)) '\x01' # 00 01 04 PWR: quiet default perf
ecw $((0x2d)) '\x04' # 04 05 PWR
set_power_limits 75 75 "performance"
echo performance | sudo tee /sys/module/pcie_aspm/parameters/policy
echo performance | sudo tee /sys/devices/system/cpu/cpufreq/policy*/energy_performance_preference
fi
if [[ $* =~ "p" ]]; then
echo "PWR - Performance"
ecw $((0xab)) '\x0a' # 08 0a SDTM (Shutdown Therm Temp) temp=val*10, default 80*c
ecw $((0x2c)) '\x04' # 00 01 04 PWR: quiet default perf
ecw $((0x2d)) '\x04' # 04 05 PWR
set_power_limits 95 95 "performance"
echo performance | sudo tee /sys/module/pcie_aspm/parameters/policy
echo performance | sudo tee /sys/devices/system/cpu/cpufreq/policy*/energy_performance_preference
fi
if [[ $* =~ "n" ]]; then
echo "PWR - nvidia-powerd restart"
sudo systemctl restart nvidia-powerd
fi
if [[ $* =~ "a" ]]; then
echo "FAN - Auto"
ecw $((0x21)) '\x10' # 10 20 30 GPUF: auto max cust
ecw $((0x22)) '\x04' # 04 08 0c CPUF: auto max cust
fi
if [[ $* =~ "c" ]]; then
if [ -z "$2" ]; then
echo "Specify FAN Percentage as Second Arg"
else
PCT="\x$(printf %x "$2")"
echo "FAN - Custom ($2%)"
ecw $((0x21)) '\x30' # 10 20 30 GPUF: auto max cust
ecw $((0x22)) '\x0c' # 04 08 0c CPUF: auto max cust
ecw $((0x37)) "$PCT" # 32 64 CPUF PCT: 0-100%
ecw $((0x3a)) "$PCT" # 32 64 GPUF PCT: 0-100%
fi
fi
if [[ $* =~ "m" ]]; then
echo "FAN - Max"
ecw $((0x21)) '\x20' # 10 20 30 GPUF: auto max cust
ecw $((0x22)) '\x08' # 04 08 0c CPUF: auto max cust
fi
else
echo "EC interface not enabled"
fi