GOSTCoin CUDA miner project, compatible with most nvidia cards, containing only gostd algo
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
3.6 KiB

/**
* Stats place holder
*
* Note: this source is C++ (requires std::map)
*
* tpruvot@github 2014
*/
#include <stdlib.h>
#include <memory.h>
#include <map>
#include "miner.h"
static std::map<uint64_t, stats_data> tlastscans;
static uint64_t uid = 0;
#define STATS_AVG_SAMPLES 30
#define STATS_PURGE_TIMEOUT 120*60 /* 120 mn */
extern uint64_t global_hashrate;
extern int opt_statsavg;
/**
* Store speed per thread
*/
void stats_remember_speed(int thr_id, uint32_t hashcount, double hashrate, uint8_t found, uint32_t height)
{
const uint64_t key = uid++;
stats_data data;
// to enough hashes to give right stats
if (hashcount < 1000 || hashrate < 0.01)
return;
// first hash rates are often erroneous
//if (uid < opt_n_threads * 2)
// return;
memset(&data, 0, sizeof(data));
data.uid = (uint32_t) uid;
data.gpu_id = (uint8_t) device_map[thr_id];
data.thr_id = (uint8_t) thr_id;
data.tm_stat = (uint32_t) time(NULL);
data.height = height;
multipool: Squashed commit (v2) commit a9d3c1ffdb71d2a4985749acba3d424161154ab4 Author: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Thu May 21 05:39:24 2015 +0200 multipool: last changes before squashed merge and fix net diff on wallets.. was longpoll specific commit a63f0024f3f1fb52d2c4369518bf87c33a9e16ae Author: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Thu May 21 05:02:27 2015 +0200 update api sample for the protocol 1.5 commit adda14b22edde6485932be56550166478f6f00dd Author: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Thu May 21 04:43:25 2015 +0200 stats: store pool number in scanlog commit e1a0274b01c29409ce16f9096b9985a35cf78ba7 Author: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Thu May 21 03:36:15 2015 +0200 api: switchpool and new pool stats variables (API v1.5) add accepted/rej by pool, wait time on conditional, net diff and rate also add scantime per pool config option and do some pool cleanup.. commit 1a30450ad2a5e068983531b9d2a96629b970c1e8 Author: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Wed May 20 06:39:09 2015 +0200 prevent concurrent pool switching and limit condtionnal wait messages to the first thread/device commit e3922c7a331a3ad2730bc83082fcd6b2547542f5 Author: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Wed May 20 05:39:45 2015 +0200 add some pool rotate options, like pool time-limit update sample pools.conf for time rotation commit 312bd905412d49fd5a9f9e7ff2bc72b23edf38ed Author: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Wed May 20 04:31:19 2015 +0200 do not try to restart threads from threads Start inconditionally the stratum and longpoll threads, these threads are just waiting a tq_push() if unused... so add some checks to know if vars are set for the right pool commit d4a9428fefdd9e9d70c3c8231f10961e7cd41760 Author: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Wed May 20 01:06:31 2015 +0200 pools: add name and removed attributes also increase max defined pools to 8 to be tested on windows.. commit d840d683ecb2cc4767f0a0612b8359c52d4bad29 Author: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Tue May 19 22:33:11 2015 +0200 parse json config file pools array commit d6c29b1f7f6b786c56e1f0cb8a90305f06cc7aec Author: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Tue May 19 03:29:30 2015 +0200 multi-pools: prepare storage/switch of credentials for the moment: - allow the storage of multiple -o params (and user/pass) - allow a failover pool on connection failed - switch to the next pool with the "seturl" api remote command - longpoll to stratum switch (reverse to check...) todo: mix stratum/getwork, new api commands, json config... commit 2d6b3fddf6631d7df1ac6ca74eee91c33a3c09ee Author: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Fri May 22 08:26:40 2015 +0200 multipool: increase stability, but not 100% perfect several problems fixed: - submit to the pool set in work (source pool) - longpoll curl timeout could be too high and could lock the switch - mutexes cant be copied on windows (stratum global var to fully remove later) I linked the -T timeout option to curl and tried to remove all fixed timeout values commit 6fd935c369cf33949dab98c8b09b2ca8cab3e7ea Author: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Fri May 22 11:23:07 2015 +0200 stratum: remove last rpc_ vars in stratum thread commit ee9c821525be303282e5dab512ffd2ae81ad524f Author: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Sat May 23 03:53:50 2015 +0200 stratum: do not alloc empty merkle tree commit 69852a2874bd18c4ed1daa9180a10d12976424dc Author: Tanguy Pruvot <tanguy.pruvot@gmail.com> Date: Sat May 23 04:25:12 2015 +0200 stratum: properly free jobs on disconnect Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
10 years ago
data.npool = (uint8_t) cur_pooln;
data.pool_type = pools[cur_pooln].type;
data.hashcount = hashcount;
data.hashfound = found;
data.hashrate = hashrate;
data.difficulty = net_diff ? net_diff : stratum_diff;
if (opt_n_threads == 1 && global_hashrate && uid > 10) {
// prevent stats on too high vardiff (erroneous rates)
double ratio = (hashrate / (1.0 * global_hashrate));
if (ratio < 0.4 || ratio > 1.6)
data.ignored = 1;
}
tlastscans[key] = data;
}
/**
* Get the computed average speed
* @param thr_id int (-1 for all threads)
*/
double stats_get_speed(int thr_id, double def_speed)
{
double speed = 0.0;
int records = 0;
std::map<uint64_t, stats_data>::reverse_iterator i = tlastscans.rbegin();
while (i != tlastscans.rend() && records < opt_statsavg) {
if (!i->second.ignored)
if (thr_id == -1 || i->second.thr_id == thr_id) {
if (i->second.hashcount > 1000) {
speed += i->second.hashrate;
records++;
// applog(LOG_BLUE, "%d %x %.1f", thr_id, i->second.thr_id, i->second.hashrate);
}
}
++i;
}
if (records)
speed /= (double)(records);
else
speed = def_speed;
if (thr_id == -1)
speed *= (double)(opt_n_threads);
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;
for (int thr_id=0; thr_id<opt_n_threads; thr_id++) {
int dev_id = device_map[thr_id];
if (gpu_id == -1 || dev_id == gpu_id)
speed += stats_get_speed(thr_id, 0.0);
}
return speed;
}
/**
* Export data for api calls
*/
int stats_get_history(int thr_id, struct stats_data *data, int max_records)
{
int records = 0;
std::map<uint64_t, stats_data>::reverse_iterator i = tlastscans.rbegin();
while (i != tlastscans.rend() && records < max_records) {
if (!i->second.ignored)
if (thr_id == -1 || i->second.thr_id == thr_id) {
memcpy(&data[records], &(i->second), sizeof(struct stats_data));
records++;
}
++i;
}
return records;
}
/**
* Remove old entries to reduce memory usage
*/
void stats_purge_old(void)
{
int deleted = 0;
uint32_t now = (uint32_t) time(NULL);
uint32_t sz = (uint32_t) tlastscans.size();
std::map<uint64_t, stats_data>::iterator i = tlastscans.begin();
while (i != tlastscans.end()) {
if (i->second.ignored || (now - i->second.tm_stat) > STATS_PURGE_TIMEOUT) {
deleted++;
tlastscans.erase(i++);
}
else ++i;
}
if (opt_debug && deleted) {
applog(LOG_DEBUG, "stats: %d/%d records purged", deleted, sz);
}
}
/**
* Reset the cache
*/
void stats_purge_all(void)
{
tlastscans.clear();
}
/**
* API meminfo
*/
void stats_getmeminfo(uint64_t *mem, uint32_t *records)
{
(*records) = (uint32_t) tlastscans.size();
(*mem) = (*records) * sizeof(stats_data);
}