检测笔记本的主板、CPU和硬盘的温度


其实不算原创,资料几乎都是通过 google 来自 internet :)


前段时间买了 hp-dv1702 笔记本电脑, 酷睿单核 cpu, 5400 转硬盘, 看电影挺不错的. 酷睿 cpu支持 speedstep 技术, 不忙的时候总是工作在 800MHz 左右,发热量小,BIOS 设定风扇启动温度为 cpu 75度,平常工作中一天下来风扇也几乎不转,硬盘的温度比较高,从网上查到左手边热是这款本本的通病。
笔者的想法是让风扇在硬盘达到48、9度的时候让风扇转动起来,到设定的温度停下,并可以看到主板、cpu、硬盘的温度。在风扇控制完成以后,检测系统温度的问题就显出来了,一边用别人的软件看系统温度,一边手工来控制风扇的停和转动,累。

1、主板温度的检测
笔记本电脑的bios和台式机有一些区别,通常本本的bios ACPI 会有一个热度表述区(ThermalZone) 或其它acpi定义的温度检测区域,读出这个区域的数值,就得到当前主板上温度传感器的值,xp/2000 支持acpi,所以很方便读到。但台式机基本没有ThermalZone,要监测温度,需要扫描系统总线。

如何读取acpi这个区域的数值呢,windows driver 读取这些值用于管理,所以通过WMI 能读到。连接到 WMI 的名字空间,请参考 MSDN 'WMI C++ Application Examples'。这里不做叙述.

  主板温度在wmi中有两个名字:1、ROOT/CIMV2/Win32_TemperatureProbe  2、ROOT/WMI/MSAcpi_ThermalZoneTemperature 先检测 Win32_TemperatureProbe 是否有对象,如没有再检测 MSAcpi_ThermalZoneTemperature 然后读取成员 CurrentTemperature 为当前温度,CriticalTripPoint 为临界温度。此温度是以绝对 0 度开始并以 1/10 度增加,公式如下

  当前摄氏度 = (CurrentTemperature - 2732) / 10

2、硬盘温度的监测
   检测硬盘温度的工具或软件,都是通过 S.M.A.R.T来读取,对硬盘直接 DeviceIoControl 或者 WMI 都可以得到SMART值.SMART 数据存储于 WMI 中 ROOT/WMI/MSStorageDriver_ATAPISmartData 命名空间中,其中属性 'VendorSpecific' 包含有硬盘温度的数据,这是ATA标准定义的。可能你读出这些数据来会有些困惑,其实这是一个结构,第一个和第二个字节代表 SMART 版本信息,从第三个字节起定义 SMART 的属性,每个属性为12字节长,每个属性的第一字节为当前属性定义,0x09 定义已经使用的小时数, 0xc2 为温度属性,第五字节表示当前温度。结构如下

struct SmartAttriubtes
{
char attrib;
char flags;
char worst;
char normal;
char current;
char current1;
char current2;
char current3;
char current4;
char current5;
char current6;
char current7;
}

struct VendorSpecific
{
unsigned short version;
SmartAttriubtes smartattrib [1];
}

如笔者硬盘读取如下数值,有些就省略了 {0xa, 0x00, 0x09, 0x32, 0, 0x63, 0x63, 0xc2, 0x03, 0, 0, 0, 0, 0, 0xc2, 0x22, 0, 0x2e, 0x3b, 0x2e, 0, 0, 0, 0x05, 0, 0, ...};


  排列如下
{
0xa, 0x00 版本信息
0x09, 0x32, 0, 0x63, 0x63, [0xc2, 0x03], 0, 0, 0, 0, 0 硬盘使用小时数 这里是 0x3c2 = 962 小时
0xc2, 0x22, 0, 0x2e, 0x3b, [0x2e], 0, 0, 0, 0x05, 0, 0 这是当前温度 数值为 0x2e = 46 度
}

win2000 不支持此 WMI 属性,只能通过 DeviceIoControl 得到,如何实现请看考附录 SMART 的OpenSource 连接

3、CPU 的温度检测

新的酷瑞CPU和AMD的CPU 内部都集成有温度传感器DTS (Digital Thermal Sensor),每个核心有一个,以前的移动CPU好像也支持温度探测,但手头没有这样的CPU没法做测试.AMD 的温度值保存在 NB 寄存器中,酷瑞CPU 的 DTS 值保存在 MSR 0x19c 中,可以通过 rdmsr 来读取

