Browse Source

Replace all remaining uses of gettimeofday for timers, with timer_set_now (aka cgtime)

Luke Dashjr 12 years ago
parent
commit
ab62fdf1f3
6 changed files with 21 additions and 19 deletions
  1. 11 11
      deviceapi.c
  2. 2 2
      driver-cpu.c
  3. 2 2
      driver-modminer.c
  4. 2 2
      driver-x6500.c
  5. 1 1
      miner.c
  6. 3 1
      util.h

+ 11 - 11
deviceapi.c

@@ -102,7 +102,7 @@ int restart_wait(struct thr_info *thr, unsigned int mstime)
 		return (thr->work_restart ? 0 : ETIMEDOUT);
 		return (thr->work_restart ? 0 : ETIMEDOUT);
 	}
 	}
 	
 	
-	gettimeofday(&tv_now, NULL);
+	timer_set_now(&tv_now);
 	timer_set_delay(&tv_timer, &tv_now, mstime * 1000);
 	timer_set_delay(&tv_timer, &tv_now, mstime * 1000);
 	while (true)
 	while (true)
 	{
 	{
@@ -118,7 +118,7 @@ int restart_wait(struct thr_info *thr, unsigned int mstime)
 				return 0;
 				return 0;
 			notifier_read(thr->work_restart_notifier);
 			notifier_read(thr->work_restart_notifier);
 		}
 		}
-		gettimeofday(&tv_now, NULL);
+		timer_set_now(&tv_now);
 	}
 	}
 }
 }
 
 
@@ -163,16 +163,16 @@ void minerloop_scanhash(struct thr_info *mythr)
 		work = get_and_prepare_work(mythr);
 		work = get_and_prepare_work(mythr);
 		if (!work)
 		if (!work)
 			break;
 			break;
