Table of Contents

Thinkpad fan control

My Thinkpad T400s kept shutting down when it was busy doing CPU intensive work. It turns out that the fan did not speed up to a high enough level to cool down the CPU, and I'd find messages in /var/log/messages stating that the CPU was dangerously hot.

Load the thinkpad_acpi module with manual fan control enabled

The first thing I did was to make it possible to manually control the fan speed. In order for this to work, the thinkpadacpi kernel module needs to be loaded with a specific parameter. This can be done manually by unloading the module and then loading it with that parameter. Even better, make this happen automatically by adding the file /etc/modprobe.d/thinkfanacpi.conf like this

# When loading the thinkpad_acpi module, allow controlling the fan
# from "the outside"
# echo "level full-speed" > /proc/acpi/ibm/fan
options thinkpad_acpi fan_control=1

After this, simply try `modprobe -r thinkpadacpi && modprobe thinkpadacpi`

Manually control the fan

Once this is done, you can use the file /proc/acpi/ibm/fan as a text file, eg by doing (as root)

echo "level full-speed" > /proc/acpi/ibm/fan

And listen as the fan speeds up to maximum speed

Build the thinkfan program

Go to http://thinkfan.sourceforge.net/ and download a tarball. Go into the directory and run make, and you should have an executable named thinkfan. Copy this file into usr/sbin (ie `/usr/sbin/thinkfan`).

Now you will need to add a config file for thinkfan. My TP has an SSD, so I'm not really worried about the warnings thinkfan emits when running with this config file. The default location for the thinkfan config file is /etc/thinkfan.conf, and mine looks like this

(0,	0,	55)
(1,	48,	60)
(2,	50,	61)
(3,	52,	63)
(4,	56,	65)
(5,	59,	66)
(7,	63,	78)
(127,	75,	32767)

This file lists three columns:

  • the fan level to be used
  • the temperature at which to spin the fan down to the previous level
  • the temperature at which to step up to the next level

So once the temperature reaches 78 degrees, my fan will be turned to level 127. This level (127) is equivalent to the full-speed setting, and spins my fan to max speed which prevents my computer from burning. Note: thinkfan doesn't seem to ship with this in any default settings, but it makes the entire difference for me.

Once this is done, try running thinkfan as root:

sudo /usr/sbin/thinkfan  -n

This will start thinkfan in the foreground and emit messages to standard out. Try running some CPU intensive tasks and watch as thinkfan speeds your fan up and down afterwards.

Run thinkfan at boot

Now that you've verified that this works, it's time to make this happen when you start your computer.

My computer uses systemd for system services, so I created a file `/usr/lib/systemd/system/thinkfan.service` which looks like this:

[Unit]
Description=simple and lightweight fan control program

[Service]
ExecStart=/usr/sbin/thinkfan -q -n

[Install]
WantedBy=multi-user.target

Note: Systemd can run daemons "in the foreground", you don't need to daemonize them yourself. Because of this, I run it with the `-n` setting, which keeps it in the foreground. Furthermore, I add the `-q` parameter, which makes it a little less noisy (messages turn up in `/var/log/messages` on my computer.

After adding this file, enable and start the service:

sudo systemctl enable thinkfan.service
sudo systemctl start thinkfan.service

That's it, you're done.

If you're on a distro which does not use systemd

If you're running some ancient Linux distro which uses /etc/init.d for system daemons, you'll have to write a program that handles the {start,stop} commands, add this to /etc/init.d and do the symlink thing to enable it (`chkconfig` or `update-rc.d`). Good luck with that.

If you're running a current version of Ubuntu, you're a bit better off, since Ubuntu uses Upstart. Upstart, like systemd, saves you the {start,stop} dance, and lets you run processes in the foreground.

Adding this file as `/etc/init/thinkfan.conf` should work (although I haven't tried it myself).

exec /usr/sbin/thinkfan -q -n

respawn

start on runlevel [3]

After saving this file, enter `sudo initctl status thinkfan` to verify that the service is recognized. Once you've done so, enter `sudo initctl start thinkfan` and check the status again. To double-check that it's working, do a search in running processes to verify that the process is running.

And to show you what a nice guy I am

I've created a RPM SPEC file which I used to build and install thinkfan for my computer. It assumes you have a working RPM build environment and download the source tarball for thinkfan 0.8.0 inside $RPM_HOME/SOURCES and this file inside =$RPMHOME/SPECS). Once you have those two files (no need to extract or patch anything), enter rpmbuild -ba =$RPM_HOME/SPECS/thinkfan.spec and find an RPM inside $RPM_HOME/RPMS/x86_64 (change the BuildArch tag to match your architecture, if necessary). Install it with yum localinstall $RPM_HOME/RPMS/x86_64/thinkfan-0.8.0-2.fc17.x86_64.rpm and you should be all set.

Summary:
Name:
Version:
Release: 1
License:
Group:
URL:
Source0: %{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root

%description

%prep
%setup -q

%build

%install
rm -rf $RPM_BUILD_ROOT

%clean
rm -rf $RPM_BUILD_ROOT


%files
%defattr(-,root,root,-)
%doc


%changelog
* Wed Dec 16 2015 Marius Mårnes Mathiesen <marius@gitorious.com> - 
- Initial build.

Name: thinkfan
Version: 0.8.0
Release: 2%{?dist}

Group: Development/Tools
Summary: Control your fan
License: GPLv3

Source0: thinkfan-0.8.0.tar.gz
URL: http://thinkfan.sourceforge.net

BuildArch: x86_64


%description
Control your thinkpad fan

%prep
%setup

%build
make %{_smp_mflags}

%install
pwd
ls
mkdir -p %{buildroot}/usr/sbin
cp thinkfan %{buildroot}/usr/sbin/

mkdir -p %{buildroot}/etc

echo "
# Sample thinkfan configuration file
(0, 0,  55)
(1, 48, 60)
(2, 50, 61)
(3, 52, 63)
(4, 56, 65)
(5, 59, 66)
(7, 63, 78)
(127, 75, 32767)" > %{buildroot}/etc/thinkfan.conf

mkdir -p %{buildroot}/etc/modprobe.d
echo '
# When loading the thinkpad_acpi module, allow controlling the fan
# from "the outside"
# echo "level full-speed" > /proc/acpi/ibm/fan
options thinkpad_acpi fan_control=1
' > %{buildroot}/etc/modprobe.d/thinkpad_acpi.conf

mkdir -p %{buildroot}/usr/lib/systemd/system/

echo "
[Unit]
Description=simple and lightweight fan control program

[Service]
ExecStart=/usr/sbin/thinkfan -q -n

[Install]
WantedBy=multi-user.target
" > %{buildroot}/usr/lib/systemd/system/thinkfan.service

%check

%clean
rm -fr %{buildroot}

%post
modprobe -r thinkpad_acpi
modprobe thinkpad_acpi
systemctl enable thinkfan.service
systemctl start thinkfan.service

%files
%defattr(0644,root,root,0755)
%attr(0711, root, root) /usr/sbin/thinkfan

%config(noreplace) /etc/thinkfan.conf
%config(noreplace) /etc/modprobe.d/thinkpad_acpi.conf
/usr/lib/systemd/system/thinkfan.service