Commit 302d087fe2ed8b471baf898eb19910fa454c6fa7

ckolivas 2014-01-24T15:38:53

Provide a helper function for determining dev runtime and use it in the hashmeters used.

diff --git a/api.c b/api.c
index 546d3a6..4c1cba4 100644
--- a/api.c
+++ b/api.c
@@ -1943,15 +1943,7 @@ static void ascstatus(struct io_data *io_data, int asc, bool isjson, bool precom
 		struct timeval now;
 		double dev_runtime;
 
-		if (cgpu->dev_start_tv.tv_sec == 0)
-			dev_runtime = total_secs;
-		else {
-			cgtime(&now);
-			dev_runtime = tdiff(&now, &(cgpu->dev_start_tv));
-		}
-
-		if (dev_runtime < 1.0)
-			dev_runtime = 1.0;
+		dev_runtime = cgpu_runtime(cgpu);
 
 		cgpu->utility = cgpu->accepted / dev_runtime * 60;
 
diff --git a/cgminer.c b/cgminer.c
index e07aa90..8008939 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -2131,12 +2131,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;
@@ -2147,6 +2145,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;
 
diff --git a/miner.h b/miner.h
index 0aac88b..dad0b00 100644
--- a/miner.h
+++ b/miner.h
@@ -660,6 +660,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);
 
 /*