Added support for Intel CPU power sensors (package and cores).
1.1 --- a/GUI/HardwareNode.cs Mon Jul 25 21:09:21 2011 +0000
1.2 +++ b/GUI/HardwareNode.cs Wed Jul 27 18:27:16 2011 +0000
1.3 @@ -65,7 +65,8 @@
1.4 typeNodes.Add(new TypeNode(SensorType.Flow));
1.5 typeNodes.Add(new TypeNode(SensorType.Control));
1.6 typeNodes.Add(new TypeNode(SensorType.Level));
1.7 -
1.8 + typeNodes.Add(new TypeNode(SensorType.Power));
1.9 +
1.10 foreach (ISensor sensor in hardware.Sensors)
1.11 SensorAdded(sensor);
1.12
2.1 --- a/GUI/SensorNode.cs Mon Jul 25 21:09:21 2011 +0000
2.2 +++ b/GUI/SensorNode.cs Wed Jul 27 18:27:16 2011 +0000
2.3 @@ -16,7 +16,7 @@
2.4
2.5 The Initial Developer of the Original Code is
2.6 Michael Möller <m.moeller@gmx.ch>.
2.7 - Portions created by the Initial Developer are Copyright (C) 2009-2010
2.8 + Portions created by the Initial Developer are Copyright (C) 2009-2011
2.9 the Initial Developer. All Rights Reserved.
2.10
2.11 Contributor(s):
2.12 @@ -75,6 +75,7 @@
2.13 case SensorType.Flow: format = "{0:F0} L/h"; break;
2.14 case SensorType.Control: format = "{0:F1} %"; break;
2.15 case SensorType.Level: format = "{0:F1} %"; break;
2.16 + case SensorType.Power: format = "{0:F1} W"; break;
2.17 }
2.18
2.19 bool hidden = settings.GetValue(new Identifier(sensor.Identifier,
3.1 --- a/GUI/SensorNotifyIcon.cs Mon Jul 25 21:09:21 2011 +0000
3.2 +++ b/GUI/SensorNotifyIcon.cs Wed Jul 27 18:27:16 2011 +0000
3.3 @@ -16,7 +16,7 @@
3.4
3.5 The Initial Developer of the Original Code is
3.6 Michael Möller <m.moeller@gmx.ch>.
3.7 - Portions created by the Initial Developer are Copyright (C) 2009-2010
3.8 + Portions created by the Initial Developer are Copyright (C) 2009-2011
3.9 the Initial Developer. All Rights Reserved.
3.10
3.11 Contributor(s):
3.12 @@ -196,6 +196,8 @@
3.13 return string.Format("{0:F0}", sensor.Value);
3.14 case SensorType.Level:
3.15 return string.Format("{0:F0}", sensor.Value);
3.16 + case SensorType.Power:
3.17 + return string.Format("{0:F0}", sensor.Value);
3.18 }
3.19 return "-";
3.20 }
3.21 @@ -283,6 +285,7 @@
3.22 case SensorType.Flow: format = "\n{0}: {1:F0} L/h"; break;
3.23 case SensorType.Control: format = "\n{0}: {1:F1} %"; break;
3.24 case SensorType.Level: format = "\n{0}: {1:F1} %"; break;
3.25 + case SensorType.Power: format = "\n{0}: {1:F0} W"; break;
3.26 }
3.27 string formattedValue = string.Format(format, sensor.Name, sensor.Value);
3.28 string hardwareName = sensor.Hardware.Name;
4.1 --- a/GUI/TypeNode.cs Mon Jul 25 21:09:21 2011 +0000
4.2 +++ b/GUI/TypeNode.cs Wed Jul 27 18:27:16 2011 +0000
4.3 @@ -16,7 +16,7 @@
4.4
4.5 The Initial Developer of the Original Code is
4.6 Michael Möller <m.moeller@gmx.ch>.
4.7 - Portions created by the Initial Developer are Copyright (C) 2009-2010
4.8 + Portions created by the Initial Developer are Copyright (C) 2009-2011
4.9 the Initial Developer. All Rights Reserved.
4.10
4.11 Contributor(s):
4.12 @@ -80,6 +80,10 @@
4.13 this.Image = Utilities.EmbeddedResources.GetImage("level.png");
4.14 this.Text = "Levels";
4.15 break;
4.16 + case SensorType.Power:
4.17 + this.Image = Utilities.EmbeddedResources.GetImage("power.png");
4.18 + this.Text = "Powers";
4.19 + break;
4.20 }
4.21
4.22 NodeAdded += new NodeEventHandler(TypeNode_NodeAdded);
5.1 --- a/Hardware/CPU/IntelCPU.cs Mon Jul 25 21:09:21 2011 +0000
5.2 +++ b/Hardware/CPU/IntelCPU.cs Wed Jul 27 18:27:16 2011 +0000
5.3 @@ -55,6 +55,8 @@
5.4 private readonly Sensor packageTemperature;
5.5 private readonly Sensor[] coreClocks;
5.6 private readonly Sensor busClock;
5.7 + private readonly Sensor packagePower;
5.8 + private readonly Sensor coresPower;
5.9
5.10 private readonly Microarchitecture microarchitecture;
5.11 private readonly double timeStampCounterMultiplier;
5.12 @@ -64,6 +66,17 @@
5.13 private const uint IA32_PERF_STATUS = 0x0198;
5.14 private const uint MSR_PLATFORM_INFO = 0xCE;
5.15 private const uint IA32_PACKAGE_THERM_STATUS = 0x1B1;
5.16 + private const uint MSR_RAPL_POWER_UNIT = 0x606;
5.17 + private const uint MSR_PKG_ENERY_STATUS = 0x611;
5.18 + private const uint MSR_PP0_ENERY_STATUS = 0x639;
5.19 +
5.20 + private float energyUnitMultiplier = 0;
5.21 + private DateTime lastPackageTime;
5.22 + private uint lastPackageEnergyConsumed;
5.23 + private DateTime lastCoresTime;
5.24 + private uint lastCoresEnergyConsumed;
5.25 +
5.26 +
5.27
5.28 private float[] Floats(float f) {
5.29 float[] result = new float[coreCount];
5.30 @@ -242,6 +255,33 @@
5.31 ActivateSensor(coreClocks[i]);
5.32 }
5.33
5.34 + if (microarchitecture == Microarchitecture.SandyBridge) {
5.35 + uint eax, edx;
5.36 + if (Ring0.Rdmsr(MSR_RAPL_POWER_UNIT, out eax, out edx))
5.37 + energyUnitMultiplier = 1.0f / (1 << (int)((eax >> 8) & 0x1FF));
5.38 +
5.39 +
5.40 + if (energyUnitMultiplier != 0 &&
5.41 + Ring0.Rdmsr(MSR_PKG_ENERY_STATUS, out eax, out edx))
5.42 + {
5.43 + lastPackageTime = DateTime.UtcNow;
5.44 + lastPackageEnergyConsumed = eax;
5.45 + packagePower = new Sensor("CPU Package", 0, SensorType.Power, this,
5.46 + settings);
5.47 + ActivateSensor(packagePower);
5.48 + }
5.49 +
5.50 + if (energyUnitMultiplier != 0 &&
5.51 + Ring0.Rdmsr(MSR_PP0_ENERY_STATUS, out eax, out edx))
5.52 + {
5.53 + lastCoresTime = DateTime.UtcNow;
5.54 + lastCoresEnergyConsumed = eax;
5.55 + coresPower = new Sensor("CPU Cores", 1, SensorType.Power, this,
5.56 + settings);
5.57 + ActivateSensor(coresPower);
5.58 + }
5.59 + }
5.60 +
5.61 Update();
5.62 }
5.63
5.64 @@ -251,7 +291,10 @@
5.65 IA32_PERF_STATUS ,
5.66 IA32_THERM_STATUS_MSR,
5.67 IA32_TEMPERATURE_TARGET,
5.68 - IA32_PACKAGE_THERM_STATUS
5.69 + IA32_PACKAGE_THERM_STATUS,
5.70 + MSR_RAPL_POWER_UNIT,
5.71 + MSR_PKG_ENERY_STATUS,
5.72 + MSR_PP0_ENERY_STATUS
5.73 };
5.74 }
5.75
5.76 @@ -340,6 +383,37 @@
5.77 ActivateSensor(this.busClock);
5.78 }
5.79 }
5.80 +
5.81 +
5.82 + if (packagePower != null) {
5.83 + uint eax, edx;
5.84 + if (Ring0.Rdmsr(MSR_PKG_ENERY_STATUS, out eax, out edx)) {
5.85 + DateTime time = DateTime.UtcNow;
5.86 + uint energyConsumed = eax;
5.87 + float deltaTime = (float)(time - lastPackageTime).TotalSeconds;
5.88 + if (deltaTime > 0.01) {
5.89 + packagePower.Value = energyUnitMultiplier *
5.90 + unchecked(energyConsumed - lastPackageEnergyConsumed) / deltaTime;
5.91 + lastPackageTime = time;
5.92 + lastPackageEnergyConsumed = energyConsumed;
5.93 + }
5.94 + }
5.95 + }
5.96 +
5.97 + if (coresPower != null) {
5.98 + uint eax, edx;
5.99 + if (Ring0.Rdmsr(MSR_PP0_ENERY_STATUS, out eax, out edx)) {
5.100 + DateTime time = DateTime.UtcNow;
5.101 + uint energyConsumed = eax;
5.102 + float deltaTime = (float)(time - lastCoresTime).TotalSeconds;
5.103 + if (deltaTime > 0.01) {
5.104 + coresPower.Value = energyUnitMultiplier *
5.105 + unchecked(energyConsumed - lastCoresEnergyConsumed) / deltaTime;
5.106 + lastCoresTime = time;
5.107 + lastCoresEnergyConsumed = energyConsumed;
5.108 + }
5.109 + }
5.110 + }
5.111 }
5.112 }
5.113 }
6.1 --- a/Hardware/ISensor.cs Mon Jul 25 21:09:21 2011 +0000
6.2 +++ b/Hardware/ISensor.cs Wed Jul 27 18:27:16 2011 +0000
6.3 @@ -16,7 +16,7 @@
6.4
6.5 The Initial Developer of the Original Code is
6.6 Michael Möller <m.moeller@gmx.ch>.
6.7 - Portions created by the Initial Developer are Copyright (C) 2009-2010
6.8 + Portions created by the Initial Developer are Copyright (C) 2009-2011
6.9 the Initial Developer. All Rights Reserved.
6.10
6.11 Contributor(s):
6.12 @@ -49,7 +49,8 @@
6.13 Fan,
6.14 Flow,
6.15 Control,
6.16 - Level
6.17 + Level,
6.18 + Power
6.19 }
6.20
6.21 public struct SensorValue {
7.1 --- a/OpenHardwareMonitor.csproj Mon Jul 25 21:09:21 2011 +0000
7.2 +++ b/OpenHardwareMonitor.csproj Wed Jul 27 18:27:16 2011 +0000
7.3 @@ -217,6 +217,9 @@
7.4 <ItemGroup>
7.5 <EmbeddedResource Include="Resources\level.png" />
7.6 </ItemGroup>
7.7 + <ItemGroup>
7.8 + <EmbeddedResource Include="Resources\power.png" />
7.9 + </ItemGroup>
7.10 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
7.11 <ProjectExtensions>
7.12 <VisualStudio AllowExistingFolder="true" />
8.1 Binary file Resources/power.png has changed