Fixed a NullReferenceException in the AMD17CPU.Update method.

This commit is contained in:
Michael Möller 2020-02-25 19:11:55 +01:00
parent f659204b5c
commit 59bd626aef

View File

@ -111,10 +111,9 @@ namespace OpenHardwareMonitor.Hardware.CPU {
"CPU Package", 0, SensorType.Power, this, settings); "CPU Package", 0, SensorType.Power, this, settings);
ActivateSensor(packagePowerSensor); ActivateSensor(packagePowerSensor);
} }
}
coresPowerSensor = new Sensor("CPU Cores", 1, SensorType.Power, this, coresPowerSensor = new Sensor("CPU Cores", 1, SensorType.Power, this,
settings); settings);
}
busClock = new Sensor("Bus Speed", 0, SensorType.Clock, this, settings); busClock = new Sensor("Bus Speed", 0, SensorType.Clock, this, settings);
timeStampCounterMultiplier = GetTimeStampCounterMultiplier(); timeStampCounterMultiplier = GetTimeStampCounterMultiplier();
@ -236,8 +235,9 @@ namespace OpenHardwareMonitor.Hardware.CPU {
ActivateSensor(ccdAvgTemperature); ActivateSensor(ccdAvgTemperature);
} }
if (Ring0.Rdmsr(MSR_PKG_ENERGY_STAT, out uint energyConsumed, out _)) { if (energyUnitMultiplier != 0 &&
Ring0.Rdmsr(MSR_PKG_ENERGY_STAT, out uint energyConsumed, out _))
{
DateTime time = DateTime.UtcNow; DateTime time = DateTime.UtcNow;
float deltaTime = (float)(time - lastEnergyTime).TotalSeconds; float deltaTime = (float)(time - lastEnergyTime).TotalSeconds;
if (deltaTime > 0.01) { if (deltaTime > 0.01) {
@ -319,6 +319,7 @@ namespace OpenHardwareMonitor.Hardware.CPU {
multiplier = GetMultiplier(); multiplier = GetMultiplier();
ThreadAffinity.Set(mask); ThreadAffinity.Set(mask);
if (cpu.energyUnitMultiplier != 0) {
float deltaTime = (float)(energyTime - lastEnergyTime).TotalSeconds; float deltaTime = (float)(energyTime - lastEnergyTime).TotalSeconds;
if (deltaTime > 0.01) { if (deltaTime > 0.01) {
power = cpu.energyUnitMultiplier * power = cpu.energyUnitMultiplier *
@ -327,6 +328,7 @@ namespace OpenHardwareMonitor.Hardware.CPU {
lastEnergyTime = energyTime; lastEnergyTime = energyTime;
lastEnergyConsumed = energyConsumed; lastEnergyConsumed = energyConsumed;
} }
}
if (multiplier.HasValue) { if (multiplier.HasValue) {
float? clock = (float?)(multiplier * cpu.busClock.Value); float? clock = (float?)(multiplier * cpu.busClock.Value);