[lm-sensors] Sensors [via-cputemp] is cpu intensive?

Jean Delvare khali at linux-fr.org
Sun Apr 22 15:42:19 CEST 2012

Hi Dave,

On Sun, 22 Apr 2012 11:19:24 +0100, lmsensors at continuingtime.com wrote:
> Historically, I've been getting my CPU thermal info from 
> /proc/acpi/thermal_zone/THRM/temperature for the longest time and it's 
> generally been giving me consistent temperature values.
> After a kernel upgrade I acpi stopped creating the above file so I 
> decided that rather than try to figure out what I did to get it working 
> many years ago, I'd give lm-sensors a try but I'm getting some really 
> weird results out of it that I want to confirm with you.

Most of /proc/acpi has been deprecated over time in favor of equivalent
(but often more generic) sysfs attributes. For
example /proc/acpi/thermal_zone/THRM/temperature would now
be /sys/class/thermal/thermal_zone0/temp. If your kernel had
CONFIG_THERMAL_HWMON enabled, you would also see this thermal zone in
the output of "sensors".

> mobo: EPIA SN (mini-itx)
> CPU: via C7 1.8GHz (cooled by half height 80mm fan)
> driver:  via-cputemp
> So if I just run /usr/bin/sensors, I get a CPU temp of 32 degC.  But, 
> when I run it from a script per...
> --------
> MAIL_SUBJECT="$(hostname -s | tr '[a-z]' '[A-Z]'): Temperature Warning"
> MAIL_RCPT='xxxx'
> MAIL_BODY=$(mktemp)
> DEBUG=''
> # Sensor thresholds
> IFS=$'\n'
> for i in $(/usr/bin/sensors | grep Core); do
>    cpu=$(echo $i | awk -F: '{ print $1 }')
>    temp=$(echo $i | awk -F: '{ print $2 }' | sed -e 's/[^0-9\.]//g' -e 
> 's/\..*//g')
>    if [ $CPU_THRESHOLD -ge $(($temp)) ]; then
>      printf "  %10s: %5s\n" $cpu $temp >> $MAIL_BODY
>    else
>      printf "**%10s: %5s  !!WARNING!!\n" $cpu $temp >> $MAIL_BODY
>      MAIL_SEND=1
>    fi
> done
> # debug
> cat $MAIL_BODY
> -----------------
> I get a temp of 36 degC.
> So, with nothing else running on this box, running something as simple 
> as bash, mktemp, grep and sensors sends my CPU temp up 4 degC.  Okay, I 
> can accept that actually using the CPU can create a temp spike but have 
> a look at this....
> ------------------
> #!/bin/bash
> for i in $(seq 1 200); do
>    /usr/bin/sensors | grep Core
> done
> sleep 1
> /usr/bin/sensors | grep Core
> -------------------
> Remember that just running sensors returns a temp of ~32.  When I run 
> the above script, the first temp is usually ~36 and through the 200 runs 
> it clocks up to ~43-45.  And the last temp on the list (after the sleep 
> 1) is ~34.

I see something similar here with a completely different CPU. Starts at
45-47°C, ends at 48-53°C. My delta is smaller than yours but my cooling
is probably much more efficient.

> Now, I know that this is low power CPU and it's got a relatively small 
> heatsink on the EPIA-SN board but I'm having trouble with the fact that 
> my CPU spikes by nearly 10 degrees just running bash once and 
> sensors+grep 202 times.
> Just how CPU intensive is 'sensors'

It isn't particularly CPU intensive. However modern x86 processors have
several power levels (known as C-states) and several operating
voltages/frequencies.The deepest C-state can only be used when the CPU
is truly idle. As soon as anything runs on the CPU, you're back to C0,
which consumed a lot more power and has thus a much higher temperature.

> and why does it give me wildly 
> different CPU temps than acpi used to?

It could be that the ACPI thermal zone reports temperature from a
different sensor in the first place. The via-cputemp driver reads a
digital thermal sensor inside the CPU directly. These integrated
digital sensors are very, very quick to react to temperature increases.
So your results aren't surprising me. Maybe the ACPI thermal zone is
backed by a different sensor, either an analog sensor inside the CPU (I
don't know if your CPU still has one), a thermistor under the CPU, or a
thermal sensor anywhere on the board.

If you want to compare the values, you should get readings from the
ACPI thermal zone, either from /sys/class/thermal/thermal_zone*/temp or
by enabling CONFIG_THERMAL_HWMON in your kernel.

> Note:  Here is the raw output of just a single run of sensors:
> -------------------
> # sensors
> via_cputemp-isa-0000
> Adapter: ISA adapter
> Core 0:      +32.0°C
> -------------------
> I'm expecting replies like 'you are suffering from Heisenberg's 
> uncertainty principle'; the act of monitoring your CPU changes the 
> temp.

This is certainly true to some extent.

> Or, 'that's a low power CPU so the moment it's not idle you see 
> the spike and the fact that a sleep 1 ramps the temperature down clearly 
> shows that it's dissipating heat from the heatsink relatively quickly.. 
> so your heatsink probably doesn't have enough mass or there's something 
> wrong with the sensor in your chip'.

I don't see anything actually wrong in the values you reported.

> But almost 10 degrees just for running sensors+grep in a loop?

It's not sensors and grep. If you run anything in a loop, this blocks
the CPU to C0 state, which is the hottest.

> Note:  I also created a script that was just 200 instances of 'sensors | 
> grep Core' and I got the same progression of temperature rise so it's 
> not like the for loop on the `seq 1 200` is contributing to the spike.
> Okay, so assuming that's the temperature profile of my CPU, I decided to 
> run 20 instances of the following script....
> ----------------------
> while [ 1 ]; do echo 1234 > /dev/null ; done &
> ----------------------
> That showed a system load of ~18 and a CPU usage 85%.  After 5 mins, I 
> ran my script and all of the CPU temps returned were at ~57 and they 
> held there.
> So loading the CPU rose the temp by another 15 degC.  Fair enough.
> So then I killed all of the while loops and re-ran my 200 'sensors' 
> runs.  The first temp was 46, the last temp was 53.  Again, sensors is 
> having a massive impact on my CPU... in fact, the 200 runs are reliably 
> causing a 10+ degC spike in the CPU, no matter what the temp.
> That seems a bit much... even for a low power CPU [that starts at 
> 'idle'] and that has airflow going over it that's way over spec and when 
> I only have one sensor module loaded.
> I don't care about the CPU cycles, I'm just wondering if the via-cputemp 
> driver is doing something silly.  Your thoughts?

I think you're looking at the numbers in the wrong way. It's not
sensors or grep or anything causing a 10°C increase in temperature.
It's the CPU being nicely designed with efficient low-power C-states
which make it possible to save 10°C in idle state.

Jean Delvare

More information about the lm-sensors mailing list