View unanswered posts    View active topics

All times are UTC - 6 hours





Post new topic Reply to topic  [ 3 posts ] 
Print view Previous topic   Next topic  
Author Message
Search for:
PostPosted: Sun Feb 21, 2010 5:15 am 
Offline
Joined: Wed Dec 10, 2003 8:31 pm
Posts: 1996
Location: /dev/null
This post is heavily based on this Arch wiki article.

Purpose: Control CPU fan speed based on CPU temps. Why? Lower RPMs = quieter and less power use :p Once configured, your system will use sensors to monitor your CPU temp(s) and CPU fan RPMs will be controlled based on a thermal need, i.e. when the CPU heats up, the fan(s) will throttle up and when the CPU temp decreases, the fan(s) will throttle down. You will have both a more quiet system and a more power efficient system.

Example using fancontrol from my workstation:
Image
Image
Graphs generated by monitorix which is available for LinHES.

:arrow: Note that your motherboard must support PWM or pulse width modulation -- most if not all modern ones do.
:arrow: Also note that you must have the CPU fan you wish to control powered on the motherboard, not on a molex lead from your case. Again, most motherboards have a 3 or 4-pin slot specially for the CPU fan.
:arrow: Some motherboards like DFI, unfortunately will not allow a 3-pin fan to operate using PWM control. Other motherboards like Gigabytes for example do it just fine. Don't worry whether or not your motherboard will do it right now. The script you will run will make this determination for you.

The guide is in two parts (three really):

1) Install and configure sensors
2) Configure fancontrol with pwmconfig
3) Optional - fine tuning pwm and fan RPM

1) Install and configure sensors

:arrow: Note that you may totally skip this section if you already setup sensors and you know that they're working and auto start on boot.

Install the lm_sensors package:
Code:
$ sudo pacman -S lm_sensors


Configure sensors for you machine:
Code:
$ sudo sensors-detect


Answer yes to the questions and allow the script to finish scanning. When it does, You'll be presented with a line like this (again the results shown below are from my system - your results may vary):

Code:
Now follows a summary of the probes I have just done.
Just press ENTER to continue:

Driver `it87' (should be inserted):
  Detects correctly:
  * ISA bus, address 0x290
    Chip `ITE IT8718F Super IO Sensors' (confidence: 9)

Driver `coretemp' (should be inserted):
  Detects correctly:
  * Chip `Intel Core family thermal sensor' (confidence: 9)


What this is telling us is that there are two kernel modules needed for sensors to work: it87 and coretemp. To test them, modprobe them and then run sensors.

Code:
$ sudo modprobe it87
$ sudo modprobe coretemp
$ sensors
coretemp-isa-0000
Adapter: ISA adapter
Core 0:      +37.0°C  (high = +76.0°C, crit = +100.0°C) 

coretemp-isa-0001
Adapter: ISA adapter
Core 1:      +37.0°C  (high = +76.0°C, crit = +100.0°C) 

coretemp-isa-0002
Adapter: ISA adapter
Core 2:      +37.0°C  (high = +76.0°C, crit = +100.0°C) 

coretemp-isa-0003
Adapter: ISA adapter
Core 3:      +38.0°C  (high = +76.0°C, crit = +100.0°C) 

it8718-isa-0290
Adapter: ISA adapter
Vcc:         +1.14 V  (min =  +0.00 V, max =  +4.08 V)   
VTT:         +2.08 V  (min =  +0.00 V, max =  +4.08 V)   
+3.3V:       +3.33 V  (min =  +0.00 V, max =  +4.08 V)   
NB Vcore:    +0.05 V  (min =  +0.00 V, max =  +4.08 V)   
VDRAM:       +2.13 V  (min =  +0.00 V, max =  +4.08 V)   
fan1:        991 RPM  (min =   10 RPM)
temp1:       +39.5°C  (low  = +129.5°C, high = +129.5°C)  sensor = thermistor
temp2:       +33.0°C  (low  = +127.0°C, high = +127.0°C)  sensor = thermal diode


So you can see the results for my workstation. I know that temp1 is the CPU temp and temp2 is the MB temp. Cores 0-3 are the respective temps of each of the CPU's cores. Fan1 is the CPU fan.

