免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1493 | 回复: 0
打印 上一主题 下一主题

lm_sensors 安装 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-09-11 10:05 |只看该作者 |倒序浏览
How to Install and Use lm_sensors
Overview
This article describes why you might want to add sensor data to
your appliance, and how to install and use lm_sensors.

Introduction to LM Sensors
Most newer motherboards and disk drives have on-board sensors to
measure system voltages, temperatures, and fan speeds. The first
common part used to make these measurements was the Nation
Semiconductor LM74, hence the "lm" in the name.  Why bother with
sensors? Because you will be able to catch a computer failure
before it occurs. Many computer components slip out of tolerance
before failure. This is especially true of moving components. For
example, the CPU fan is usually the critical component most likely
to fail. The lubrication in the bearings drys out and the increased
friction in the fan causes it to heat up and to eventually fail. The
failure is easy to predict since the fan speed will drop off as the
bearing friction goes up.
You get a failure warning when the fan speed drops by
more than 10 percent. While this example focuses on fan speed, the
other sensors can be used to predict other types of failures. Out of
tolerance voltages may predict a power supply failure or a cooling
problem in the power supply. A high case temperature may indicate
dirty or blocked air filters.
There are a few requirements for using sensors. First, you need to
care. After all, you don't want to spend the cost and effort of
including sensors if the cost of system failure is low. For example,
a consumer set-top box is expected to only last a couple of years
and consumers are relatively unbothered by appliance failures.
A second, more critical, requirement is that the information be
"actionable". That is, if you can predict a system failure, there
needs to be a way for someone to prevent it and there needs to be
a reliable way to tell someone of the impending failure. This where
logs and alarms enter the picture. If your system does not include
logs and alarms, you probably don't need to support sensors.

