Commit eeac9d81fcb7593da8db76af0701f8bb0c1a8ebb

Con Kolivas 2013-08-20T19:23:49

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

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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
diff --git a/adl.c b/adl.c
index 928efe0..8d14c27 100644
--- a/adl.c
+++ b/adl.c
@@ -1399,7 +1399,7 @@ updated:
 		clear_logwin();
 		return;
 	}
-	nmsleep(1000);
+	cgsleep_ms(1000);
 	goto updated;
 }
 #endif
diff --git a/api.c b/api.c
index 11215dd..4fcc66f 100644
--- a/api.c
+++ b/api.c
@@ -4317,7 +4317,7 @@ void api(int api_thr_id)
 
 	/* This should be done before curl in needed
 	 * 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);
 	if (*apisock == INVSOCK) {
@@ -4363,7 +4363,7 @@ void api(int api_thr_id)
 				break;
 			else {
 				applog(LOG_WARNING, "API bind to port %d failed - trying again in 30sec", port);
-				nmsleep(30000);
+				cgsleep_ms(30000);
 			}
 		} else
 			bound = 1;
diff --git a/cgminer.c b/cgminer.c
index 2cf679c..8e921be 100644
--- a/cgminer.c
+++ b/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);
 		}
-		nmsleep(5000);
+		cgsleep_ms(5000);
 		goto out;
 	} else if (pool_tclear(pool, &pool->submit_fail))
 		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)) {
 					if (pool->removed)
 						goto out;
-					nmsleep(30000);
+					cgsleep_ms(30000);
 				}
 			}
 		}
@@ -5097,7 +5097,7 @@ static void *stratum_rthread(void *userdata)
 			while (!restart_stratum(pool)) {
 				if (pool->removed)
 					goto out;
-				nmsleep(30000);
+				cgsleep_ms(30000);
 			}
 			stratum_resumed(pool);
 			continue;
@@ -6314,7 +6314,7 @@ retry_pool:
 	if (!pool) {
 		applog(LOG_WARNING, "No suitable long-poll found for %s", cp->rpc_url);
 		while (!pool) {
-			nmsleep(60000);
+			cgsleep_ms(60000);
 			pool = select_longpoll_pool(cp);
 		}
 	}
@@ -6390,7 +6390,7 @@ retry_pool:
 				continue;
 			if (failures == 1)
 				applog(LOG_WARNING, "longpoll failed for %s, retrying every 30s", lp_url);
-			nmsleep(30000);
+			cgsleep_ms(30000);
 		}
 
 		if (pool != cp) {
@@ -6502,7 +6502,7 @@ static void *watchpool_thread(void __maybe_unused *userdata)
 			switch_pools(NULL);
 		}
 
-		nmsleep(30000);
+		cgsleep_ms(30000);
 			
 	}
 	return NULL;
@@ -7329,13 +7329,13 @@ static void *hotplug_thread(void __maybe_unused *userdata)
 
 	hotplug_mode = true;
 
-	nmsleep(5000);
+	cgsleep_ms(5000);
 
 	while (0x2a) {
 // Version 0.1 just add the devices on - worry about using nodev later
 
 		if (hotplug_time == 0)
-			nmsleep(5000);
+			cgsleep_ms(5000);
 		else {
 			new_devices = 0;
 			new_threads = 0;
@@ -7364,7 +7364,7 @@ static void *hotplug_thread(void __maybe_unused *userdata)
 				hotplug_process();
 
 			// 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) {
 				struct pool *altpool = select_pool(true);
 
-				nmsleep(5000);
+				cgsleep_ms(5000);
 				if (altpool != pool) {
 					pool = altpool;
 					goto retry;
@@ -7935,7 +7935,7 @@ retry:
 			while (pool->idle) {
 				struct pool *altpool = select_pool(true);
 
-				nmsleep(5000);
+				cgsleep_ms(5000);
 				if (altpool != pool) {
 					pool = altpool;
 					goto retry;
@@ -7969,7 +7969,7 @@ retry:
 			 * requests but is up as we'll keep hammering it */
 			if (++pool->seq_getfails > mining_threads + opt_queue)
 				pool_died(pool);
-			nmsleep(5000);
+			cgsleep_ms(5000);
 			push_curl_entry(ce, pool);
 			pool = select_pool(!opt_fail_only);
 			goto retry;
