Thermal_zone type and temp merge

Hi!

I have a 5G Router from a Chinese company based on OpenWrt software
(OpenWrt 19.07-SNAPSHOT, r11306-c4a6851c72)
I can access the commands I want via Telnet.

At the moment I care about the thing that shows the temperature of the router

cat /sys/class/thermal/thermal_zone*/type

cat /sys/class/thermal/thermal_zone*/temp | awk '{ print ($1 / 1000) "°C" }'

But I tried to combine the two Commands so that the temperature appears next to each piece, but it failed

paste <(cat /sys/class/thermal/therm
al_zone*/type) <(cat /sys/class/thermal/thermal_
zone*/temp) | column -s $'\t' -t | sed 's/\(.\).
.$/.\1°C/'
-ash: syntax error: unexpected "("

How about something basic like this?

for i in /sys/class/thermal/thermal_zone*
do
echo -n $(cat $i/type)
awk ' { print ": " ($1 / 1000) "C" }' $i/temp
done
3 Likes

thanks it work, But is it possible that the temperature for example is like this 60.2°C, instead of 60.200°C?

Also, isn't there a way for it to look like this in the example?

$ paste <(cat /sys/class/thermal/thermal_zone*/type) <(cat /sys/class/thermal/thermal_zone*/temp) | column -s $'\t' -t | sed 's/\(.\)..$/.\1°C/'
INT3400 Thermal  20.0°C
SEN1             45.0°C
SEN2             51.0°C
SEN3             57.0°C
SEN4             59.0°C
pch_skylake      77.5°C
B0D4             50.0°C
x86_pkg_temp     51.0°C

Sure, use printf for the awk output:

$ awk ' { printf ": %5.1f°C\n", $1/1000 }' /sys/class/thermal/thermal_zone0/temp
: 51.5°C
2 Likes

And playing with it a bit more, you can get output into a single line, using Dave's loop and a single printf (no awk or echo).

for i in /sys/class/thermal/thermal_zone*
do
    printf "%-10s: %5.1f°C\n" $(cat $i/type) $(($(cat $i/temp) / 1000))
done
2 Likes

Excellent, but for some reason he does not write the full temperature, just for example. If the temperature is 45.6°C, he writes it as 45.0°C. Can you edit it?

Shell arithmetic won’t keep the decimal value, only integers. Use the awk option.

for i in /sys/class/thermal/thermal_zone*
do
echo $(cat $i/type) $(cat $i/temp) | awk ' { printf "%-10s: %5.1f°C\n" , $1, ($2 / 1000) }'
done
2 Likes

Oops. How many spacecraft have been lost due to int/float confusion? There goes another one. :grinning:

2 Likes

Bonus code:

for d in /sys/devices/system/cpu/cpu*/cpufreq ; do
    echo $(cat "$d"/affected_cpus) $(cat "$d"/scaling_cur_freq) | awk '{printf "CPU %d: %8.3f MHz\n", $1, $2/1000}'
done

CPU 0:  560.915 MHz
CPU 1:  624.644 MHz
CPU 2: 1248.746 MHz
CPU 3:  789.143 MHz

I even ran it through https://www.shellcheck.net/ and got down to only one warning ("quote everything, in fact, do it twice").

1 Like

@efahl
@dave14305

The router is Outdoor 5G NR and LTE router, and I do not know if these temperatures are correct or not.

soc_max : 45.0°C
cpu_little0: 44.3°C
md_4g : 45.0°C
md_3g : 43.9°C
soc_dram_ntc: 40.6°C
nrpa_ntc : 39.1°C
ltepa_ntc : 39.8°C
rf_ntc : 40.3°C
crystal : 40.8°C
pmic : 44.1°C
pmic_vcore: 42.8°C
pmic_vproc: 42.2°C
cpu_little1: 44.8°C
pmic_vgpu : 42.2°C
md_rf : 46.0°C
conn_gps : -274.0°C
cpu_little2: 44.8°C
cpu_little3: 44.9°C
gpu0 : 44.5°C
gpu1 : 44.7°C
dramc : 44.6°C
mmsys : 43.0°C
md_5g : 43.2°C

i think, md_5g is related to temperature of NR 5G module chipset, md_4g is related to temperature of LTE 4G module chipset, and cpu_little0-3 is related to CPU.!!
Other temperatures, I don't know what they belong to.

The router contains Wi-Fi 2.4, but I did not find its temperature in the list. Is it md_rf?

WOW, that's the slowest CPU I've seen in a long time (I started my career on a 1976 KIM-1 and even it had a 1.0 MHz single core).

What do you see when you cat those scaling_cur_freq files?

$ cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq
929219
1200631
1200159
1199890

