Skip to content

Commit

Permalink
api: add gpu pci bus id, unified id + bloc height
Browse files Browse the repository at this point in the history
  • Loading branch information
tpruvot committed Nov 18, 2014
1 parent 17cf376 commit b24b65a
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 9 deletions.
11 changes: 6 additions & 5 deletions api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ static void gpustatus(int thr_id)

#ifdef USE_WRAPNVML
cgpu->has_monitoring = true;
cgpu->gpu_bus = gpu_busid(cgpu);
cgpu->gpu_temp = gpu_temp(cgpu);
cgpu->gpu_fan = gpu_fanpercent(cgpu);
cgpu->gpu_pstate = gpu_pstate(cgpu);
Expand Down Expand Up @@ -154,9 +155,9 @@ static void gpustatus(int thr_id)

card = device_name[gpuid];

snprintf(buf, sizeof(buf), "THR=%d;GPU=%d;CARD=%s;TEMP=%.1f;FAN=%d;"
snprintf(buf, sizeof(buf), "GPU=%d;BUS=%d;CARD=%s;TEMP=%.1f;FAN=%d;"
"FREQ=%d;PST=%s;KHS=%.2f;HWF=%d;I=%d|",
thr_id, gpuid, card, cgpu->gpu_temp, cgpu->gpu_fan,
gpuid, cgpu->gpu_bus, card, cgpu->gpu_temp, cgpu->gpu_fan,
cgpu->gpu_clock, pstate, cgpu->khashes,
cgpu->hw_errors, cgpu->intensity);

Expand Down Expand Up @@ -207,16 +208,16 @@ static char *getthreads(char *params)
*/
static char *gethistory(char *params)
{
struct stats_data data[20];
struct stats_data data[50];
int thrid = params ? atoi(params) : -1;
char *p = buffer;
*buffer = '\0';
int records = stats_get_history(thrid, data, ARRAY_SIZE(data));
for (int i = 0; i < records; i++) {
time_t ts = data[i].tm_stat;
p += sprintf(p, "THR=%d|GPU=%d;KHS=%.2f;DIFF=%.6f;"
p += sprintf(p, "GPU=%d;H=%u;KHS=%.2f;DIFF=%.6f;"
"COUNT=%u;FOUND=%u;TS=%u|",
data[i].thr_id, data[i].gpu_id, data[i].hashrate, data[i].difficulty,
data[i].gpu_id, data[i].height, data[i].hashrate, data[i].difficulty,
data[i].hashcount, data[i].hashfound, (uint32_t)ts);
}
return buffer;
Expand Down
3 changes: 2 additions & 1 deletion api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function getdataFromPears()
function ignoreField($key)
{
$ignored = array(
'API','VER','THR','GPU',
'API','VER','GPU','BUS',
'CARD','GPUS','CPU','TS',
);
return in_array($key, $ignored);
Expand All @@ -50,6 +50,7 @@ function translateField($key)
$intl['UPTIME'] = 'Miner up time';
$intl['TS'] = 'Last update';

$intl['H'] = 'Bloc height';
$intl['I'] = 'Intensity';

$intl['TEMP'] = 'T°c';
Expand Down
2 changes: 1 addition & 1 deletion ccminer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ static void *miner_thread(void *userdata)
if (rc > 1)
thr_hashrates[thr_id] = (rc * hashes_done) / (diff.tv_sec + 1e-6 * diff.tv_usec);
thr_hashrates[thr_id] *= rate_factor;
stats_remember_speed(thr_id, hashes_done, thr_hashrates[thr_id], (uint8_t) rc);
stats_remember_speed(thr_id, hashes_done, thr_hashrates[thr_id], (uint8_t) rc, work.height);
}
pthread_mutex_unlock(&stats_lock);
}
Expand Down
4 changes: 3 additions & 1 deletion miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ struct cgpu_info {
double khashes;
uint8_t intensity;
uint8_t has_monitoring;
int gpu_bus;
float gpu_temp;
int gpu_fan;
int gpu_clock;
Expand Down Expand Up @@ -534,6 +535,7 @@ struct work {
struct stats_data {
uint32_t tm_stat;
uint32_t hashcount;
uint32_t height;
double difficulty;
double hashrate;
uint8_t thr_id;
Expand Down Expand Up @@ -562,7 +564,7 @@ void hashlog_purge_all(void);
void hashlog_dump_job(char* jobid);
void hashlog_getmeminfo(uint64_t *mem, uint32_t *records);

void stats_remember_speed(int thr_id, uint32_t hashcount, double hashrate, uint8_t found);
void stats_remember_speed(int thr_id, uint32_t hashcount, double hashrate, uint8_t found, uint32_t height);
double stats_get_speed(int thr_id, double def_speed);
int stats_get_history(int thr_id, struct stats_data *data, int max_records);
void stats_purge_old(void);
Expand Down
35 changes: 35 additions & 0 deletions nvml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,16 @@ int wrap_nvml_get_pstate(wrap_nvml_handle *nvmlh, int cudaindex, int *pstate)
return 0;
}

int wrap_nvml_get_busid(wrap_nvml_handle *nvmlh, int cudaindex, int *busid)
{
int gpuindex = nvmlh->cuda_nvml_device_id[cudaindex];
if (gpuindex < 0 || gpuindex >= nvmlh->nvml_gpucount)
return -1;

(*busid) = nvmlh->nvml_pci_bus_id[gpuindex];
return 0;
}

int wrap_nvml_destroy(wrap_nvml_handle *nvmlh)
{
nvmlh->nvmlShutdown();
Expand Down Expand Up @@ -445,6 +455,15 @@ int nvapi_getpstate(unsigned int devNum, unsigned int *power)
return 0;
}

int nvapi_getbusid(unsigned int devNum, int *busid)
{
if (devNum >= 0 && devNum <= 8) {
(*busid) = device_bus_ids[devNum];
return 0;
}
return -1;
}

int wrap_nvapi_init()
{
NvAPI_Status ret = NvAPI_Initialize();
Expand Down Expand Up @@ -578,6 +597,22 @@ int gpu_pstate(struct cgpu_info *gpu)
return pstate;
}

int gpu_busid(struct cgpu_info *gpu)
{
int busid = -1;
int support = -1;
if (hnvml) {
support = wrap_nvml_get_busid(hnvml, device_map[gpu->thr_id], &busid);
}
#ifdef WIN32
if (support == -1) {
nvapi_getbusid(nvapi_dev_map[gpu->gpu_id], &busid);
}
#endif
return busid;
}


unsigned int gpu_power(struct cgpu_info *gpu)
{
unsigned int mw = 0;
Expand Down
1 change: 1 addition & 0 deletions nvml.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ float gpu_temp(struct cgpu_info *gpu);
int gpu_clock(struct cgpu_info *gpu);
unsigned int gpu_power(struct cgpu_info *gpu);
int gpu_pstate(struct cgpu_info *gpu);
int gpu_busid(struct cgpu_info *gpu);

#if defined(__cplusplus)
}
Expand Down
3 changes: 2 additions & 1 deletion stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extern int device_map[8];
/**
* Store speed per thread (todo: compute vardiff ?)
*/
void stats_remember_speed(int thr_id, uint32_t hashcount, double hashrate, uint8_t found)
void stats_remember_speed(int thr_id, uint32_t hashcount, double hashrate, uint8_t found, uint32_t height)
{
uint64_t gpu = device_map[thr_id];
uint64_t key = (gpu << 56) + (uid++ % UINT32_MAX);
Expand All @@ -42,6 +42,7 @@ void stats_remember_speed(int thr_id, uint32_t hashcount, double hashrate, uint8
data.gpu_id = (uint8_t)gpu;
data.thr_id = (uint8_t)thr_id;
data.tm_stat = (uint32_t) time(NULL);
data.height = height;
data.hashcount = hashcount;
data.hashfound = found;
data.hashrate = hashrate;
Expand Down

0 comments on commit b24b65a

Please sign in to comment.