Browse Source

Replace all references to the old n*sleep functions with the equivalent cgsleep_*s replacements.

nfactor-troky
Con Kolivas 12 years ago
parent
commit
eeac9d81fc
  1. 2
      adl.c
  2. 4
      api.c
  3. 24
      cgminer.c
  4. 10
      driver-avalon.c
  5. 6
      driver-bflsc.c
  6. 10
      driver-bitforce.c
  7. 6
      driver-modminer.c
  8. 6
      driver-ztex.c
  9. 4
      libztex.c
  10. 20
      usbutils.c
  11. 13
      util.c
  12. 2
      util.h

2
adl.c

@ -1399,7 +1399,7 @@ updated:
clear_logwin(); clear_logwin();
return; return;
} }
nmsleep(1000); cgsleep_ms(1000);
goto updated; goto updated;
} }
#endif #endif

4
api.c

@ -4317,7 +4317,7 @@ void api(int api_thr_id)
/* This should be done before curl in needed /* This should be done before curl in needed
* to ensure curl has already called WSAStartup() in windows */ * to ensure curl has already called WSAStartup() in windows */
nmsleep(opt_log_interval*1000); cgsleep_ms(opt_log_interval*1000);
*apisock = socket(AF_INET, SOCK_STREAM, 0); *apisock = socket(AF_INET, SOCK_STREAM, 0);
if (*apisock == INVSOCK) { if (*apisock == INVSOCK) {
@ -4363,7 +4363,7 @@ void api(int api_thr_id)
break; break;
else { else {
applog(LOG_WARNING, "API bind to port %d failed - trying again in 30sec", port); applog(LOG_WARNING, "API bind to port %d failed - trying again in 30sec", port);
nmsleep(30000); cgsleep_ms(30000);
} }
} else } else
bound = 1; bound = 1;

24
cgminer.c

