3 Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 The contents of this file are subject to the Mozilla Public License Version
6 1.1 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
9 http://www.mozilla.org/MPL/
11 Software distributed under the License is distributed on an "AS IS" basis,
12 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 for the specific language governing rights and limitations under the License.
15 The Original Code is the Open Hardware Monitor code.
17 The Initial Developer of the Original Code is
18 Michael Möller <m.moeller@gmx.ch>.
19 Portions created by the Initial Developer are Copyright (C) 2009-2010
20 the Initial Developer. All Rights Reserved.
24 Alternatively, the contents of this file may be used under the terms of
25 either the GNU General Public License Version 2 or later (the "GPL"), or
26 the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 in which case the provisions of the GPL or the LGPL are applicable instead
28 of those above. If you wish to allow use of your version of this file only
29 under the terms of either the GPL or the LGPL, and not to allow others to
30 use your version of this file under the terms of the MPL, indicate your
31 decision by deleting the provisions above and replace them with the notice
32 and other provisions required by the GPL or the LGPL. If you do not delete
33 the provisions above, a recipient may use your version of this file under
34 the terms of any one of the MPL, the GPL or the LGPL.
39 using System.Collections.Generic;
41 namespace OpenHardwareMonitor.Hardware.CPU {
42 internal sealed class IntelCPU : GenericCPU {
44 private Sensor[] coreTemperatures;
45 private Sensor[] coreClocks;
46 private Sensor busClock;
48 private uint maxNehalemMultiplier = 0;
50 private const uint IA32_THERM_STATUS_MSR = 0x019C;
51 private const uint IA32_TEMPERATURE_TARGET = 0x01A2;
52 private const uint IA32_PERF_STATUS = 0x0198;
53 private const uint MSR_PLATFORM_INFO = 0xCE;
55 private float[] Floats(float f) {
56 float[] result = new float[coreCount];
57 for (int i = 0; i < coreCount; i++)
62 public IntelCPU(int processorIndex, CPUID[][] cpuid, ISettings settings)
63 : base(processorIndex, cpuid, settings)
69 case 0x0F: // Intel Core (65nm)
74 tjMax = Floats(80 + 10); break;
76 tjMax = Floats(90 + 10); break;
78 tjMax = Floats(85 + 10); break;
80 tjMax = Floats(80 + 10); break;
82 tjMax = Floats(90 + 10); break;
84 tjMax = Floats(85 + 10); break;
86 tjMax = Floats(85 + 10); break;
88 case 0x17: // Intel Core (45nm)
89 tjMax = Floats(100); break;
90 case 0x1C: // Intel Atom (45nm)
93 tjMax = Floats(90); break;
95 tjMax = Floats(100); break;
97 tjMax = Floats(90); break;
99 case 0x1A: // Intel Core i7 LGA1366 (45nm)
100 case 0x1E: // Intel Core i5, i7 LGA1156 (45nm)
101 case 0x25: // Intel Core i3, i5, i7 LGA1156 (32nm)
102 case 0x2C: // Intel Core i7 LGA1366 (32nm) 6 Core
104 tjMax = new float[coreCount];
105 for (int i = 0; i < coreCount; i++) {
106 if (WinRing0.RdmsrTx(IA32_TEMPERATURE_TARGET, out eax,
107 out edx, (UIntPtr)(1L << cpuid[i][0].Thread))) {
108 tjMax[i] = (eax >> 16) & 0xFF;
113 if (WinRing0.Rdmsr(MSR_PLATFORM_INFO, out eax, out edx)) {
114 maxNehalemMultiplier = (eax >> 8) & 0xff;
118 tjMax = Floats(100); break;
121 default: tjMax = Floats(100); break;
124 // check if processor supports a digital thermal sensor
125 if (cpuid[0][0].Data.GetLength(0) > 6 &&
126 (cpuid[0][0].Data[6, 0] & 1) != 0) {
127 coreTemperatures = new Sensor[coreCount];
128 for (int i = 0; i < coreTemperatures.Length; i++) {
129 coreTemperatures[i] = new Sensor(CoreString(i), i,
130 SensorType.Temperature, this, new ParameterDescription[] {
131 new ParameterDescription(
132 "TjMax [°C]", "TjMax temperature of the core.\n" +
133 "Temperature = TjMax - TSlope * Value.", tjMax[i]),
134 new ParameterDescription("TSlope [°C]",
135 "Temperature slope of the digital thermal sensor.\n" +
136 "Temperature = TjMax - TSlope * Value.", 1)}, settings);
137 ActivateSensor(coreTemperatures[i]);
140 coreTemperatures = new Sensor[0];
143 busClock = new Sensor("Bus Speed", 0, SensorType.Clock, this, settings);
144 coreClocks = new Sensor[coreCount];
145 for (int i = 0; i < coreClocks.Length; i++) {
147 new Sensor(CoreString(i), i + 1, SensorType.Clock, this, settings);
149 ActivateSensor(coreClocks[i]);
155 protected override uint[] GetMSRs() {
159 IA32_THERM_STATUS_MSR,
160 IA32_TEMPERATURE_TARGET
164 public override void Update() {
167 for (int i = 0; i < coreTemperatures.Length; i++) {
169 if (WinRing0.RdmsrTx(
170 IA32_THERM_STATUS_MSR, out eax, out edx,
171 (UIntPtr)(1L << cpuid[i][0].Thread))) {
172 // if reading is valid
173 if ((eax & 0x80000000) != 0) {
174 // get the dist from tjMax from bits 22:16
175 float deltaT = ((eax & 0x007F0000) >> 16);
176 float tjMax = coreTemperatures[i].Parameters[0].Value;
177 float tSlope = coreTemperatures[i].Parameters[1].Value;
178 coreTemperatures[i].Value = tjMax - tSlope * deltaT;
180 coreTemperatures[i].Value = null;
186 double newBusClock = 0;
188 for (int i = 0; i < coreClocks.Length; i++) {
189 System.Threading.Thread.Sleep(1);
190 if (WinRing0.RdmsrTx(IA32_PERF_STATUS, out eax, out edx,
191 (UIntPtr)(1L << cpuid[i][0].Thread))) {
192 if (maxNehalemMultiplier > 0) { // Core i3, i5, i7
193 uint nehalemMultiplier = eax & 0xff;
194 coreClocks[i].Value =
195 (float)(nehalemMultiplier * MaxClock / maxNehalemMultiplier);
196 newBusClock = (float)(MaxClock / maxNehalemMultiplier);
198 uint multiplier = (eax >> 8) & 0x1f;
199 uint maxMultiplier = (edx >> 8) & 0x1f;
200 // factor = multiplier * 2 to handle non integer multipliers
201 uint factor = (multiplier << 1) | ((eax >> 14) & 1);
202 uint maxFactor = (maxMultiplier << 1) | ((edx >> 14) & 1);
204 coreClocks[i].Value = (float)(factor * MaxClock / maxFactor);
205 newBusClock = (float)(2 * MaxClock / maxFactor);
208 } else { // Intel Pentium 4
209 // if IA32_PERF_STATUS is not available, assume maxClock
210 coreClocks[i].Value = (float)MaxClock;
213 if (newBusClock > 0) {
214 this.busClock.Value = (float)newBusClock;
215 ActivateSensor(this.busClock);