api: add device uuid (nvml), and OS in hwinfo

move nvdriver to sys infos (unique on system)

prepare pool query
This commit is contained in:
Tanguy Pruvot 2014-11-24 21:07:38 +01:00
parent dc5d1b112d
commit 3e8457d76c
4 changed files with 105 additions and 41 deletions

43
api.cpp
View File

@ -207,6 +207,16 @@ static char *getsummary(char *params)
return buffer;
}
/**
* Returns current pool infos
*/
static char *getpoolnfo(char *params)
{
char *p = buffer;
*p = '\0';
return p;
}
/*****************************************************************************/
static void gpuhwinfos(int gpu_id)
@ -233,7 +243,6 @@ static void gpuhwinfos(int gpu_id)
cgpu->gpu_fan = gpu_fanpercent(cgpu);
cgpu->gpu_pstate = gpu_pstate(cgpu);
gpu_info(cgpu);
gpu_nvids(cgpu);
#endif
gpu_clocks(cgpu);
@ -246,19 +255,28 @@ static void gpuhwinfos(int gpu_id)
snprintf(buf, sizeof(buf), "GPU=%d;BUS=%hd;CARD=%s;MEM=%lu;"
"TEMP=%.1f;FAN=%d;FREQ=%d;MEMFREQ=%d;PST=%s;"
"VID=%hx;PID=%hx;NVML=%d;NVAPI=%d;DRIVER=%s;BIOS=%s|",
"VID=%hx;PID=%hx;NVML=%d;NVAPI=%d;SN=%s;BIOS=%s|",
gpu_id, cgpu->gpu_bus, card, cgpu->gpu_mem,
cgpu->gpu_temp, cgpu->gpu_fan, cgpu->gpu_clock, cgpu->gpu_memclock,
pstate, cgpu->gpu_vid, cgpu->gpu_pid, cgpu->nvml_id, cgpu->nvapi_id,
driver_version, cgpu->gpu_desc);
cgpu->gpu_sn, cgpu->gpu_desc);
strcat(buffer, buf);
}
static const char* os_name()
{
#ifdef WIN32
return "windows";
#else
return "linux";
#endif
}
/**
* CPU Infos
* System and CPU Infos
*/
static void cpuhwinfos()
static void syshwinfos()
{
char buf[256];
@ -266,8 +284,8 @@ static void cpuhwinfos()
uint32_t clock = cpu_clock(0);
memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), "CPUS=%d;TEMP=%.1f;FREQ=%d|",
num_cpus, temp, clock);
snprintf(buf, sizeof(buf), "OS=%s;NVDRIVER=%s;CPUS=%d;CPUTEMP=%.1f;CPUFREQ=%d|",
os_name(), driver_version, num_cpus, temp, clock);
strcat(buffer, buf);
}
@ -279,10 +297,12 @@ static char *gethwinfos(char *params)
*buffer = '\0';
for (int i = 0; i < cuda_num_devices(); i++)
gpuhwinfos(i);
cpuhwinfos();
syshwinfos();
return buffer;
}
/*****************************************************************************/
/**
* Returns the last 50 scans stats
* optional param thread id (default all)
@ -342,6 +362,8 @@ static char *getmeminfo(char *params)
return buffer;
}
/*****************************************************************************/
static char *gethelp(char *params);
struct CMDS {
const char *name;
@ -349,10 +371,11 @@ struct CMDS {
} cmds[] = {
{ "summary", getsummary },
{ "threads", getthreads },
{ "pool", getpoolnfo },
{ "histo", gethistory },
{ "scanlog", getscanlog },
{ "meminfo", getmeminfo },
{ "hwinfo", gethwinfos },
{ "meminfo", getmeminfo },
{ "scanlog", getscanlog },
/* keep it the last */
{ "help", gethelp },
};

View File

@ -391,6 +391,7 @@ struct cgpu_info {
int8_t nvml_id;
int8_t nvapi_id;
char gpu_sn[64];
char gpu_desc[64];
};

View File

@ -137,6 +137,8 @@ wrap_nvml_handle * wrap_nvml_create()
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetFanSpeed");
nvmlh->nvmlDeviceGetPerformanceState = (wrap_nvmlReturn_t (*)(wrap_nvmlDevice_t, int *))
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetPowerUsage");
nvmlh->nvmlDeviceGetSerial = (wrap_nvmlReturn_t (*)(wrap_nvmlDevice_t, char *, unsigned int))
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetSerial");
nvmlh->nvmlDeviceGetUUID = (wrap_nvmlReturn_t (*)(wrap_nvmlDevice_t, char *, unsigned int))
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetUUID");
nvmlh->nvmlDeviceGetVbiosVersion = (wrap_nvmlReturn_t (*)(wrap_nvmlDevice_t, char *, unsigned int))
@ -332,33 +334,48 @@ int wrap_nvml_get_busid(wrap_nvml_handle *nvmlh, int cudaindex, int *busid)
return 0;
}
int wrap_nvml_get_desc(wrap_nvml_handle *nvmlh, int cudaindex, char *desc, int maxlen)
int wrap_nvml_get_serial(wrap_nvml_handle *nvmlh, int cudaindex, char *sn, int maxlen)
{
uint32_t subids = 0;
char uuid[NVML_DEVICE_UUID_BUFFER_SIZE];
int gpuindex = nvmlh->cuda_nvml_device_id[cudaindex];
wrap_nvmlReturn_t res;
if (gpuindex < 0 || gpuindex >= nvmlh->nvml_gpucount)
return -1;
res = nvmlh->nvmlDeviceGetSerial(nvmlh->devs[gpuindex], sn, maxlen);
if (res == WRAPNVML_SUCCESS) {
return 0;
}
// nvmlDeviceGetUUID: GPU-f2bd642c-369f-5a14-e0b4-0d22dfe9a1fc
// use a part of uuid to generate an unique serial
// todo: check if there is vendor id is inside
memset(uuid, 0, sizeof(uuid));
res = nvmlh->nvmlDeviceGetUUID(nvmlh->devs[gpuindex], uuid, sizeof(uuid)-1);
if (res != WRAPNVML_SUCCESS) {
if (opt_debug)
applog(LOG_DEBUG, "nvmlDeviceGetUUID: %s", nvmlh->nvmlErrorString(res));
return -1;
}
strncpy(sn, &uuid[4], min((int) strlen(uuid), maxlen));
sn[maxlen-1] = '\0';
return 0;
}
int wrap_nvml_get_bios(wrap_nvml_handle *nvmlh, int cudaindex, char *desc, int maxlen)
{
uint32_t subids = 0;
int gpuindex = nvmlh->cuda_nvml_device_id[cudaindex];
if (gpuindex < 0 || gpuindex >= nvmlh->nvml_gpucount)
return -1;
#if 0
// todo: check if there is vendor id is inside
// nvmlDeviceGetUUID: GPU-f2bd642c-369f-5a14-e0b4-0d22dfe9a1fc
wrap_nvmlReturn_t res = nvmlh->nvmlDeviceGetUUID(nvmlh->devs[gpuindex], desc, maxlen);
if (res != WRAPNVML_SUCCESS) {
if (opt_debug)
applog(LOG_DEBUG, "nvmlDeviceGetUUID: %s", nvmlh->nvmlErrorString(res));
} else {
applog(LOG_DEBUG, "nvml Device UUID: %s", desc);
}
#endif
wrap_nvmlReturn_t res = nvmlh->nvmlDeviceGetVbiosVersion(nvmlh->devs[gpuindex], desc, maxlen);
if (res != WRAPNVML_SUCCESS) {
if (opt_debug)
applog(LOG_DEBUG, "nvmlDeviceGetVbiosVersion: %s", nvmlh->nvmlErrorString(res));
return -1;
}
applog(LOG_DEBUG, "nvmlDeviceGetVbiosVersion: %s", desc);
return 0;
}
@ -523,7 +540,31 @@ int nvapi_getinfo(unsigned int devNum, uint16_t *vid, uint16_t *pid)
return 0;
}
int nvapi_getdesc(unsigned int devNum, char *desc, unsigned int maxlen)
int nvapi_getserial(unsigned int devNum, char *serial, unsigned int maxlen)
{
// NvAPI_Status ret;
if (devNum >= nvapi_dev_cnt)
return -1;
sprintf(serial, "");
if (maxlen < 64) // Short String
return -1;
#if 0
ret = NvAPI_GPU_Get..(phys[devNum], serial);
if (ret != NVAPI_OK) {
NvAPI_ShortString string;
NvAPI_GetErrorMessage(ret, string);
if (opt_debug)
applog(LOG_DEBUG, "NVAPI ...: %s", string);
return -1;
}
#endif
return 0;
}
int nvapi_getbios(unsigned int devNum, char *desc, unsigned int maxlen)
{
NvAPI_Status ret;
if (devNum >= nvapi_dev_cnt)
@ -704,19 +745,6 @@ unsigned int gpu_power(struct cgpu_info *gpu)
}
int gpu_info(struct cgpu_info *gpu)
{
if (hnvml) {
wrap_nvml_get_info(hnvml, gpu->gpu_id, &gpu->gpu_vid, &gpu->gpu_pid);
wrap_nvml_get_desc(hnvml, gpu->gpu_id, gpu->gpu_desc, sizeof(gpu->gpu_desc));
}
#ifdef WIN32
nvapi_getinfo(nvapi_dev_map[gpu->gpu_id], &gpu->gpu_vid, &gpu->gpu_pid);
nvapi_getdesc(nvapi_dev_map[gpu->gpu_id], gpu->gpu_desc, sizeof(gpu->gpu_desc));
#endif
return 0;
}
int gpu_nvids(struct cgpu_info *gpu)
{
int id = gpu->gpu_id;
@ -726,10 +754,17 @@ int gpu_nvids(struct cgpu_info *gpu)
if (id < 0)
return -1;
if (hnvml && id < hnvml->nvml_gpucount)
if (hnvml) {
gpu->nvml_id = (int8_t) hnvml->cuda_nvml_device_id[id];
wrap_nvml_get_info(hnvml, id, &gpu->gpu_vid, &gpu->gpu_pid);
wrap_nvml_get_serial(hnvml, id, gpu->gpu_sn, sizeof(gpu->gpu_sn));
wrap_nvml_get_bios(hnvml, id, gpu->gpu_desc, sizeof(gpu->gpu_desc));
}
#ifdef WIN32
gpu->nvapi_id = (int8_t) nvapi_dev_map[id];
nvapi_getinfo(nvapi_dev_map[id], &gpu->gpu_vid, &gpu->gpu_pid);
nvapi_getserial(nvapi_dev_map[id], gpu->gpu_sn, sizeof(gpu->gpu_sn));
nvapi_getbios(nvapi_dev_map[id], gpu->gpu_desc, sizeof(gpu->gpu_desc));
#endif
return 0;
}