All of those values look very much reasonable to me. My APU usually runs 48-60 C, wandering up and down with ambient changes (18-28 over the course of the year in my office here). My N5105 has better cooling, so it's almost always ambient+20, so 40-50 C or so.

I think that the CPU cooler is excellent, (Mediatik T750 MT6890-Fibocom FG360)

knowing that the outside temperatures at night range between 30-35°C and during the day it may reach 45°C.

Oh, I see the "affected_cpus" looks like it doesn't exist on your device. I wonder if it's due to your older kernel, here's what's there on an RT3200 with a 5.10 kernel. Maybe just delete the CPU id stuff in that line, and it'll spit out the frequencies in order...

$ ls -la /sys/devices/system/cpu/cpu0/cpufreq/
drwxr-xr-x    4 root     root             0 Aug 14 08:43 .
drwxr-xr-x    3 root     root             0 Aug 14 08:43 ..
-r--r--r--    1 root     root          4096 Aug 23 16:04 affected_cpus
-r--------    1 root     root          4096 Aug 23 16:04 cpuinfo_cur_freq
-r--r--r--    1 root     root          4096 Aug 23 16:04 cpuinfo_max_freq
-r--r--r--    1 root     root          4096 Aug 23 16:04 cpuinfo_min_freq
-r--r--r--    1 root     root          4096 Aug 23 16:04 cpuinfo_transition_latency
drwxr-xr-x    2 root     root             0 Aug 14 08:43 ondemand
-r--r--r--    1 root     root          4096 Aug 23 16:04 related_cpus
-r--r--r--    1 root     root          4096 Aug 23 16:04 scaling_available_frequencies
-r--r--r--    1 root     root          4096 Aug 23 16:04 scaling_available_governors
-r--r--r--    1 root     root          4096 Aug 14 08:45 scaling_cur_freq
-r--r--r--    1 root     root          4096 Aug 23 16:04 scaling_driver
-rw-r--r--    1 root     root          4096 Aug 14 08:43 scaling_governor
-rw-r--r--    1 root     root          4096 Aug 23 16:04 scaling_max_freq
-rw-r--r--    1 root     root          4096 Aug 23 16:04 scaling_min_freq
-rw-r--r--    1 root     root          4096 Aug 23 16:04 scaling_setspeed
drwxr-xr-x    2 root     root             0 Aug 23 16:04 stats
root@ODU:~# ls -la /sys/devices/system/cpu/cpu0/
cpufreq/
drwxr-xr-x    4 root     root             0 Aug 24 06:44 .
drwxr-xr-x    3 root     root             0 Aug 24 06:44 ..
-r--r--r--    1 root     root          4096 Aug 24 06:44 affected_cpus
-r--r--r--    1 root     root          4096 Aug 24 07:07 cpuinfo_max_freq
-r--r--r--    1 root     root          4096 Aug 24 07:07 cpuinfo_min_freq
-r--r--r--    1 root     root          4096 Aug 24 07:07 cpuinfo_transition_latency
-r--r--r--    1 root     root          4096 Aug 24 07:07 related_cpus
-r--r--r--    1 root     root          4096 Aug 24 07:07 scaling_available_frequencies
-r--r--r--    1 root     root          4096 Aug 24 07:07 scaling_available_governors
-r--r--r--    1 root     root          4096 Aug 24 06:44 scaling_cur_freq
-r--r--r--    1 root     root          4096 Aug 24 07:07 scaling_driver
-rw-r--r--    1 root     root          4096 Aug 24 07:07 scaling_governor
-rw-r--r--    1 root     root          4096 Aug 24 07:07 scaling_max_freq
-rw-r--r--    1 root     root          4096 Aug 24 07:07 scaling_min_freq
-rw-r--r--    1 root     root          4096 Aug 24 07:07 scaling_setspeed
drwxr-xr-x    2 root     root             0 Aug 24 07:07 schedutil
drwxr-xr-x    2 root     root             0 Aug 24 07:07 stats

Turns out affected_cpus is a list on SoC-type CPUs. This should work better:

for d in /sys/devices/system/cpu/cpu*/cpufreq ; do
    cpu=$(basename $(dirname $d))
    echo "$cpu" $(cat "$d"/scaling_cur_freq) | awk '{printf "%s: %8.3f MHz\n", $1, $2/1000}'
done

From an RT3200:

cpu0:  437.500 MHz
cpu1: 1350.000 MHz
1 Like

Thanks it work

root@ODU:~# for d in /sys/devices/system/cpu/cpu
*/cpufreq ; do
>     cpu=$(basename $(dirname $d))
>     echo "$cpu" $(cat "$d"/scaling_cur_freq) |
 awk '{printf "%s: %8.3f MHz\n", $1, $2/1000}'
> done
cpu0: 1387.000 MHz
cpu1: 1275.000 MHz
cpu2: 1275.000 MHz
cpu3: 1275.000 MHz