:arrow: Note to get the needed kernel modules loaded at a reboot, simply add them to the modules array in /etc/rc.conf (again, this example is from my system so do NOT just copy/paste into your file):

Code:
MODULES=($MOD_BLACKLIST_ acpi_cpufreq !cpufreq_ondemand coretemp it87)


2) Configure fancontrol with pwmconfig to control your fan RPMs

Load the pwmconfig script which will walk you though the process:
Code:
$ sudo pwmconfig


Follow the on screen instructions. It'll figure out which if any fans you have can be controlled and tell you some info about them. Here is the output from my system, your system will very likely differ!

:arrow: Note that when the script generates a detailed correlation, it often goes too fast as it steps down from full speed to 0. There isn't anything wrong with your system, it's just the way the script works. You should probably skip the "generate a detailed correlation" when prompted. I wrote a little script shown in section 3 of this guide that will do the same thing for you with a 10 second delay between steps. It works much better :p

When the script finishes probing all the possible PWM controls (my board had three), it'll ask you to edit the config file now. Do it.

Code:
Testing is complete.
Please verify that all fans have returned to their normal speed.

The fancontrol script can automatically respond to temperature changes
of your system by changing fanspeeds.
Do you want to set up its configuration file now (y)?


:arrow: Note that my system is using hwmon4/device/pwm1 but that doesn't mean that your system will!

Code:
Select fan output to configure, or other action:
1) hwmon4/device/pwm1  3) Just quit         5) Show configuration
2) Change INTERVAL     4) Save and quit


Select #1 which should be the right pwm to your system fan. Now save the file and quit (#4). Let's have a look at the /etc/fancontrol file.

Code:
$ sudo nano /etc/fancontrol
# Configuration file generated by pwmconfig, changes will be lost
INTERVAL=10
DEVPATH=hwmon3=devices/platform/coretemp.3 hwmon4=devices/platform/it87.656
DEVNAME=hwmon3=coretemp hwmon4=it8718
FCTEMPS=hwmon4/device/pwm1=hwmon3/device/temp1_input
FCFANS= hwmon4/device/pwm1=hwmon4/device/fan1_input

MINTEMP=hwmon4/device/pwm1=20
MAXTEMP=hwmon4/device/pwm1=50
MINSTART=hwmon4/device/pwm1=75
MINSTOP=hwmon4/device/pwm1=0


What does it mean?
INTERVAL: time in sec that the daemon will poll cpu temp and adjust fan speed
FCTEMPS: The temperature input device to read for cpu temperature. The above example corresponds to /sys/class/hwmon/hwmon3/device/temp1_input
FCFANS: The current fan speed in RPM, which can be read (like the temperature) in
/sys/class/hwmon/hwmon4/device/fan1_input
MINTEMP: The temperature (°C) at which to SHUT OFF the cpu fan. Efficient CPU's often will not need a fan while idling. Be sure to set this to a temperature that you know is safe. Setting this to 0 is not recommended, use a sane value
MAXTEMP: The temperature (°C) at which to spin the fan at it's MAXIMUM speed. This should be probably be set to perhaps 10 or 20 degrees (°C) below your CPU's critical/shutdown temperature. Setting it closer to MINTEMP will result in higher fan speeds overall.
MINSTOP: The PWM value at which your fan stops spinning. Each fan is a little different. Power tweakers can cat different values (between 0 and 255) to /sys/class/hwmon/hwmon0/device/pwm1 and then watch the cpu fan. When it stops, use this value.
MINSTART: The PWM value at which your fan starts to spin again. This is often a higher value than MINSTOP as more voltage is required to overcome inertia.

You can tweak your settings to match mine or develop your own based on manually setting your pwm (described below). To start fancontrol do:

Code:
$ sudo /etc/rc.d/fancontrol start


If and only if you are happy with the performance, add it to your daemons array in /etc/rc.conf to have it start on system boot.

3) Fine tuning of pwm and fanspeed

I wrote a little bash script to allow you to see how a given PWM correlates to CPU fan RPM. Paste this into an empty file (I called mine fancon.sh)

Code:
#!/bin/bash
clear

#################################################
# change the following lines to match your system
#################################################
pwmcontrol=/sys/class/hwmon/hwmon4/device/pwm1
fanrpmread=/sys/class/hwmon/hwmon4/device/fan1_input

