Ubuntu 16.04でのクーリングファンの制御方法

この記事のまとめ:
  • Ubuntu 16.04でクーリングファンの回転数の制御を行う方法をまとめてみました。
背景:

Windowsではマザーボードメーカーがクーリングファインの制御用のソフトウェアを用意してくれていて、それを使えば自由に設定を変更できますが、Linux用には用意してくれていないのがほとんどです。そのため、自分で設定するしかなく、今回その設定を行ってみました。

設定の流れ
  1. パッケージインストール
  2. 温度センサーの検出
  3. 温度センサーの確認
  4. ファン制御設定
  5. ファン制御の実行
1. パッケージインストール

lm-sensorsというパッケージを使いますのでまずはこれをインストールします。

$ sudo apt install lm-sensors
2. 温度センサーの検出

センサーモジュールを検出するためにsensors-detectコマンドを実行します。下記が私の環境での実行例で、私の環境ではIntel digital thermal sensor (ドライバー: coretemp)Nuvoton NCT6791D Super IO Sensors (ドライバー: nct6775)というモジュールが見つかったことがわかります(私のPC環境が丸裸ですw)。後者がマザーボードに搭載してあるモジュールのようです。

$ sudo sensors-detect
# sensors-detect revision 6284 (2015-05-31 14:00:33 +0200)
# System: ASUS All Series
# Board: ASUSTeK COMPUTER INC. H87-PLUS
# Kernel: 4.15.0-34-generic x86_64
# Processor: Intel(R) Core(TM) i5-4460 CPU @ 3.20GHz (6/60/3)
 
This program will help you determine which kernel modules you need
to load to use lm_sensors most effectively. It is generally safe
and recommended to accept the default answers to all questions,
unless you know what you're doing.
 
