Skip to content

Commit

Permalink
use same functions for ati and nv
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-bl committed May 25, 2011
1 parent 6b7bc23 commit 0b392c6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
36 changes: 24 additions & 12 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,31 @@ void lock_fdust_devices(int *rdevs, int opmode) {


int _get_number_of_nvidia_devices() {
int ngpu;
char nvpath[PATH_MAX] = {0}; /* path to /dev/nvidiaX */
struct stat nvstat; /* stat struct */

for(ngpu=0;ngpu<MAX_GPUCOUNT;ngpu++) {
sprintf(nvpath, "/dev/nvidia%d", ngpu);
if(stat(nvpath,&nvstat) != 0)
break;
}
return ngpu;
return _get_number_of_sysfs_devices_whoa_this_function_name_is_too_long("/sys/bus/pci/drivers/nvidia");
}

int _get_number_of_ati_devices() {
printf("NOT IMPLEMENTED\n");
exit(1);
return _get_number_of_sysfs_devices_whoa_this_function_name_is_too_long("/sys/bus/pci/drivers/fglrx_pci");
}

int _get_number_of_sysfs_devices_whoa_this_function_name_is_too_long(char *path) {

DIR *dfh;
struct dirent *dent;
int ngpu = 0;

dfh = opendir(path);
if(dfh != NULL) {
for(;;) {
dent = readdir(dfh);
if(dent == NULL)
break;

if(dent->d_type == DT_LNK && strlen(dent->d_name) == 12 && strncmp("0000:", dent->d_name, 5)==0)
ngpu++;
}
closedir(dfh);
}
printf("> %s: returning %d\n", __func__, ngpu);
return ngpu;
}
2 changes: 2 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <dirent.h>

/* max. number of supported GPUs per system */
#define MAX_GPUCOUNT 256
Expand Down Expand Up @@ -54,3 +55,4 @@ const char *__fdust_mode();
void lock_fdust_devices(int *rdevs, int opmode);
int _get_number_of_nvidia_devices();
int _get_number_of_ati_devices();
int _get_number_of_sysfs_devices_whoa_this_function_name_is_too_long(char *path);

0 comments on commit 0b392c6

Please sign in to comment.