# do not edit below this line
#################################################
log=`pwd`/fandata.log
echo "PWM RPM" > $log

echo "This script will set your PWM to values from full power down to 0 decreasing in"
echo "approx 5 % steps and pausing 10 sec between steps to allow the fan RPM to catch"
echo "up to the new settings.  Data are logged to ${log}"
echo "which can be used to generate a graph or use as-is."

collectdata() {
array=( 255 242 230 217 204 191 178 165 152 139 126 113 100 87 74 48 22 0 )
for item in ${array[*]}
do
echo $item > $pwmcontrol
sleep 10s
rpm=`cat ${fanrpmread}`
echo $item $rpm >> $log
echo "PWM: ${item} RPM: ${rpm}"
done
}

/etc/rc.d/fancontrol stop
echo "1" > ${pwmcontrol}_enable

collectdata

echo "0" > ${pwmcontrol}_enable
/etc/rc.d/fancontrol start


Make it a script:
Code:
$ sudo chmod +x fancon.sh


You need only to change the first two lines to match the ones you found for you system! Once you do that, run the script as root! It's VERY basic as you can see but it will generate PWM/RPM values for your fan both to the screen and to a log file, Use these data to modify your /etc/fancontrol as you see fit.

Example output on my system:
Code:
# ./scripts/fancon

This script will set your PWM to values from full power down to 0 decreasing in
approx 5 % steps and pausing 10 sec between steps to allow the fan RPM to catch
up to the new settings.  Data are logged to /home/mythtv/scripts/fandata.log
which can be used to generate a graph or use as-is.
:: Stopping fancontrol                                                                            [DONE]
PWM: 255 RPM: 1530
PWM: 242 RPM: 1493
PWM: 230 RPM: 1424
PWM: 217 RPM: 1339
PWM: 204 RPM: 1268
PWM: 191 RPM: 1184
PWM: 178 RPM: 1106
PWM: 165 RPM: 1015
PWM: 152 RPM: 934
PWM: 139 RPM: 838
PWM: 126 RPM: 755
PWM: 113 RPM: 650
PWM: 100 RPM: 560
PWM: 87 RPM: 447
PWM: 74 RPM: 348
PWM: 48 RPM: 0
PWM: 22 RPM: 0
PWM: 0 RPM: 0


The script also generates a log file you can import into openoffice or excel and generate a graph if you want.
Image

What's the point? You can find out where MINSTART and MINSTOP are for your specific fan. Also verify that the fan reacts in a linear fashion to the applied wattage (which it should). In my case, the MINSTART is around 75 as you can see and it also gives a nice linear response from about 75 up to 255.

_________________
Retired KM user (R4 - R6.04); friend to LH users.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 28, 2010 5:06 am 
Offline
Joined: Mon Sep 28, 2009 5:42 am
Posts: 50
Thanks for the comprehensive howto.

How did you know that temp1 was related to the CPU? I've always driven my CPU fan off of one of the (abitrarily chosen) core temps. It would seem more sensible to use a temp (like temp1) that was correlated with both cores.

Just one comment: using /etc/rc.d doesn't seem like a very LinHES way to do it ... I was under the impression that the LinHES boot sequence ignored the rc.conf daemons array. Rather than that you can create a /etc/sv/fancontrol directory with a file called run, looking something like this
Code:
#!/bin/sh
exec 2>&1
export TERM=linux
. /etc/rc.conf
. /etc/rc.d/functions
stat_runit "Starting fancontrol"

exec /usr/sbin/fancontrol > /dev/null
then make a link to that directory in /var/service. It should then start automatically, restart automatically on boot and also restart automatically if something goes wrong with the fancontrol process.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 28, 2010 6:33 am 
Offline
Joined: Wed Dec 10, 2003 8:31 pm
Posts: 1996
Location: /dev/null
I usually fire-up linpack or mprime (both of which stress the CPU and raise the temp) and just watch to see how the temps correlate to the coretemps. Using a coretemp is completely fine by the way.

As to your observation about runit, you're right. I just haven't learned how to use runit. BTW, the daemons array is honored on LinHES currently.

_________________
Retired KM user (R4 - R6.04); friend to LH users.


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 


All times are UTC - 6 hours




Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group

Theme Created By ceyhansuyu