nvml: fan: get rpm instead of percentage

pull/1001/head
FlightlessMango 1 year ago
parent 238a621c11
commit 1093de8c44

@ -45,7 +45,7 @@ void getNvidiaGpuInfo(const struct overlay_params& params){
gpu_info.MemClock = nvidiaMemClock; gpu_info.MemClock = nvidiaMemClock;
gpu_info.powerUsage = nvidiaPowerUsage / 1000; gpu_info.powerUsage = nvidiaPowerUsage / 1000;
gpu_info.memoryTotal = nvidiaMemory.total / (1024.f * 1024.f * 1024.f); gpu_info.memoryTotal = nvidiaMemory.total / (1024.f * 1024.f * 1024.f);
gpu_info.fan_speed = NvidiaFanSpeed; gpu_info.fan_speed = nvidiaFanSpeed;
if (params.enabled[OVERLAY_PARAM_ENABLED_throttling_status]){ if (params.enabled[OVERLAY_PARAM_ENABLED_throttling_status]){
gpu_info.is_temp_throttled = (nvml_throttle_reasons & 0x0000000000000060LL) != 0; gpu_info.is_temp_throttled = (nvml_throttle_reasons & 0x0000000000000060LL) != 0;
gpu_info.is_power_throttled = (nvml_throttle_reasons & 0x000000000000008CLL) != 0; gpu_info.is_power_throttled = (nvml_throttle_reasons & 0x000000000000008CLL) != 0;

@ -215,14 +215,27 @@ bool libnvml_loader::Load(const std::string& library_name) {
} }
#if defined(LIBRARY_LOADER_NVML_H_DLOPEN) #if defined(LIBRARY_LOADER_NVML_H_DLOPEN)
nvmlDeviceGetFanSpeed = nvmlUnitGetFanSpeedInfo =
reinterpret_cast<decltype(this->nvmlDeviceGetFanSpeed)>( reinterpret_cast<decltype(this->nvmlUnitGetFanSpeedInfo)>(
dlsym(library_, "nvmlDeviceGetPowerUsage")); dlsym(library_, "nvmlUnitGetFanSpeedInfo"));
#endif
#if defined(LIBRARY_LOADER_NVML_H_DT_NEEDED)
nvmlUnitGetFanSpeedInfo = &::nvmlUnitGetFanSpeedInfo;
#endif
if (!nvmlUnitGetFanSpeedInfo) {
CleanUp(true);
return false;
}
#if defined(LIBRARY_LOADER_NVML_H_DLOPEN)
nvmlUnitGetHandleByIndex =
reinterpret_cast<decltype(this->nvmlUnitGetHandleByIndex)>(
dlsym(library_, "nvmlUnitGetHandleByIndex"));
#endif #endif
#if defined(LIBRARY_LOADER_NVML_H_DT_NEEDED) #if defined(LIBRARY_LOADER_NVML_H_DT_NEEDED)
nvmlDeviceGetFanSpeed = &::nvmlDeviceGetFanSpeed; nvmlUnitGetHandleByIndex = &::nvmlUnitGetHandleByIndex;
#endif #endif
if (!nvmlDeviceGetFanSpeed) { if (!nvmlUnitGetHandleByIndex) {
CleanUp(true); CleanUp(true);
return false; return false;
} }
@ -249,5 +262,6 @@ void libnvml_loader::CleanUp(bool unload) {
nvmlDeviceGetHandleByIndex_v2 = NULL; nvmlDeviceGetHandleByIndex_v2 = NULL;
nvmlDeviceGetHandleByPciBusId_v2 = NULL; nvmlDeviceGetHandleByPciBusId_v2 = NULL;
nvmlDeviceGetCurrentClocksThrottleReasons = NULL; nvmlDeviceGetCurrentClocksThrottleReasons = NULL;
nvmlDeviceGetFanSpeed = NULL; nvmlUnitGetFanSpeedInfo = NULL;
nvmlUnitGetHandleByIndex = NULL;
} }

@ -38,8 +38,9 @@ class libnvml_loader {
decltype(&::nvmlErrorString) nvmlErrorString; decltype(&::nvmlErrorString) nvmlErrorString;
decltype(&::nvmlDeviceGetPowerUsage) nvmlDeviceGetPowerUsage; decltype(&::nvmlDeviceGetPowerUsage) nvmlDeviceGetPowerUsage;
decltype(&::nvmlDeviceGetCurrentClocksThrottleReasons) nvmlDeviceGetCurrentClocksThrottleReasons; decltype(&::nvmlDeviceGetCurrentClocksThrottleReasons) nvmlDeviceGetCurrentClocksThrottleReasons;
decltype(&::nvmlDeviceGetFanSpeed) nvmlDeviceGetFanSpeed; decltype(&::nvmlUnitGetFanSpeedInfo) nvmlUnitGetFanSpeedInfo;
decltype(&::nvmlUnitGetHandleByIndex) nvmlUnitGetHandleByIndex;
private: private:
void CleanUp(bool unload); void CleanUp(bool unload);

@ -6,7 +6,7 @@
#include "overlay_params.h" #include "overlay_params.h"
extern nvmlReturn_t result; extern nvmlReturn_t result;
extern unsigned int nvidiaTemp, processSamplesCount, *vgpuInstanceSamplesCount, nvidiaCoreClock, nvidiaMemClock, nvidiaPowerUsage, NvidiaFanSpeed; extern unsigned int nvidiaTemp, processSamplesCount, *vgpuInstanceSamplesCount, nvidiaCoreClock, nvidiaMemClock, nvidiaPowerUsage, nvidiaFanSpeed;
extern nvmlDevice_t nvidiaDevice; extern nvmlDevice_t nvidiaDevice;
extern struct nvmlUtilization_st nvidiaUtilization; extern struct nvmlUtilization_st nvidiaUtilization;
extern struct nvmlMemory_st nvidiaMemory; extern struct nvmlMemory_st nvidiaMemory;

@ -9,10 +9,12 @@ nvmlReturn_t result;
nvmlDevice_t nvidiaDevice; nvmlDevice_t nvidiaDevice;
nvmlPciInfo_t nvidiaPciInfo; nvmlPciInfo_t nvidiaPciInfo;
bool nvmlSuccess = false; bool nvmlSuccess = false;
unsigned int nvidiaTemp = 0, nvidiaCoreClock = 0, nvidiaMemClock = 0, nvidiaPowerUsage = 0, NvidiaFanSpeed = 0; unsigned int nvidiaTemp = 0, nvidiaCoreClock = 0, nvidiaMemClock = 0, nvidiaPowerUsage = 0, nvidiaFanSpeed = 0;
unsigned long long nvml_throttle_reasons; unsigned long long nvml_throttle_reasons;
struct nvmlUtilization_st nvidiaUtilization; struct nvmlUtilization_st nvidiaUtilization;
struct nvmlMemory_st nvidiaMemory {}; struct nvmlMemory_st nvidiaMemory {};
struct nvmlUnitFanSpeeds_st nvidiaFanSpeeds {};
struct nvmlUnit_st* nvidiaUnit {};
bool checkNVML(const char* pciBusId){ bool checkNVML(const char* pciBusId){
auto& nvml = get_libnvml_loader(); auto& nvml = get_libnvml_loader();
@ -55,7 +57,9 @@ bool getNVMLInfo(const struct overlay_params& params){
nvml.nvmlDeviceGetClockInfo(nvidiaDevice, NVML_CLOCK_GRAPHICS, &nvidiaCoreClock); nvml.nvmlDeviceGetClockInfo(nvidiaDevice, NVML_CLOCK_GRAPHICS, &nvidiaCoreClock);
nvml.nvmlDeviceGetClockInfo(nvidiaDevice, NVML_CLOCK_MEM, &nvidiaMemClock); nvml.nvmlDeviceGetClockInfo(nvidiaDevice, NVML_CLOCK_MEM, &nvidiaMemClock);
nvml.nvmlDeviceGetPowerUsage(nvidiaDevice, &nvidiaPowerUsage); nvml.nvmlDeviceGetPowerUsage(nvidiaDevice, &nvidiaPowerUsage);
nvml.nvmlDeviceGetFanSpeed(nvidiaDevice, &NvidiaFanSpeed); nvml.nvmlUnitGetHandleByIndex(0, &nvidiaUnit);
nvml.nvmlUnitGetFanSpeedInfo(nvidiaUnit, &nvidiaFanSpeeds);
nvidiaFanSpeed = nvidiaFanSpeeds.fans[0].speed;
deviceID = nvidiaPciInfo.pciDeviceId >> 16; deviceID = nvidiaPciInfo.pciDeviceId >> 16;
if (params.enabled[OVERLAY_PARAM_ENABLED_throttling_status]) if (params.enabled[OVERLAY_PARAM_ENABLED_throttling_status])
nvml.nvmlDeviceGetCurrentClocksThrottleReasons(nvidiaDevice, &nvml_throttle_reasons); nvml.nvmlDeviceGetCurrentClocksThrottleReasons(nvidiaDevice, &nvml_throttle_reasons);

Loading…
Cancel
Save