|
|
#1 | |
|
Registered User
Join Date: Feb 2011
Posts: 3
|
I would like to obtain the GPU temperature for the Quadro FX 1800 through C code in Linux. The constraint that I have is that I can't use libraries that are GPL licensed.
What I know so far: * I notice that there is an NVAPI dll for Windows, but I haven't seen an equivalent for Linux. * I also notice that nvidia-settings uses a library called libXNVCtrl in order to query the driver for the GPU temperature, but libXNVCtrl is GPL licensed, so I can't use it in my code. * I also have a constraint that I can't fork another process that runs the command for nvidia-settings, and then pipe the data from the output of nvidia-settings to the process that is running my code. Is there another way (much like in Windows) to obtain the GPU temperature without linking in the libXNVCtrl GPL library into my code? Thanks for your help, Sandra |
|
|
|
|
|
|
#2 | |
|
Registered User
Join Date: Feb 2011
Posts: 3
|
Also one more thing I thought about - a different way to pose the problem, I suppose: Is it possible to get the GPU info from the sysfs or something like that, since the nvidia X driver (nv-settings talks to it) has to be giving this info from somewhere, right?
I've been able to find the device entry in sysfs using lspci, now just what (if anything) can I do with this sort of information? I've seen something (briefly) on accessing pci memory, but I'm not sure if this the direction I should take if I'm looking for the GPU temperature (by not using libXNVCtrl). Thanks for your help, Sandra |
|
|
|
|
|
|
#3 | |
|
Linux kernel hacker
Join Date: Feb 2009
Location: Ottawa, Canada
Posts: 173
|
One way to avoid linking with unwanted libraries is to use the vendor provided binary to read the temperature. Eg, like this:
Code:
/* Free code sample by Mark Lord */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
int nv_get_temperature (int *temperature)
{
int err = EIO;
char token[32];
FILE *fp = popen("nvidia-smi -q -g 0", "r");
if (fp == NULL) {
err = errno;
perror("nvidia-smi");
return err;
}
while (1 == fscanf(fp, " %31s ", token)) {
if (0 == strcmp(token, "Temperature")) {
if (1 == fscanf(fp, " : %4s C", token)) {
*temperature = atoi(token);
err = 0; /* success */
break;
}
}
}
fclose(fp);
if (err)
fprintf(stderr, "nvidia-smi did not report the temperature\n");
return err;
}
int main (void)
{
int err, temperature;
err = nv_get_temperature(&temperature);
if (!err)
printf("Temperature: %d C\n", temperature);
return err;
}
Quote:
|
|
|
|
|
|
|
#4 | |
|
Linux kernel hacker
Join Date: Feb 2009
Location: Ottawa, Canada
Posts: 173
|
If you really want to artificially constrain things and live very dangerously, then just "strace nvdia-smi" and then mimic the exact same ioctl() calls that it does, using the exact same parameters. No libraries or forks required, and the code will break the next time NVIDIA updates the ioctl() interface they use.
Cheers |
|
|
|
|
|
|
#5 |
|
Registered User
Join Date: Feb 2011
Posts: 3
|
Thank you for your reply, mlord! This strace (I'm sure you can tell I'm a Linux n00b
) will be quite useful for me for another project! I got a hold of nVidia support and was told that libXNVCtrl is actually under MIT license! Initially, I had thought that it was under GPL, since the package descriptions for it (i.e Fedora) said that it was GPL (and plus the GPL notice in nvidia-settings source code). So, for anyone who has been pulling his/her hair out for days trying to figure this out - here it is. ![]() (Thanks to Mike from nVidia Support...wherever you are.) |
|
|
|
|
|
#6 | |
|
NVIDIA Corporation
Join Date: Mar 2005
Posts: 2,487
|
Yeah, sorry about that. libXNVCtrl and nvidia-settings sources live in the same package but are under different licenses, confusing everybody. I've been meaning to split libXNVCtrl out into its own package, but so far just pointing out that it's X11-licensed has been easier.
![]() |
|
|
|
|
![]() |
| Thread Tools | |
|
|