Provide wrappers for commonly used timer routines with API stats.
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
diff --git a/cgminer.c b/cgminer.c
index 64cf779..9547fa8 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -5653,34 +5653,22 @@ static void hash_sole_work(struct thr_info *mythr)
do {
cgtime(&tv_start);
- timersub(&tv_start, &getwork_start, &getwork_start);
-
- timeradd(&getwork_start,
- &(dev_stats->getwork_wait),
- &(dev_stats->getwork_wait));
- if (timercmp(&getwork_start, &(dev_stats->getwork_wait_max), >)) {
- dev_stats->getwork_wait_max.tv_sec = getwork_start.tv_sec;
- dev_stats->getwork_wait_max.tv_usec = getwork_start.tv_usec;
- }
- if (timercmp(&getwork_start, &(dev_stats->getwork_wait_min), <)) {
- dev_stats->getwork_wait_min.tv_sec = getwork_start.tv_sec;
- dev_stats->getwork_wait_min.tv_usec = getwork_start.tv_usec;
- }
+ subtime(&tv_start, &getwork_start);
+
+ addtime(&getwork_start, &dev_stats->getwork_wait);
+ if (time_more(&getwork_start, &dev_stats->getwork_wait_max))
+ copy_time(&dev_stats->getwork_wait_max, &getwork_start);
+ if (time_less(&getwork_start, &dev_stats->getwork_wait_min))
+ copy_time(&dev_stats->getwork_wait_min, &getwork_start);
dev_stats->getwork_calls++;
pool_stats = &(work->pool->cgminer_stats);
- timeradd(&getwork_start,
- &(pool_stats->getwork_wait),
- &(pool_stats->getwork_wait));
- if (timercmp(&getwork_start, &(pool_stats->getwork_wait_max), >)) {
- pool_stats->getwork_wait_max.tv_sec = getwork_start.tv_sec;
- pool_stats->getwork_wait_max.tv_usec = getwork_start.tv_usec;
- }
- if (timercmp(&getwork_start, &(pool_stats->getwork_wait_min), <)) {
- pool_stats->getwork_wait_min.tv_sec = getwork_start.tv_sec;
- pool_stats->getwork_wait_min.tv_usec = getwork_start.tv_usec;
- }
+ addtime(&getwork_start, &pool_stats->getwork_wait);
+ if (time_more(&getwork_start, &pool_stats->getwork_wait_max))
+ copy_time(&pool_stats->getwork_wait_max, &getwork_start);
+ if (time_less(&getwork_start, &pool_stats->getwork_wait_min))
+ copy_time(&pool_stats->getwork_wait_min, &getwork_start);
pool_stats->getwork_calls++;
cgtime(&(work->tv_work_start));
diff --git a/util.c b/util.c
index c3693c7..c810560 100644
--- a/util.c
+++ b/util.c
@@ -852,6 +852,31 @@ void cgtime(struct timeval *tv)
#endif
}
+void subtime(struct timeval *a, struct timeval *b)
+{
+ timersub(a, b, b);
+}
+
+void addtime(struct timeval *a, struct timeval *b)
+{
+ timeradd(a, b, b);
+}
+
+bool time_more(struct timeval *a, struct timeval *b)
+{
+ return timercmp(a, b, >);
+}
+
+bool time_less(struct timeval *a, struct timeval *b)
+{
+ return timercmp(a, b, <);
+}
+
+void copy_time(struct timeval *dest, const struct timeval *src)
+{
+ memcpy(dest, src, sizeof(struct timeval));
+}
+
/* Returns the microseconds difference between end and start times as a double */
double us_tdiff(struct timeval *end, struct timeval *start)
{
diff --git a/util.h b/util.h
index ccfa37d..1c0187e 100644
--- a/util.h
+++ b/util.h
@@ -51,6 +51,11 @@ void thr_info_freeze(struct thr_info *thr);
void thr_info_cancel(struct thr_info *thr);
void nmsleep(unsigned int msecs);
void cgtime(struct timeval *tv);
+void subtime(struct timeval *a, struct timeval *b);
+void addtime(struct timeval *a, struct timeval *b);
+bool time_more(struct timeval *a, struct timeval *b);
+bool time_less(struct timeval *a, struct timeval *b);
+void copy_time(struct timeval *dest, const struct timeval *src);
double us_tdiff(struct timeval *end, struct timeval *start);
double tdiff(struct timeval *end, struct timeval *start);
bool stratum_send(struct pool *pool, char *s, ssize_t len);