home · contact · privacy
Improve Raspi setup.
authorChristian Heller <c.heller@plomlompom.de>
Sun, 3 Nov 2024 00:12:11 +0000 (01:12 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 3 Nov 2024 00:12:11 +0000 (01:12 +0100)
many_releases/etc/raspi/systemd/system/throttle_cpu.service [new file with mode: 0644]
many_releases/home/raspi/.nonpath_bins/status.sh
many_releases/home/raspi_root/throttle_cpu.sh [new file with mode: 0755]
many_releases/scripts/_misc.sh
testing/scripts/setup_raspi.sh

diff --git a/many_releases/etc/raspi/systemd/system/throttle_cpu.service b/many_releases/etc/raspi/systemd/system/throttle_cpu.service
new file mode 100644 (file)
index 0000000..58043aa
--- /dev/null
@@ -0,0 +1,12 @@
+[Unit]
+Description=Monitor temperature to throttle CPU if necessary
+
+[Service]
+Type=simple
+ExecStart=/root/throttle_cpu.sh
+Restart=always
+RestartSec=10
+User=root
+
+[Install]
+WantedBy=multi-user.target
index 418a52be1fd5a7c8d385dd9701ac634f5d93d4ed..c58e8bfeed3e06808b8816b3b885dfeeaaf94158 100755 (executable)
@@ -1,11 +1,13 @@
 #!/bin/sh
 # see sway-bar(5) and swaybar-protocol(7)
+MEGA=1000
+GIGA=1000000
 printf '{ "version": 1 }\n[\n' 
 while true; do
   printf '  [\n'
   printf '    {"full_text": "%s"},\n' "$(ip -4 addr show scope global | grep -oP '(?<=inet\s)\d+(\.\d+){3}')"
-  printf '    {"full_text": "%d° C"},\n' $(calc "$(cat /sys/class/thermal/thermal_zone0/temp) // 1000")
-  printf '    {"full_text": "%.1f GHz"},\n' $(calc "$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq) / 1000000")
+  printf '    {"full_text": "%d° C"},\n' $(calc "$(cat /sys/class/thermal/thermal_zone0/temp) // ${MEGA}")
+  printf '    {"full_text": "%.1f/%.1f GHz"},\n' $(calc "$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq) / ${GIGA}") $(calc "$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq) / ${GIGA}") 
   printf '    {"full_text": "%s"},\n' "$(date +'%Y-%m-%d %X')"
   printf '  ],\n'
   sleep 1
diff --git a/many_releases/home/raspi_root/throttle_cpu.sh b/many_releases/home/raspi_root/throttle_cpu.sh
new file mode 100755 (executable)
index 0000000..99f5549
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/sh
+set -e
+
+MED_TEMP=65000
+MAX_TEMP=80000
+
+MIN_FREQ=600000
+MED_FREQ=1000000
+MAX_FREQ=1500000
+
+PATH_TEMP='/sys/class/thermal/thermal_zone0/temp'
+
+set_max_freq() {
+  for cpu in /sys/devices/system/cpu/cpu[0-9]*; do
+    echo "$1" > "$cpu/cpufreq/scaling_max_freq" 
+  done
+  echo "$1"
+}
+
+freq_set=$(set_max_freq "${MIN_FREQ}")
+while true; do
+  temp=$(cat "${PATH_TEMP}")
+  if [ "${temp}" -ge "${MAX_TEMP}" ]; then
+    if [ "${freq_set}" -gt "${MIN_FREQ}" ]; then
+      freq_set=$(set_max_freq "${MIN_FREQ}")
+    fi
+  elif [ "${temp}" -ge "${MED_TEMP}" ]; then
+    if [ "${freq_set}" -gt "${MED_FREQ}" ]; then
+      freq_set=$(set_max_freq "${MED_FREQ}")
+    fi
+  elif [ "${freq_set}" -lt "${MAX_FREQ}" ]; then 
+    freq_set=$(set_max_freq "${MAX_FREQ}")
+  fi 
+  sleep 1
+done
index 98b486f8aae5f686336d5abc2620d5c63d7513b2..756c9f5d11793006b3a1c8fa4c51dfe755e7f1d9 100755 (executable)
@@ -148,7 +148,6 @@ setup_for_desktop() {
     for root in "${PATH_MANY}" '..'; do
         copy_dirtree "${root}${PATH_REL_HOME}" "${PATH_USER_HOME}" all desktop $@
     done
-    cp -a "${PATH_REPO}" "${PATH_USER_HOME}"
     mkdir "${PATH_USER_SSH}"
     cp "${PATH_AUTHORIZED_KEYS}" "${PATH_USER_SSH}"
     chown -R "${USERNAME}:${USERNAME}" "${PATH_USER_HOME}"
index 995a822bd554b440ff92a718b072e3399edc34c2..9131b130434225cfe0ceab6a091aee361bae56c5 100755 (executable)
@@ -16,3 +16,7 @@ upgrade_from_older_release
 
 # actual setup
 setup_for_desktop raspi
+
+copy_dirtree "${PATH_MANY}${PATH_REL_HOME}" '/root' raspi_root
+# systemctl enable throttle_cpu.service
+# systemctl start throttle_cpu.service