Merge pull request #480 from kanoi/master usbutils cps sleep_estimate is not an underestimate
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
diff --git a/usbutils.c b/usbutils.c
index 4a3fbdc..1a0fa75 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -2416,18 +2416,17 @@ int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *pro
got = 0;
if (first && usbdev->usecps && usbdev->last_write_siz) {
- cgtimer_t now, already;
+ cgtimer_t now, already_done;
double sleep_estimate;
double write_time = (double)(usbdev->last_write_siz) /
(double)(usbdev->cps);
cgtimer_time(&now);
- cgtimer_sub(&now, &usbdev->cgt_last_write, &already);
- sleep_estimate = write_time - cgtimer_to_ms(&already);
-
- cgsleep_ms_r(&usbdev->cgt_last_write, write_time * 1000.0);
+ cgtimer_sub(&now, &usbdev->cgt_last_write, &already_done);
+ sleep_estimate = write_time - cgtimer_to_ms(&already_done);
if (sleep_estimate > 0.0) {
+ cgsleep_ms_r(&usbdev->cgt_last_write, write_time * 1000.0);
cgpu->usbinfo.read_delay_count++;
cgpu->usbinfo.total_read_delay += sleep_estimate;
}
@@ -2521,18 +2520,17 @@ int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *pro
}
got = 0;
if (first && usbdev->usecps && usbdev->last_write_siz) {
- cgtimer_t now, already;
+ cgtimer_t now, already_done;
double sleep_estimate;
double write_time = (double)(usbdev->last_write_siz) /
(double)(usbdev->cps);
cgtimer_time(&now);
- cgtimer_sub(&now, &usbdev->cgt_last_write, &already);
- sleep_estimate = write_time - cgtimer_to_ms(&already);
-
- cgsleep_ms_r(&usbdev->cgt_last_write, write_time * 1000.0);
+ cgtimer_sub(&now, &usbdev->cgt_last_write, &already_done);
+ sleep_estimate = write_time - cgtimer_to_ms(&already_done);
if (sleep_estimate > 0.0) {
+ cgsleep_ms_r(&usbdev->cgt_last_write, write_time * 1000.0);
cgpu->usbinfo.read_delay_count++;
cgpu->usbinfo.total_read_delay += sleep_estimate;
}
@@ -2660,18 +2658,17 @@ int _usb_write(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *pr
sent = 0;
if (usbdev->usecps) {
if (usbdev->last_write_siz) {
- cgtimer_t now, already;
+ cgtimer_t now, already_done;
double sleep_estimate;
double write_time = (double)(usbdev->last_write_siz) /
(double)(usbdev->cps);
cgtimer_time(&now);
- cgtimer_sub(&now, &usbdev->cgt_last_write, &already);
- sleep_estimate = write_time - cgtimer_to_ms(&already);
-
- cgsleep_ms_r(&usbdev->cgt_last_write, write_time * 1000.0);
+ cgtimer_sub(&now, &usbdev->cgt_last_write, &already_done);
+ sleep_estimate = write_time - cgtimer_to_ms(&already_done);
if (sleep_estimate > 0.0) {
+ cgsleep_ms_r(&usbdev->cgt_last_write, write_time * 1000.0);
cgpu->usbinfo.write_delay_count++;
cgpu->usbinfo.total_write_delay += sleep_estimate;
}
@@ -2757,18 +2754,17 @@ int __usb_transfer(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bReques
if (usbdev->usecps) {
if (usbdev->last_write_siz) {
- cgtimer_t now, already;
+ cgtimer_t now, already_done;
double sleep_estimate;
double write_time = (double)(usbdev->last_write_siz) /
(double)(usbdev->cps);
cgtimer_time(&now);
- cgtimer_sub(&now, &usbdev->cgt_last_write, &already);
- sleep_estimate = write_time - cgtimer_to_ms(&already);
-
- cgsleep_ms_r(&usbdev->cgt_last_write, write_time * 1000.0);
+ cgtimer_sub(&now, &usbdev->cgt_last_write, &already_done);
+ sleep_estimate = write_time - cgtimer_to_ms(&already_done);
if (sleep_estimate > 0.0) {
+ cgsleep_ms_r(&usbdev->cgt_last_write, write_time * 1000.0);
cgpu->usbinfo.write_delay_count++;
cgpu->usbinfo.total_write_delay += sleep_estimate;
}
@@ -2835,18 +2831,17 @@ int _usb_transfer_read(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRe
*amount = 0;
if (usbdev->usecps && usbdev->last_write_siz) {
- cgtimer_t now, already;
+ cgtimer_t now, already_done;
double sleep_estimate;
double write_time = (double)(usbdev->last_write_siz) /
(double)(usbdev->cps);
cgtimer_time(&now);
- cgtimer_sub(&now, &usbdev->cgt_last_write, &already);
- sleep_estimate = write_time - cgtimer_to_ms(&already);
-
- cgsleep_ms_r(&usbdev->cgt_last_write, write_time * 1000.0);
+ cgtimer_sub(&now, &usbdev->cgt_last_write, &already_done);
+ sleep_estimate = write_time - cgtimer_to_ms(&already_done);
if (sleep_estimate > 0.0) {
+ cgsleep_ms_r(&usbdev->cgt_last_write, write_time * 1000.0);
cgpu->usbinfo.read_delay_count++;
cgpu->usbinfo.total_read_delay += sleep_estimate;
}