@ -2592,7 +2592,7 @@ static bool submit_upstream_work(struct work *work, CURL *curl, bool resubmit)
} }
applog(LOG_WARNING, "Pool %d communication failure, caching submissions", pool->pool_no); applog(LOG_WARNING, "Pool %d communication failure, caching submissions", pool->pool_no);
} }
nmsleep(5000); cgsleep_ms(5000);
goto out; goto out;
} else if (pool_tclear(pool, &pool->submit_fail)) } else if (pool_tclear(pool, &pool->submit_fail))
applog(LOG_WARNING, "Pool %d communication resumed, submitting work", pool->pool_no); applog(LOG_WARNING, "Pool %d communication resumed, submitting work", pool->pool_no);
@ -5057,7 +5057,7 @@ static void *stratum_rthread(void *userdata)
while (!restart_stratum(pool)) { while (!restart_stratum(pool)) {
if (pool->removed) if (pool->removed)
goto out; goto out;
nmsleep(30000); cgsleep_ms(30000);
} }
} }
} }
@ -5097,7 +5097,7 @@ static void *stratum_rthread(void *userdata)
while (!restart_stratum(pool)) { while (!restart_stratum(pool)) {
if (pool->removed) if (pool->removed)
goto out; goto out;
nmsleep(30000); cgsleep_ms(30000);
} }
stratum_resumed(pool); stratum_resumed(pool);
continue; continue;
@ -6314,7 +6314,7 @@ retry_pool:
if (!pool) { if (!pool) {
applog(LOG_WARNING, "No suitable long-poll found for %s", cp->rpc_url); applog(LOG_WARNING, "No suitable long-poll found for %s", cp->rpc_url);
while (!pool) { while (!pool) {
nmsleep(60000); cgsleep_ms(60000);
pool = select_longpoll_pool(cp); pool = select_longpoll_pool(cp);
} }
} }
@ -6390,7 +6390,7 @@ retry_pool:
continue; continue;
if (failures == 1) if (failures == 1)
applog(LOG_WARNING, "longpoll failed for %s, retrying every 30s", lp_url); applog(LOG_WARNING, "longpoll failed for %s, retrying every 30s", lp_url);
nmsleep(30000); cgsleep_ms(30000);
} }
if (pool != cp) { if (pool != cp) {
@ -6502,7 +6502,7 @@ static void *watchpool_thread(void __maybe_unused *userdata)
switch_pools(NULL); switch_pools(NULL);
} }
nmsleep(30000); cgsleep_ms(30000);
} }
return NULL; return NULL;
@ -7329,13 +7329,13 @@ static void *hotplug_thread(void __maybe_unused *userdata)
hotplug_mode = true; hotplug_mode = true;
nmsleep(5000); cgsleep_ms(5000);
while (0x2a) { while (0x2a) {
// Version 0.1 just add the devices on - worry about using nodev later // Version 0.1 just add the devices on - worry about using nodev later
if (hotplug_time == 0) if (hotplug_time == 0)
nmsleep(5000); cgsleep_ms(5000);
else { else {
new_devices = 0; new_devices = 0;
new_threads = 0; new_threads = 0;
@ -7364,7 +7364,7 @@ static void *hotplug_thread(void __maybe_unused *userdata)
hotplug_process(); hotplug_process();
// hotplug_time >0 && <=9999 // hotplug_time >0 && <=9999
nmsleep(hotplug_time * 1000); cgsleep_ms(hotplug_time * 1000);
} }
} }
@ -7919,7 +7919,7 @@ retry:
while (!pool->stratum_active || !pool->stratum_notify) { while (!pool->stratum_active || !pool->stratum_notify) {
struct pool *altpool = select_pool(true); struct pool *altpool = select_pool(true);
nmsleep(5000); cgsleep_ms(5000);
if (altpool != pool) { if (altpool != pool) {
pool = altpool; pool = altpool;
goto retry; goto retry;
@ -7935,7 +7935,7 @@ retry:
while (pool->idle) { while (pool->idle) {
struct pool *altpool = select_pool(true); struct pool *altpool = select_pool(true);
nmsleep(5000); cgsleep_ms(5000);
if (altpool != pool) { if (altpool != pool) {
pool = altpool; pool = altpool;
goto retry; goto retry;
@ -7969,7 +7969,7 @@ retry:
* requests but is up as we'll keep hammering it */ * requests but is up as we'll keep hammering it */
if (++pool->seq_getfails > mining_threads + opt_queue) if (++pool->seq_getfails > mining_threads + opt_queue)
pool_died(pool); pool_died(pool);
nmsleep(5000); cgsleep_ms(5000);
push_curl_entry(ce, pool); push_curl_entry(ce, pool);
pool = select_pool(!opt_fail_only); pool = select_pool(!opt_fail_only);
goto retry; goto retry;

10
driver-avalon.c

@ -227,7 +227,7 @@ static bool avalon_decode_nonce(struct thr_info *thr, struct cgpu_info *avalon,
static void wait_avalon_ready(struct cgpu_info *avalon) static void wait_avalon_ready(struct cgpu_info *avalon)
{ {
while (avalon_buffer_full(avalon)) { while (avalon_buffer_full(avalon)) {
nmsleep(40); cgsleep_ms(40);
} }
} }
@ -1048,7 +1048,7 @@ static void *avalon_send_tasks(void *userdata)
int64_t us_timeout; int64_t us_timeout;
while (avalon_buffer_full(avalon)) while (avalon_buffer_full(avalon))
nmsleep(40); cgsleep_ms(40);
avalon_adjust_freq(info, avalon); avalon_adjust_freq(info, avalon);
@ -1133,14 +1133,14 @@ static void *bitburner_send_tasks(void *userdata)
bool idled = false; bool idled = false;
while (avalon_buffer_full(avalon)) while (avalon_buffer_full(avalon))
nmsleep(40); cgsleep_ms(40);
avalon_adjust_freq(info, avalon); avalon_adjust_freq(info, avalon);
/* Give other threads a chance to acquire qlock. */ /* Give other threads a chance to acquire qlock. */
i = 0; i = 0;
do { do {
nmsleep(40); cgsleep_ms(40);
} while (!avalon->shutdown && i++ < 15 } while (!avalon->shutdown && i++ < 15
&& avalon->queued < avalon_get_work_count); && avalon->queued < avalon_get_work_count);
@ -1149,7 +1149,7 @@ static void *bitburner_send_tasks(void *userdata)
end_count = start_count + avalon_get_work_count; end_count = start_count + avalon_get_work_count;
for (i = start_count, j = 0; i < end_count; i++, j++) { for (i = start_count, j = 0; i < end_count; i++, j++) {
while (avalon_buffer_full(avalon)) while (avalon_buffer_full(avalon))
nmsleep(40); cgsleep_ms(40);
if (likely(j < avalon->queued && !info->overheat && avalon->works[i])) { if (likely(j < avalon->queued && !info->overheat && avalon->works[i])) {
avalon_init_task(&at, 0, 0, info->fan_pwm, avalon_init_task(&at, 0, 0, info->fan_pwm,

6
driver-bflsc.c

@ -734,7 +734,7 @@ reinit:
applog(LOG_WARNING, "%s detect (%s) 2nd init failed (%d:%d) - retrying", applog(LOG_WARNING, "%s detect (%s) 2nd init failed (%d:%d) - retrying",
bflsc->drv->dname, bflsc->device_path, amount, err); bflsc->drv->dname, bflsc->device_path, amount, err);
} }
nmsleep(init_sleep); cgsleep_ms(init_sleep);
if ((init_sleep * 2) <= REINIT_TIME_MAX_MS) if ((init_sleep * 2) <= REINIT_TIME_MAX_MS)
init_sleep *= 2; init_sleep *= 2;
goto reinit; goto reinit;
@ -783,7 +783,7 @@ reinit:
if (++tries > 2) if (++tries > 2)
goto unshin; goto unshin;
nmsleep(40); cgsleep_ms(40);
} }
switch (sc_info->driver_version) { switch (sc_info->driver_version) {
@ -1849,7 +1849,7 @@ static bool bflsc_get_stats(struct cgpu_info *bflsc)
return false; return false;
if (i < (sc_info->sc_count - 1)) if (i < (sc_info->sc_count - 1))
nmsleep(BFLSC_TEMP_SLEEPMS); cgsleep_ms(BFLSC_TEMP_SLEEPMS);
} }
bflsc_set_fanspeed(bflsc); bflsc_set_fanspeed(bflsc);

10
driver-bitforce.c

@ -199,7 +199,7 @@ reinit:
applog(LOG_WARNING, "%s detect (%s) 2nd init failed (%d:%d) - retrying", applog(LOG_WARNING, "%s detect (%s) 2nd init failed (%d:%d) - retrying",
bitforce->drv->dname, bitforce->device_path, amount, err); bitforce->drv->dname, bitforce->device_path, amount, err);
} }
nmsleep(init_sleep); cgsleep_ms(init_sleep);
if ((init_sleep * 2) <= REINIT_TIME_MAX_MS) if ((init_sleep * 2) <= REINIT_TIME_MAX_MS)
init_sleep *= 2; init_sleep *= 2;
goto reinit; goto reinit;
@ -333,7 +333,7 @@ static void bitforce_flash_led(struct cgpu_info *bitforce)
} else { } else {
/* However, this stops anything else getting a reply /* However, this stops anything else getting a reply
* So best to delay any other access to the BFL */ * So best to delay any other access to the BFL */
nmsleep(4000); cgsleep_ms(4000);
} }
/* Once we've tried - don't do it until told to again */ /* Once we've tried - don't do it until told to again */
@ -462,7 +462,7 @@ re_send:
if (amount == 0 || !buf[0] || !strncasecmp(buf, "B", 1)) { if (amount == 0 || !buf[0] || !strncasecmp(buf, "B", 1)) {
mutex_unlock(&bitforce->device_mutex); mutex_unlock(&bitforce->device_mutex);
nmsleep(WORK_CHECK_INTERVAL_MS); cgsleep_ms(WORK_CHECK_INTERVAL_MS);
goto re_send; goto re_send;
} else if (unlikely(strncasecmp(buf, "OK", 2))) { } else if (unlikely(strncasecmp(buf, "OK", 2))) {
mutex_unlock(&bitforce->device_mutex); mutex_unlock(&bitforce->device_mutex);
@ -574,7 +574,7 @@ static int64_t bitforce_get_result(struct thr_info *thr, struct work *work)
/* if BFL is throttling, no point checking so quickly */ /* if BFL is throttling, no point checking so quickly */
delay_time_ms = (buf[0] ? BITFORCE_CHECK_INTERVAL_MS : 2 * WORK_CHECK_INTERVAL_MS); delay_time_ms = (buf[0] ? BITFORCE_CHECK_INTERVAL_MS : 2 * WORK_CHECK_INTERVAL_MS);
nmsleep(delay_time_ms); cgsleep_ms(delay_time_ms);
bitforce->wait_ms += delay_time_ms; bitforce->wait_ms += delay_time_ms;
} }
@ -721,7 +721,7 @@ static bool bitforce_thread_init(struct thr_info *thr)
wait = thr->id * MAX_START_DELAY_MS; wait = thr->id * MAX_START_DELAY_MS;
applog(LOG_DEBUG, "%s%d: Delaying start by %dms", applog(LOG_DEBUG, "%s%d: Delaying start by %dms",
bitforce->drv->name, bitforce->device_id, wait / 1000); bitforce->drv->name, bitforce->device_id, wait / 1000);
nmsleep(wait); cgsleep_ms(wait);
return true; return true;
} }

6
driver-modminer.c

@ -553,7 +553,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
modminer->drv->name, modminer->device_id, devmsg); modminer->drv->name, modminer->device_id, devmsg);
// Give it a 2/3s delay after programming // Give it a 2/3s delay after programming
nmsleep(666); cgsleep_ms(666);
usb_set_dev_start(modminer); usb_set_dev_start(modminer);
@ -1016,7 +1016,7 @@ tryagain:
break; break;
// 1/10th sec to lower CPU usage // 1/10th sec to lower CPU usage
nmsleep(100); cgsleep_ms(100);
if (work_restart(thr)) if (work_restart(thr))
break; break;
} }
@ -1065,7 +1065,7 @@ static int64_t modminer_scanhash(struct thr_info *thr, struct work *work, int64_
return 0; return 0;
// Give it 1s rest then check again // Give it 1s rest then check again
nmsleep(1000); cgsleep_ms(1000);
} }
} }
} }

