From a58ef1b8c7bbe4a03d0351fe739ea4f48532bf46 Mon Sep 17 00:00:00 2001 From: ckolivas Date: Fri, 24 Jan 2014 15:38:53 +1100 Subject: [PATCH] Provide a helper function for determining dev runtime and use it in the hashmeters used. --- api.c | 5 ++++- miner.h | 1 + sgminer.c | 16 ++++++++++++---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/api.c b/api.c index d4cac000..562eb510 100644 --- a/api.c +++ b/api.c @@ -1632,8 +1632,11 @@ static void gpustatus(struct io_data *io_data, int gpu, bool isjson, bool precom if (gpu >= 0 && gpu < nDevs) { struct cgpu_info *cgpu = &gpus[gpu]; + double dev_runtime; - cgpu->utility = cgpu->accepted / ( total_secs ? total_secs : 1 ) * 60; + dev_runtime = cgpu_runtime(cgpu); + + cgpu->utility = cgpu->accepted / dev_runtime * 60; #ifdef HAVE_ADL if (!gpu_stats(gpu, >, &gc, &gm, &gv, &ga, &gf, &gp, &pt)) diff --git a/miner.h b/miner.h index 44d5fba3..7f9285f4 100644 --- a/miner.h +++ b/miner.h @@ -691,6 +691,7 @@ endian_flip128(void __maybe_unused *dest_p, const void __maybe_unused *src_p) } #endif +extern double cgpu_runtime(struct cgpu_info *cgpu); extern void _quit(int status); /* diff --git a/sgminer.c b/sgminer.c index efc56882..f1939159 100644 --- a/sgminer.c +++ b/sgminer.c @@ -2071,12 +2071,10 @@ static void suffix_string(uint64_t val, char *buf, size_t bufsiz, int sigdigits) } } -static void get_statline(char *buf, size_t bufsiz, struct cgpu_info *cgpu) +double cgpu_runtime(struct cgpu_info *cgpu) { - char displayed_hashes[16], displayed_rolling[16]; - uint64_t dh64, dr64; struct timeval now; - double dev_runtime, wu; + double dev_runtime; if (cgpu->dev_start_tv.tv_sec == 0) dev_runtime = total_secs; @@ -2087,6 +2085,16 @@ static void get_statline(char *buf, size_t bufsiz, struct cgpu_info *cgpu) if (dev_runtime < 1.0) dev_runtime = 1.0; + return dev_runtime; +} + +static void get_statline(char *buf, size_t bufsiz, struct cgpu_info *cgpu) +{ + char displayed_hashes[16], displayed_rolling[16]; + double dev_runtime, wu; + uint64_t dh64, dr64; + + dev_runtime = cgpu_runtime(cgpu); wu = cgpu->diff1 / dev_runtime * 60.0;