7
nvml.h
View File

@ -45,6 +45,10 @@ NVML_CLOCK_SM = 1,
NVML_CLOCK_MEM = 2
} wrap_nvmlClockType_t;
#define NVML_DEVICE_SERIAL_BUFFER_SIZE 30
#define NVML_DEVICE_UUID_BUFFER_SIZE 80
#define NVML_DEVICE_VBIOS_VERSION_BUFFER_SIZE 32
/*
* Handle to hold the function pointers for the entry points we need,
* and the shared library itself.
@ -71,6 +75,7 @@ typedef struct {
wrap_nvmlReturn_t (*nvmlDeviceGetFanSpeed)(wrap_nvmlDevice_t, unsigned int *);
wrap_nvmlReturn_t (*nvmlDeviceGetPerformanceState)(wrap_nvmlDevice_t, int *); /* enum */
wrap_nvmlReturn_t (*nvmlDeviceGetPowerUsage)(wrap_nvmlDevice_t, unsigned int *);
wrap_nvmlReturn_t (*nvmlDeviceGetSerial)(wrap_nvmlDevice_t, char *serial, unsigned int len);
wrap_nvmlReturn_t (*nvmlDeviceGetUUID)(wrap_nvmlDevice_t, char *uuid, unsigned int len);
wrap_nvmlReturn_t (*nvmlDeviceGetVbiosVersion)(wrap_nvmlDevice_t, char *version, unsigned int len);
wrap_nvmlReturn_t (*nvmlSystemGetDriverVersion)(char *version, unsigned int len);
@ -143,7 +148,7 @@ unsigned int gpu_usage(struct cgpu_info *gpu);
int gpu_pstate(struct cgpu_info *gpu);
int gpu_busid(struct cgpu_info *gpu);
int gpu_nvids(struct cgpu_info *gpu);
/* pid/vid, sn and bios rev */
int gpu_info(struct cgpu_info *gpu);
#endif