Some south bridges, CPUs or memory controllers contain embedded sensors.
Do you want to scan for them? This is totally safe. (YES/no):
Module cpuid loaded successfully.
Silicon Integrated Systems SIS5595...                       No
VIA VT82C686 Integrated Sensors...                          No
VIA VT8231 Integrated Sensors...                            No
AMD K8 thermal sensors...                                   No
AMD Family 10h thermal sensors...                           No
AMD Family 11h thermal sensors...                           No
AMD Family 12h and 14h thermal sensors...                   No
AMD Family 15h thermal sensors...                           No
AMD Family 16h thermal sensors...                           No
AMD Family 15h power sensors...                             No
AMD Family 16h power sensors...                             No
Intel digital thermal sensor...                             Success!
    (driver `coretemp')
Intel AMB FB-DIMM thermal sensor...                         No
Intel 5500/5520/X58 thermal sensor...                       No
VIA C7 thermal sensor...                                    No
VIA Nano thermal sensor...                                  No
 
Some Super I/O chips contain embedded sensors. We have to write to
standard I/O ports to probe them. This is usually safe.
Do you want to scan for Super I/O sensors? (YES/no):
Probing for Super-I/O at 0x2e/0x2f
Trying family `National Semiconductor/ITE'...               No
Trying family `SMSC'...                                     No
Trying family `VIA/Winbond/Nuvoton/Fintek'...               Yes
Found `Nuvoton NCT6791D Super IO Sensors'                   Success!
    (address 0x290, driver `nct6775')
Probing for Super-I/O at 0x4e/0x4f
Trying family `National Semiconductor/ITE'...               No
Trying family `SMSC'...                                     No
Trying family `VIA/Winbond/Nuvoton/Fintek'...               No
Trying family `ITE'...                                      No
 
Some systems (mainly servers) implement IPMI, a set of common interfaces
through which system health data may be retrieved, amongst other things.
We first try to get the information from SMBIOS. If we don't find it
there, we have to read from arbitrary I/O ports to probe for such
interfaces. This is normally safe. Do you want to scan for IPMI
interfaces? (YES/no):
Probing for `IPMI BMC KCS' at 0xca0...                      No
Probing for `IPMI BMC SMIC' at 0xca8...                     No
 
Some hardware monitoring chips are accessible through the ISA I/O ports.
We have to write to arbitrary I/O ports to probe them. This is usually
safe though. Yes, you do have ISA I/O ports even if you do not have any
ISA slots! Do you want to scan the ISA I/O ports? (yes/NO): yes
Probing for `National Semiconductor LM78' at 0x290...       No
Probing for `National Semiconductor LM79' at 0x290...       No
Probing for `Winbond W83781D' at 0x290...                   No
Probing for `Winbond W83782D' at 0x290...                   No
 
Lastly, we can probe the I2C/SMBus adapters for connected hardware
monitoring devices. This is the most risky part, and while it works
reasonably well on most systems, it has been reported to cause trouble
on some systems.
Do you want to probe the I2C/SMBus adapters now? (YES/no):
Using driver `i2c-i801' for device 0000:00:1f.3: Intel Lynx Point (PCH)
Module i2c-i801 loaded successfully.
 
Next adapter: NVIDIA i2c adapter 1 at 1:00.0 (i2c-0)
Do you want to scan it? (yes/NO/selectively): yes
 
Next adapter: NVIDIA i2c adapter 2 at 1:00.0 (i2c-1)
Do you want to scan it? (yes/NO/selectively): yes
 
Next adapter: NVIDIA i2c adapter 4 at 1:00.0 (i2c-2)
Do you want to scan it? (yes/NO/selectively): yes
 
Next adapter: NVIDIA i2c adapter 6 at 1:00.0 (i2c-3)
Do you want to scan it? (yes/NO/selectively): yes
 
Next adapter: NVIDIA i2c adapter 7 at 1:00.0 (i2c-4)
Do you want to scan it? (yes/NO/selectively): yes
 
Next adapter: NVIDIA i2c adapter 1 at 6:00.0 (i2c-5)
Do you want to scan it? (yes/NO/selectively): yes
 
Next adapter: NVIDIA i2c adapter 2 at 6:00.0 (i2c-6)
Do you want to scan it? (yes/NO/selectively): yes
 
Next adapter: NVIDIA i2c adapter 4 at 6:00.0 (i2c-7)
Do you want to scan it? (yes/NO/selectively): yes
 
Next adapter: NVIDIA i2c adapter 6 at 6:00.0 (i2c-8)
Do you want to scan it? (yes/NO/selectively): yes
 
Next adapter: NVIDIA i2c adapter 7 at 6:00.0 (i2c-9)
Do you want to scan it? (yes/NO/selectively): yes
 
Next adapter: NVIDIA i2c adapter 8 at 6:00.0 (i2c-10)
Do you want to scan it? (yes/NO/selectively): yes
 
Next adapter: SMBus I801 adapter at f000 (i2c-11)
Do you want to scan it? (YES/no/selectively): yes
Client found at address 0x51
Probing for `Analog Devices ADM1033'...                     No
Probing for `Analog Devices ADM1034'...                     No
Probing for `SPD EEPROM'...                                 Yes
    (confidence 8, not a hardware monitoring chip)
Client found at address 0x53
Probing for `Analog Devices ADM1033'...                     No
Probing for `Analog Devices ADM1034'...                     No
Probing for `SPD EEPROM'...                                 Yes
    (confidence 8, not a hardware monitoring chip)
 
 
Now follows a summary of the probes I have just done.
Just press ENTER to continue:
 
Driver `nct6775':
  * ISA bus, address 0x290
    Chip `Nuvoton NCT6791D Super IO Sensors' (confidence: 9)
 
Driver `coretemp':
  * Chip `Intel digital thermal sensor' (confidence: 9)
 
To load everything that is needed, add this to /etc/modules:
#----cut here----
# Chip drivers
coretemp
nct6775
#----cut here----
If you have some drivers built into your kernel, the list above will
contain too many modules. Skip the appropriate ones!
 
Do you want to add these lines automatically to /etc/modules? (yes/NO)yes
Successful!
 
Monitoring programs won't work until the needed modules are
loaded. You may want to run '/etc/init.d/kmod start'
to load them.
 
Unloading i2c-i801... OK
Unloading cpuid... OK

上記コマンドの出力結果として、/etc/modulesに搭載しているモジュールのドライバー情報が追記されます。私の環境ではcoretempnct6775のドライバーが追加されました。

# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
 
# Generated by sensors-detect on Sun Sep 30 01:06:09 2018
# Chip drivers
coretemp
nct6775
3. 温度センサーの確認

センサーから取得できる情報はsensorsコマンドで取得できます。Nuvoton NCT6791D Super IO Sensorsと思われるnct6791-isa-0290と、Intel digital thermal sensorと思われるcoretemp-isa-0000が表示されています。それ以外に2つありますが今回は無視します。なお、各項目についてはマザーボードごとのコンフィグファイルがGithubにありますのでこれを参考にするとわかるかもしれません。

$ sensors
nct6791-isa-0290
Adapter: ISA adapter
Vcore:                  +0.80 V  (min =  +0.00 V, max =  +1.74 V)
in1:                    +1.03 V  (min =  +0.00 V, max =  +0.00 V)  ALARM
AVCC:                   +3.38 V  (min =  +2.98 V, max =  +3.63 V)
+3.3V:                  +3.38 V  (min =  +2.98 V, max =  +3.63 V)
in4:                    +1.00 V  (min =  +0.00 V, max =  +0.00 V)  ALARM
in5:                    +0.16 V  (min =  +0.00 V, max =  +0.00 V)  ALARM
in6:                    +0.79 V  (min =  +0.00 V, max =  +0.00 V)  ALARM
3VSB:                   +3.31 V  (min =  +2.98 V, max =  +3.63 V)
Vbat:                   +3.41 V  (min =  +2.70 V, max =  +3.63 V)
in9:                    +1.01 V  (min =  +0.00 V, max =  +0.00 V)  ALARM
in10:                   +0.16 V  (min =  +0.00 V, max =  +0.00 V)  ALARM
in11:                   +0.14 V  (min =  +0.00 V, max =  +0.00 V)  ALARM
in12:                   +0.14 V  (min =  +0.00 V, max =  +0.00 V)  ALARM
in13:                   +0.14 V  (min =  +0.00 V, max =  +0.00 V)  ALARM
in14:                   +0.14 V  (min =  +0.00 V, max =  +0.00 V)  ALARM
fan1:                     0 RPM  (min =    0 RPM)
fan2:                   413 RPM  (min =    0 RPM)
fan3:                     0 RPM  (min =    0 RPM)
fan4:                     0 RPM  (min =    0 RPM)
fan5:                     0 RPM  (min =    0 RPM)
SYSTIN:                +115.0ーC  (high =  +0.0ーC, hyst =  +0.0ーC)  sensor = ther
CPUTIN:                 +29.0ーC  (high = +80.0ーC, hyst = +75.0ーC)  sensor = ther ← CPU温度
AUXTIN0:                +37.0ーC  (high =  +0.0ーC, hyst =  +0.0ーC)  ALARM  sensor ← MB温度?
AUXTIN1:               +106.0ーC    sensor = thermistor
AUXTIN2:               +106.0ーC    sensor = thermistor
AUXTIN3:               +107.0ーC    sensor = thermistor
PECI Agent 0:           +31.0ーC                         ← 各CPUコアの最大温度
PCH_CHIP_CPU_MAX_TEMP:   +0.0ーC
PCH_CHIP_TEMP:           +0.0ーC
PCH_CPU_TEMP:            +0.0ーC
intrusion0:            ALARM
intrusion1:            ALARM
beep_enable:           disabled
 
acpitz-virtual-0
Adapter: Virtual device
temp1:        +27.8ーC  (crit = +105.0ーC)
temp2:        +29.8ーC  (crit = +105.0ーC)
 
asus-isa-0000
Adapter: ISA adapter
cpu_fan:        0 RPM
 
coretemp-isa-0000
Adapter: ISA adapter
Package id 0:  +31.0ーC  (high = +80.0ーC, crit = +100.0ーC)
Core 0:        +27.0ーC  (high = +80.0ーC, crit = +100.0ーC)
Core 1:        +29.0ーC  (high = +80.0ーC, crit = +100.0ーC)
Core 2:        +26.0ーC  (high = +80.0ーC, crit = +100.0ーC)
Core 3:        +29.0ーC  (high = +80.0ーC, crit = +100.0ーC)
4. ファン制御設定

pwmconfigコマンドを使うことでファン制御用の設定ファイルを作る支援をしてくれます。

一度実行すると長いのでパートごとに分けて説明します。

まずは実行すると、先ほど検出したモジュールとそれのファン制御 (pwm)情報を表示してくれます。私の環境ではhwmon2にpwmが5つあり、ファンが3つ接続されていることがわかります。

$ sudo pwmconfig
# pwmconfig revision 6243 (2014-03-20)
This program will search your sensors for pulse width modulation (pwm)
controls, and test each one to see if it controls a fan on
your motherboard. Note that many motherboards do not have pwm
circuitry installed, even if your sensor chip supports pwm.
 
We will attempt to briefly stop each fan using the pwm controls.
The program will attempt to restore each fan to full speed
after testing. However, it is ** very important ** that you
physically verify that the fans have been to full speed
after the program has completed.
 
Found the following devices:
   hwmon0 is acpitz
   hwmon1 is coretemp
   hwmon2 is nct6791
   hwmon3 is asus
 
Found the following PWM controls:
   hwmon2/pwm1           current value: 255
   hwmon2/pwm2           current value: 255
   hwmon2/pwm3           current value: 255
   hwmon2/pwm4           current value: 255
   hwmon2/pwm5           current value: 255
 
Giving the fans some time to reach full speed...
Found the following fan sensors:
   hwmon2/fan1_input     current speed: 929 RPM
   hwmon2/fan2_input     current speed: 1345 RPM
   hwmon2/fan3_input     current speed: 1221 RPM
   hwmon2/fan4_input     current speed: 0 ... skipping!
   hwmon2/fan5_input     current speed: 0 ... skipping!
   hwmon3/fan1_input     current speed: 0 ... skipping!
 
Warning!!! This program will stop your fans, one at a time,
for approximately 5 seconds each!!!
This may cause your processor temperature to rise!!!
If you do not want to do this hit control-C now!!!
Hit return to continue:

続いて、接続されているファンがどのpwmに制御されていて、制御値とファンの回転数を表示してくれます。私の環境では、fan1はhwmon2/pwm1に、fan2はhwmon2/pwm2に、fan3はhwmon2/pwm3に制御されているということがわかります。

Testing pwm control hwmon2/pwm1 ...
  hwmon2/fan1_input ... speed was 929 now 0
    It appears that fan hwmon2/fan1_input
    is controlled by pwm hwmon2/pwm1
Would you like to generate a detailed correlation (y)?
Note: If you had gnuplot installed, I could generate a graphical plot.
    PWM 255 FAN 926
    PWM 240 FAN 907
    PWM 225 FAN 860
    PWM 210 FAN 809
    PWM 195 FAN 771
    PWM 180 FAN 725
    PWM 165 FAN 686
    PWM 150 FAN 638
    PWM 135 FAN 593
    PWM 120 FAN 538
    PWM 105 FAN 487
    PWM 90 FAN 443
    PWM 75 FAN 367
    PWM 60 FAN 298
    PWM 45 FAN 0
    Fan Stopped at PWM = 45
 
  hwmon2/fan2_input ... speed was 1345 now 1398
    no correlation
  hwmon2/fan3_input ... speed was 1221 now 1211
    no correlation
 
Testing pwm control hwmon2/pwm2 ...
  hwmon2/fan1_input ... speed was 929 now 932
    no correlation
  hwmon2/fan2_input ... speed was 1345 now 403
    It appears that fan hwmon2/fan2_input
    is controlled by pwm hwmon2/pwm2
Would you like to generate a detailed correlation (y)? y
Note: If you had gnuplot installed, I could generate a graphical plot.
    PWM 255 FAN 1341
    PWM 240 FAN 1315
    PWM 225 FAN 1238
    PWM 210 FAN 1180
    PWM 195 FAN 1119
    PWM 180 FAN 1072
    PWM 165 FAN 999
    PWM 150 FAN 903
    PWM 135 FAN 827
    PWM 120 FAN 734
    PWM 105 FAN 646
    PWM 90 FAN 532
    PWM 75 FAN 454
    PWM 60 FAN 412
    PWM 45 FAN 394
    PWM 30 FAN 387
    PWM 28 FAN 387
    PWM 26 FAN 388
    PWM 24 FAN 388
    PWM 22 FAN 388
    PWM 20 FAN 389
    PWM 18 FAN 390
    PWM 16 FAN 390
    PWM 14 FAN 392
    PWM 12 FAN 390
    PWM 10 FAN 389
    PWM 8 FAN 390
    PWM 6 FAN 390
    PWM 4 FAN 391
    PWM 2 FAN 390
    PWM 0 FAN 391
 
  hwmon2/fan3_input ... speed was 1221 now 1215
    no correlation
 
Testing pwm control hwmon2/pwm3 ...
  hwmon2/fan1_input ... speed was 929 now 933
    no correlation
  hwmon2/fan2_input ... speed was 1345 now 1387
    no correlation
  hwmon2/fan3_input ... speed was 1221 now 0
    It appears that fan hwmon2/fan3_input
    is controlled by pwm hwmon2/pwm3
Would you like to generate a detailed correlation (y)? y
Note: If you had gnuplot installed, I could generate a graphical plot.
    PWM 255 FAN 1223
    PWM 240 FAN 1186
    PWM 225 FAN 1134
    PWM 210 FAN 1074
    PWM 195 FAN 1036
    PWM 180 FAN 965
    PWM 165 FAN 915
    PWM 150 FAN 854
    PWM 135 FAN 799
    PWM 120 FAN 720
    PWM 105 FAN 657
    PWM 90 FAN 558
    PWM 75 FAN 484
    PWM 60 FAN 417
    PWM 45 FAN 0
    Fan Stopped at PWM = 45
 
 
Testing pwm control hwmon2/pwm4 ...
  hwmon2/fan1_input ... speed was 929 now 925
    no correlation
  hwmon2/fan2_input ... speed was 1345 now 1369
    no correlation
  hwmon2/fan3_input ... speed was 1221 now 1182
    no correlation
 
No correlations were detected.
There is either no fan connected to the output of hwmon2/pwm4,
or the connected fan has no rpm-signal connected to one of
the tested fan sensors. (Note: not all motherboards have
the pwm outputs connected to the fan connectors,
check out the hardware database on http://www.almico.com/forumindex.php)
 
Did you see/hear a fan stopping during the above test (n)? n
 
Testing pwm control hwmon2/pwm5 ...
  hwmon2/fan1_input ... speed was 929 now 924
    no correlation
  hwmon2/fan2_input ... speed was 1345 now 1330
    no correlation
  hwmon2/fan3_input ... speed was 1221 now 1228
    no correlation
 
No correlations were detected.
There is either no fan connected to the output of hwmon2/pwm5,
or the connected fan has no rpm-signal connected to one of
the tested fan sensors. (Note: not all motherboards have
the pwm outputs connected to the fan connectors,
check out the hardware database on http://www.almico.com/forumindex.php)
 
Did you see/hear a fan stopping during the above test (n)? n
 
Testing is complete.
Please verify that all fans have returned to their normal speed.

最後に、ファンの制御のコンフィグファイルを作成します。下記の実行例では hwmon2/pwm1 (fan1) を40℃未満ではPWM 0(最弱)で動作させ、40℃になるとPWM 100、60℃にはPWM 255 (最強)の強さでファンを制御する設定を作っています。

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)? y
What should be the path to your fancontrol config file (/etc/fancontrol)?
Loading configuration from /etc/fancontrol ...
 
Select fan output to configure, or other action:
1) hwmon2/pwm3         4) Change INTERVAL     7) Show configuration
2) hwmon2/pwm2         5) Just quit
3) hwmon2/pwm1         6) Save and quit
select (1-n): 3
 
Devices:
hwmon0 is acpitz
hwmon1 is coretemp
hwmon2 is nct6791
hwmon3 is asus
 
Current temperature readings are as follows:
hwmon0/temp1_input      27
hwmon0/temp2_input      29
hwmon1/temp1_input      30
hwmon1/temp2_input      28
hwmon1/temp3_input      26
hwmon1/temp4_input      26
hwmon1/temp5_input      27
hwmon2/temp1_input      115 ← SYSIN (sensorsコマンドの表示順)
hwmon2/temp2_input      29  ← CPUIN
hwmon2/temp3_input      37  ← AUXTIN0
hwmon2/temp4_input      106 ← AUXTIN1
hwmon2/temp5_input      106 ← AUXTIN2
hwmon2/temp6_input      108 ← AUXTIN3
hwmon2/temp7_input      30  ← PECI Agent 0
hwmon2/temp8_input      0   ← PCH_CHIP_CPU_MAX_TEMP
hwmon2/temp9_input      0   ← PCH_CHIP_TEMP
 
Select a temperature sensor as source for hwmon2/pwm1:
 1) hwmon0/temp1_input
 2) hwmon0/temp2_input
 3) hwmon1/temp1_input
 4) hwmon1/temp2_input
 5) hwmon1/temp3_input
 6) hwmon1/temp4_input
 7) hwmon1/temp5_input
 8) hwmon2/temp1_input
 9) hwmon2/temp2_input
10) hwmon2/temp3_input
11) hwmon2/temp4_input
12) hwmon2/temp5_input
13) hwmon2/temp6_input
14) hwmon2/temp7_input
15) hwmon2/temp8_input
16) hwmon2/temp9_input
17) None (Do not affect this PWM output)
select (1-n): 14
 
Enter the low temperature (degree C)
below which the fan should spin at minimum speed (20): 40
 
Enter the high temperature (degree C)
over which the fan should spin at maximum speed (60): 60
 
Enter the minimum PWM value (0-255)
at which the fan STOPS spinning (press t to test) (100): 0
 
Enter the minimum PWM value (0-255)
at which the fan STARTS spinning (press t to test) (150): 100
 
Enter the PWM value (0-255) to use when the temperature
is over the high temperature limit (255): 255
 
 
Select fan output to configure, or other action:
1) hwmon2/pwm3         4) Change INTERVAL     7) Show configuration
2) hwmon2/pwm2         5) Just quit
3) hwmon2/pwm1         6) Save and quit
select (1-n): 6
 
Saving configuration to /etc/fancontrol...
Configuration saved
5. ファン制御の実行

下記を実行することで上記の設定ファイルに基づいてファンの制御をしてくれます。

$ sudo /etc/init.d/fancontrol restart

なお、ファン制御を実行中にはpwmconfigコマンドは次のように表示され実行できません。pwmconfigコマンドを再度実行する際は、一度、fancontrolを停止しましょう。

$ sudo pwmconfig
File /var/run/fancontrol.pid exists. This typically means that the
fancontrol deamon is running. You should stop it before running pwmconfig.
If you are certain that fancontrol is not running, then you can delete
/var/run/fancontrol.pid manually.
$ sudo /etc/init.d/fancontrol stop

pwmconfigコマンドで作成したコンフィグファイルは/etc/fancontrolに保存されています。このファイルは直接編集しても問題ないです。なお、私の設定は下記の通りです。

# Configuration file generated by pwmconfig, changes will be lost
INTERVAL=60
DEVPATH=hwmon2=devices/platform/nct6775.656
DEVNAME=hwmon2=nct6791
FCTEMPS=hwmon2/pwm1=hwmon2/temp7_input hwmon2/pwm2=hwmon2/temp3_input hwmon2/pwm3=hwmon2/temp3_input
FCFANS=hwmon2/pwm1=hwmon2/fan1_input hwmon2/pwm2=hwmon2/fan2_input hwmon2/pwm3=hwmon2/fan3_input
MINTEMP=hwmon2/pwm1=40 hwmon2/pwm2=40 hwmon2/pwm3=40
MAXTEMP=hwmon2/pwm1=60 hwmon2/pwm2=60 hwmon2/pwm3=60
MINSTART=hwmon2/pwm1=100 hwmon2/pwm2=100 hwmon2/pwm3=100
MINSTOP=hwmon2/pwm1=0 hwmon2/pwm2=0 hwmon2/pwm3=0
MAXPWM=hwmon2/pwm1=255 hwmon2/pwm2=255 hwmon2/pwm3=255

今回は以上です。 最後まで読んでいただき、ありがとうございます。


コメント

このブログの人気の投稿

LinuxでのnVidia GPUのオーバークロック・電力チューニング方法