Installing LM Sensors
Sensors are really just devices so an "installation" should leave
us with the proper device drivers loaded. The next two sections show
how to identify and install the proper device drivers for your
motherboard.
Installation Requirements
Make sure your motherboard has sensors. You can usually determine
this from one of the BIOS menus at system power-on. The motherboard
manual should also tell you if sensors are on the board or not.
If you use one of the standard Linux distributions, be sure to have
your installation disks handy. You can also get the packages you'll
need with app-get or from www.rpmfind.org.  Two packages are required,
liblm_sensors, and lm_sensors itself, and you will need to be root
to install lm_sensors.  The sensor detection process tries to install
several modules, so you will need to have modules enabled on your
system.
Installation Procedure
We need to determine the types of sensors used on our motherboard
and the program to do that is sensors-detect from the lm_sensors
package. We install liblm_sensors first.
The lm_sensors library installs only a single file and a symbolic
link to that file.
# rpm -qlp liblm_sensors3-2.9.1-4mdk.i586.rpm
/usr/lib64/libsensors.so.3
/usr/lib64/libsensors.so.3.0.8
# rpm -i liblm_sensors-2.9.1-4mdk.i586.rpm
The lm_sensors package nominally requires the "Round Robin Database".
In fact, it does not, and it's unfortunate that the maintainer of
lm_sensors lists it as a requirement. Install lm_sensors with --nodeps
to keep it from complaining about the lack of the rrd package.
# rpm -i --nodeps lm_sensors-2.9.1-4mdk.i586.rpm
With lm_sensors installed, you can run sensors-detect to locate and
identify the sensors on your system. The sensors-detect program asks
lots of questions about what it should probe for. Take the default
answers the first time you try the sensor detection. We show below
just the start of the sensors-detect run.
# sensors-detect
This program will help you to determine which I2C/SMBus modules you
need to load to use lm_sensors most effectively. If you are installing
from a tarball or have a custom kernel, you may need to do a `make
install', issue a `depmod -a' and made sure that `/etc/conf.modules'
(or `/etc/modules.conf') contains the appropriate module path before
you can use sensors-detect.
If you are using a standard distribution, you almost certainly do not
need to "make install" in order to use sensors-detect. Sensors-detect
will try to detect what is on your system and which modules to load.
If all goes well, sensors-detect will output a list of which modules
you need to load. For example, on my system the final output was:
To make the sensors modules behave correctly, add these lines to
either /etc/modules.conf or /etc/conf.modules:
#----cut here----
# I2C module options
alias char-major-89 i2c-dev
#----cut here----
To load everything that is needed, add this to some /etc/rc* file:
#----cut here----
# I2C adapter drivers
modprobe i2c-viapro
modprobe i2c-isa
# I2C chip drivers
modprobe w83781d
# sleep 2 # optional
/usr/local/bin/sensors -s # recommended
#----cut here----
If sensors-detect does not find any sensors, you may need to run it
again answering the questions in such a way as to ask it to do more
extensive probing. Since some of the extensive probes can interfere
with some VGA hardware, you should run extensive probes from a system
console and not from X-Windows.
If you have a very recent motherboard, your distribution's kernel
might not have the drivers for the sensors on your motherboard. It
is a lot of work, but you can get around this by downloading and
building the latest kernel and lm_sensors. A web search on the make
and model of your motherboard and lm_sensors may give you a clue how
others have solved the same problem.

Using Sensors
After running sensors-detect, do a modprobe on each of the modules
it recommends.
#modprobe i2c-viapro
#modprobe i2c-isa
#modprobe w83627hf
Getting Sensor Data
With the modules successfully installed, you can finally see the
values of your motherboard's sensors with the sensors command.
# sensors
w83697hf-isa-0290
Adapter: ISA adapter
VCore:     +1.50 V  (min =  +0.59 V, max =  +0.06 V)
+3.3V:     +3.25 V  (min =  +0.56 V, max =  +2.05 V)
+5V:       +4.95 V  (min =  +0.91 V, max =  +0.05 V)
+12V:     +11.86 V  (min =  +1.46 V, max =  +0.06 V)
-12V:     -11.70 V  (min = -14.58 V, max =  -7.01 V)
-5V:       -5.20 V  (min =  -2.49 V, max =  -6.50 V)
V5SB:      +5.46 V  (min =  +0.00 V, max =  +0.86 V)
VBat:      +3.55 V  (min =  +0.26 V, max =  +1.09 V)
fan1:      3850 RPM  (min = 112500 RPM, div = 2)
fan2:      0 RPM  (min = 3461 RPM, div = 2)
temp1:     +33°C  (high =   +32°C, hyst =    +8°C)   sensor = thermistor
temp2:     +48.0°C  (high =   +80°C, hyst =   +75°C)   sensor = diode
alarms:
beep_enable:
          Sound alarm disabled
The sensors command is fine if a user wants to see the data, but
a more convenient way for programs and scripts to get the data is
from the /proc filesystem. Depending on the version of your kernel,
the sensor data will appear in either /proc/sys/dev/sensors/xxxx,
where xxxx a string based on the type and location of the sensors
detected, or in a similar location in /sys/devices/platform/i2c-2/.
On my system the sensor data is in /sys/devices/platform/i2c-2/2-0290.
A listing the contents of the directory show a file for each of the
sensors on the system.
# ls /sys/devices/platform/i2c-2/2-0290
alarms       fan2_min   in4_input  in7_max      temp1_max
beep_enable  in0_input  in4_max    in7_min      temp1_max_hyst
beep_mask    in0_max    in4_min    in8_input    temp1_type
bus@         in0_min    in5_input  in8_max      temp2_input
driver@      in2_input  in5_max    in8_min      temp2_max
fan1_div     in2_max    in5_min    name         temp2_max_hyst
fan1_input   in2_min    in6_input  power/       temp2_type
fan1_min     in3_input  in6_max    pwm1
fan2_div     in3_max    in6_min    pwm2
fan2_input   in3_min    in7_input  temp1_input
You can just cat the file corresponding to the sensor that you want
to read.
# cat /sys/devices/platform/i2c-2/2-0290/temp1_input
33000
There are two warning to heed if you use /sys or /proc to read the
sensor values. The first is that the values in the files may need to
be calibrated. On my system, temp1, the CPU temperature, clearly does
not read the real value.  Be sure to calibrate your reading against
the values that you see in the BIOS screen with sensor data.
The other problem is that taking a reading can sometimes take a long
time. The chip that does the actual measurement sometime needs
hundreds of milliseconds to take a reading. Do not use blocking IO
if your program needs to respond to other, faster events.

Undoing the Installation
Once you've run sensors-detect and found which modules to load, you
can remove the lm_sensors packages if you wish, You'll lose the
sensors program but if you're working on an appliance you don't
really need it.
# rpm -e lm_sensors-2.9.1-4mdk
# rpm -e liblm_sensors3-2.9.1-4mdk
We usually remove the sensors packages from the shipping appliances
as a way to save flash disk space.  We also use the "tbl2file"
utility to map the sensors values in /sys into values that we can
read as a DB table.  Treating the sensor data as values in a DB
makes some aspects of user interface design much simpler.
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/68769/showart_1183606.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP