Commit a84f71de9aa9282130a538882fed126adf6fb3db

Con Kolivas 2014-03-14T09:46:34

Keep track of when the last restart and work updates were triggered and provide helper functions for knowing the time since then.

diff --git a/cgminer.c b/cgminer.c
index 2370b6a..9be9e86 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -280,6 +280,7 @@ pthread_cond_t gws_cond;
 double total_rolling;
 double total_mhashes_done;
 static struct timeval total_tv_start, total_tv_end;
+static struct timeval restart_tv_start, update_tv_start;
 
 cglock_t control_lock;
 pthread_mutex_t stats_lock;
@@ -2336,6 +2337,22 @@ double cgpu_runtime(struct cgpu_info *cgpu)
 	return dev_runtime;
 }
 
+double tsince_restart(void)
+{
+	struct timeval now;
+
+	cgtime(&now);
+	return tdiff(&now, &restart_tv_start);
+}
+
+double tsince_update(void)
+{
+	struct timeval now;
+
+	cgtime(&now);
+	return tdiff(&now, &update_tv_start);
+}
+
 static void get_statline(char *buf, size_t bufsiz, struct cgpu_info *cgpu)
 {
 	char displayed_hashes[16], displayed_rolling[16];
@@ -4305,6 +4322,7 @@ static void restart_threads(void)
 {
 	pthread_t rthread;
 
+	cgtime(&restart_tv_start);
 	if (unlikely(pthread_create(&rthread, NULL, restart_thread, NULL)))
 		quit(1, "Failed to create restart thread");
 }
@@ -4315,6 +4333,7 @@ static void signal_work_update(void)
 
 	applog(LOG_INFO, "Work update message received");
 
+	cgtime(&update_tv_start);
 	rd_lock(&mining_thr_lock);
 	for (i = 0; i < mining_threads; i++)
 		mining_thr[i]->work_update = true;
diff --git a/miner.h b/miner.h
index f557b0d..353b51a 100644
--- a/miner.h
+++ b/miner.h
@@ -679,6 +679,8 @@ endian_flip128(void __maybe_unused *dest_p, const void __maybe_unused *src_p)
 #endif
 
 extern double cgpu_runtime(struct cgpu_info *cgpu);
+extern double tsince_restart(void);
+extern double tsince_update(void);
 extern void __quit(int status, bool clean);
 extern void _quit(int status);