eudean Posted January 18, 2019 Share #1 Posted January 18, 2019 (edited) I recently installed Xpenology on a Terramaster F4-220 I picked up during the holiday sales that were going on. I noticed the hard drives were consistently operating at a very high temperature (50+ C while idle) so I decided to investigate how to control the fans. I had read elsewhere there is some BIOS option to drive the fans faster, but lacking the VGA dongle to get into the BIOS I figured I'd investigate how to control them from Linux. So I discovered the hardware contains an IT8772E chip for which Google helpfully brings up this datasheet: https://master-chip.ru/files/e0ec6325-b20e-079c-f0ce-275a3ec60f51/IT8772E-ITE.pdf I noticed that there is already a kernel driver for this chip, but since I only needed very limited capabilities (just the ability to write the fan PWMs) I decided to just write a custom script to do this. I'm sharing it here so others can take advantage of it. I'm guessing it wouldn't be hard to also drive the LEDs to the right colors as well but I haven't spent time on that since I never look at the LEDs anyway. The basic flow of the code is: Initialize the IT8772E chip Write a default PWM value for the fans Read the max hard drive temperature and use a PID loop to calculate a new PWM value to drive the max hard drive temperature to some setpoint After playing with the PID values for a few days I concluded that just using a P value was sufficient to give decent behavior so I just left kp = 1, ki = kd = 0. I just modified the script to make all of these things overridable in case someone wants to play around with it further without having to recompile. With defaults I find it settles to reasonable values in about 30 minutes. By default the script uses a setpoint of 37 C but again this can be overridden. I chose this after looking at various suggestions online, it seems 30-40 C is the safest range to maintain for average temps in terms of drive failure rate, so 37 C should give some buffer in case of sudden spikes in utilization that PID doesn't react to quickly enough. My argument parsing is really simple, you can use ./fancontrol -h to see how to use the script. Here are some sample uses: ./fancontrol (default behavior) ./fancontrol -h (print out usage info) ./fancontrol 1 40 (enable debug logging, setpoint = 40) ./fancontrol 0 37 255 (use the maximum PWM value initially before entering the PID loop) ./fancontrol 0 37 150 10 50 80 0 0 0 0 (use PWM value 150 initially and disable PID by setting all coefficients to 0, this would be like hard-coding the PWM to 150 forever) Anyway, I hope other Terramaster users find this useful. I suspect this will also work on similar Terramaster NASes that use the same chip for fan control but I have only tested on the F4-220 since that's what I own. I've attached the cpp source and a binary built for x86_64 running DSM 6.2 using Synology's build environment (ds.x64-6.2). Some side notes: The synostorage daemon already reads drive temperatures and reports them in /var/run/synostorage/disks/sd[abcd]. I initially used these to drive my code but later realized these values may be updated very infrequently (as in many minutes) so I decided to poll via smartctl. I still rely on the disks listed in /var/run/synostorage to know which drives to query. I don't read the CPU temp (or any other sensors). I think keeping the drives at 40 C or below will likely be a stronger constraint on fan speed than CPU usage, but if you expect heavy CPU usage at times when there isn't heavy storage utilization (unlikely for a NAS) then this may not be what you want. I chose an MIT license for the source I don't really intend to maintain this long term except for myself but if people have suggestions let me know and I can try to tackle them. You can run this at boot time using "Task Scheduler" fancontrol fancontrol.cpp Edited January 18, 2019 by eudean 2 Quote Link to comment Share on other sites More sharing options...
manicdefender Posted February 11, 2019 Share #2 Posted February 11, 2019 Thanks for this eudean. About to load Xpenology on my F2-420 so will try this out Quote Link to comment Share on other sites More sharing options...
kgp721 Posted February 12, 2019 Share #3 Posted February 12, 2019 HI I have an F2-420 on DS918+ 6.2.1-23824U4 and would like to try this I have searched and read a bit about custom scripts, but if you can help me understand how I would go about executing this Thanks in advance KP Quote Link to comment Share on other sites More sharing options...
eudean Posted February 12, 2019 Author Share #4 Posted February 12, 2019 (edited) 13 hours ago, kgp721 said: I have searched and read a bit about custom scripts, but if you can help me understand how I would go about executing this So when developing I logged in via ssh to run the script from a shell. But for general usage you should use "Task Scheduler" (in the Control Panel) to create a task that runs at boot up that just executes the script. See https://www.synology.com/en-us/knowledgebase/DSM/help/DSM/AdminCenter/system_taskscheduler for details. Then just reboot your NAS. The fans will take some time to stabilize so after you boot it, wait an hour or two, then check the hard drive temperatures in Storage Manager and they should be pretty close to 37 C (unless you're room is super hot or cold, in which case it may take longer). Then check on it periodically and it should be very close to 37 C just to make sure it's working fine. Unfortunately I don't see a way for DSM to send a notification if the temperature goes outside of a certain range (only it if goes above the hard drive operating temperature, which is kind of late to send a notification). Maybe someday I'll add something to the script for that. Edited February 12, 2019 by eudean Quote Link to comment Share on other sites More sharing options...
richv31 Posted March 3, 2019 Share #5 Posted March 3, 2019 (edited) HI - Thanks for developing this. I just tried it out on my f4-220 running the 1.04b (ds918) bootloader. fancontrol -h works, but anything else gives me "segmentation fault" - any clues? Running as admin from a putty ssh session. Thx Edited March 3, 2019 by richv31 Quote Link to comment Share on other sites More sharing options...
eudean Posted March 3, 2019 Author Share #6 Posted March 3, 2019 Try using sudo (i.e., sudo ./fancontrol). If you aren't root iopl will probably fail and you'll be writing to invalid memory very quickly (I don't have a lot of error checking for these kinds of things). Quote Link to comment Share on other sites More sharing options...
richv31 Posted March 3, 2019 Share #7 Posted March 3, 2019 thanks, that fixed it! Quote Link to comment Share on other sites More sharing options...
DONIII Posted June 2, 2019 Share #8 Posted June 2, 2019 (edited) Thanks alot for sharing this! I just signed up for this. I'm not actually using Xpenology but rather Openmediavault and the fans seem to kick in to 100% and then ramp down. Your code helped me figure out how to manage the fans. For reference to anyone stumbling on this thread and wants to port it to OMV: 1. You need to change where the drives are detected since it's different from DSM. For me it was located in /run/disks EDIT: These did not exist by default. I've created this directory and just created empty files inside (as root): mkdir /run/disks cd /run/disks touch sda sdb sdc This far from perfect and if you're a Linux wizard you probably can do something better with regex, e.g. /dev/sd*[a-z] 2. Replace the directory in line 51 (fancontrol.cpp) with the directory containing your drives. For me that was: const static char * synostoragedir = "/run/disks"; 3. Compile fancontrol.cpp and run with sudo. Tip: You can use a docker gcc image to avoid installing dependencies on OMV/Debian/Ubuntu Pull the image: docker pull gcc Compile fancontrol.cpp (you must be in the same directory) docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp gcc gcc -o fancontrol fancontrol.cpp Make sure run with fancontrol with sudo. Edited June 2, 2019 by DONIII 1 Quote Link to comment Share on other sites More sharing options...
Regi1442 Posted August 17, 2019 Share #9 Posted August 17, 2019 (edited) I am trying that on f2-220 DS3615xs compiled the fancontrol (sudo)running it with any argument gives me Segmentation fault Edited August 17, 2019 by Regi1442 Quote Link to comment Share on other sites More sharing options...
SNN72 Posted August 18, 2019 Share #10 Posted August 18, 2019 (edited) HEY I AM LOOKING FOR THIS FOR A SIMILAR REASON LMSENSOR SAYS: sensors | grep fan fan1: 0 RPM (min = 41 RPM) ALARM fan2: 0 RPM (min = 18 RPM) ALARM fan3: 241 RPM (min = 28 RPM) ALARM I THINK MY BOARD IS STILL GOOD MY FANS ARE JUST SHOT. I AM POSTING HERE AS newest member BUT MY ID ON OMV ID IS seth.nordmeyer PLZ PM ME THERE SORRY ABOUT CAPS I AM BLIND ANY IDEA WHERE TO GET FANS? PEACE, SNN Edited August 18, 2019 by SNN72 Quote Link to comment Share on other sites More sharing options...
tdse13 Posted August 31, 2019 Share #11 Posted August 31, 2019 Could somebody please explain how to implement / use this script in DSM. Thank you. Quote Link to comment Share on other sites More sharing options...
TylerGo Posted September 10, 2019 Share #12 Posted September 10, 2019 I am completely new to this and have done my best to ask others for help before posting here. How/where do we upload this script so that we can run it as a scheduled task? Quote Link to comment Share on other sites More sharing options...
eudean Posted September 10, 2019 Author Share #13 Posted September 10, 2019 3 hours ago, TylerGo said: I am completely new to this and have done my best to ask others for help before posting here. How/where do we upload this script so that we can run it as a scheduled task? You can put it anywhere Task Scheduler can read from, which includes in the DSM filesystem or in your NAS storage. You just need to pass the full path to the script in the "User-defined script", e.g., in mine I put /usr/local/bin/fancontrol Quote Link to comment Share on other sites More sharing options...
Regi1442 Posted September 18, 2019 Share #14 Posted September 18, 2019 On 8/17/2019 at 9:15 PM, Regi1442 said: I am trying that on f2-220 DS3615xs compiled the fancontrol (sudo)running it with any argument gives me Segmentation fault works after installing lm-sensors 😳 Quote Link to comment Share on other sites More sharing options...
brandonjkessler Posted July 8, 2020 Share #15 Posted July 8, 2020 On 6/2/2019 at 8:01 AM, DONIII said: Thanks alot for sharing this! I just signed up for this. I'm not actually using Xpenology but rather Openmediavault and the fans seem to kick in to 100% and then ramp down. Your code helped me figure out how to manage the fans. For reference to anyone stumbling on this thread and wants to port it to OMV: 1. You need to change where the drives are detected since it's different from DSM. For me it was located in /run/disks EDIT: These did not exist by default. I've created this directory and just created empty files inside (as root): mkdir /run/disks cd /run/disks touch sda sdb sdc This far from perfect and if you're a Linux wizard you probably can do something better with regex, e.g. /dev/sd*[a-z] 2. Replace the directory in line 51 (fancontrol.cpp) with the directory containing your drives. For me that was: const static char * synostoragedir = "/run/disks"; 3. Compile fancontrol.cpp and run with sudo. Tip: You can use a docker gcc image to avoid installing dependencies on OMV/Debian/Ubuntu Pull the image: docker pull gcc Compile fancontrol.cpp (you must be in the same directory) docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp gcc gcc -o fancontrol fancontrol.cpp Make sure run with fancontrol with sudo. This helped me out tremendously. I'm running this on OMV 5 and it works flawlessly. The only issue I had is that I didn't pay attention to where the /run/disks was supposed to be created at. It's /var/run/disks, and then you create each file with that name. Quote Link to comment Share on other sites More sharing options...
MrBerni Posted November 15, 2020 Share #16 Posted November 15, 2020 Hi there, just trying to control my fan on the "new" TerraMaster F2-221 (different IO-Chip). Here we use the IT8613E and fancontrol does not work. Looking at the source it seems the sanity check blocking me, but there may be other differences in the memory ranges need to be addressed... Code for the IT87-Kernel-Module is here: https://github.com/hannesha/it87 Any chance to get this nice app re-compiled for the F2-221 with IT8613E? Regards Quote Link to comment Share on other sites More sharing options...
eudean Posted November 16, 2020 Author Share #17 Posted November 16, 2020 I can offer to re-compile with the sanity check removed. Whether the rest of the logic will work with the IT8613E I can't say, though. I'll have to figure out how to set up the appropriate development environment again, but please check back later this week and I will post a new binary for you. Quote Link to comment Share on other sites More sharing options...
MrBerni Posted November 16, 2020 Share #18 Posted November 16, 2020 34 minutes ago, eudean said: I can offer to re-compile with the sanity check removed. Whether the rest of the logic will work with the IT8613E I can't say, though. I'll have to figure out how to set up the appropriate development environment again, but please check back later this week and I will post a new binary for you. Great, I will give it a try then and report back. Regards Quote Link to comment Share on other sites More sharing options...
eudean Posted November 16, 2020 Author Share #19 Posted November 16, 2020 Please see attached binary with the sanity check removed. fancontrol Quote Link to comment Share on other sites More sharing options...
MrBerni Posted November 17, 2020 Share #20 Posted November 17, 2020 Great, will give this a try later and report back. Thx! Quote Link to comment Share on other sites More sharing options...
Misty Posted December 11, 2020 Share #21 Posted December 11, 2020 I've adapted the code to integrate into Synology's own fan controlling system. You can find my code here : https://github.com/NyaMisty/scemd_fanspeed_hook Quote Link to comment Share on other sites More sharing options...
MrBerni Posted December 15, 2020 Share #22 Posted December 15, 2020 On 12/11/2020 at 2:12 AM, Misty said: I've adapted the code to integrate into Synology's own fan controlling system. You can find my code here : https://github.com/NyaMisty/scemd_fanspeed_hook Very nice idea. But will it work with an IT8613E? And how/where to compile? Regards Quote Link to comment Share on other sites More sharing options...
T-REX-XP Posted December 16, 2020 Share #23 Posted December 16, 2020 (edited) On 12/11/2020 at 3:12 AM, Misty said: I've adapted the code to integrate into Synology's own fan controlling system. You can find my code here : https://github.com/NyaMisty/scemd_fanspeed_hook Nice. Can we adapting your code for supporting nuvoton NCT6791D??? https://github.com/T-REX-XP/nct6775 . thanks Edited December 16, 2020 by T-REX-XP Quote Link to comment Share on other sites More sharing options...
fantomel Posted January 10, 2021 Share #24 Posted January 10, 2021 Would be very nice to have support also for our F2-221 with IT8613E . I just took a brand new one and i am willing to help to it's development. Quote Link to comment Share on other sites More sharing options...
Misty Posted January 26, 2021 Share #25 Posted January 26, 2021 On 12/17/2020 at 3:13 AM, T-REX-XP said: Nice. Can we adapting your code for supporting nuvoton NCT6791D??? https://github.com/T-REX-XP/nct6775 . thanks On 1/10/2021 at 11:01 PM, fantomel said: Would be very nice to have support also for our F2-221 with IT8613E . I just took a brand new one and i am willing to help to it's development. Oh sorry for the late reply. I'm very happy to see more support. As I use the code from credits, the license are inherited from theirs (which should be MIT) Because the code is soooo simple, I think you can fork the repo, add the chip-related code. Then I can simply put your repo's link in my repo, and people with different chip can then find the corresponding repo. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.