I finally found a way to query my GPU for getting RPM fan values.
I made reverse engineering over the psensor source code and I wrote this simple C code snippet to get the RPM value of a specific fan of the GPU (passing 0 or 1 as identifier to the binary).
Here is my get_GPU_fan_RPM_values.c script:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <X11/Xlib.h>
#include <NVCtrl/NVCtrl.h>
#include <NVCtrl/NVCtrlLib.h>
static Display *display;
static double get_att(int target, int id, int att)
{
Bool res;
int temp;
res = XNVCTRLQueryTargetAttribute(display, target, id, 0, att, &temp);
if (res == True)
return temp;
return -1;
}
void nvidia_cleanup(void)
{
if (display) {
XCloseDisplay(display);
display = NULL;
}
}
bool isFanId(char number[])
{
int i = 0;
if (number[0] == '-')
return false;
for (; number[i] != 0; i++)
{
if (number[i] > '1' || number[i] < '0')
return false;
}
return true;
}
int main(int argc, char** argv) {
if ( !(argc == 2) ) return 1;
if ( !isFanId(argv[1]) ) return 1;
int fanId = atoi(argv[1]);
display = XOpenDisplay(NULL);
if (!display) {
printf("Cannot open connection to X11 server\n");
nvidia_cleanup();
return 1;
}
int evt, err;
if (!XNVCTRLQueryExtension(display, &evt, &err)) {
printf("XNVCTRLQueryExtension error %d (evt %d)\n", err, evt);
nvidia_cleanup();
return 1;
}
printf("%d\n", (int)get_att(NV_CTRL_TARGET_TYPE_COOLER, 1, NV_CTRL_THERMAL_COOLER_SPEED));
//printf("fan %d: %d RPM\n", fanId, (int)get_att(NV_CTRL_TARGET_TYPE_COOLER, 1, NV_CTRL_THERMAL_COOLER_SPEED));
nvidia_cleanup();
return 0;
}
Compile it with:
Code:
gcc -o get_GPU_fan_RPM_values get_GPU_fan_RPM_values.c -lX11 -lXNVCtrl
Execute it like this:
Code:
./get_GPU_fan_RPM_values 0
or
Code:
./get_GPU_fan_RPM_values 1
Bookmarks