public override void Update() { if (sensorConfig.GetSensorEvaluate(totalLoad.IdentifierString) || sensorConfig.GetSensorEvaluate(maxLoad.IdentifierString) || coreLoads.Any(sensor => sensorConfig.GetSensorEvaluate(sensor.IdentifierString))) { if (HasTimeStampCounter && isInvariantTimeStampCounter) { // make sure always the same thread is used var previousAffinity = ThreadAffinity.Set(cpuid[0][0].Affinity); // read time before and after getting the TSC to estimate the error long firstTime = Stopwatch.GetTimestamp(); ulong timeStampCount = Opcode.Rdtsc(); long time = Stopwatch.GetTimestamp(); // restore the thread affinity mask ThreadAffinity.Set(previousAffinity); double delta = ((double)(time - lastTime)) / Stopwatch.Frequency; double error = ((double)(time - firstTime)) / Stopwatch.Frequency; // only use data if they are measured accuarte enough (max 0.1ms delay) if (error < 1E-04) { // ignore the first reading because there are no initial values // ignore readings with too large or too small time window if (lastTime != 0 && delta > 0.5 && delta < 2) { // update the TSC frequency with the new value TimeStampCounterFrequency = (timeStampCount - lastTimeStampCount) / (1e6 * delta); } lastTimeStampCount = timeStampCount; lastTime = time; } } } if (cpuLoad.IsAvailable) { cpuLoad.Update(); for (int i = 0; i < coreLoads.Length; i++) { coreLoads[i].Value = cpuLoad.GetCoreLoad(i); } if (totalLoad != null) { totalLoad.Value = cpuLoad.GetTotalLoad(); } if (maxLoad != null) { maxLoad.Value = cpuLoad.GetMaxLoad(); } } }
public override void Update() { base.Update(); if (coreTemperatures.Any(temps => sensorConfig.GetSensorEvaluate(temps.IdentifierString))) { if (Ring0.WaitPciBusMutex(10)) { if (miscellaneousControlAddress != Ring0.InvalidPciAddress) { for (uint i = 0; i < coreTemperatures.Length; i++) { if (Ring0.WritePciConfig( miscellaneousControlAddress, THERMTRIP_STATUS_REGISTER, i > 0 ? thermSenseCoreSelCPU1 : thermSenseCoreSelCPU0)) { if (Ring0.ReadPciConfig( miscellaneousControlAddress, THERMTRIP_STATUS_REGISTER, out uint value)) { coreTemperatures[i].Value = ((value >> 16) & 0xFF) + coreTemperatures[i].Parameters[0].Value; ActivateSensor(coreTemperatures[i]); } else { DeactivateSensor(coreTemperatures[i]); } } } } Ring0.ReleasePciBusMutex(); } } if (coreClocks.Any(clocks => sensorConfig.GetSensorEvaluate(clocks.IdentifierString)) || sensorConfig.GetSensorEvaluate(coreMaxClocks.IdentifierString) || sensorConfig.GetSensorEvaluate(busClock.IdentifierString)) { if (HasTimeStampCounter) { double newBusClock = 0; for (int i = 0; i < coreClocks.Length; i++) { Thread.Sleep(1); if (Ring0.RdmsrTx(FIDVID_STATUS, out uint eax, out uint edx, cpuid[i][0].Affinity))
public override void Update() { NativeMethods.MemoryStatusEx status = new NativeMethods.MemoryStatusEx { Length = checked ((uint)Marshal.SizeOf( typeof(NativeMethods.MemoryStatusEx))) }; if (sensorConfig.GetSensorEvaluate(usedMemory.IdentifierString) || sensorConfig.GetSensorEvaluate(availableMemory.IdentifierString) || sensorConfig.GetSensorEvaluate(loadSensor.IdentifierString)) { if (!NativeMethods.GlobalMemoryStatusEx(ref status)) { return; } loadSensor.Value = 100.0f - (100.0f * status.AvailablePhysicalMemory) / status.TotalPhysicalMemory; usedMemory.Value = (status.TotalPhysicalMemory - status.AvailablePhysicalMemory) / SCALE; availableMemory.Value = status.AvailablePhysicalMemory / SCALE; } if (sensorConfig.GetSensorEvaluate(usedMemoryProcess.IdentifierString)) { lock (_performanceCounterLock) { usedMemoryProcess.Value = ramUsageGamePerformanceCounter != null ? ramUsageGamePerformanceCounter.NextValue() / SCALE : 0f; } } if (sensorConfig.GetSensorEvaluate(usedMemoryAndCacheProcess.IdentifierString)) { lock (_performanceCounterLock) { usedMemoryAndCacheProcess.Value = ramAndCacheUsageGamePerformanceCounter != null ? ramAndCacheUsageGamePerformanceCounter.NextValue() / SCALE : 0f; } } }
private void GetODNTemperature(ADLODNTemperatureType type, Sensor sensor) { bool eval = sensorConfig.GetSensorEvaluate(sensor.IdentifierString); if (eval && (ADL.ADL2_OverdriveN_Temperature_Get(context, adapterIndex, type, out int temperature) == ADL.ADL_OK)) { if (temperature >= 1E03) { sensor.Value = 1E-03f * temperature; } else { sensor.Value = temperature; } if (sensor.Value != 0) { ActivateSensor(sensor); } } else { sensor.Value = null; } }
public override void Update() { if (temperatures.Any(sensor => sensorConfig.GetSensorEvaluate(sensor.IdentifierString))) { NvGPUThermalSettings settings = GetThermalSettings(); foreach (Sensor sensor in temperatures) { sensor.Value = settings.Sensor[sensor.Index].CurrentTemp; } } else { foreach (Sensor sensor in temperatures) { sensor.Value = null; } } bool tachReadingOk = false; if (sensorConfig.GetSensorEvaluate(fan.IdentifierString)) { if (NVAPI.NvAPI_GPU_GetTachReading != null && NVAPI.NvAPI_GPU_GetTachReading(handle, out int fanValue) == NvStatus.OK) { fan.Value = fanValue; ActivateSensor(fan); tachReadingOk = true; } } else { fan.Value = null; } if (clocks.Any(sensor => sensorConfig.GetSensorEvaluate(sensor.IdentifierString))) { uint[] values = GetClocks(); if (values != null) { clocks[1].Value = 0.001f * values[8]; if (values[30] != 0) { clocks[0].Value = 0.0005f * values[30]; clocks[2].Value = 0.001f * values[30]; } else { clocks[0].Value = 0.001f * values[0]; clocks[2].Value = 0.001f * values[14]; } } } else { for (int i = 0; i < clocks.Length; i++) { clocks[i].Value = null; } } if (sensorConfig.GetSensorEvaluate(voltage.IdentifierString)) { var gpuVoltageStatus = new NvGpuVoltageStatus { Version = NVAPI.GPU_VOLTAGE_STATUS_VER, Unknown2 = new uint[8], Unknown3 = new uint[8] }; if (NVAPI.NvAPI_GPU_GetCurrentVoltage != null && NVAPI.NvAPI_GPU_GetCurrentVoltage(handle, ref gpuVoltageStatus) == NvStatus.OK) { voltage.Value = gpuVoltageStatus.ValueInuV / 1E06f; ActivateSensor(voltage); } } else { voltage.Value = null; } if (loads.Any(sensor => sensorConfig.GetSensorEvaluate(sensor.IdentifierString))) { var infoEx = new NvDynamicPstatesInfoEx { Version = NVAPI.GPU_DYNAMIC_PSTATES_INFO_EX_VER, UtilizationDomains = new NvUtilizationDomainEx[NVAPI.NVAPI_MAX_GPU_UTILIZATIONS] }; if (NVAPI.NvAPI_GPU_GetDynamicPstatesInfoEx != null && NVAPI.NvAPI_GPU_GetDynamicPstatesInfoEx(handle, ref infoEx) == NvStatus.OK) { for (int i = 0; i < loads.Length; i++) { if (infoEx.UtilizationDomains[i].Present) { loads[i].Value = infoEx.UtilizationDomains[i].Percentage; ActivateSensor(loads[i]); } } } else { var info = new NvDynamicPstatesInfo { Version = NVAPI.GPU_DYNAMIC_PSTATES_INFO_VER, UtilizationDomains = new NvUtilizationDomain[NVAPI.NVAPI_MAX_GPU_UTILIZATIONS] }; if (NVAPI.NvAPI_GPU_GetDynamicPstatesInfo != null && NVAPI.NvAPI_GPU_GetDynamicPstatesInfo(handle, ref info) == NvStatus.OK) { for (int i = 0; i < loads.Length; i++) { if (info.UtilizationDomains[i].Present) { loads[i].Value = info.UtilizationDomains[i].Percentage; ActivateSensor(loads[i]); } } } } } else { for (int i = 0; i < loads.Length; i++) { loads[i].Value = null; } } if (sensorConfig.GetSensorEvaluate(control.IdentifierString) || sensorConfig.GetSensorEvaluate(fan.IdentifierString)) { var coolerSettings = GetCoolerSettings(); var coolerSettingsOk = false; if (coolerSettings.Count > 0) { control.Value = coolerSettings.Cooler[0].CurrentLevel; ActivateSensor(control); coolerSettingsOk = true; } if (!tachReadingOk || !coolerSettingsOk) { var coolersStatus = GetFanCoolersStatus(); if (coolersStatus.Count > 0) { if (!coolerSettingsOk) { control.Value = coolersStatus.Items[0].CurrentLevel; ActivateSensor(control); coolerSettingsOk = true; } if (!tachReadingOk) { fan.Value = coolersStatus.Items[0].CurrentRpm; ActivateSensor(fan); tachReadingOk = true; } } } } else { control.Value = null; fan.Value = null; } if (!(!sensorConfig.GetSensorEvaluate(memoryAvail.IdentifierString) && !sensorConfig.GetSensorEvaluate(memoryUsed.IdentifierString) && !sensorConfig.GetSensorEvaluate(memoryFree.IdentifierString) && !sensorConfig.GetSensorEvaluate(memoryLoad.IdentifierString))) { NvDisplayDriverMemoryInfo memoryInfo = new NvDisplayDriverMemoryInfo { Version = NVAPI.DISPLAY_DRIVER_MEMORY_INFO_VER, Values = new uint[NVAPI.MAX_MEMORY_VALUES_PER_GPU] }; if (NVAPI.NvAPI_GetDisplayDriverMemoryInfo != null && displayHandle.HasValue && NVAPI.NvAPI_GetDisplayDriverMemoryInfo(displayHandle.Value, ref memoryInfo) == NvStatus.OK) { uint totalMemory = memoryInfo.Values[0]; uint freeMemory = memoryInfo.Values[4]; float usedMemory = Math.Max(totalMemory - freeMemory, 0); memoryFree.Value = (float)freeMemory / 1024 / 1024; memoryAvail.Value = (float)totalMemory / 1024 / 1024; memoryUsed.Value = usedMemory / 1024 / 1024; memoryLoad.Value = 100f * usedMemory / totalMemory; ActivateSensor(memoryAvail); ActivateSensor(memoryUsed); ActivateSensor(memoryFree); ActivateSensor(memoryLoad); } } else { memoryAvail.Value = null; memoryUsed.Value = null; memoryFree.Value = null; memoryLoad.Value = null; } if (power != null) { if (sensorConfig.GetSensorEvaluate(power.IdentifierString)) { var channels = new NvGpuPowerMonitorPowerChannelStatus[NVAPI.POWER_STATUS_CHANNEL_COUNT]; for (int i = 0; i < channels.Length; i++) { channels[i].Rsvd = new byte[NVAPI.POWER_STATUS_RSVD_SIZE]; } var powerStatus = new NvGpuPowerStatus { Version = NVAPI.GPU_POWER_MONITOR_STATUS_VER, Rsvd = new byte[NVAPI.POWER_STATUS_RSVD_SIZE], Channels = channels }; if (NVAPI.NvAPI_GPU_PowerMonitorGetStatus != null && NVAPI.NvAPI_GPU_PowerMonitorGetStatus(handle, ref powerStatus) == NvStatus.OK) { power.Value = powerStatus.TotalGpuPowermW * 1E-03f; ActivateSensor(power); } } else { power.Value = null; } } // update VRAM usage if (dedicatedVramUsagePerformCounter != null) { try { if (sensorConfig.GetSensorEvaluate(memoryUsageDedicated.IdentifierString)) { memoryUsageDedicated.Value = dedicatedVramUsagePerformCounter.NextValue() / SCALE; ActivateSensor(memoryUsageDedicated); } else { memoryUsageDedicated.Value = null; } } catch { memoryUsageDedicated.Value = null; } } if (sharedVramUsagePerformCounter != null) { try { if (sensorConfig.GetSensorEvaluate(memoryUsageShared.IdentifierString)) { memoryUsageShared.Value = (float)sharedVramUsagePerformCounter.NextValue() / SCALE; ActivateSensor(memoryUsageShared); } else { memoryUsageShared.Value = null; } } catch { memoryUsageShared.Value = null; } } try { if (sensorConfig.GetSensorEvaluate(processMemoryUsageDedicated.IdentifierString)) { lock (_performanceCounterLock) { processMemoryUsageDedicated.Value = dedicatedVramUsageProcessPerformCounter == null ? 0f : (float)dedicatedVramUsageProcessPerformCounter.NextValue() / SCALE; } ActivateSensor(processMemoryUsageDedicated); } else { processMemoryUsageDedicated.Value = null; } } catch { processMemoryUsageDedicated.Value = null; } try { if (sensorConfig.GetSensorEvaluate(processMemoryUsageShared.IdentifierString)) { lock (_performanceCounterLock) { processMemoryUsageShared.Value = sharedVramUsageProcessPerformCounter == null ? 0f : (float)sharedVramUsageProcessPerformCounter.NextValue() / SCALE; } ActivateSensor(processMemoryUsageShared); } else { processMemoryUsageShared.Value = null; } } catch { processMemoryUsageShared.Value = null; } if (pcieThroughputRx != null) { if (sensorConfig.GetSensorEvaluate(pcieThroughputRx.IdentifierString)) { if (NVML.NvmlDeviceGetPcieThroughput(device.Value, NVML.NvmlPcieUtilCounter.RxBytes, out uint value) == NVML.NvmlReturn.Success) { pcieThroughputRx.Value = value / 1024f; ActivateSensor(pcieThroughputRx); } } else { pcieThroughputRx.Value = null; } } if (pcieThroughputTx != null) { if (sensorConfig.GetSensorEvaluate(pcieThroughputTx.IdentifierString)) { if (NVML.NvmlDeviceGetPcieThroughput(device.Value, NVML.NvmlPcieUtilCounter.TxBytes, out uint value) == NVML.NvmlReturn.Success) { pcieThroughputTx.Value = value / 1024f; ActivateSensor(pcieThroughputTx); } } else { pcieThroughputTx.Value = null; } } if (sensorConfig.GetSensorEvaluate(monitorRefreshRate.IdentifierString)) { if (NVAPI.NvAPI_GetVBlankCounter(displayHandle.Value, out uint pCounter) == NvStatus.OK) { var deltaTicks = stopwatch.ElapsedTicks; stopwatch.Restart(); lock (_displayLock) { var currentRefreshRate = (float)(pCounter - lastpCounter) / deltaTicks * Stopwatch.Frequency; refreshRateBuffer.Add(currentRefreshRate); var refreshRateFiltered = (float)Math.Ceiling(refreshRateBuffer.RefreshRates.Average()); monitorRefreshRate.Value = refreshRateFiltered > refreshRateCurrentWindowHandle ? refreshRateCurrentWindowHandle : refreshRateFiltered; } lastpCounter = pCounter; ActivateSensor(monitorRefreshRate); } } else { monitorRefreshRate.Value = null; } }
public override void Update() { base.Update(); if (sensorConfig.GetSensorEvaluate(coreTemperature.IdentifierString)) { if (temperatureStream == null) { if (miscellaneousControlAddress != Ring0.InvalidPciAddress) { uint value; bool valueValid; if (hasSmuTemperatureRegister) { valueValid = ReadSmuRegister(SMU_REPORTED_TEMP_CONTROL_REGISTER, out value); } else { valueValid = Ring0.ReadPciConfig(miscellaneousControlAddress, REPORTED_TEMPERATURE_CONTROL_REGISTER, out value); } if (valueValid) { if ((family == 0x15 || family == 0x16) && (value & 0x30000) == 0x30000) { coreTemperature.Value = ((value >> 21) & 0x7FF) * 0.125f + coreTemperature.Parameters[0].Value - 49; } else { coreTemperature.Value = ((value >> 21) & 0x7FF) * 0.125f + coreTemperature.Parameters[0].Value; } ActivateSensor(coreTemperature); } else { DeactivateSensor(coreTemperature); } } } else { string s = ReadFirstLine(temperatureStream); try { coreTemperature.Value = 0.001f * long.Parse(s, CultureInfo.InvariantCulture); ActivateSensor(coreTemperature); } catch { DeactivateSensor(coreTemperature); } } } if (coreClocks.Any(clock => sensorConfig.GetSensorEvaluate(clock.IdentifierString)) || sensorConfig.GetSensorEvaluate(coreMaxClocks.IdentifierString) || sensorConfig.GetSensorEvaluate(busClock.IdentifierString)) { if (HasTimeStampCounter) { double newBusClock = 0; for (int i = 0; i < coreClocks.Length; i++) { Thread.Sleep(1); if (Ring0.RdmsrTx(COFVID_STATUS, out uint curEax, out uint curEdx, cpuid[i][0].Affinity))