Attempt to query number of coolers before fan_speed. Inspiration: https://github.com/NVIDIA/nvidia-settings/blob/main/samples/nv-control-targets.c

mangoconfig
Self Denial 8 months ago committed by flightlessmango
parent 10c0f608fd
commit 10e5abcccc

@ -80,6 +80,14 @@ bool libnvctrl_loader::Load(const std::string& library_name) {
return false;
}
XNVCTRLQueryTargetCount =
reinterpret_cast<decltype(this->XNVCTRLQueryTargetCount)>(
dlsym(library_, "XNVCTRLQueryTargetCount"));
if (!XNVCTRLQueryTargetCount) {
CleanUp(true);
return false;
}
#endif
#if defined(LIBRARY_LOADER_NVCTRL_H_DT_NEEDED)

@ -24,6 +24,7 @@ class libnvctrl_loader {
decltype(&::XNVCTRLQueryAttribute) XNVCTRLQueryAttribute;
decltype(&::XNVCTRLQueryTargetStringAttribute) XNVCTRLQueryTargetStringAttribute;
decltype(&::XNVCTRLQueryTargetAttribute64) XNVCTRLQueryTargetAttribute64;
decltype(&::XNVCTRLQueryTargetCount) XNVCTRLQueryTargetCount;
private:
void CleanUp(bool unload);

@ -164,6 +164,19 @@ void getNvctrlInfo(){
int64_t getNvctrlFanSpeed(){
auto& nvctrl = get_libnvctrl_loader();
int64_t fan_speed = 0;
/* Get the number of Cooler devices in the system */
int num_coolers;
bool ret = nvctrl.XNVCTRLQueryTargetCount(display.get(),
NV_CTRL_TARGET_TYPE_COOLER,
&num_coolers);
if (!ret) {
SPDLOG_ERROR("XNVCtrl Failed to query number of Coolers");
} else {
SPDLOG_DEBUG("XNVCtrl number of Cooler Devices: {}", num_coolers);
if (num_coolers <= 0) {
return fan_speed;
}
}
nvctrl.XNVCTRLQueryTargetAttribute64(display.get(),
NV_CTRL_TARGET_TYPE_COOLER,
0,

Loading…
Cancel
Save