Browse Source

get_datestamp: Change timeval parameter to time_t, and implement get_now_datestamp for common "current time" use case

Luke Dashjr 12 years ago
parent
commit
313f7f9ac8
10 changed files with 36 additions and 44 deletions
  1. 1 3
      driver-avalon.c
  2. 1 3
      driver-bitforce.c
  3. 1 4
      driver-icarus.c
  4. 1 3
      driver-modminer.c
  5. 3 7
      driver-opencl.c
  6. 1 3
      driver-ztex.c
  7. 15 14
      logging.c
  8. 9 6
      miner.c
  9. 2 1
      miner.h
  10. 2 0
      util.h

+ 1 - 3
driver-avalon.c

@@ -662,7 +662,6 @@ static bool avalon_prepare(struct thr_info *thr)
 {
 {
 	struct cgpu_info *avalon = thr->cgpu;
 	struct cgpu_info *avalon = thr->cgpu;
 	struct avalon_info *info = avalon->device_data;
 	struct avalon_info *info = avalon->device_data;
-	struct timeval now;
 
 
 	free(avalon->works);
 	free(avalon->works);
 	avalon->works = calloc(info->miner_count * sizeof(struct work *),
 	avalon->works = calloc(info->miner_count * sizeof(struct work *),
@@ -674,8 +673,7 @@ static bool avalon_prepare(struct thr_info *thr)
 	else
 	else
 		__avalon_init(avalon);
 		__avalon_init(avalon);
 
 
-	cgtime(&now);
-	get_datestamp(avalon->init, &now);
+	get_now_datestamp(avalon->init);
 	avalon->status = LIFE_INIT2;
 	avalon->status = LIFE_INIT2;
 	return true;
 	return true;
 }
 }

+ 1 - 3
driver-bitforce.c

@@ -356,7 +356,6 @@ static bool bitforce_thread_prepare(struct thr_info *thr)
 {
 {
 	struct cgpu_info *bitforce = thr->cgpu;
 	struct cgpu_info *bitforce = thr->cgpu;
 	int fdDev = BFopen(bitforce->device_path);
 	int fdDev = BFopen(bitforce->device_path);
-	struct timeval now;
 
 
 	if (unlikely(fdDev == -1)) {
 	if (unlikely(fdDev == -1)) {
 		applog(LOG_ERR, "%s: Failed to open %s", bitforce->dev_repr, bitforce->device_path);
 		applog(LOG_ERR, "%s: Failed to open %s", bitforce->dev_repr, bitforce->device_path);
@@ -366,8 +365,7 @@ static bool bitforce_thread_prepare(struct thr_info *thr)
 	bitforce->device_fd = fdDev;
 	bitforce->device_fd = fdDev;
 
 
 	applog(LOG_INFO, "%s: Opened %s", bitforce->dev_repr, bitforce->device_path);
 	applog(LOG_INFO, "%s: Opened %s", bitforce->dev_repr, bitforce->device_path);
-	cgtime(&now);
-	get_datestamp(bitforce->init, &now);
+	get_now_datestamp(bitforce->init);
 
 
 	return true;
 	return true;
 }
 }

+ 1 - 4
driver-icarus.c

@@ -645,8 +645,6 @@ static bool icarus_prepare(struct thr_info *thr)
 	struct cgpu_info *icarus = thr->cgpu;
 	struct cgpu_info *icarus = thr->cgpu;
 	struct ICARUS_INFO *info = icarus->device_data;
 	struct ICARUS_INFO *info = icarus->device_data;
 
 
-	struct timeval now;
-
 	icarus->device_fd = -1;
 	icarus->device_fd = -1;
 
 
 	int fd = icarus_open2(icarus->device_path, info->baud, true);
 	int fd = icarus_open2(icarus->device_path, info->baud, true);
@@ -659,8 +657,7 @@ static bool icarus_prepare(struct thr_info *thr)
 	icarus->device_fd = fd;
 	icarus->device_fd = fd;
 
 
 	applog(LOG_INFO, "Opened Icarus on %s", icarus->device_path);
 	applog(LOG_INFO, "Opened Icarus on %s", icarus->device_path);
-	cgtime(&now);
-	get_datestamp(icarus->init, &now);
+	get_now_datestamp(icarus->init);
 
 
 	struct icarus_state *state;
 	struct icarus_state *state;
 	thr->cgpu_data = state = calloc(1, sizeof(*state));
 	thr->cgpu_data = state = calloc(1, sizeof(*state));

+ 1 - 3
driver-modminer.c

@@ -276,9 +276,7 @@ modminer_device_prepare(struct cgpu_info *modminer)
 	modminer->device->device_fd = fd;
 	modminer->device->device_fd = fd;
 	applog(LOG_INFO, "%s: Opened %s", modminer->dev_repr, modminer->device_path);
 	applog(LOG_INFO, "%s: Opened %s", modminer->dev_repr, modminer->device_path);
 
 
-	struct timeval now;
-	gettimeofday(&now, NULL);
-	get_datestamp(modminer->init, &now);
+	get_now_datestamp(modminer->init);
 
 
 	return true;
 	return true;
 }
 }

+ 3 - 7
driver-opencl.c

@@ -888,7 +888,7 @@ void opencl_wlogprint_status(struct cgpu_info *cgpu)
 		if (thr->cgpu != cgpu)
 		if (thr->cgpu != cgpu)
 			continue;
 			continue;
 		
 		
-		get_datestamp(checkin, &thr->last);
+		get_datestamp(checkin, thr->last.tv_sec);
 		displayed_rolling = thr->rolling;
 		displayed_rolling = thr->rolling;
 		if (!mhash_base)
 		if (!mhash_base)
 			displayed_rolling *= 1000;
 			displayed_rolling *= 1000;
@@ -1251,7 +1251,6 @@ void *reinit_gpu(void *userdata)
 	struct thr_info *mythr = userdata;
 	struct thr_info *mythr = userdata;
 	struct cgpu_info *cgpu, *sel_cgpu;
 	struct cgpu_info *cgpu, *sel_cgpu;
 	struct thr_info *thr;
 	struct thr_info *thr;
-	struct timeval now;
 	char name[256];
 	char name[256];
 	int thr_id;
 	int thr_id;
 	int i;
 	int i;
@@ -1317,8 +1316,7 @@ select_cgpu:
 		applog(LOG_WARNING, "Thread %d restarted", thr_id);
 		applog(LOG_WARNING, "Thread %d restarted", thr_id);
 	}
 	}
 
 