6
driver-ztex.c

@ -194,7 +194,7 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
if (i < 0) { if (i < 0) {
// Something wrong happened in send // Something wrong happened in send
applog(LOG_ERR, "%s: Failed to send hash data with err %d, retrying", ztex->repr, i); applog(LOG_ERR, "%s: Failed to send hash data with err %d, retrying", ztex->repr, i);
nmsleep(500); cgsleep_ms(500);
i = libztex_sendHashData(ztex, sendbuf); i = libztex_sendHashData(ztex, sendbuf);
if (i < 0) { if (i < 0) {
// And there's nothing we can do about it // And there's nothing we can do about it
@ -233,7 +233,7 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
int sleepcount = 0; int sleepcount = 0;
while (thr->work_restart == 0 && sleepcount < 25) { while (thr->work_restart == 0 && sleepcount < 25) {
nmsleep(10); cgsleep_ms(10);
sleepcount += 1; sleepcount += 1;
} }
@ -247,7 +247,7 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
if (i < 0) { if (i < 0) {
// Something wrong happened in read // Something wrong happened in read
applog(LOG_ERR, "%s: Failed to read hash data with err %d, retrying", ztex->repr, i); applog(LOG_ERR, "%s: Failed to read hash data with err %d, retrying", ztex->repr, i);
nmsleep(500); cgsleep_ms(500);
i = libztex_readHashData(ztex, &hdata[0]); i = libztex_readHashData(ztex, &hdata[0]);
if (i < 0) { if (i < 0) {
// And there's nothing we can do about it // And there's nothing we can do about it

4
libztex.c

@ -421,7 +421,7 @@ static int libztex_configureFpgaHS(struct libztex_device *ztex, const char* firm
libusb_release_interface(ztex->hndl, settings[1]); libusb_release_interface(ztex->hndl, settings[1]);
nmsleep(200); cgsleep_ms(200);
applog(LOG_INFO, "%s: HS FPGA configuration done", ztex->repr); applog(LOG_INFO, "%s: HS FPGA configuration done", ztex->repr);
return 0; return 0;
} }
@ -486,7 +486,7 @@ static int libztex_configureFpgaLS(struct libztex_device *ztex, const char* firm
return -3; return -3;
} }
nmsleep(200); cgsleep_ms(200);
applog(LOG_INFO, "%s: FPGA configuration done", ztex->repr); applog(LOG_INFO, "%s: FPGA configuration done", ztex->repr);
return 0; return 0;
} }

20
usbutils.c

@ -1262,7 +1262,7 @@ static bool cgminer_usb_lock_bd(struct device_drv *drv, uint8_t bus_number, uint
// TODO: add a timeout fail - restart the resource thread? // TODO: add a timeout fail - restart the resource thread?
while (true) { while (true) {
nmsleep(50); cgsleep_ms(50);
mutex_lock(&cgusbres_lock); mutex_lock(&cgusbres_lock);
if (res_reply_head) { if (res_reply_head) {
@ -1961,7 +1961,7 @@ void usb_detect(struct device_drv *drv, bool (*device_detect)(struct libusb_devi
if (count == 0) if (count == 0)
applog(LOG_DEBUG, "USB scan devices: found no devices"); applog(LOG_DEBUG, "USB scan devices: found no devices");
else else
nmsleep(166); cgsleep_ms(166);
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
if (total_count >= total_limit) { if (total_count >= total_limit) {
@ -2429,7 +2429,7 @@ int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *pro
if (need > 0.0 && need < 1.0) { if (need > 0.0 && need < 1.0) {
cgpu->usbinfo.read_delay_count++; cgpu->usbinfo.read_delay_count++;
cgpu->usbinfo.total_read_delay += need; cgpu->usbinfo.total_read_delay += need;
nmsleep((unsigned int)(need * 1000.0)); cgsleep_ms((unsigned int)(need * 1000.0));
} }
} }
} }
@ -2535,7 +2535,7 @@ int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *pro
if (need > 0.0 && need < 1.0) { if (need > 0.0 && need < 1.0) {
cgpu->usbinfo.read_delay_count++; cgpu->usbinfo.read_delay_count++;
cgpu->usbinfo.total_read_delay += need; cgpu->usbinfo.total_read_delay += need;
nmsleep((unsigned int)(need * 1000.0)); cgsleep_ms((unsigned int)(need * 1000.0));
} }
} }
} }
@ -2674,7 +2674,7 @@ int _usb_write(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *pr
if (need > 0.0 && need < 1.0) { if (need > 0.0 && need < 1.0) {
cgpu->usbinfo.write_delay_count++; cgpu->usbinfo.write_delay_count++;
cgpu->usbinfo.total_write_delay += need; cgpu->usbinfo.total_write_delay += need;
nmsleep((unsigned int)(need * 1000.0)); cgsleep_ms((unsigned int)(need * 1000.0));
} }
} }
cgtime(&(usbdev->last_write_tv)); cgtime(&(usbdev->last_write_tv));
@ -2770,7 +2770,7 @@ int __usb_transfer(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bReques
if (need > 0.0 && need < 1.0) { if (need > 0.0 && need < 1.0) {
cgpu->usbinfo.write_delay_count++; cgpu->usbinfo.write_delay_count++;
cgpu->usbinfo.total_write_delay += need; cgpu->usbinfo.total_write_delay += need;
nmsleep((unsigned int)(need * 1000.0)); cgsleep_ms((unsigned int)(need * 1000.0));
} }
} }
cgtime(&(usbdev->last_write_tv)); cgtime(&(usbdev->last_write_tv));
@ -2848,7 +2848,7 @@ int _usb_transfer_read(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRe
if (need > 0.0 && need < 1.0) { if (need > 0.0 && need < 1.0) {
cgpu->usbinfo.read_delay_count++; cgpu->usbinfo.read_delay_count++;
cgpu->usbinfo.total_read_delay += need; cgpu->usbinfo.total_read_delay += need;
nmsleep((unsigned int)(need * 1000.0)); cgsleep_ms((unsigned int)(need * 1000.0));
} }
} }
} }
@ -3119,7 +3119,7 @@ void usb_cleanup()
hotplug_time = 0; hotplug_time = 0;
nmsleep(10); cgsleep_ms(10);
count = 0; count = 0;
for (i = 0; i < total_devices; i++) { for (i = 0; i < total_devices; i++) {
@ -3149,7 +3149,7 @@ void usb_cleanup()
cgtime(&start); cgtime(&start);
while (42) { while (42) {
nmsleep(50); cgsleep_ms(50);
mutex_lock(&cgusbres_lock); mutex_lock(&cgusbres_lock);
@ -3528,7 +3528,7 @@ fail:
} }
if (opt.buf->sem_otime != 0) if (opt.buf->sem_otime != 0)
break; break;
nmsleep(1); cgsleep_ms(1);
} }
} }

