Browse Source

Provide wrappers for commonly used timer routines with API stats.

nfactor-troky
Con Kolivas 12 years ago
parent
commit
d2abaa8317
  1. 36
      cgminer.c
  2. 25
      util.c
  3. 5
      util.h

36
cgminer.c

@ -5653,34 +5653,22 @@ static void hash_sole_work(struct thr_info *mythr) @@ -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));

25
util.c

@ -852,6 +852,31 @@ void cgtime(struct timeval *tv) @@ -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)
{

5
util.h

@ -51,6 +51,11 @@ void thr_info_freeze(struct thr_info *thr); @@ -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);

Loading…
Cancel
Save