修改 panic.c 和 hdaps.c
现在已经准备好开始一些可快速完成的内核配置。确保位于 ~/rpmbuild/BUILD/kernel-2.6.15/linux-2.6.15.i686 目录。一定要先包含 hdaps 模块作为内核的内置组件,从而准备好在计算机的运行模式中提供对各处的震动检查。
使用 make menuconfig 命令并选择 Device Drivers > Hardware Monitoring Support。键入 Y 以包含 Hardware Monitoring Support 模块,因为 HDAPS 模块依赖于此模块。滚动到清单底部,并在 IBM Hard Drive Active Protection System (hdaps) 条目的旁边再次键入 Y。退出菜单并保存配置。
打开 drivers/hwmon/hdaps.c 文件,然后将以下文本添加到 include 部分中:#include 。并紧挨着 hdaps_read_pair 子程序后面添加下面的新子程序:
/* * panicShake - reboot the machine if shaken
*/extern void panicShake(void)
{ int ret, x, y; // return value and x,y from hdaps
int int baseX = -5000; // off scale default values
int baseY = -5000; int totalDev = 0; // running total of deviations
from rest (shaking total)
int devThreshold = 4000; // larger threshold for more shaking
int dimShiftX = 150; // in case your users shake more in a certain dimension
int dimShiftY = 150;
while(1)
{ ret = hdaps_read_pair(HDAPS_PORT_XPOS, HDAPS_PORT_YPOS, &x, &y);
if (!ret) { if( x != 0 && y != 0 )
{ // if its a successful read and not a zero read
if( baseX == -5000 ) { baseX = x; baseY = y; }
if( abs(baseX - x) > dimShiftX || abs(baseY - y) > dimShiftY )
{ totalDev += abs(baseX - x); totalDev += abs(baseY - y); }
if( totalDev > devThreshold )
{ printk(KERN_EMERG
"ok, ok! you're shaking my substrate - restarting");
emergency_restart(); } }//if not a zero value
}//if successful read of hdaps data
}//infinite while}//panicShake |
清单 2. 来自 hdaps.c 的完整的 panicShake 子程序
震动检测程序就绪后,需要在系统出现紧急情况时调用该检测程序。打开 kernel/panic.c 文件,并在紧挨着 panicBlink 条件部分之前的位置上放置一个对 panicShake(); 子程序的调用。发出 make 命令。趁着对内核进行重新构建时,让我们复查一下震动检测代码。首先,设置一些变量:
int ret, x, y; // return value and x,y from hdaps
int baseX = -5000; // off scale default values
int baseY = -5000; int totalDev = 0; // running total of deviations
from rest (shaking total)
int devThreshold = 4000; // larger threshold for more shaking
int dimShiftX = 150; // in case your users shake more in a certain dimension
int dimShiftY = 150; |
清单 3. panicShake 变量