-	cgtime(&now);
-	get_datestamp(sel_cgpu->init, &now);
+	get_now_datestamp(sel_cgpu->init);
 
 
 	proc_enable(cgpu);
 	proc_enable(cgpu);
 
 
@@ -1500,7 +1498,6 @@ static uint32_t *blank_res;
 static bool opencl_thread_prepare(struct thr_info *thr)
 static bool opencl_thread_prepare(struct thr_info *thr)
 {
 {
 	char name[256];
 	char name[256];
-	struct timeval now;
 	struct cgpu_info *cgpu = thr->cgpu;
 	struct cgpu_info *cgpu = thr->cgpu;
 	int gpu = cgpu->device_id;
 	int gpu = cgpu->device_id;
 	int virtual_gpu = cgpu->virtual_gpu;
 	int virtual_gpu = cgpu->virtual_gpu;
@@ -1571,8 +1568,7 @@ static bool opencl_thread_prepare(struct thr_info *thr)
 		}
 		}
 	}
 	}
 	applog(LOG_INFO, "initCl() finished. Found %s", name);
 	applog(LOG_INFO, "initCl() finished. Found %s", name);
-	cgtime(&now);
-	get_datestamp(cgpu->init, &now);
+	get_now_datestamp(cgpu->init);
 
 
 	have_opencl = true;
 	have_opencl = true;
 
 

+ 1 - 3
driver-ztex.c