这里只说酷睿CPU的读取过程

Intel 定义 eax=6 执行 cpuid, 然后测试 eax 第一位是否为1,如果为1表示CPU支持DTS ,当然之前应该以 eax=0 执行 cpuid 检测 eax 支持的最大命令数,如果小于6就肯定不支持DTS。

读取DTS:1 以 ecx=0xee 执行 rdmsr 指令, 测试 eax 的第30位是否为 1, 如果为 1 表示温度计算的初始值为 85 度否则表示从100度开始计算,这个值称为 Tjunction. 然后以 ecx=0x19c 执行 rdmsr 指令, eax 的 16:23 位为表示当前DTS 值,这个值并不代表当前温度,而要以下面公式计算.

当前cpu温度 = Tjunction - DTS

注意 signature 为 0x6f1, 0x6f0的 CPU DTS 值直接代表当前温度而不用Tjunction 相减. 而 signature 小于等于 0x6f4 的 Tjunction 一直为100, 如果你是双核的cpu 可以使用 SetProcessAffinityMask API 来指定执行的CPU,以检测这个核心的温度。呵呵,我就不用啦,本本是单核的

另 rdmsr 指令需要运行在 0 级的代码才能执行.所以写一个简单的驱动也是必须的.

如果你想看看效果可以到我的共享资源中下载 FAN1702ii.rar 不操作风扇他还是可以工作的
http://download.csdn.net/source/185999

22:40 2007-5-27 Treeyan email:yanjiafu33@163.com QQ: 42412685

呵呵,很少写文,不通顺之处请包含,Enjoy!

附录参考

S.M.A.R.T 的 OpenSource
http://smartlinux.sourceforge.net/smart/index.php

在 intel 网站上的骂站,可以看到关于 DTS 和 Tjunction 的一些信息
http://softwarecommunity.intel.com/isn/Community/en-US/forums/thread/30231056.aspx

Core temp 讲述她是如何工作的
http://www.thecoolest.zerobrains.com/CoreTemp/howitworks.html

关于 MSStorageDriver_ATAPISmartData
http://www.hardforum.com/showthread.php?t=1162248

测试cpu速度,开源
http://www.diefer.de/speedswitchxp/index.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
笔记本的风扇控制 ---------------------------------------- 09 November 2006. Summary of changes for version 20061109: 1) ACPI CA Core Subsystem: Optimized the Load ASL operator in the case where the source operand is an operation region. Simply map the operation region memory, instead of performing a bytewise read. (Region must be of type SystemMemory, see below.) Fixed the Load ASL operator for the case where the source operand is a region field. A buffer object is also allowed as the source operand. BZ 480 Fixed a problem where the Load ASL operator allowed the source operand to be an operation region of any type. It is now restricted to regions of type SystemMemory, as per the ACPI specification. BZ 481 Additional cleanup and optimizations for the new Table Manager code. AcpiEnable will now fail if all of the required ACPI tables are not loaded (FADT, FACS, DSDT). BZ 477 Added #pragma pack(8/4) to acobject.h to ensure that the structures in this header are always compiled as aligned. The ACPI_OPERAND_OBJECT has been manually optimized to be aligned and will not work if it is byte-packed. Example Code and Data Size: These are the sizes for the OS- independent acpica.lib produced by the Microsoft Visual C++ 6.0 32- bit compiler. The debug version of the code includes the debug output trace mechanism and has a much larger code and data size. Previous Release: Non-Debug Version: 78.1K Code, 17.1K Data, 95.2K Total Debug Version: 155.4K Code, 63.1K Data, 218.5K Total Current Release: Non-Debug Version: 77.9K Code, 17.0K Data, 94.9K Total Debug Version: 155.2K Code, 63.1K Data, 218.3K Total 2) iASL Compiler/Disassembler and Tools: Fixed a problem where the presence of the _OSI predefined control method within complex expressions could cause an internal compiler error. AcpiExec: Implemented full region support for multiple address spaces. SpaceId is now part of the REGION object. BZ 429 ---------------------------------------- 11 Oc

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值