Timersub is supported on all build platforms so do away with custom timerval_subtract function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
diff --git a/cgminer.c b/cgminer.c
index cbb730c..bbb0799 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -3368,8 +3368,9 @@ static void hashmeter(int thr_id, struct timeval *diff,
if (want_per_device_stats) {
struct timeval now;
struct timeval elapsed;
+
gettimeofday(&now, NULL);
- timeval_subtract(&elapsed, &now, &thr->cgpu->last_message_tv);
+ timersub(&now, &thr->cgpu->last_message_tv, &elapsed);
if (opt_log_interval <= elapsed.tv_sec) {
struct cgpu_info *cgpu = thr->cgpu;
char logline[255];
@@ -3389,7 +3390,7 @@ static void hashmeter(int thr_id, struct timeval *diff,
/* Totals are updated by all threads so can race without locking */
mutex_lock(&hash_lock);
gettimeofday(&temp_tv_end, NULL);
- timeval_subtract(&total_diff, &temp_tv_end, &total_tv_end);
+ timersub(&temp_tv_end, &total_tv_end, &total_diff);
total_mhashes_done += local_mhashes;
local_mhashes_done += local_mhashes;
@@ -3403,7 +3404,7 @@ static void hashmeter(int thr_id, struct timeval *diff,
decay_time(&rolling, local_mhashes_done / local_secs);
global_hashrate = roundl(rolling) * 1000000;
- timeval_subtract(&total_diff, &total_tv_end, &total_tv_start);
+ timersub(&total_tv_end, &total_tv_start, &total_diff);
total_secs = (double)total_diff.tv_sec +
((double)total_diff.tv_usec / 1000000.0);
@@ -3957,7 +3958,7 @@ void *miner_thread(void *userdata)
/* Try to cycle approximately 5 times before each log update */
const long cycle = opt_log_interval / 5 ? : 1;
struct timeval tv_start, tv_end, tv_workstart, tv_lastupdate;
- struct timeval diff, sdiff, wdiff;
+ struct timeval diff, sdiff, wdiff = {0, 0};
uint32_t max_nonce = api->can_limit_work ? api->can_limit_work(mythr) : 0xffffffff;
unsigned long long hashes_done = 0;
unsigned long long hashes;
@@ -4074,7 +4075,7 @@ void *miner_thread(void *userdata)
cgpu->max_hashes = hashes;
gettimeofday(&tv_end, NULL);
- timeval_subtract(&diff, &tv_end, &tv_start);
+ timersub(&tv_end, &tv_start, &diff);
sdiff.tv_sec += diff.tv_sec;
sdiff.tv_usec += diff.tv_usec;
if (sdiff.tv_usec > 1000000) {
@@ -4082,7 +4083,7 @@ void *miner_thread(void *userdata)
sdiff.tv_usec -= 1000000;
}
- timeval_subtract(&wdiff, &tv_end, &tv_workstart);
+ timersub(&tv_end, &tv_workstart, &wdiff);
if (!requested) {
if (wdiff.tv_sec > request_interval || work->blk.nonce > request_nonce) {
thread_reportout(mythr);
@@ -4118,7 +4119,7 @@ void *miner_thread(void *userdata)
max_nonce = max_nonce * 0x400 / (((cycle * 1000000) + sdiff.tv_usec) / (cycle * 1000000 / 0x400));
}
- timeval_subtract(&diff, &tv_end, &tv_lastupdate);
+ timersub(&tv_end, &tv_lastupdate, &diff);
if (diff.tv_sec >= opt_log_interval) {
hashmeter(thr_id, &diff, hashes_done);
hashes_done = 0;
@@ -4588,7 +4589,7 @@ static void print_summary(void)
int hours, mins, secs, i;
double utility, efficiency = 0.0;
- timeval_subtract(&diff, &total_tv_end, &total_tv_start);
+ timersub(&total_tv_end, &total_tv_start, &diff);
hours = diff.tv_sec / 3600;
mins = (diff.tv_sec % 3600) / 60;
secs = diff.tv_sec % 60;
diff --git a/driver-modminer.c b/driver-modminer.c
index 2f8ee11..5b00aac 100644
--- a/driver-modminer.c
+++ b/driver-modminer.c
@@ -466,7 +466,7 @@ modminer_process_results(struct thr_info*thr)
struct timeval tv_workend, elapsed;
gettimeofday(&tv_workend, NULL);
- timeval_subtract(&elapsed, &tv_workend, &state->tv_workstart);
+ timersub(&tv_workend, &state->tv_workstart, &elapsed);
uint64_t hashes = (uint64_t)state->clock * (((uint64_t)elapsed.tv_sec * 1000000) + elapsed.tv_usec);
if (hashes > 0xffffffff)
diff --git a/miner.h b/miner.h
index 57fa774..0520cbc 100644
--- a/miner.h
+++ b/miner.h
@@ -550,9 +550,6 @@ typedef bool (*sha256_func)(int thr_id, const unsigned char *pmidstate,
uint32_t *last_nonce,
uint32_t nonce);
-extern int
-timeval_subtract (struct timeval *result, struct timeval *x, struct timeval *y);
-
extern bool fulltest(const unsigned char *hash, const unsigned char *target);
extern int opt_scantime;
diff --git a/util.c b/util.c
index c1feb4d..923bb82 100644
--- a/util.c
+++ b/util.c
@@ -491,35 +491,6 @@ bool hex2bin(unsigned char *p, const char *hexstr, size_t len)
return (len == 0 && *hexstr == 0) ? true : false;
}
-/* Subtract the `struct timeval' values X and Y,
- storing the result in RESULT.
- Return 1 if the difference is negative, otherwise 0. */
-
-int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y)
-{
- /* Perform the carry for the later subtraction by updating Y. */
- if (x->tv_usec < y->tv_usec) {
- int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
-
- y->tv_usec -= 1000000 * nsec;
- y->tv_sec += nsec;
- }
- if (x->tv_usec - y->tv_usec > 1000000) {
- int nsec = (x->tv_usec - y->tv_usec) / 1000000;
-
- y->tv_usec += 1000000 * nsec;
- y->tv_sec -= nsec;
- }
-
- /* Compute the time remaining to wait.
- * `tv_usec' is certainly positive. */
- result->tv_sec = x->tv_sec - y->tv_sec;
- result->tv_usec = x->tv_usec - y->tv_usec;
-
- /* Return 1 if result is negative. */
- return x->tv_sec < y->tv_sec;
-}
-
bool fulltest(const unsigned char *hash, const unsigned char *target)
{
unsigned char hash_swap[32], target_swap[32];