Browse Source

Display the actual share diff next to the pool required diff, using a suffix creation function to prevent values of >1000 being shown in their entirety.

nfactor-troky
Con Kolivas 12 years ago
parent
commit
420fdf32d6
  1. 76
      cgminer.c
  2. 2
      miner.h

76
cgminer.c

@ -1472,6 +1472,51 @@ void tailsprintf(char *f, const char *fmt, ...)
va_end(ap); va_end(ap);
} }
/* Convert a uint64_t value into a truncated string for displaying with its
* associated suitable for Mega, Giga etc. Buf array needs to be long enough */
static void suffix_string(uint64_t val, char *buf, int sigdigits)
{
const uint64_t kilo = 1000ull;
const uint64_t mega = 1000000ull;
const uint64_t giga = 1000000000ull;
const uint64_t tera = 1000000000000ull;
const uint64_t peta = 1000000000000000ull;
const uint64_t exa = 1000000000000000000ull;
char suffix[2] = "";
double dval;
if (val >= exa) {
val /= peta;
dval = (double)val / kilo;
sprintf(suffix, "E");
} else if (val >= peta) {
val /= tera;
dval = (double)val / kilo;
sprintf(suffix, "P");
} else if (val >= tera) {
val /= giga;
dval = (double)val / kilo;
sprintf(suffix, "T");
} else if (val >= giga) {
val /= mega;
dval = (double)val / kilo;
sprintf(suffix, "G");
} else if (val >= mega) {
val /= kilo;
dval = (double)val / kilo;
sprintf(suffix, "M");
} else if (val >= kilo) {
dval = (double)val / kilo;
sprintf(suffix, "K");
} else
dval = val;
if (!sigdigits)
sprintf(buf, "%d%s", (unsigned int)dval, suffix);
else
sprintf(buf, "%.*g%s", sigdigits, dval, suffix);
}
static void get_statline(char *buf, struct cgpu_info *cgpu) static void get_statline(char *buf, struct cgpu_info *cgpu)
{ {
double displayed_hashes, displayed_rolling = cgpu->rolling; double displayed_hashes, displayed_rolling = cgpu->rolling;
@ -1929,6 +1974,26 @@ share_result(json_t *val, json_t *res, json_t *err, const struct work *work,
} }
} }
static uint64_t share_diff(const struct work *work)
{
const uint64_t h64 = 0xFFFF000000000000ull;
char rtarget[33], *target;
uint64_t *data64, d64;
uint64_t ret;
target = bin2hex(work->hash, 32);
if (unlikely(!target))
quit(1, "Failed to bin2hex in share_diff");
swab256(rtarget, target);
free(target);
data64 = (uint64_t *)(rtarget + 4);
d64 = be64toh(*data64);
if (unlikely(!d64))
d64 = 1;
ret = h64 / d64;
return ret;
}
static bool submit_upstream_work(const struct work *work, CURL *curl, bool resubmit) static bool submit_upstream_work(const struct work *work, CURL *curl, bool resubmit)
{ {
char *hexstr = NULL; char *hexstr = NULL;
@ -1991,8 +2056,12 @@ static bool submit_upstream_work(const struct work *work, CURL *curl, bool resub
sprintf(hashshow, "%08lx.%08lx", (unsigned long)(hash32[7]), (unsigned long)(hash32[6])); sprintf(hashshow, "%08lx.%08lx", (unsigned long)(hash32[7]), (unsigned long)(hash32[6]));
else { else {
int intdiff = round(work->work_difficulty); int intdiff = round(work->work_difficulty);
uint64_t sharediff = share_diff(work);
char diffdisp[16];
suffix_string(sharediff, diffdisp, 0);
sprintf(hashshow, "%08lx Diff %d%s", (unsigned long)(hash32[6]), intdiff, sprintf(hashshow, "%08lx Diff %s/%d%s", (unsigned long)(hash32[6]), diffdisp, intdiff,
work->block? " BLOCK!" : ""); work->block? " BLOCK!" : "");
} }
@ -4079,13 +4148,16 @@ static void stratum_share_result(json_t *val, json_t *res_val, json_t *err_val,
struct stratum_share *sshare) struct stratum_share *sshare)
{ {
struct work *work = &sshare->work; struct work *work = &sshare->work;
uint64_t sharediff = share_diff(work);
char hashshow[65]; char hashshow[65];
uint32_t *hash32; uint32_t *hash32;
char diffdisp[16];
int intdiff; int intdiff;
hash32 = (uint32_t *)(work->hash); hash32 = (uint32_t *)(work->hash);
intdiff = round(work->work_difficulty); intdiff = round(work->work_difficulty);
sprintf(hashshow, "%08lx Diff %d%s", (unsigned long)(hash32[6]), intdiff, suffix_string(sharediff, diffdisp, 0);
sprintf(hashshow, "%08lx Diff %s/%d%s", (unsigned long)(hash32[6]), diffdisp, intdiff,
work->block? " BLOCK!" : ""); work->block? " BLOCK!" : "");
share_result(val, res_val, err_val, work, hashshow, false, ""); share_result(val, res_val, err_val, work, hashshow, false, "");
} }

2
miner.h

@ -144,10 +144,12 @@ static inline int fsync (int fd)
#ifndef htobe32 #ifndef htobe32
# if __BYTE_ORDER == __LITTLE_ENDIAN # if __BYTE_ORDER == __LITTLE_ENDIAN
# define be32toh(x) bswap_32(x) # define be32toh(x) bswap_32(x)
# define be64toh(x) bswap_64(x)
# define htobe32(x) bswap_32(x) # define htobe32(x) bswap_32(x)
# define htobe64(x) bswap_64(x) # define htobe64(x) bswap_64(x)
# elif __BYTE_ORDER == __BIG_ENDIAN # elif __BYTE_ORDER == __BIG_ENDIAN
# define be32toh(x) (x) # define be32toh(x) (x)
# define be64toh(x) (x)
# define htobe32(x) (x) # define htobe32(x) (x)
# define htobe64(x) (x) # define htobe64(x) (x)
#else #else

Loading…
Cancel
Save