mirror of
https://github.com/GOSTSec/sgminer
synced 2025-01-11 07:17:58 +00:00
Timersub is supported on all build platforms so do away with custom timerval_subtract function.
This commit is contained in:
parent
75ea616422
commit
1e9421475c
17
cgminer.c
17
cgminer.c
@ -3368,8 +3368,9 @@ static void hashmeter(int thr_id, struct timeval *diff,
|
|||||||
if (want_per_device_stats) {
|
if (want_per_device_stats) {
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
struct timeval elapsed;
|
struct timeval elapsed;
|
||||||
|
|
||||||
gettimeofday(&now, NULL);
|
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) {
|
if (opt_log_interval <= elapsed.tv_sec) {
|
||||||
struct cgpu_info *cgpu = thr->cgpu;
|
struct cgpu_info *cgpu = thr->cgpu;
|
||||||
char logline[255];
|
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 */
|
/* Totals are updated by all threads so can race without locking */
|
||||||
mutex_lock(&hash_lock);
|
mutex_lock(&hash_lock);
|
||||||
gettimeofday(&temp_tv_end, NULL);
|
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;
|
total_mhashes_done += local_mhashes;
|
||||||
local_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);
|
decay_time(&rolling, local_mhashes_done / local_secs);
|
||||||
global_hashrate = roundl(rolling) * 1000000;
|
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 +
|
total_secs = (double)total_diff.tv_sec +
|
||||||
((double)total_diff.tv_usec / 1000000.0);
|
((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 */
|
/* Try to cycle approximately 5 times before each log update */
|
||||||
const long cycle = opt_log_interval / 5 ? : 1;
|
const long cycle = opt_log_interval / 5 ? : 1;
|
||||||
struct timeval tv_start, tv_end, tv_workstart, tv_lastupdate;
|
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;
|
uint32_t max_nonce = api->can_limit_work ? api->can_limit_work(mythr) : 0xffffffff;
|
||||||
unsigned long long hashes_done = 0;
|
unsigned long long hashes_done = 0;
|
||||||
unsigned long long hashes;
|
unsigned long long hashes;
|
||||||
@ -4074,7 +4075,7 @@ void *miner_thread(void *userdata)
|
|||||||
cgpu->max_hashes = hashes;
|
cgpu->max_hashes = hashes;
|
||||||
|
|
||||||
gettimeofday(&tv_end, NULL);
|
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_sec += diff.tv_sec;
|
||||||
sdiff.tv_usec += diff.tv_usec;
|
sdiff.tv_usec += diff.tv_usec;
|
||||||
if (sdiff.tv_usec > 1000000) {
|
if (sdiff.tv_usec > 1000000) {
|
||||||
@ -4082,7 +4083,7 @@ void *miner_thread(void *userdata)
|
|||||||
sdiff.tv_usec -= 1000000;
|
sdiff.tv_usec -= 1000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
timeval_subtract(&wdiff, &tv_end, &tv_workstart);
|
timersub(&tv_end, &tv_workstart, &wdiff);
|
||||||
if (!requested) {
|
if (!requested) {
|
||||||
if (wdiff.tv_sec > request_interval || work->blk.nonce > request_nonce) {
|
if (wdiff.tv_sec > request_interval || work->blk.nonce > request_nonce) {
|
||||||
thread_reportout(mythr);
|
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));
|
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) {
|
if (diff.tv_sec >= opt_log_interval) {
|
||||||
hashmeter(thr_id, &diff, hashes_done);
|
hashmeter(thr_id, &diff, hashes_done);
|
||||||
hashes_done = 0;
|
hashes_done = 0;
|
||||||
@ -4588,7 +4589,7 @@ static void print_summary(void)
|
|||||||
int hours, mins, secs, i;
|
int hours, mins, secs, i;
|
||||||
double utility, efficiency = 0.0;
|
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;
|
hours = diff.tv_sec / 3600;
|
||||||
mins = (diff.tv_sec % 3600) / 60;
|
mins = (diff.tv_sec % 3600) / 60;
|
||||||
secs = diff.tv_sec % 60;
|
secs = diff.tv_sec % 60;
|
||||||
|
@ -466,7 +466,7 @@ modminer_process_results(struct thr_info*thr)
|
|||||||
|
|
||||||
struct timeval tv_workend, elapsed;
|
struct timeval tv_workend, elapsed;
|
||||||
gettimeofday(&tv_workend, NULL);
|
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);
|
uint64_t hashes = (uint64_t)state->clock * (((uint64_t)elapsed.tv_sec * 1000000) + elapsed.tv_usec);
|
||||||
if (hashes > 0xffffffff)
|
if (hashes > 0xffffffff)
|
||||||
|
3
miner.h
3
miner.h
@ -550,9 +550,6 @@ typedef bool (*sha256_func)(int thr_id, const unsigned char *pmidstate,
|
|||||||
uint32_t *last_nonce,
|
uint32_t *last_nonce,
|
||||||
uint32_t 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 bool fulltest(const unsigned char *hash, const unsigned char *target);
|
||||||
|
|
||||||
extern int opt_scantime;
|
extern int opt_scantime;
|
||||||
|
29
util.c
29
util.c
@ -491,35 +491,6 @@ bool hex2bin(unsigned char *p, const char *hexstr, size_t len)
|
|||||||
return (len == 0 && *hexstr == 0) ? true : false;
|
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)
|
bool fulltest(const unsigned char *hash, const unsigned char *target)
|
||||||
{
|
{
|
||||||
unsigned char hash_swap[32], target_swap[32];
|
unsigned char hash_swap[32], target_swap[32];
|
||||||
|
Loading…
Reference in New Issue
Block a user