Skip to content

Commit

Permalink
Add support for VID sensors per core on Intel CPUs (#741)
Browse files Browse the repository at this point in the history
* Add support for VID sensors per core on Intel CPUs

* Remove pointless variable assignment
  • Loading branch information
EMN-CSharp committed May 12, 2022
1 parent d83ad41 commit eed7742
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions LibreHardwareMonitorLib/Hardware/Cpu/IntelCpu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ internal sealed class IntelCpu : GenericCpu
private readonly Sensor _coreMax;
private readonly Sensor[] _coreTemperatures;
private readonly Sensor _coreVoltage;
private readonly Sensor[] _coreVIDs;
private readonly Sensor[] _distToTjMaxTemperatures;

private readonly uint[] _energyStatusMsrs = { MSR_PKG_ENERY_STATUS, MSR_PP0_ENERY_STATUS, MSR_PP1_ENERY_STATUS, MSR_DRAM_ENERGY_STATUS };
private readonly uint[] _energyStatusMsrs = { MSR_PKG_ENERGY_STATUS, MSR_PP0_ENERGY_STATUS, MSR_PP1_ENERGY_STATUS, MSR_DRAM_ENERGY_STATUS };
private readonly float _energyUnitMultiplier;
private readonly uint[] _lastEnergyConsumed;
private readonly DateTime[] _lastEnergyTime;
Expand All @@ -36,6 +37,7 @@ internal sealed class IntelCpu : GenericCpu
public IntelCpu(int processorIndex, CpuId[][] cpuId, ISettings settings) : base(processorIndex, cpuId, settings)
{
uint eax;
uint edx;

// set tjMax
float[] tjMax;
Expand Down Expand Up @@ -240,7 +242,7 @@ public IntelCpu(int processorIndex, CpuId[][] cpuId, ISettings settings) : base(
case MicroArchitecture.Core:
case MicroArchitecture.NetBurst:
{
if (Ring0.ReadMsr(IA32_PERF_STATUS, out uint _, out uint edx))
if (Ring0.ReadMsr(IA32_PERF_STATUS, out uint _, out edx))
{
_timeStampCounterMultiplier = ((edx >> 8) & 0x1f) + 0.5 * ((edx >> 14) & 1);
}
Expand Down Expand Up @@ -429,6 +431,13 @@ public IntelCpu(int processorIndex, CpuId[][] cpuId, ISettings settings) : base(
ActivateSensor(_coreVoltage);
}

_coreVIDs = new Sensor[_coreCount];
for (int i = 0; i < _coreVIDs.Length; i++)
{
_coreVIDs[i] = new Sensor(CoreString(i), i + 1, SensorType.Voltage, this, settings);
ActivateSensor(_coreVIDs[i]);
}

Update();
}

Expand Down Expand Up @@ -465,10 +474,10 @@ protected override uint[] GetMsrs()
IA32_TEMPERATURE_TARGET,
IA32_PACKAGE_THERM_STATUS,
MSR_RAPL_POWER_UNIT,
MSR_PKG_ENERY_STATUS,
MSR_PKG_ENERGY_STATUS,
MSR_DRAM_ENERGY_STATUS,
MSR_PP0_ENERY_STATUS,
MSR_PP1_ENERY_STATUS
MSR_PP0_ENERGY_STATUS,
MSR_PP1_ENERGY_STATUS
};
}

Expand All @@ -491,6 +500,7 @@ public override void Update()
float coreMax = float.MinValue;
float coreAvg = 0;
uint eax = 0;
uint edx;

for (int i = 0; i < _coreTemperatures.Length; i++)
{
Expand Down Expand Up @@ -627,9 +637,22 @@ public override void Update()
}
}

if (_coreVoltage != null && Ring0.ReadMsr(IA32_PERF_STATUS, out eax, out uint _))
if (_coreVoltage != null && Ring0.ReadMsr(IA32_PERF_STATUS, out _, out edx))
{
_coreVoltage.Value = ((edx >> 32) & 0xFFFF) / (float)(1 << 13);
}

for (int i = 0; i < _coreVIDs.Length; i++)
{
_coreVoltage.Value = ((eax >> 32) & 0xFFFF) / (float)(1 << 13);
if (Ring0.ReadMsr(IA32_PERF_STATUS, out _, out edx, _cpuId[i][0].Affinity) && ((edx >> 32) & 0xFFFF) > 0)
{
_coreVIDs[i].Value = ((edx >> 32) & 0xFFFF) / (float)(1 << 13);
ActivateSensor(_coreVIDs[i]);
}
else
{
DeactivateSensor(_coreVIDs[i]);
}
}
}

Expand Down Expand Up @@ -668,10 +691,10 @@ private enum MicroArchitecture
private const uint IA32_THERM_STATUS_MSR = 0x019C;

private const uint MSR_DRAM_ENERGY_STATUS = 0x619;
private const uint MSR_PKG_ENERY_STATUS = 0x611;
private const uint MSR_PKG_ENERGY_STATUS = 0x611;
private const uint MSR_PLATFORM_INFO = 0xCE;
private const uint MSR_PP0_ENERY_STATUS = 0x639;
private const uint MSR_PP1_ENERY_STATUS = 0x641;
private const uint MSR_PP0_ENERGY_STATUS = 0x639;
private const uint MSR_PP1_ENERGY_STATUS = 0x641;

private const uint MSR_RAPL_POWER_UNIT = 0x606;
// ReSharper restore InconsistentNaming
Expand Down

0 comments on commit eed7742

Please sign in to comment.