@@ -339,12 +339,10 @@ get_ztex_drv_extra_device_status(struct cgpu_info *ztex)
 
 
 static bool ztex_prepare(struct thr_info *thr)
 static bool ztex_prepare(struct thr_info *thr)
 {
 {
-	struct timeval now;
 	struct cgpu_info *cgpu = thr->cgpu;
 	struct cgpu_info *cgpu = thr->cgpu;
 	struct libztex_device *ztex = cgpu->device_ztex;
 	struct libztex_device *ztex = cgpu->device_ztex;
 
 
-	cgtime(&now);
-	get_datestamp(cgpu->init, &now);
+	get_now_datestamp(cgpu->init);
 	
 	
 	{
 	{
 		char fpganame[LIBZTEX_SNSTRING_LEN+3+1];
 		char fpganame[LIBZTEX_SNSTRING_LEN+3+1];

+ 15 - 14
logging.c

@@ -69,25 +69,26 @@ void _applog(int prio, const char *str)
 			return;
 			return;
 
 
 		char datetime[64];
 		char datetime[64];
-		struct timeval tv = {0, 0};
-		struct tm _tm;
-		struct tm *tm = &_tm;
-
-		cgtime(&tv);
-
-		localtime_r(&tv.tv_sec, tm);
 
 
 		if (opt_log_microseconds)
 		if (opt_log_microseconds)
+		{
+			struct timeval tv;
+			struct tm tm;
+			
+			cgtime(&tv);
+			localtime_r(&tv.tv_sec, &tm);
+			
 			sprintf(datetime, "[%d-%02d-%02d %02d:%02d:%02d.%06ld]",
 			sprintf(datetime, "[%d-%02d-%02d %02d:%02d:%02d.%06ld]",
-				tm->tm_year + 1900,
-				tm->tm_mon + 1,
-				tm->tm_mday,
-				tm->tm_hour,
-				tm->tm_min,
-				tm->tm_sec,
+				tm.tm_year + 1900,
+				tm.tm_mon + 1,
+				tm.tm_mday,
+				tm.tm_hour,
+				tm.tm_min,
+				tm.tm_sec,
 				(long)tv.tv_usec);
 				(long)tv.tv_usec);
+		}
 		else
 		else
-			get_datestamp(datetime, &tv);
+			get_now_datestamp(datetime);
 
 
 		/* Only output to stderr if it's not going to the screen as well */
 		/* Only output to stderr if it's not going to the screen as well */
 		if (writetofile) {
 		if (writetofile) {

+ 9 - 6
miner.c

@@ -393,12 +393,15 @@ static bool should_run(void)
 	return within_range;
 	return within_range;
 }
 }
 
 
-void get_datestamp(char *f, struct timeval *tv)
+void get_datestamp(char *f, time_t tt)
 {
 {
 	struct tm _tm;
 	struct tm _tm;
 	struct tm *tm = &_tm;
 	struct tm *tm = &_tm;
+	
+	if (tt == INVALID_TIMESTAMP)
+		tt = time(NULL);
 
 
-	localtime_r(&tv->tv_sec, tm);
+	localtime_r(&tt, tm);
 	sprintf(f, "[%d-%02d-%02d %02d:%02d:%02d]",
 	sprintf(f, "[%d-%02d-%02d %02d:%02d:%02d]",
 		tm->tm_year + 1900,
 		tm->tm_year + 1900,
 		tm->tm_mon + 1,
 		tm->tm_mon + 1,
@@ -408,12 +411,12 @@ void get_datestamp(char *f, struct timeval *tv)
 		tm->tm_sec);
 		tm->tm_sec);
 }
 }
 
 
-void get_timestamp(char *f, struct timeval *tv)
+void get_timestamp(char *f, time_t tt)
 {
 {
 	struct tm _tm;
 	struct tm _tm;
 	struct tm *tm = &_tm;
 	struct tm *tm = &_tm;
 
 
-	localtime_r(&tv->tv_sec, tm);
+	localtime_r(&tt, tm);
 	sprintf(f, "[%02d:%02d:%02d]",
 	sprintf(f, "[%02d:%02d:%02d]",
 		tm->tm_hour,
 		tm->tm_hour,
 		tm->tm_min,
 		tm->tm_min,
@@ -4861,7 +4864,7 @@ static void set_curblock(char *hexstr, unsigned char *hash)
 	free(current_fullhash);
 	free(current_fullhash);
 	current_fullhash = malloc(65);
 	current_fullhash = malloc(65);
 	bin2hex(current_fullhash, hash_swap, 32);
 	bin2hex(current_fullhash, hash_swap, 32);
-	get_timestamp(blocktime, &block_timeval);
+	get_timestamp(blocktime, block_timeval.tv_sec);
 	cg_wunlock(&ch_lock);
 	cg_wunlock(&ch_lock);
 
 
 	applog(LOG_INFO, "New block: %s diff %s (%s)", current_hash, block_diff, net_hashrate);
 	applog(LOG_INFO, "New block: %s diff %s (%s)", current_hash, block_diff, net_hashrate);
@@ -9468,7 +9471,7 @@ begin_bench:
 		localtime_r(&miner_started.tv_sec, &schedstart.tm);
 		localtime_r(&miner_started.tv_sec, &schedstart.tm);
 	if (schedstop.tm.tm_sec)
 	if (schedstop.tm.tm_sec)
 		localtime_r(&miner_started.tv_sec, &schedstop .tm);
 		localtime_r(&miner_started.tv_sec, &schedstop .tm);
-	get_datestamp(datestamp, &total_tv_start);
+	get_datestamp(datestamp, total_tv_start.tv_sec);
 
 
 	// Initialise processors and threads
 	// Initialise processors and threads
 	k = 0;
 	k = 0;

+ 2 - 1
miner.h

@@ -1248,7 +1248,8 @@ struct work {
 	struct work *next;
 	struct work *next;
 };
 };
 
 
-extern void get_datestamp(char *, struct timeval *);
+extern void get_datestamp(char *, time_t);
+#define get_now_datestamp(buf)  get_datestamp(buf, INVALID_TIMESTAMP)
 extern void inc_hw_errors(struct thr_info *, const struct work *, const uint32_t bad_nonce);
 extern void inc_hw_errors(struct thr_info *, const struct work *, const uint32_t bad_nonce);
 #define inc_hw_errors_only(thr)  inc_hw_errors(thr, NULL, 0)
 #define inc_hw_errors_only(thr)  inc_hw_errors(thr, NULL, 0)
 enum test_nonce2_result {
 enum test_nonce2_result {

+ 2 - 0
util.h

@@ -18,6 +18,8 @@
 
 
 #include "compat.h"
 #include "compat.h"
 
 
+#define INVALID_TIMESTAMP ((time_t)-1)
+
 #if defined(unix) || defined(__APPLE__)
 #if defined(unix) || defined(__APPLE__)
 	#include <errno.h>
 	#include <errno.h>
 	#include <sys/socket.h>
 	#include <sys/socket.h>