Browse Source

measure effective hashrate

master
tcatm 14 years ago
parent
commit
80b2d6f1c1
  1. 4
      findnonce.c
  2. 2
      findnonce.h
  3. 39
      miner.c

4
findnonce.c

@ -132,7 +132,7 @@ void precalc_hash(dev_blk_ctx *blk, uint32_t *state, uint32_t *data) { @@ -132,7 +132,7 @@ void precalc_hash(dev_blk_ctx *blk, uint32_t *state, uint32_t *data) {
R(E, F, G, H, A, B, C, D, P(u+4), SHA256_K[u+4]); \
R(D, E, F, G, H, A, B, C, P(u+5), SHA256_K[u+5])
uint32_t postcalc_hash(dev_blk_ctx *blk, struct work_t *work, uint32_t start, uint32_t end, uint32_t *best_nonce, int pool_mode) {
uint32_t postcalc_hash(dev_blk_ctx *blk, struct work_t *work, uint32_t start, uint32_t end, uint32_t *best_nonce, int pool_mode, unsigned int *h0count) {
cl_uint A, B, C, D, E, F, G, H;
cl_uint W[16];
cl_uint nonce;
@ -169,6 +169,8 @@ uint32_t postcalc_hash(dev_blk_ctx *blk, struct work_t *work, uint32_t start, ui @@ -169,6 +169,8 @@ uint32_t postcalc_hash(dev_blk_ctx *blk, struct work_t *work, uint32_t start, ui
FR(48); PFR(56);
if(H == 0xA41F32E7) {
(*h0count)++;
if (pool_mode)
submit_nonce(work, nonce);

2
findnonce.h

@ -31,5 +31,5 @@ struct work_t { @@ -31,5 +31,5 @@ struct work_t {
};
extern void precalc_hash(dev_blk_ctx *blk, uint32_t *state, uint32_t *data);
extern uint32_t postcalc_hash(dev_blk_ctx *blk, struct work_t *work, uint32_t start, uint32_t end, uint32_t *best_nonce, int pool_mode);
extern uint32_t postcalc_hash(dev_blk_ctx *blk, struct work_t *work, uint32_t start, uint32_t end, uint32_t *best_nonce, int pool_mode, unsigned int *h0count);
extern void submit_nonce(struct work_t *work, uint32_t nonce);

39
miner.c

@ -22,6 +22,7 @@ @@ -22,6 +22,7 @@
#include <getopt.h>
#include <jansson.h>
#include <inttypes.h>
#include <math.h>
#include "miner.h"
#include "findnonce.h"
@ -193,24 +194,31 @@ out: @@ -193,24 +194,31 @@ out:
free(hexstr);
}
double time2secs(struct timeval *tv_start) {
struct timeval tv_end, diff;
double secs;
gettimeofday(&tv_end, NULL);
timeval_subtract(&diff, &tv_end, tv_start);
secs = (double)diff.tv_sec + ((double)diff.tv_usec / 1000000.0);
return secs;
}
static void hashmeter(int thr_id, struct timeval *tv_start,
unsigned long hashes_done)
{
struct timeval tv_end, diff;
double khashes, secs;
gettimeofday(&tv_end, NULL);
timeval_subtract(&diff, &tv_end, tv_start);
secs = time2secs(tv_start);
khashes = hashes_done / 1000.0;
secs = (double)diff.tv_sec + ((double)diff.tv_usec / 1000000.0);
hashrates[thr_id] = khashes / secs;
}
static void print_hashmeter(double hashrate, char *rates) {
printf("\r \rHashMeter: %.2f Mhash/sec (%s)", hashrate / 1000, rates);
printf("\r \rHashMeter: %.2f Mhash/sec (%s)", hashrate, rates);
fflush(stdout);
}
@ -280,6 +288,11 @@ static void *miner_thread(void *thr_id_int) @@ -280,6 +288,11 @@ static void *miner_thread(void *thr_id_int)
unsigned long hashes_done;
hashes_done = 0;
unsigned int h0count = 0;
struct timeval tv_start0;
gettimeofday(&tv_start0, NULL);
while (1) {
struct timeval tv_start;
bool rc;
@ -317,9 +330,6 @@ static void *miner_thread(void *thr_id_int) @@ -317,9 +330,6 @@ static void *miner_thread(void *thr_id_int)
need_work = false;
}
if (hashes_done != 0)
hashmeter(thr_id, &tv_start, hashes_done);
gettimeofday(&tv_start, NULL);
int threads = 102400 * 4;
@ -350,7 +360,7 @@ static void *miner_thread(void *thr_id_int) @@ -350,7 +360,7 @@ static void *miner_thread(void *thr_id_int)
if(res[j]) {
uint32_t start = (work[res_frame].res_nonce + j)<<10;
uint32_t my_g, my_nonce;
my_g = postcalc_hash(&work[res_frame].blk, &work[res_frame], start, start + 1024, &my_nonce, opt_pool);
my_g = postcalc_hash(&work[res_frame].blk, &work[res_frame], start, start + 1026, &my_nonce, opt_pool, &h0count);
if (!opt_pool) {
if (opt_debug)
@ -381,6 +391,13 @@ static void *miner_thread(void *thr_id_int) @@ -381,6 +391,13 @@ static void *miner_thread(void *thr_id_int)
need_work = true;
}
}
if (h0count != 0) {
double secs;
secs = time2secs(&tv_start0);
hashrates[thr_id] = h0count * pow(2, 256) / (secs * 1e6 * (pow(2, 224) - 1.0));
}
status = clEnqueueReadBuffer(clState->commandQueue, clState->outputBuffer, CL_TRUE, 0,
@ -541,7 +558,7 @@ int main (int argc, char *argv[]) @@ -541,7 +558,7 @@ int main (int argc, char *argv[])
for(i = 0; i < nDevs; i++) {
hashrate += hashrates[i];
sprintf(buffer, "%.02f", hashrates[i] / 1000);
sprintf(buffer, "%.02f", hashrates[i]);
strcat(rates, buffer);
if (i != nDevs-1) strcat(rates, " ");

Loading…
Cancel
Save