Added core and bus clock support for Intel CPUs (Core 2).

This commit is contained in:
Michael Möller
2010-02-14 20:16:30 +00:00
parent ae694b9b60
commit f10c7cb524
5 changed files with 116 additions and 56 deletions

View File

@@ -107,9 +107,9 @@ namespace OpenHardwareMonitor.GUI {
set { set {
this.color = value; this.color = value;
this.darkColor = Color.FromArgb(255, this.darkColor = Color.FromArgb(255,
Math.Max(this.color.R - 100, 0), this.color.R / 3,
Math.Max(this.color.G - 100, 0), this.color.G / 3,
Math.Max(this.color.B - 100, 0)); this.color.B / 3);
Brush brush = this.brush; Brush brush = this.brush;
this.brush = new SolidBrush(this.color); this.brush = new SolidBrush(this.color);
if (brush != null) if (brush != null)

View File

@@ -131,10 +131,8 @@ namespace OpenHardwareMonitor.Hardware.CPU {
switch (cpuVendor) { switch (cpuVendor) {
case "GenuineIntel": case "GenuineIntel":
// check if processor supports a digital thermal sensor hardware.Add(new IntelCPU(name, family, model, stepping,
if (maxCPUID >= 6 && (cpuidData[6, 0] & 1) != 0) cpuidData, cpuidExtData));
hardware.Add(new IntelCPU(name, family, model, stepping,
cpuidData, cpuidExtData));
break; break;
case "AuthenticAMD": case "AuthenticAMD":
// check if processor supports a digital thermal sensor // check if processor supports a digital thermal sensor

View File

@@ -51,6 +51,8 @@ namespace OpenHardwareMonitor.Hardware.CPU {
private Sensor[] coreTemperatures; private Sensor[] coreTemperatures;
private Sensor totalLoad; private Sensor totalLoad;
private Sensor[] coreLoads; private Sensor[] coreLoads;
private Sensor[] coreClocks;
private Sensor busClock;
private float tjMax = 0; private float tjMax = 0;
private uint logicalProcessors; private uint logicalProcessors;
@@ -58,9 +60,13 @@ namespace OpenHardwareMonitor.Hardware.CPU {
private uint coreCount; private uint coreCount;
private CPULoad cpuLoad; private CPULoad cpuLoad;
private ulong lastCount;
private long lastTime;
private const uint IA32_THERM_STATUS_MSR = 0x019C; private const uint IA32_THERM_STATUS_MSR = 0x019C;
private const uint IA32_TEMPERATURE_TARGET = 0x01A2; private const uint IA32_TEMPERATURE_TARGET = 0x01A2;
private const uint IA32_PERF_STATUS = 0x0198;
public IntelCPU(string name, uint family, uint model, uint stepping, public IntelCPU(string name, uint family, uint model, uint stepping,
uint[,] cpuidData, uint[,] cpuidExtData) { uint[,] cpuidData, uint[,] cpuidExtData) {
@@ -89,58 +95,64 @@ namespace OpenHardwareMonitor.Hardware.CPU {
coreCount = logicalProcessors / logicalProcessorsPerCore; coreCount = logicalProcessors / logicalProcessorsPerCore;
switch (family) { // check if processor supports a digital thermal sensor
case 0x06: { if (cpuidData.GetLength(0) > 6 && (cpuidData[6, 0] & 1) != 0) {
switch (model) {
case 0x0F: // Intel Core 65nm switch (family) {
switch (stepping) { case 0x06: {
case 0x06: // B2 switch (model) {
switch (coreCount) { case 0x0F: // Intel Core 65nm
case 2: switch (stepping) {
case 0x06: // B2
switch (coreCount) {
case 2:
tjMax = 80; break;
case 4:
tjMax = 90; break;
default:
tjMax = 85; break;
}
tjMax = 80; break; tjMax = 80; break;
case 4: case 0x0B: // G0
tjMax = 90; break; tjMax = 90; break;
case 0x0D: // M0
tjMax = 85; break;
default: default:
tjMax = 85; break; tjMax = 85; break;
} } break;
tjMax = 80; break; case 0x17: // Intel Core 45nm
case 0x0B: // G0 tjMax = 100; break;
case 0x1C: // Intel Atom
tjMax = 90; break; tjMax = 90; break;
case 0x0D: // M0 case 0x1A:
tjMax = 85; break; uint eax = 0, edx = 0;
if (WinRing0.RdmsrPx(
IA32_TEMPERATURE_TARGET, ref eax, ref edx, (UIntPtr)1)) {
tjMax = (eax >> 16) & 0xFF;
} else
tjMax = 100;
break;
default: default:
tjMax = 85; break; tjMax = 100; break;
} break; }
case 0x17: // Intel Core 45nm } break;
tjMax = 100; break; default: tjMax = 100; break;
case 0x1C: // Intel Atom }
tjMax = 90; break;
case 0x1A: coreTemperatures = new Sensor[coreCount];
uint eax = 0, edx = 0; for (int i = 0; i < coreTemperatures.Length; i++) {
if (WinRing0.RdmsrPx( coreTemperatures[i] = new Sensor("Core #" + (i + 1), i, tjMax,
IA32_TEMPERATURE_TARGET, ref eax, ref edx, (UIntPtr)1)) { SensorType.Temperature, this);
tjMax = (eax >> 16) & 0xFF; }
} else } else {
tjMax = 100; coreTemperatures = new Sensor[0];
break;
default:
tjMax = 100; break;
}
} break;
default: tjMax = 100; break;
} }
totalLoad = new Sensor("CPU Total", 0, SensorType.Load, this); totalLoad = new Sensor("CPU Total", 0, SensorType.Load, this);
coreTemperatures = new Sensor[coreCount];
coreLoads = new Sensor[coreCount]; coreLoads = new Sensor[coreCount];
for (int i = 0; i < coreTemperatures.Length; i++) { for (int i = 0; i < coreLoads.Length; i++)
coreTemperatures[i] = new Sensor("Core #" + (i + 1), i, tjMax, coreLoads[i] = new Sensor("Core #" + (i + 1), i + 1,
SensorType.Temperature, this); SensorType.Load, this);
coreLoads[i] = new Sensor("Core #" + (i + 1), i + 1,
SensorType.Load, this);
}
cpuLoad = new CPULoad(coreCount, logicalProcessorsPerCore); cpuLoad = new CPULoad(coreCount, logicalProcessorsPerCore);
if (cpuLoad.IsAvailable) { if (cpuLoad.IsAvailable) {
foreach (Sensor sensor in coreLoads) foreach (Sensor sensor in coreLoads)
@@ -148,6 +160,16 @@ namespace OpenHardwareMonitor.Hardware.CPU {
ActivateSensor(totalLoad); ActivateSensor(totalLoad);
} }
lastCount = 0;
lastTime = 0;
busClock = new Sensor("Bus Speed", 0, SensorType.Clock, this);
coreClocks = new Sensor[coreCount];
for (int i = 0; i < coreClocks.Length; i++) {
coreClocks[i] =
new Sensor("Core #" + (i + 1), i + 1, SensorType.Clock, this);
ActivateSensor(coreClocks[i]);
}
Update(); Update();
} }
@@ -180,9 +202,9 @@ namespace OpenHardwareMonitor.Hardware.CPU {
} }
public void Update() { public void Update() {
uint eax = 0, edx = 0;
for (int i = 0; i < coreTemperatures.Length; i++) { for (int i = 0; i < coreTemperatures.Length; i++) {
uint eax = 0, edx = 0;
if (WinRing0.RdmsrPx( if (WinRing0.RdmsrPx(
IA32_THERM_STATUS_MSR, ref eax, ref edx, IA32_THERM_STATUS_MSR, ref eax, ref edx,
(UIntPtr)(1 << (int)(logicalProcessorsPerCore * i)))) (UIntPtr)(1 << (int)(logicalProcessorsPerCore * i))))
@@ -204,6 +226,42 @@ namespace OpenHardwareMonitor.Hardware.CPU {
coreLoads[i].Value = cpuLoad.GetCoreLoad(i); coreLoads[i].Value = cpuLoad.GetCoreLoad(i);
totalLoad.Value = cpuLoad.GetTotalLoad(); totalLoad.Value = cpuLoad.GetTotalLoad();
} }
uint lsb = 0, msb = 0;
bool valid = WinRing0.RdtscPx(ref lsb, ref msb, (UIntPtr)1);
long time = Stopwatch.GetTimestamp();
ulong count = ((ulong)msb << 32) | lsb;
double delta = ((double)(time - lastTime)) / Stopwatch.Frequency;
if (valid && delta > 0.5) {
double maxClock = (float)((count - lastCount) / (1e6 * delta));
double busClock = 0;
uint eax, edx;
for (int i = 0; i < coreClocks.Length; i++) {
eax = 0; edx = 0;
System.Threading.Thread.Sleep(1);
if (WinRing0.RdmsrPx(IA32_PERF_STATUS, ref eax, ref edx,
(UIntPtr)(1 << (int)(logicalProcessorsPerCore * i)))) {
uint multiplier = (eax >> 8) & 0x1f;
uint maxMultiplier = (edx >> 8) & 0x1f;
// factor = multiplier * 2 to handle non integer multipliers
uint factor = (multiplier << 1) | ((eax >> 14) & 1);
uint maxFactor = (maxMultiplier << 1) | ((edx >> 14) & 1);
if (maxFactor > 0) {
coreClocks[i].Value = (float)(factor * maxClock / maxFactor);
busClock = (float)(2 * maxClock / maxFactor);
}
} else {
// if IA32_PERF_STATUS is not available, assume maxClock
coreClocks[i].Value = (float)maxClock;
}
}
if (busClock > 0) {
this.busClock.Value = (float)busClock;
ActivateSensor(this.busClock);
}
}
lastCount = count;
lastTime = time;
} }
} }
} }

View File

@@ -94,6 +94,8 @@ namespace OpenHardwareMonitor.Hardware {
uint regAddress, out uint value); uint regAddress, out uint value);
public delegate bool WritePciConfigDwordExDelegate(uint pciAddress, public delegate bool WritePciConfigDwordExDelegate(uint pciAddress,
uint regAddress, uint value); uint regAddress, uint value);
public delegate bool RdtscPxDelegate(ref uint eax, ref uint edx,
UIntPtr processAffinityMask);
private static InitializeOlsDelegate InitializeOls; private static InitializeOlsDelegate InitializeOls;
private static DeinitializeOlsDelegate DeinitializeOls; private static DeinitializeOlsDelegate DeinitializeOls;
@@ -108,7 +110,8 @@ namespace OpenHardwareMonitor.Hardware {
public static SetPciMaxBusIndexDelegate SetPciMaxBusIndex; public static SetPciMaxBusIndexDelegate SetPciMaxBusIndex;
public static FindPciDeviceByIdDelegate FindPciDeviceById; public static FindPciDeviceByIdDelegate FindPciDeviceById;
public static ReadPciConfigDwordExDelegate ReadPciConfigDwordEx; public static ReadPciConfigDwordExDelegate ReadPciConfigDwordEx;
public static WritePciConfigDwordExDelegate WritePciConfigDwordEx; public static WritePciConfigDwordExDelegate WritePciConfigDwordEx;
public static RdtscPxDelegate RdtscPx;
private static void GetDelegate<T>(string entryPoint, out T newDelegate) private static void GetDelegate<T>(string entryPoint, out T newDelegate)
where T : class where T : class
@@ -135,6 +138,7 @@ namespace OpenHardwareMonitor.Hardware {
GetDelegate("FindPciDeviceById", out FindPciDeviceById); GetDelegate("FindPciDeviceById", out FindPciDeviceById);
GetDelegate("ReadPciConfigDwordEx", out ReadPciConfigDwordEx); GetDelegate("ReadPciConfigDwordEx", out ReadPciConfigDwordEx);
GetDelegate("WritePciConfigDwordEx", out WritePciConfigDwordEx); GetDelegate("WritePciConfigDwordEx", out WritePciConfigDwordEx);
GetDelegate("RdtscPx", out RdtscPx);
try { try {
if (InitializeOls != null && InitializeOls()) if (InitializeOls != null && InitializeOls())

View File

@@ -69,5 +69,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.1.19.0")] [assembly: AssemblyVersion("0.1.20.0")]
[assembly: AssemblyFileVersion("0.1.19.0")] [assembly: AssemblyFileVersion("0.1.20.0")]