diff --git a/src/gpu.cpp b/src/gpu.cpp index f046f20b..198b9656 100644 --- a/src/gpu.cpp +++ b/src/gpu.cpp @@ -51,6 +51,10 @@ void getNvidiaGpuInfo(const struct overlay_params& params){ gpu_info.is_power_throttled = (nvml_throttle_reasons & 0x000000000000008CLL) != 0; gpu_info.is_other_throttled = (nvml_throttle_reasons & 0x0000000000000112LL) != 0; } + static bool nvctrl_available = checkXNVCtrl(); + if (nvctrl_available) + gpu_info.fan_speed = getNvctrlFanSpeed(); + return; } #endif diff --git a/src/nvctrl.cpp b/src/nvctrl.cpp index 73c260f4..a3ca11e5 100644 --- a/src/nvctrl.cpp +++ b/src/nvctrl.cpp @@ -24,7 +24,7 @@ static bool find_nv_x11(libnvctrl_loader& nvctrl, Display*& dpy) snprintf(buf, sizeof(buf), ":%d", i); Display *d = g_x11->XOpenDisplay(buf); if (d) { - if (nvctrl.XNVCTRLIsNvScreen(d, 0)) { + if (nvctrl.XNVCTRLIsNvScreen(d, i)) { dpy = d; SPDLOG_DEBUG("XNVCtrl is using display {}", buf); return true; @@ -157,12 +157,17 @@ void getNvctrlInfo(){ &memused); nvctrl_info.memoryUsed = memused; + nvctrl_info.fan_speed = getNvctrlFanSpeed(); +} + +int64_t getNvctrlFanSpeed(){ + auto& nvctrl = get_libnvctrl_loader(); int64_t fan_speed = 0; nvctrl.XNVCTRLQueryTargetAttribute64(display.get(), - NV_CTRL_TARGET_TYPE_GPU, - 0, - 0, - NV_CTRL_THERMAL_COOLER_SPEED, - &fan_speed); - nvctrl_info.fan_speed = fan_speed; + NV_CTRL_TARGET_TYPE_COOLER, + 0, + 0, + NV_CTRL_THERMAL_COOLER_SPEED, + &fan_speed); + return fan_speed; } diff --git a/src/nvctrl.h b/src/nvctrl.h index 4326b604..2335a5a0 100644 --- a/src/nvctrl.h +++ b/src/nvctrl.h @@ -16,5 +16,6 @@ extern struct nvctrlInfo nvctrl_info; extern bool nvctrlSuccess; bool checkXNVCtrl(void); void getNvctrlInfo(void); +int64_t getNvctrlFanSpeed(); #endif //MANGOHUD_NVCTRL_H diff --git a/src/nvml.cpp b/src/nvml.cpp index 3e76e6fc..7bf3c03e 100644 --- a/src/nvml.cpp +++ b/src/nvml.cpp @@ -4,6 +4,7 @@ #include #include "overlay.h" #include "overlay_params.h" +#include "nvctrl.h" nvmlReturn_t result; nvmlDevice_t nvidiaDevice; @@ -57,9 +58,6 @@ bool getNVMLInfo(const struct overlay_params& params){ nvml.nvmlDeviceGetClockInfo(nvidiaDevice, NVML_CLOCK_GRAPHICS, &nvidiaCoreClock); nvml.nvmlDeviceGetClockInfo(nvidiaDevice, NVML_CLOCK_MEM, &nvidiaMemClock); nvml.nvmlDeviceGetPowerUsage(nvidiaDevice, &nvidiaPowerUsage); - nvml.nvmlUnitGetHandleByIndex(0, &nvidiaUnit); - nvml.nvmlUnitGetFanSpeedInfo(nvidiaUnit, &nvidiaFanSpeeds); - nvidiaFanSpeed = nvidiaFanSpeeds.fans[0].speed; deviceID = nvidiaPciInfo.pciDeviceId >> 16; if (params.enabled[OVERLAY_PARAM_ENABLED_throttling_status]) nvml.nvmlDeviceGetCurrentClocksThrottleReasons(nvidiaDevice, &nvml_throttle_reasons);