Skip to content

Commit

Permalink
Move temp source stuff from 30-sysinfo to armhwinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Kaiser committed Apr 18, 2017
1 parent ae0fc2e commit 0ad08c3
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 53 deletions.
50 changes: 41 additions & 9 deletions scripts/armhwinfo
Expand Up @@ -41,6 +41,37 @@ set_io_scheduler() {
done
} # set_io_scheduler

prepare_temp_monitoring() {
# still an ugly hack but better do it just once at startup instead of every login
[ -d /etc/armbianmonitor/datasources ] || mkdir -p -m775 /etc/armbianmonitor/datasources

# AXP209 PMIC check
if [[ -f /sys/power/axp_pmu/pmu/temp ]]; then
ln -fs /sys/power/axp_pmu/pmu/temp /etc/armbianmonitor/datasources/pmictemp
elif [[ -f /sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034//temp1_input ]]; then
ln -fs /sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034/temp1_input \
/etc/armbianmonitor/datasources/pmictemp
fi

# SoC temp: check standard location first
if [[ -d "/sys/devices/virtual/thermal/thermal_zone0" ]]; then
# mainline kernel, Armada 38x, sun50i legacy
ln -fs /sys/devices/virtual/thermal/thermal_zone0/temp /etc/armbianmonitor/datasources/soctemp
elif [[ -d "/sys/class/thermal/thermal_zone1" ]]; then
# sun8i legacy
ln -fs /sys/class/thermal/thermal_zone1/temp /etc/armbianmonitor/datasources/soctemp
elif [[ -d "/sys/devices/virtual/thermal/thermal_zone1" ]]; then
# S500
ln -fs /sys/devices/virtual/thermal/thermal_zone1/temp /etc/armbianmonitor/datasources/soctemp
elif [[ -d "/sys/class/thermal/thermal_zone2" ]]; then
# RK3288 legacy
ln -fs /sys/class/thermal/thermal_zone2/temp /etc/armbianmonitor/datasources/soctemp
elif [[ -d "/sys/devices/platform/a20-tp-hwmon" ]]; then
# sun7i legacy
ln -fs /sys/devices/platform/a20-tp-hwmon/temp1_input /etc/armbianmonitor/datasources/soctemp
fi
} # prepare_temp_monitoring

prepare_board() {
# prevent logrotate from compressing rotated logs when /var/log lives on compressed fs
CheckDevice=$(for i in /var/log /var / ; do findmnt -n -o SOURCE $i && break ; done)
Expand All @@ -52,10 +83,10 @@ prepare_board() {

# IRQ distribution based on $HARDWARE and/or $BOARD, probably some sort of user feedback (leds)
case ${HARDWARE} in
Freescale) # i.MX6 boards, send Ethernet to cpu1, MMC to cpu2/cpu3 (when available)
echo 2 >/proc/irq/$(awk -F":" "/ethernet/ {print \$1}" </proc/interrupts | sed 's/\ //g' | head -1)/smp_affinity 2>/dev/null
Freescale) # i.MX6 boards, send Ethernet to cpu3, MMC to cpu1/cpu2 (when available)
echo 2 >/proc/irq/$(awk -F":" "/mmc0/ {print \$1}" </proc/interrupts | sed 's/\ //g' | head -1)/smp_affinity 2>/dev/null
echo 4 >/proc/irq/$(awk -F":" "/mmc1/ {print \$1}" </proc/interrupts | sed 's/\ //g' | head -1)/smp_affinity 2>/dev/null
echo 8 >/proc/irq/$(awk -F":" "/mmc0/ {print \$1}" </proc/interrupts | sed 's/\ //g' | head -1)/smp_affinity 2>/dev/null
echo 8 >/proc/irq/$(awk -F":" "/ethernet/ {print \$1}" </proc/interrupts | sed 's/\ //g' | head -1)/smp_affinity 2>/dev/null
;;
gs705a) # Roseapple Pi/LeMaker Guitar: send USB IRQs to cpu1/cpu2, DMA0 to cpu2 and Ethernet + SD card to cpu3
echo 2 >/proc/irq/$(awk -F":" "/usb1/ {print \$1}" </proc/interrupts | sed 's/\ //g')/smp_affinity
Expand All @@ -70,13 +101,13 @@ prepare_board() {
echo 2 >/proc/irq/$i/smp_affinity
done
;;
ODROID-C2) # send eth0 to cpu1, mmc/usb2 to cpu2 and usb1 to cpu3
ODROID-C2) # send eth0 to cpu3, mmc/usb2 to cpu2 and usb1 to cpu1
# Basics: http://forum.odroid.com/viewtopic.php?f=115&t=8121#p65777
echo 1 >/proc/irq/$(awk -F":" "/eth0/ {print \$1}" </proc/interrupts | sed 's/\ //g')/smp_affinity_list
echo 3 >/proc/irq/$(awk -F":" "/eth0/ {print \$1}" </proc/interrupts | sed 's/\ //g')/smp_affinity_list
for i in $(awk -F':' '/sd_emmc|usb2/{print $1}' /proc/interrupts); do
echo 2 >/proc/irq/$i/smp_affinity_list
done
echo 3 >/proc/irq/$(awk -F":" "/usb1/ {print \$1}" </proc/interrupts | sed 's/\ //g')/smp_affinity_list
echo 1 >/proc/irq/$(awk -F":" "/usb1/ {print \$1}" </proc/interrupts | sed 's/\ //g')/smp_affinity_list
;;
ODROID-XU3|EXYNOS) # ODROID XU3/XU4
echo 2 >/proc/irq/$(awk -F":" "/usb2/ {print \$1}" </proc/interrupts | sed 's/\ //g')/smp_affinity
Expand All @@ -94,13 +125,13 @@ prepare_board() {
sun4i|sun5i) # only one core, nothing to improve
:
;;
sun6i) # Banana Pi M2: process eth0 on cpu1, SDIO on cpu2, USB on cpu3
echo 2 >/proc/irq/$(awk -F":" '/eth0/ {print $1}' </proc/interrupts | sed 's/\ //g')/smp_affinity
sun6i) # Banana Pi M2: process eth0 on cpu3, SDIO on cpu2, USB on cpu1
echo 8 >/proc/irq/$(awk -F":" '/eth0/ {print $1}' </proc/interrupts | sed 's/\ //g')/smp_affinity
for i in $(awk -F':' '/sunxi-mmc/{print $1}' /proc/interrupts); do
echo 4 >/proc/irq/$i/smp_affinity
done
for i in $(awk -F':' '/hcd:usb/{print $1}' /proc/interrupts); do
echo 8 >/proc/irq/$i/smp_affinity
echo 2 >/proc/irq/$i/smp_affinity
done
;;
sun7i) # try to redistribute eth0 irq to dedicated core
Expand Down Expand Up @@ -261,6 +292,7 @@ case $1 in