diff --git a/driver-avalon.c b/driver-avalon.c
index 94b0eb2..995abd8 100644
--- a/driver-avalon.c
+++ b/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)
 {
 	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;
 
 		while (avalon_buffer_full(avalon))
-			nmsleep(40);
+			cgsleep_ms(40);
 
 		avalon_adjust_freq(info, avalon);
 
@@ -1133,14 +1133,14 @@ static void *bitburner_send_tasks(void *userdata)
 		bool idled = false;
 
 		while (avalon_buffer_full(avalon))
-			nmsleep(40);
+			cgsleep_ms(40);
 
 		avalon_adjust_freq(info, avalon);
 
 		/* Give other threads a chance to acquire qlock. */
 		i = 0;
 		do {
-			nmsleep(40);
+			cgsleep_ms(40);
 		} while (!avalon->shutdown && i++ < 15
 			&& 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;
 		for (i = start_count, j = 0; i < end_count; i++, j++) {
 			while (avalon_buffer_full(avalon))
-				nmsleep(40);
+				cgsleep_ms(40);
 
 			if (likely(j < avalon->queued && !info->overheat && avalon->works[i])) {
 				avalon_init_task(&at, 0, 0, info->fan_pwm,
diff --git a/driver-bflsc.c b/driver-bflsc.c
index 20725b5..2f93f7b 100644
--- a/driver-bflsc.c
+++ b/driver-bflsc.c
@@ -734,7 +734,7 @@ reinit:
 				applog(LOG_WARNING, "%s detect (%s) 2nd init failed (%d:%d) - retrying",
 					bflsc->drv->dname, bflsc->device_path, amount, err);
 			}
-			nmsleep(init_sleep);
+			cgsleep_ms(init_sleep);
 			if ((init_sleep * 2) <= REINIT_TIME_MAX_MS)
 				init_sleep *= 2;
 			goto reinit;
@@ -783,7 +783,7 @@ reinit:
 		if (++tries > 2)
 			goto unshin;
 
-		nmsleep(40);
+		cgsleep_ms(40);
 	}
 
 	switch (sc_info->driver_version) {
@@ -1849,7 +1849,7 @@ static bool bflsc_get_stats(struct cgpu_info *bflsc)
 			return false;
 
 		if (i < (sc_info->sc_count - 1))
-			nmsleep(BFLSC_TEMP_SLEEPMS);
+			cgsleep_ms(BFLSC_TEMP_SLEEPMS);
 	}
 
 	bflsc_set_fanspeed(bflsc);
diff --git a/driver-bitforce.c b/driver-bitforce.c
index 9afa36d..41deae3 100644
--- a/driver-bitforce.c
+++ b/driver-bitforce.c
@@ -199,7 +199,7 @@ reinit:
 				applog(LOG_WARNING, "%s detect (%s) 2nd init failed (%d:%d) - retrying",
 					bitforce->drv->dname, bitforce->device_path, amount, err);
 			}
-			nmsleep(init_sleep);
+			cgsleep_ms(init_sleep);
 			if ((init_sleep * 2) <= REINIT_TIME_MAX_MS)
 				init_sleep *= 2;
 			goto reinit;
@@ -333,7 +333,7 @@ static void bitforce_flash_led(struct cgpu_info *bitforce)
 	} else {
 		/* However, this stops anything else getting a reply
 		 * 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 */
@@ -462,7 +462,7 @@ re_send:
 
 	if (amount == 0 || !buf[0] || !strncasecmp(buf, "B", 1)) {
 		mutex_unlock(&bitforce->device_mutex);
-		nmsleep(WORK_CHECK_INTERVAL_MS);
+		cgsleep_ms(WORK_CHECK_INTERVAL_MS);
 		goto re_send;
 	} else if (unlikely(strncasecmp(buf, "OK", 2))) {
 		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 */
 		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;
 	}
 
@@ -721,7 +721,7 @@ static bool bitforce_thread_init(struct thr_info *thr)
 	wait = thr->id * MAX_START_DELAY_MS;
 	applog(LOG_DEBUG, "%s%d: Delaying start by %dms",
 			bitforce->drv->name, bitforce->device_id, wait / 1000);
-	nmsleep(wait);
+	cgsleep_ms(wait);
 
 	return true;
 }
diff --git a/driver-modminer.c b/driver-modminer.c
index bfe3040..8f85855 100644
--- a/driver-modminer.c
+++ b/driver-modminer.c
@@ -553,7 +553,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
 		modminer->drv->name, modminer->device_id, devmsg);
 
 	// Give it a 2/3s delay after programming
-	nmsleep(666);
+	cgsleep_ms(666);
 
 	usb_set_dev_start(modminer);
 
@@ -1016,7 +1016,7 @@ tryagain:
 			break;
 
 		// 1/10th sec to lower CPU usage
-		nmsleep(100);
+		cgsleep_ms(100);
 		if (work_restart(thr))
 			break;
 	}