13
util.c

@ -991,19 +991,6 @@ void cgsleep_us(int64_t us)
cgsleep_us_r(&ts_start, us); cgsleep_us_r(&ts_start, us);
} }
/* Provide a ms based sleep that uses nanosleep to avoid poor usleep accuracy
* on SMP machines */
void nmsleep(unsigned int msecs)
{
cgsleep_ms((int)msecs);
}
/* Same for usecs */
void nusleep(unsigned int usecs)
{
cgsleep_us((int64_t)usecs);
}
/* Returns the microseconds difference between end and start times as a double */ /* Returns the microseconds difference between end and start times as a double */
double us_tdiff(struct timeval *end, struct timeval *start) double us_tdiff(struct timeval *end, struct timeval *start)
{ {

2
util.h

@ -72,8 +72,6 @@ enum dev_reason;
struct cgpu_info; struct cgpu_info;
int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) (void *), void *arg); int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) (void *), void *arg);
void thr_info_cancel(struct thr_info *thr); void thr_info_cancel(struct thr_info *thr);
void nmsleep(unsigned int msecs);
void nusleep(unsigned int usecs);
void cgtime(struct timeval *tv); void cgtime(struct timeval *tv);
void subtime(struct timeval *a, struct timeval *b); void subtime(struct timeval *a, struct timeval *b);
void addtime(struct timeval *a, struct timeval *b); void addtime(struct timeval *a, struct timeval *b);

Loading…
Cancel
Save