Code movement. Update stats counter more frequently.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
diff --git a/cpu-miner.c b/cpu-miner.c
index 81363dc..857c186 100644
--- a/cpu-miner.c
+++ b/cpu-miner.c
@@ -25,6 +25,7 @@
enum {
STAT_SLEEP_INTERVAL = 10,
POW_SLEEP_INTERVAL = 1,
+ STAT_CTR_INTERVAL = 10000000,
};
static bool opt_verbose;
@@ -70,6 +71,17 @@ struct work {
BIGNUM *target;
};
+#define ___constant_swab32(x) ((u32)( \
+ (((u32)(x) & (u32)0x000000ffUL) << 24) | \
+ (((u32)(x) & (u32)0x0000ff00UL) << 8) | \
+ (((u32)(x) & (u32)0x00ff0000UL) >> 8) | \
+ (((u32)(x) & (u32)0xff000000UL) >> 24)))
+
+static inline uint32_t swab32(uint32_t v)
+{
+ return ___constant_swab32(v);
+}
+
static void databuf_free(struct data_buffer *db)
{
if (!db)
@@ -325,17 +337,6 @@ static void inc_stats(uint64_t n_hashes)
pthread_mutex_unlock(&stats_mutex);
}
-#define ___constant_swab32(x) ((u32)( \
- (((u32)(x) & (u32)0x000000ffUL) << 24) | \
- (((u32)(x) & (u32)0x0000ff00UL) << 8) | \
- (((u32)(x) & (u32)0x00ff0000UL) >> 8) | \
- (((u32)(x) & (u32)0xff000000UL) >> 24)))
-
-static inline uint32_t swab32(uint32_t v)
-{
- return ___constant_swab32(v);
-}
-
static void runhash(void *state, void *input, const void *init)
{
memcpy(state, init, 32);
@@ -354,6 +355,7 @@ static uint32_t scanhash(unsigned char *midstate, unsigned char *data,
uint32_t *hash32 = (uint32_t *) hash;
uint32_t *nonce = (uint32_t *)(data + 12);
uint32_t n;
+ unsigned long stat_ctr = 0;
while (1) {
n = *nonce;
@@ -376,8 +378,14 @@ static uint32_t scanhash(unsigned char *midstate, unsigned char *data,
return n;
}
+ stat_ctr++;
+ if (stat_ctr >= STAT_CTR_INTERVAL) {
+ inc_stats(STAT_CTR_INTERVAL);
+ stat_ctr = 0;
+ }
+
if ((n & 0xffffff) == 0) {
- inc_stats(n);
+ inc_stats(stat_ctr);
if (opt_debug)
fprintf(stderr, "DBG: end of nonce range\n");