More checks for XNVCtrl support. Favor NVML but fallback to XNVCtrl if supported.

pull/109/head
jackun 4 years ago
parent b059fa26bc
commit fbae1dfcc0
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3

@ -8,13 +8,13 @@ pthread_t cpuThread, gpuThread, cpuInfoThread;
void *getNvidiaGpuInfo(void *){
if (nvmlSuccess){
getNvidiaInfo();
getNVMLInfo();
gpu_info.load = nvidiaUtilization.gpu;
gpu_info.temp = nvidiaTemp;
gpu_info.memoryUsed = nvidiaMemory.used / (1024.f * 1024.f * 1024.f);
gpu_info.CoreClock = nvidiaCoreClock;
gpu_info.MemClock = nvidiaMemClock;
} else {
} else if (nvctrlSuccess) {
getNvctrlInfo();
gpu_info.load = nvctrl_info.load;
gpu_info.temp = nvctrl_info.temp;

@ -29,6 +29,13 @@ bool libnvctrl_loader::Load(const std::string& library_name) {
if (!library_)
return false;
XNVCTRLIsNvScreen =
reinterpret_cast<decltype(this->XNVCTRLIsNvScreen)>(
dlsym(library_, "XNVCTRLIsNvScreen"));
if (!XNVCTRLIsNvScreen) {
CleanUp(true);
return false;
}
XNVCTRLQueryVersion =
reinterpret_cast<decltype(this->XNVCTRLQueryVersion)>(

@ -21,6 +21,7 @@ class libnvctrl_loader {
bool Load(const std::string& library_name);
bool IsLoaded() { return loaded_; }
decltype(&::XNVCTRLIsNvScreen) XNVCTRLIsNvScreen;
decltype(&::XNVCTRLQueryVersion) XNVCTRLQueryVersion;
decltype(&::XNVCTRLQueryAttribute) XNVCTRLQueryAttribute;
decltype(&::XNVCTRLQueryTargetStringAttribute) XNVCTRLQueryTargetStringAttribute;

@ -12,6 +12,16 @@ Display *display = XOpenDisplay(NULL);
libnvctrl_loader nvctrl("libXNVCtrl.so");
struct nvctrlInfo nvctrl_info;
bool nvctrlSuccess = false;
bool checkXNVCtrl()
{
if (nvctrl.IsLoaded()) {
nvctrlSuccess = nvctrl.XNVCTRLIsNvScreen(display, 0);
return nvctrlSuccess;
}
return false;
}
void parse_token(std::string token, string_map& options) {
std::string param, value;

@ -8,5 +8,7 @@ struct nvctrlInfo{
};
extern struct nvctrlInfo nvctrl_info;
extern bool nvctrlSuccess;
bool checkXNVCtrl(void);
void getNvctrlInfo(void);
char *get_attr_target_string(int attr, int target_type, int target_id);

@ -9,5 +9,5 @@ extern struct nvmlUtilization_st nvidiaUtilization;
extern struct nvmlMemory_st nvidiaMemory;
extern bool nvmlSuccess;
bool checkNvidia(void);
void getNvidiaInfo(void);
bool checkNVML(void);
void getNVMLInfo(void);

@ -10,7 +10,7 @@ unsigned int nvidiaTemp, nvidiaCoreClock, nvidiaMemClock;
struct nvmlUtilization_st nvidiaUtilization;
struct nvmlMemory_st nvidiaMemory {};
bool checkNvidia(){
bool checkNVML(){
if (nvml.IsLoaded()){
result = nvml.nvmlInit();
if (NVML_SUCCESS != result) {
@ -25,7 +25,7 @@ bool checkNvidia(){
return false;
}
void getNvidiaInfo(){
void getNVMLInfo(){
nvmlReturn_t response;
nvml.nvmlDeviceGetHandleByIndex(0, &nvidiaDevice);
response = nvml.nvmlDeviceGetUtilizationRates(nvidiaDevice, &nvidiaUtilization);
@ -33,6 +33,6 @@ void getNvidiaInfo(){
nvml.nvmlDeviceGetMemoryInfo(nvidiaDevice, &nvidiaMemory);
nvml.nvmlDeviceGetClockInfo(nvidiaDevice, NVML_CLOCK_GRAPHICS, &nvidiaCoreClock);
nvml.nvmlDeviceGetClockInfo(nvidiaDevice, NVML_CLOCK_MEM, &nvidiaMemClock);
if (response == 3)
if (response == NVML_ERROR_NOT_SUPPORTED)
nvmlSuccess = false;
}

@ -782,7 +782,14 @@ void init_gpu_stats(uint32_t& vendorID, overlay_params& params)
// NVIDIA or Intel but maybe has Optimus
if (vendorID == 0x8086
|| vendorID == 0x10de) {
if ((params.enabled[OVERLAY_PARAM_ENABLED_gpu_stats] = checkNvidia())) {
if (checkNVML())
getNVMLInfo();
if (!nvmlSuccess)
checkXNVCtrl();
if ((params.enabled[OVERLAY_PARAM_ENABLED_gpu_stats] = (nvmlSuccess || nvctrlSuccess))) {
vendorID = 0x10de;
}
}

Loading…
Cancel
Save