-		gettimeofday(&(work->tv_work_start), NULL);
+		timer_set_now(&work->tv_work_start);
 		
 		
 		do {
 		do {
 			thread_reportin(mythr);
 			thread_reportin(mythr);
 			/* Only allow the mining thread to be cancelled when
 			/* Only allow the mining thread to be cancelled when
 			* it is not in the driver code. */
 			* it is not in the driver code. */
 			pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
 			pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
-			gettimeofday(&tv_start, NULL);
+			timer_set_now(&tv_start);
 			hashes = api->scanhash(mythr, work, work->blk.nonce + max_nonce);
 			hashes = api->scanhash(mythr, work, work->blk.nonce + max_nonce);
-			gettimeofday(&tv_end, NULL);
+			timer_set_now(&tv_end);
 			pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
 			pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
 			pthread_testcancel();
 			pthread_testcancel();
 			thread_reportin(mythr);
 			thread_reportin(mythr);
@@ -276,7 +276,7 @@ void job_results_fetched(struct thr_info *mythr)
 	{
 	{
 		struct timeval tv_now;
 		struct timeval tv_now;
 		
 		
-		gettimeofday(&tv_now, NULL);
+		timer_set_now(&tv_now);
 		
 		
 		do_process_results(mythr, &tv_now, mythr->prev_work, true);
 		do_process_results(mythr, &tv_now, mythr->prev_work, true);
 	}
 	}
@@ -295,7 +295,7 @@ void mt_job_transition(struct thr_info *mythr)
 {
 {
 	struct timeval tv_now;
 	struct timeval tv_now;
 	
 	
-	gettimeofday(&tv_now, NULL);
+	timer_set_now(&tv_now);
 	
 	
 	if (mythr->starting_next_work)
 	if (mythr->starting_next_work)
 	{
 	{
@@ -314,7 +314,7 @@ void job_start_complete(struct thr_info *mythr)
 {
 {
 	struct timeval tv_now;
 	struct timeval tv_now;
 	
 	
-	gettimeofday(&tv_now, NULL);
+	timer_set_now(&tv_now);
 	
 	
 	do_process_results(mythr, &tv_now, mythr->prev_work, false);
 	do_process_results(mythr, &tv_now, mythr->prev_work, false);
 }
 }
@@ -358,7 +358,7 @@ void do_notifier_select(struct thr_info *thr, struct timeval *tvp_timeout)
 	int maxfd;
 	int maxfd;
 	fd_set rfds;
 	fd_set rfds;
 	
 	
-	gettimeofday(&tv_now, NULL);
+	timer_set_now(&tv_now);
 	FD_ZERO(&rfds);
 	FD_ZERO(&rfds);
 	FD_SET(thr->notifier[0], &rfds);
 	FD_SET(thr->notifier[0], &rfds);
 	maxfd = thr->notifier[0];
 	maxfd = thr->notifier[0];
@@ -403,7 +403,7 @@ void minerloop_async(struct thr_info *mythr)
 	
 	
 	while (likely(!cgpu->shutdown)) {
 	while (likely(!cgpu->shutdown)) {
 		tv_timeout.tv_sec = -1;
 		tv_timeout.tv_sec = -1;
-		gettimeofday(&tv_now, NULL);
+		timer_set_now(&tv_now);
 		for (proc = cgpu; proc; proc = proc->next_proc)
 		for (proc = cgpu; proc; proc = proc->next_proc)
 		{
 		{
 			mythr = proc->thr[0];
 			mythr = proc->thr[0];
@@ -488,7 +488,7 @@ void minerloop_queue(struct thr_info *thr)
 	
 	
 	while (likely(!cgpu->shutdown)) {
 	while (likely(!cgpu->shutdown)) {
 		tv_timeout.tv_sec = -1;
 		tv_timeout.tv_sec = -1;
-		gettimeofday(&tv_now, NULL);
+		timer_set_now(&tv_now);
 		for (proc = cgpu; proc; proc = proc->next_proc)
 		for (proc = cgpu; proc; proc = proc->next_proc)
 		{
 		{
 			mythr = proc->thr[0];
 			mythr = proc->thr[0];

+ 2 - 2
driver-cpu.c

@@ -246,7 +246,7 @@ double bench_algo_stage3(
 
 
 	memcpy(&hash1[0], &hash1_init[0], sizeof(hash1));
 	memcpy(&hash1[0], &hash1_init[0], sizeof(hash1));
 
 
-	gettimeofday(&start, 0);
+	timer_set_now(&start);
 			{
 			{
 				sha256_func func = sha256_funcs[algo];
 				sha256_func func = sha256_funcs[algo];
 				(*func)(
 				(*func)(
@@ -261,7 +261,7 @@ double bench_algo_stage3(
 					work.blk.nonce
 					work.blk.nonce
 				);
 				);
 			}
 			}
-	gettimeofday(&end, 0);
+	timer_set_now(&end);
 
 
 	uint64_t usec_end = ((uint64_t)end.tv_sec)*1000*1000 + end.tv_usec;
 	uint64_t usec_end = ((uint64_t)end.tv_sec)*1000*1000 + end.tv_usec;
 	uint64_t usec_start = ((uint64_t)start.tv_sec)*1000*1000 + start.tv_usec;
 	uint64_t usec_start = ((uint64_t)start.tv_sec)*1000*1000 + start.tv_usec;

+ 2 - 2
driver-modminer.c

@@ -592,7 +592,7 @@ fd_set fds;
 
 
 	if (46 != write(fd, state->next_work_cmd, 46))
 	if (46 != write(fd, state->next_work_cmd, 46))
 		bailout2(LOG_ERR, "%s: Error writing (start work)", modminer->proc_repr);
 		bailout2(LOG_ERR, "%s: Error writing (start work)", modminer->proc_repr);
-	gettimeofday(&state->tv_workstart, NULL);
+	timer_set_now(&state->tv_workstart);
 	state->hashes = 0;
 	state->hashes = 0;
 	status_read("start work");
 	status_read("start work");
 	mutex_unlock(mutexp);
 	mutex_unlock(mutexp);
@@ -673,7 +673,7 @@ modminer_process_results(struct thr_info*thr)
 	}
 	}
 
 
 	struct timeval tv_workend, elapsed;
 	struct timeval tv_workend, elapsed;
-	gettimeofday(&tv_workend, NULL);
+	timer_set_now(&tv_workend);
 	timersub(&tv_workend, &state->tv_workstart, &elapsed);
 	timersub(&tv_workend, &state->tv_workstart, &elapsed);
 
 
 	uint64_t hashes = (uint64_t)state->dclk.freqM * 2 * (((uint64_t)elapsed.tv_sec * 1000000) + elapsed.tv_usec);
 	uint64_t hashes = (uint64_t)state->dclk.freqM * 2 * (((uint64_t)elapsed.tv_sec * 1000000) + elapsed.tv_usec);

+ 2 - 2
driver-x6500.c

@@ -638,7 +638,7 @@ void x6500_job_start(struct thr_info *thr)
 
 
 	ft232r_flush(jp->a->ftdi);
 	ft232r_flush(jp->a->ftdi);
 
 
-	gettimeofday(&tv_now, NULL);
+	timer_set_now(&tv_now);
 	if (!thr->prev_work)
 	if (!thr->prev_work)
 		fpga->tv_hashstart = tv_now;
 		fpga->tv_hashstart = tv_now;
 	else
 	else
@@ -694,7 +694,7 @@ int64_t x6500_process_results(struct thr_info *thr, struct work *work)
 	bool bad;
 	bool bad;
 
 
 	while (1) {
 	while (1) {
-		gettimeofday(&tv_now, NULL);
+		timer_set_now(&tv_now);
 		nonce = x6500_get_register(jtag, 0xE);
 		nonce = x6500_get_register(jtag, 0xE);
 		if (nonce != 0xffffffff) {
 		if (nonce != 0xffffffff) {
 			bad = !(work && test_nonce(work, nonce, false));
 			bad = !(work && test_nonce(work, nonce, false));

+ 1 - 1
miner.c

@@ -2644,7 +2644,7 @@ static void curses_print_status(void)
 
 
 	wattron(statuswin, A_BOLD);
 	wattron(statuswin, A_BOLD);
 	mvwprintw(statuswin, 0, 0, " " PACKAGE " version " VERSION " - Started: %s", datestamp);
 	mvwprintw(statuswin, 0, 0, " " PACKAGE " version " VERSION " - Started: %s", datestamp);
-	if (!gettimeofday(&now, NULL))
+	timer_set_now(&now);
 	{
 	{
 		unsigned int days, hours;
 		unsigned int days, hours;
 		div_t d;
 		div_t d;

+ 3 - 1
util.h

@@ -223,6 +223,8 @@ bool timer_isset(const struct timeval *tvp)
 	return tvp->tv_sec != -1;
 	return tvp->tv_sec != -1;
 }
 }
 
 
+#define timer_set_now(tvp)  cgtime(tvp)
+
 #define TIMEVAL_USECS(usecs)  (  \
 #define TIMEVAL_USECS(usecs)  (  \
 	(struct timeval){  \
 	(struct timeval){  \
 		.tv_sec = (usecs) / 1000000,  \
 		.tv_sec = (usecs) / 1000000,  \
@@ -237,7 +239,7 @@ bool timer_isset(const struct timeval *tvp)
 
 
 #define timer_set_delay_from_now(tvp_timer, usecs)  do {  \
 #define timer_set_delay_from_now(tvp_timer, usecs)  do {  \
 	struct timeval tv_now;  \
 	struct timeval tv_now;  \
-	gettimeofday(&tv_now, NULL);  \
+	timer_set_now(&tv_now);  \
 	timer_set_delay(tvp_timer, &tv_now, usecs);  \
 	timer_set_delay(tvp_timer, &tv_now, usecs);  \
 } while(0)
 } while(0)