From ff27ccb80eac07b2c9641faae175fff5147458fe Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 12 May 2015 02:32:05 +0200 Subject: [PATCH] stats: simplify the storage filter the gpu id key filter was useless, use thread ids... --- api.cpp | 2 +- miner.h | 1 + stats.cpp | 33 ++++++++++++++++++++++++--------- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/api.cpp b/api.cpp index cdce35c..5df7121 100644 --- a/api.cpp +++ b/api.cpp @@ -130,7 +130,7 @@ static void gpustatus(int thr_id) cgpu->accepted = accepted_count; cgpu->rejected = rejected_count; - cgpu->khashes = stats_get_speed(cgpu->gpu_id, 0.0) / 1000.0; + cgpu->khashes = stats_get_speed(thr_id, 0.0) / 1000.0; card = device_name[gpuid]; diff --git a/miner.h b/miner.h index 5a93947..b75dc62 100644 --- a/miner.h +++ b/miner.h @@ -635,6 +635,7 @@ void hashlog_getmeminfo(uint64_t *mem, uint32_t *records); 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); +double stats_get_gpu_speed(int gpu_id); int stats_get_history(int thr_id, struct stats_data *data, int max_records); void stats_purge_old(void); void stats_purge_all(void); diff --git a/stats.cpp b/stats.cpp index f5a2d82..090c19b 100644 --- a/stats.cpp +++ b/stats.cpp @@ -25,8 +25,7 @@ extern int opt_statsavg; */ void stats_remember_speed(int thr_id, uint32_t hashcount, double hashrate, uint8_t found, uint32_t height) { - const uint8_t gpu = (uint8_t) device_map[thr_id]; - const uint64_t key = ((uid++ % UINT32_MAX) << 32) + gpu; + const uint64_t key = uid++; stats_data data; // to enough hashes to give right stats if (hashcount < 1000 || hashrate < 0.01) @@ -38,7 +37,7 @@ void stats_remember_speed(int thr_id, uint32_t hashcount, double hashrate, uint8 memset(&data, 0, sizeof(data)); data.uid = (uint32_t) uid; - data.gpu_id = gpu; + data.gpu_id = device_map[thr_id]; data.thr_id = (uint8_t)thr_id; data.tm_stat = (uint32_t) time(NULL); data.height = height; @@ -61,15 +60,13 @@ void stats_remember_speed(int thr_id, uint32_t hashcount, double hashrate, uint8 */ double stats_get_speed(int thr_id, double def_speed) { - const uint64_t gpu = device_map[thr_id]; - const uint64_t keymsk = 0xffULL; // last u8 is the gpu double speed = 0.0; int records = 0; std::map::reverse_iterator i = tlastscans.rbegin(); while (i != tlastscans.rend() && records < opt_statsavg) { if (!i->second.ignored) - if (thr_id == -1 || (keymsk & i->first) == gpu) { + if (thr_id == -1 || i->second.thr_id == thr_id) { if (i->second.hashcount > 1000) { speed += i->second.hashrate; records++; @@ -90,19 +87,37 @@ double stats_get_speed(int thr_id, double def_speed) return speed; } +/** + * Get the gpu average speed + * @param gpu_id int (-1 for all threads) + */ +double stats_get_gpu_speed(int gpu_id) +{ + double speed = 0.0; + double speeds[MAX_GPUS] = { 0 }; + int records[MAX_GPUS] = { 0 }; + int count = 0; + + for (int thr_id=0; thr_id::reverse_iterator i = tlastscans.rbegin(); while (i != tlastscans.rend() && records < max_records) { if (!i->second.ignored) - if (thr_id == -1 || (keymsk & i->first) == gpu) { + if (thr_id == -1 || i->second.thr_id == thr_id) { memcpy(&data[records], &(i->second), sizeof(struct stats_data)); records++; }