Commit 2c54522d7dee649a63e89705eda23e07505ada49

Paul Sheppard 2012-07-11T08:11:53

Add average wait time to api stats

diff --git a/driver-bitforce.c b/driver-bitforce.c
index be266e2..8e41bb9 100644
--- a/driver-bitforce.c
+++ b/driver-bitforce.c
@@ -29,6 +29,7 @@
 #define WORK_CHECK_INTERVAL_MS 50
 #define MAX_START_DELAY_US 100000
 #define tv_to_ms(tval) (tval.tv_sec * 1000 + tval.tv_usec / 1000)
+#define TIME_AVE_CONSTANT 8
 
 struct device_api bitforce_api;
 
@@ -101,7 +102,7 @@ static bool bitforce_detect_one(const char *devpath)
 		s[0] = '\0';
 		bitforce->name = strdup(pdevbuf + 7);
 	}
-	
+
 	mutex_init(&bitforce->device_mutex);
 
 	return add_cgpu(bitforce);
@@ -407,6 +408,10 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work)
 
 		if (delay_time_ms != bitforce->sleep_ms)
 			  applog(LOG_DEBUG, "BFL%i: Wait time changed to: %d", bitforce->device_id, bitforce->sleep_ms, bitforce->wait_ms);
+
+        /* Work out the average time taken. Float for calculation, uint for display */
+        bitforce->ave_wait_f += (tv_to_ms(elapsed) - bitforce->ave_wait_f) / TIME_AVE_CONSTANT;
+        bitforce->ave_wait_d = (unsigned int) (bitforce->ave_wait_f + 0.5);
 	}
 
 	applog(LOG_DEBUG, "BFL%i: waited %dms until %s", bitforce->device_id, bitforce->wait_ms, pdevbuf);
@@ -432,7 +437,6 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work)
 				bitforce->nonce_range = false;
 				work->blk.nonce = 0xffffffff;
 				bitforce->sleep_ms *= 5;
-				bitforce->kname = "Single";
 		}
 			
 		submit_nonce(thr, work, nonce);
@@ -520,6 +524,7 @@ static struct api_data *bitforce_api_stats(struct cgpu_info *cgpu)
 	// locking access to displaying API debug 'stats'
 	// If locking becomes an issue for any of them, use copy_data=true also
 	root = api_add_uint(root, "Sleep Time", &(cgpu->sleep_ms), false);
+	root = api_add_uint(root, "Ave Wait", &(cgpu->ave_wait_d), false);
 
 	return root;
 }
diff --git a/miner.h b/miner.h
index 4acb8f9..fc8a108 100644
--- a/miner.h
+++ b/miner.h
@@ -321,8 +321,11 @@ struct cgpu_info {
 	};
 #ifdef USE_BITFORCE
 	struct timeval work_start_tv;
+	unsigned int ave_wait;
 	unsigned int wait_ms;
 	unsigned int sleep_ms;
+	double ave_wait_f;
+	unsigned int ave_wait_d;
 	uint32_t nonces;
 	bool nonce_range;
 #endif