Release version 0.1.10. Changed core count for Intel Core i5/i7 CPUs. Added CpuidEx function.
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 using System.Reflection;
44 namespace OpenHardwareMonitor.Hardware.CPU {
45 public class IntelCPU : IHardware {
50 private Sensor[] coreTemperatures;
52 private float tjMax = 0;
53 private uint logicalProcessors;
54 private uint logicalProcessorsPerCore;
55 private uint coreCount;
57 private const uint IA32_THERM_STATUS_MSR = 0x019C;
58 private const uint IA32_TEMPERATURE_TARGET = 0x01A2;
60 public IntelCPU(string name, uint family, uint model, uint stepping,
61 uint[,] cpuidData, uint[,] cpuidExtData) {
64 this.icon = Utilities.EmbeddedResources.GetImage("cpu.png");
66 logicalProcessorsPerCore = 1;
67 if (cpuidData.GetLength(0) > 0x0B) {
68 uint eax, ebx, ecx, edx;
69 WinRing0.CpuidEx(0x0B, 0, out eax, out ebx, out ecx, out edx);
70 logicalProcessorsPerCore = ebx & 0xFF;
71 WinRing0.CpuidEx(0x0B, 1, out eax, out ebx, out ecx, out edx);
72 logicalProcessors = ebx & 0xFF;
73 } else if (cpuidData.GetLength(0) > 0x04) {
74 logicalProcessors = ((cpuidData[4, 0] >> 26) & 0x3F) + 1;
75 logicalProcessorsPerCore = 1;
77 logicalProcessors = 1;
78 logicalProcessorsPerCore = 1;
81 coreCount = logicalProcessors / logicalProcessorsPerCore;
86 case 0x0F: // Intel Core 65nm
105 case 0x17: // Intel Core 45nm
107 case 0x1C: // Intel Atom
110 uint eax = 0, edx = 0;
111 if (WinRing0.RdmsrPx(
112 IA32_TEMPERATURE_TARGET, ref eax, ref edx, (UIntPtr)1)) {
113 tjMax = (eax >> 16) & 0xFF;
121 default: tjMax = 100; break;
124 coreTemperatures = new Sensor[coreCount];
125 for (int i = 0; i < coreTemperatures.Length; i++)
126 coreTemperatures[i] =
127 new Sensor("Core #" + (i + 1), i, tjMax, SensorType.Temperature,
137 public string Identifier {
138 get { return "/intelcpu/0"; }
145 public ISensor[] Sensors {
147 return coreTemperatures;
151 public string GetReport() {
152 StringBuilder r = new StringBuilder();
154 r.AppendLine("Intel CPU");
156 r.AppendFormat("Name: {0}{1}", name, Environment.NewLine);
157 r.AppendFormat("Number of cores: {0}{1}", coreCount,
158 Environment.NewLine);
159 r.AppendFormat("Threads per core: {0}{1}", logicalProcessorsPerCore,
160 Environment.NewLine);
161 r.AppendFormat("TjMax: {0}{1}", tjMax, Environment.NewLine);
167 public void Update() {
169 uint eax = 0, edx = 0;
170 for (int i = 0; i < coreTemperatures.Length; i++) {
171 if (WinRing0.RdmsrPx(
172 IA32_THERM_STATUS_MSR, ref eax, ref edx,
173 (UIntPtr)(1 << (int)(logicalProcessorsPerCore * i))))
175 // if reading is valid
176 if ((eax & 0x80000000) != 0) {
177 // get the dist from tjMax from bits 22:16
178 coreTemperatures[i].Value = tjMax - ((eax & 0x007F0000) >> 16);
184 #pragma warning disable 67
185 public event SensorEventHandler SensorAdded;
186 public event SensorEventHandler SensorRemoved;
187 #pragma warning restore 67