Jun 9, 2012

An enhanced version of Simple MacBook Pro Fan Daemon for Linux

MacBook Pro Ubuntu Header

I wanted to refresh my C knowledge. At the same time, I was complaining about how much macfanctld aggressively turns the fans of my Macbook Pro under Ubuntu 12.04. Sometimes I am afraid it is going to lift-off.

I took the occasion to give a small contribution to a small opensource project, written in C.
Allan McRae’s mbpfan uses a very interesting approach to control the fans, based on the reported temperature. Read his post for more details.

Unfortunately, his program is highly tied to his machine (a Macbook Pro 5,5 13″ with a Core i7). There are many issues when creating a fan daemon for Linux and Apple computers:

  • The location of the sensors is different for different Macbook/Macbook Pro models
    • On Allan’s machine, they are located at /sys/devices/platform/coretemp.0/temp{2,3}_input
    • On my Macbook Pro 6,2 15″, they are located at /sys/devices/platform/coretemp.0/temp{2,4}_input
  • The new Linux Kernel v3.x changed the location of the temperature sensors.
  • mbpfan assumes two processors and a single fan (not true for all MacBook Pros, as Allan wrote). My machine has got two CPU related sensors and two fans.
  • On recent Linux kernels (probably only the v3.x series), a manual control of the fan must be taken.

I wanted to overcome these issues. Rvega’s Fan-Control-Daemon is an enhanced version of mbpfan. I did not have time to see which were the enhancements. Rvega is welcomed to comment here to fill this lack. I forked his project and began to look at these issues.

The approach that my version of Fan-Control-Daemon uses is different.
First, the program tries to look at the available sensors located in /sys/devices/platform/coretemp.0/. Then, it looks for the available fans in /sys/devices/platform/applesmc.768/. The program associates each fan to the sensors. After this, it takes manual control of the fans. From this point the program has the same behavior (and code) of mbpfan, because I like it. I changed the polling frequency to 5 seconds because I find it more suitable for my needs.

I tested Fan-Control-Daemon on my Macbook Pro 6,2 15″ with a Core i7. I would like to see it tested on every other possible model, as well. It should work on any GNU/Linux distribution out there, but it was tested with a 3.2.x kernel.

You can clone/download Fan-Control-Daemon/mbpfan on GitHub: https://github.com/dgraziotin/Fan-Control-Daemon.
You can download “stable” releases as gzipped tars on the Tag page: https://github.com/dgraziotin/Fan-Control-Daemon/tags
You can report issues either as comments here or on the issue tracker.

I am not responsible for any burned Macbook out there.

I would like to warn you that this project was implemented as a C refresh. Memory leaks could be everywhere, as well as bugs.
This program is certainly not more evolved than macfanctld, because it only looks for CPU-related sensors.
Nevertheless, I am using it everyday and I find its fan control algorithm more quiet but still powerful.

I will probably update it. What is going to be next is:

  • Check for root permissions
  • Check for the required modules applesmc and coretemp
  • Implement debugging messages as an option
  • Create an init.d file for loading it at boot time
  • Implement the make install command
  • Create an Ubuntu deb

At this moment, I did not package the program for any distribution. You have to manually compile it and manually run it. Check the README.md file for more information.

I kept Allan’s PKGBUILD and mbpfan.rc files, but I did not modify them.
Somebody using Archlinux should check if they still work fine.

I hope that someone else finds this program useful.

written by dgraziotin

Dr. Daniel Graziotin received his PhD in computer science, software engineering at the Free University of Bozen-Bolzano, Italy. His research interests include human aspects in empirical software engineering with psychological measurements, Web engineering, and open science. He researches, publishes, and reviews for venues in software engineering, human-computer interaction, and psychology. Daniel is the founder of the psychoempirical software engineering discipline and guidelines. He is associate editor at the Journal of Open Research Software, academic editor at the Research Ideas and Outcomes (RIO) journal, and academic editor at the Open Communications in Computer Science journal. He is the local coordinator of the Italian Open science local group for the Open Knowledge Foundation. He is a member of ACM, SIGSOFT, and IEEE.

  • alexandros Jul 27, 2013 Reply

    I’ve followed the instruction on your github and as soon as I compiled and run your program my laptop fans reduced their speed a lot, but when I restarted it they started working hard again. I’ve done the run on boot thing and there’s a mbpfan.conf in /etc/init/ but it doesn’t seem to work…
    Can you help me out? I’m on a MacBook 5,2 with dual boot with Ubuntu 12.04.

    • dgraziotin Jul 30, 2013 Reply

      Hi. Can you confirm that mbpfan is running after you start the machine?

      would do the trick.

  • Jancis Dec 28, 2013 Reply

    using on mbp 6.2 i5, it’s pefect and quiet. thanks!

  • Julius Aug 14, 2014 Reply

    Been using Fan-Control-Daemon on MBA 2,1 for a few months. It works quite well! It used to be rather loud and warm but now it’s quiet most of the time and keeps within safe limits. If I set the cpufreq governor to “conservative” it keeps about as warm as is it does on Mac OS X, even cooler.
    Thank you! 🙂

    • dgraziotin Aug 17, 2014 Reply

      I am glad it works well for you!

Leave a comment