如何访问CPU的热传感器?
我正在开发需要访问 CPU 中的温度传感器并控制它们的软件。
我不太了解硬件接口;我只知道如何与鼠标交互。我用谷歌搜索了很多相关信息,但未能找到任何相关信息或代码。
我真的需要将其添加到我的软件中。请指导我如何使用 C 或 C++ 或 ASM 来控制传感器。
I am working on software in which I need to access the temperature sensors in the CPU and get control over them.
I don't know much hardware interfacing; I just know how to interface with the mouse. I have googled a lot about it but failed to find any relevant information or piece of code.
I really need to add this in my software. Please guide me how to have the control over the sensors using C or C++ or ASM.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果没有特定的内核驱动程序,除了通过 WMI 之外,很难查询温度。下面是一段基于 WMI 的 MSAcpi_ThermalZoneTemperature 类的 C 代码:
以及一些测试代码:
Without a specific kernel driver, it's difficult to query the temperature, other than through WMI. Here is a piece of C code that does it, based on WMI's MSAcpi_ThermalZoneTemperature class:
and some test code:
我假设您对 IA-32(英特尔架构,32 位)CPU 和 Microsoft Windows 感兴趣。
型号特定寄存器 (MSR)
IA32_THERM_STATUS
有 7 位编码“数字读数(位 22:16,RO)——相对于 TCC 激活温度的数字温度读数,单位为 1 摄氏度”。 (请参阅“英特尔® 64 和 IA-32 架构 - 软件开发人员手册 - 第 3 卷(3A 和 3B):系统编程指南”中的“14.5.5.2 读取数字传感器”http://www.intel.com/Assets/PDF/manual/325384.pdf)。因此,
IA32_THERM_STATUS
不会为您提供“CPU 温度”,而是提供一些代理。为了读取
IA32_THERM_STATUS
寄存器,您使用 asm 指令rdmsr
,现在rdmsr
无法从用户空间代码调用,因此您需要一些内核空间代码(也许是设备驱动程序?)。您还可以使用内部
__readmsr
(请参阅 http://msdn.microsoft.com/en-us/library/y55zyfdx(v=VS.100).aspx) 无论如何都有相同的限制:“此功能仅在内核中可用模式”。每个 CPU 核心都有自己的数字热传感器 (DTS),因此需要更多代码来获取所有温度(也许使用亲和性掩码?请参阅 Win32 API
SetThreadAffinityMask
)。我做了一些测试,实际上发现了
IA32_THERM_STATUS
DTS 读数与 Prime95“就地大型 FFT(最大热量、功耗、测试了一些 RAM)”测试之间的相关性。 Prime95 是 ftp://mersenne.org/gimps/p95v266.zip我没有找到公式从 DTS 读数中获取“CPU 温度”(无论这意味着什么)。
编辑:
引用一篇有趣的文章TJunction 最大? #热旅行? #PROCHOT? 作者:"fgw"(2007 年 12 月) :
I assume you are interested in a IA-32 (Intel Architecture, 32-bit) CPU and Microsoft Windows.
The Model Specific Register (MSR)
IA32_THERM_STATUS
has 7 bits encoding the "Digital Readout (bits 22:16, RO) — Digital temperature reading in 1 degree Celsius relative to the TCC activation temperature." (see "14.5.5.2 Reading the Digital Sensor" in "Intel® 64 and IA-32 Architectures - Software Developer’s Manual - Volume 3 (3A & 3B): System Programming Guide" http://www.intel.com/Assets/PDF/manual/325384.pdf).So
IA32_THERM_STATUS
will not give you the "CPU temperature" but some proxy for it.In order to read the
IA32_THERM_STATUS
register you use the asm instructionrdmsr
, nowrdmsr
cannot be called from user space code and so you need some kernel space code (maybe a device driver?).You can also use the intrinsic
__readmsr
(see http://msdn.microsoft.com/en-us/library/y55zyfdx(v=VS.100).aspx) which has anyway the same limitation: "This function is only available in kernel mode".Every CPU cores has its own Digital Thermal Sensors (DTS) and so some more code is needed to get all the temperatures (maybe with the affinity mask? see Win32 API
SetThreadAffinityMask
).I did some tests and actually found a correlation between the
IA32_THERM_STATUS
DTS readouts and the Prime95 "In-place large FFTs (maximum heat, power consumption, some RAM tested)" test. Prime95 is ftp://mersenne.org/gimps/p95v266.zipI did not find a formula to get the "CPU temperature" (whatever that may mean) from the DTS readout.
Edit:
Quoting from an interesting post TJunction Max? #THERMTRIP? #PROCHOT? by "fgw" (December 2007):
您可以从 WMI 中的 MSAcpi_ThermalZoneTemperature 中读取它。
使用 C++ 中的 WMI 有点复杂,请参阅 MSDN 解释和示例
注意:更改了原来无用的答案
You can read it from the MSAcpi_ThermalZoneTemperature in WMI
Using WMI from C++ is a bit involved, see MSDN explanantion and examples
note: changed original unhelpful answer