@@ -1065,7 +1065,7 @@ static int64_t modminer_scanhash(struct thr_info *thr, struct work *work, int64_
 					return 0;
 
 				// Give it 1s rest then check again
-				nmsleep(1000);
+				cgsleep_ms(1000);
 			}
 		}
 	}
diff --git a/driver-ztex.c b/driver-ztex.c
index 077d0ca..2525471 100644
--- a/driver-ztex.c
+++ b/driver-ztex.c
@@ -194,7 +194,7 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
 	if (i < 0) {
 		// Something wrong happened in send
 		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);
 		if (i < 0) {
 			// 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;
 		while (thr->work_restart == 0 && sleepcount < 25) {
-			nmsleep(10);
+			cgsleep_ms(10);
 			sleepcount += 1;
 		}
 
@@ -247,7 +247,7 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
 		if (i < 0) {
 			// Something wrong happened in read
 			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]);
 			if (i < 0) {
 				// And there's nothing we can do about it
diff --git a/libztex.c b/libztex.c
index dd56334..860a842 100644
--- a/libztex.c
+++ b/libztex.c
@@ -421,7 +421,7 @@ static int libztex_configureFpgaHS(struct libztex_device *ztex, const char* firm
 
 	libusb_release_interface(ztex->hndl, settings[1]);
 
-	nmsleep(200);
+	cgsleep_ms(200);
 	applog(LOG_INFO, "%s: HS FPGA configuration done", ztex->repr);
 	return 0;
 }
@@ -486,7 +486,7 @@ static int libztex_configureFpgaLS(struct libztex_device *ztex, const char* firm
 		return -3;
 	}
 
-	nmsleep(200);
+	cgsleep_ms(200);
 	applog(LOG_INFO, "%s: FPGA configuration done", ztex->repr);
 	return 0;
 }
diff --git a/usbutils.c b/usbutils.c
index f5c5da2..adcd3da 100644
--- a/usbutils.c
+++ b/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?
 	while (true) {
-		nmsleep(50);
+		cgsleep_ms(50);
 
 		mutex_lock(&cgusbres_lock);
 		if (res_reply_head) {
@@ -1961,7 +1961,7 @@ void usb_detect(struct device_drv *drv, bool (*device_detect)(struct libusb_devi
 	if (count == 0)
 		applog(LOG_DEBUG, "USB scan devices: found no devices");
 	else
-		nmsleep(166);
+		cgsleep_ms(166);
 
 	for (i = 0; i < count; i++) {
 		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) {
 						cgpu->usbinfo.read_delay_count++;
 						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) {
 					cgpu->usbinfo.read_delay_count++;
 					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) {
 					cgpu->usbinfo.write_delay_count++;
 					cgpu->usbinfo.total_write_delay += need;
-					nmsleep((unsigned int)(need * 1000.0));
+					cgsleep_ms((unsigned int)(need * 1000.0));
 				}
 			}
 			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) {
 				cgpu->usbinfo.write_delay_count++;
 				cgpu->usbinfo.total_write_delay += need;
-				nmsleep((unsigned int)(need * 1000.0));
+				cgsleep_ms((unsigned int)(need * 1000.0));
 			}
 		}
 		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) {
 				cgpu->usbinfo.read_delay_count++;
 				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;
 
-	nmsleep(10);
+	cgsleep_ms(10);
 
 	count = 0;
 	for (i = 0; i < total_devices; i++) {
@@ -3149,7 +3149,7 @@ void usb_cleanup()
 
 		cgtime(&start);
 		while (42) {
-			nmsleep(50);
+			cgsleep_ms(50);
 
 			mutex_lock(&cgusbres_lock);
 
@@ -3528,7 +3528,7 @@ fail:
 			}
 			if (opt.buf->sem_otime != 0)
 				break;
-			nmsleep(1);
+			cgsleep_ms(1);
 		}
 	}
 
diff --git a/util.c b/util.c
index ffba6fa..f555c6e 100644
--- a/util.c
+++ b/util.c
@@ -991,19 +991,6 @@ void cgsleep_us(int64_t 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 */
 double us_tdiff(struct timeval *end, struct timeval *start)
 {
diff --git a/util.h b/util.h
index 59b91a7..08eeaf7 100644
--- a/util.h
+++ b/util.h
@@ -72,8 +72,6 @@ enum dev_reason;
 struct cgpu_info;
 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 nmsleep(unsigned int msecs);
-void nusleep(unsigned int usecs);
 void cgtime(struct timeval *tv);
 void subtime(struct timeval *a, struct timeval *b);
 void addtime(struct timeval *a, struct timeval *b);