mirror of
https://github.com/GOSTSec/sgminer
synced 2025-01-25 14:04:25 +00:00
Use timespecs on windows as cgtimer_t to capitalise on the higher resolution clock changes.
This commit is contained in:
parent
d8e2a43712
commit
e1433f8ef8
69
util.c
69
util.c
@ -875,6 +875,11 @@ void timeraddspec(struct timespec *a, const struct timespec *b)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int timespec_to_ms(struct timespec *ts)
|
||||||
|
{
|
||||||
|
return ts->tv_sec * 1000 + ts->tv_nsec / 1000000;
|
||||||
|
}
|
||||||
|
|
||||||
/* These are cgminer specific sleep functions that use an absolute nanosecond
|
/* These are cgminer specific sleep functions that use an absolute nanosecond
|
||||||
* resolution timer to avoid poor usleep accuracy and overruns. */
|
* resolution timer to avoid poor usleep accuracy and overruns. */
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
@ -913,11 +918,6 @@ void cgsleep_us_r(cgtimer_t *ts_start, int64_t us)
|
|||||||
nanosleep_abstime(&ts_end);
|
nanosleep_abstime(&ts_end);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int timespec_to_ms(struct timespec *ts)
|
|
||||||
{
|
|
||||||
return ts->tv_sec * 1000 + ts->tv_nsec / 1000000;
|
|
||||||
}
|
|
||||||
|
|
||||||
int cgtimer_to_ms(cgtimer_t *cgt)
|
int cgtimer_to_ms(cgtimer_t *cgt)
|
||||||
{
|
{
|
||||||
return timespec_to_ms(cgt);
|
return timespec_to_ms(cgt);
|
||||||
@ -971,52 +971,65 @@ void cgtime(struct timeval *tv)
|
|||||||
|
|
||||||
void cgtimer_time(cgtimer_t *ts_start)
|
void cgtimer_time(cgtimer_t *ts_start)
|
||||||
{
|
{
|
||||||
cgtime(ts_start);
|
lldiv_t lidiv;;
|
||||||
|
|
||||||
|
decius_time(&lidiv);
|
||||||
|
ts_start->tv_sec = lidiv.quot;
|
||||||
|
ts_start->tv_nsec = lidiv.quot * 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ms_to_timeval(struct timeval *val, int ms)
|
/* Subtract b from a */
|
||||||
|
static void timersubspec(struct timespec *a, const struct timespec *b)
|
||||||
{
|
{
|
||||||
ldiv_t tvdiv = ldiv(ms, 1000);
|
a->tv_sec -= b->tv_sec;
|
||||||
|
a->tv_nsec -= b->tv_nsec;
|
||||||
|
if (a->tv_nsec < 0) {
|
||||||
|
a->tv_nsec += 1000000000;
|
||||||
|
a->tv_sec--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val->tv_sec = tvdiv.quot;
|
static void cgsleep_spec(struct timespec *ts_diff, const struct timespec *ts_start)
|
||||||
val->tv_usec = tvdiv.rem * 1000;
|
{
|
||||||
|
struct timespec now;
|
||||||
|
|
||||||
|
timeraddspec(ts_diff, ts_start);
|
||||||
|
cgtimer_time(&now);
|
||||||
|
timersubspec(ts_diff, &now);
|
||||||
|
if (unlikely(ts_diff->tv_sec < 0))
|
||||||
|
return;
|
||||||
|
nanosleep(ts_diff, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cgsleep_ms_r(cgtimer_t *ts_start, int ms)
|
void cgsleep_ms_r(cgtimer_t *ts_start, int ms)
|
||||||
{
|
{
|
||||||
struct timeval now, tv_end, tv_diff;
|
|
||||||
struct timespec ts_diff;
|
struct timespec ts_diff;
|
||||||
|
|
||||||
ms_to_timeval(&tv_diff, ms);
|
ms_to_timespec(&ts_diff, ms);
|
||||||
timeradd(ts_start, &tv_diff, &tv_end);
|
cgsleep_spec(&ts_diff, ts_start);
|
||||||
cgtime(&now);
|
|
||||||
if (unlikely(time_more(&now, &tv_end)))
|
|
||||||
return;
|
|
||||||
timersub(&tv_end, &now, &tv_diff);
|
|
||||||
timeval_to_spec(&ts_diff, &tv_diff);
|
|
||||||
nanosleep(&ts_diff, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cgsleep_us_r(cgtimer_t *ts_start, int64_t us)
|
void cgsleep_us_r(cgtimer_t *ts_start, int64_t us)
|
||||||
{
|
{
|
||||||
int ms = us / 1000;
|
struct timespec ts_diff;
|
||||||
|
|
||||||
cgsleep_ms_r(ts_start, ms);
|
us_to_timespec(&ts_diff, us);
|
||||||
}
|
cgsleep_spec(&ts_diff, ts_start);
|
||||||
|
|
||||||
static int timeval_to_ms(struct timeval *tv)
|
|
||||||
{
|
|
||||||
return tv->tv_sec * 1000 + tv->tv_usec / 1000;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int cgtimer_to_ms(cgtimer_t *cgt)
|
int cgtimer_to_ms(cgtimer_t *cgt)
|
||||||
{
|
{
|
||||||
return timeval_to_ms(cgt);
|
return timespec_to_ms(cgt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cgtimer_sub(cgtimer_t *a, cgtimer_t *b, cgtimer_t *res)
|
void cgtimer_sub(cgtimer_t *a, cgtimer_t *b, cgtimer_t *res)
|
||||||
{
|
{
|
||||||
timersub(a, b, res);
|
res->tv_sec = a->tv_sec - b->tv_sec;
|
||||||
|
res->tv_nsec = a->tv_nsec - b->tv_nsec;
|
||||||
|
if (res->tv_nsec < 0) {
|
||||||
|
res->tv_nsec += 1000000000;;
|
||||||
|
res->tv_sec--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
3
util.h
3
util.h
@ -20,7 +20,6 @@
|
|||||||
{
|
{
|
||||||
return (errno == EAGAIN || errno == EWOULDBLOCK);
|
return (errno == EAGAIN || errno == EWOULDBLOCK);
|
||||||
}
|
}
|
||||||
typedef struct timespec cgtimer_t;
|
|
||||||
#elif defined WIN32
|
#elif defined WIN32
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
@ -45,7 +44,6 @@
|
|||||||
#ifndef in_addr_t
|
#ifndef in_addr_t
|
||||||
#define in_addr_t uint32_t
|
#define in_addr_t uint32_t
|
||||||
#endif
|
#endif
|
||||||
typedef struct timeval cgtimer_t;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if JANSSON_MAJOR_VERSION >= 2
|
#if JANSSON_MAJOR_VERSION >= 2
|
||||||
@ -65,6 +63,7 @@ typedef struct cgsem cgsem_t;
|
|||||||
#else
|
#else
|
||||||
typedef sem_t cgsem_t;
|
typedef sem_t cgsem_t;
|
||||||
#endif
|
#endif
|
||||||
|
typedef struct timespec cgtimer_t;
|
||||||
|
|
||||||
struct thr_info;
|
struct thr_info;
|
||||||
struct pool;
|
struct pool;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user