# hardware preparation
prepare_board &
prepare_temp_monitoring &

# display message, log hardware id to file, write log
echo -e "[\e[0;32m ok \x1B[0m] Starting ARM hardware info: $ID (${VERSION})"
Expand Down
60 changes: 16 additions & 44 deletions scripts/update-motd.d/30-sysinfo
Expand Up @@ -33,50 +33,21 @@ function display() {
} # display

function getboardtemp() {
# read temperature from different locations and create a symlink to a unique location
[ -d /etc/armbianmonitor/datasources ] || mkdir -p -m775 /etc/armbianmonitor/datasources

# where it should be
if [[ -d "/sys/devices/virtual/thermal/thermal_zone0/" ]]; then
ln -fs /sys/devices/virtual/thermal/thermal_zone0/temp /etc/armbianmonitor/datasources/soctemp
read TempType </sys/devices/virtual/thermal/thermal_zone0/type
case ${TempType} in
cpu_thermal) # mainline kernel
awk '{printf("%d",$1/1000)}' </sys/devices/virtual/thermal/thermal_zone0/temp
return
;;
armada_thermal) # Marvell Armada, reduce reported temp by 30 degress for whatever reasons
echo -n $(( $(awk '{printf("%d",$1/1000)}' </sys/devices/virtual/thermal/thermal_zone0/temp) - 30 ))
return
;;
soc_thermal) # pine64 legacy
cat /sys/devices/virtual/thermal/thermal_zone0/temp
return
;;
esac
elif [[ -d "/sys/class/thermal/thermal_zone1" ]]; then
# sun8i legacy kernel
cat /sys/class/thermal/thermal_zone1/temp
ln -fs /sys/devices/virtual/thermal/thermal_zone1/temp /etc/armbianmonitor/datasources/soctemp
return
fi

# S500 and RK3288 legacy kernels
for tempsource in /sys/devices/virtual/thermal/thermal_zone1 /sys/class/thermal/thermal_zone2 ; do
if [ -d ${tempsource} ]; then
awk '{printf("%d",$1/1000)}' ${tempsource}/temp
ln -fs ${tempsource}/temp /etc/armbianmonitor/datasources/soctemp
return
fi
done

# deal with the exceptions first: legacy Allwinner variants (if SoC is not available take PMU)
for tempsource in /sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034 /sys/devices/platform/a20-tp-hwmon ; do
if [ -d ${tempsource} ]; then
awk '{printf("%d",$1/1000)}' ${tempsource}/temp1_input
ln -fs ${tempsource}/temp1_input /etc/armbianmonitor/datasources/soctemp
if [ -f /etc/armbianmonitor/datasources/soctemp ]; then
read raw_temp </etc/armbianmonitor/datasources/soctemp
if [ ${raw_temp} -le 200 ]; then
# Allwinner legacy kernels output degree C
board_temp=${raw_temp}
else
# Marvell gets special treatment for whatever reasons
grep -qi Marvell /proc/cpuinfo && \
board_temp=$(( $(awk '{printf("%d",$1/1000)}' <<<${raw_temp}) - 30 )) || \
board_temp=$(awk '{printf("%d",$1/1000)}' <<<${raw_temp})
fi
done
elif [ -f /etc/armbianmonitor/datasources/pmictemp ]; then
# fallback to PMIC temperature
board_temp=$(awk '{printf("%d",$1/1000)}' </etc/armbianmonitor/datasources/pmictemp)
fi
} # getboardtemp

function batteryinfo() {
Expand Down Expand Up @@ -145,7 +116,7 @@ amb_temp=$(ambienttemp &)
ip_address=$(get_ip_addresses &)
batteryinfo
storage_info
board_temp=$(getboardtemp)
getboardtemp
critical_load=$(( 1 + $(grep -c processor /proc/cpuinfo) / 2 ))

# get uptime, logged in users and load in one take
Expand Down Expand Up @@ -190,3 +161,4 @@ display "storage/" "$storage_usage" "90" "1" "%" " of $storage_total"
display "Battery" "$battery_percent" "20" "1" "%" "$status_battery_text"
echo ""
echo ""

0 comments on commit 0ad08c3

Please sign in to comment.