Merge branch 'master' into hashfast
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
diff --git a/api.c b/api.c
index 9076bd5..08b8093 100644
--- a/api.c
+++ b/api.c
@@ -136,7 +136,7 @@ static const char SEPARATOR = '|';
#define SEPSTR "|"
static const char GPUSEP = ',';
-static const char *APIVERSION = "1.31";
+static const char *APIVERSION = "1.32";
static const char *DEAD = "Dead";
#if defined(HAVE_OPENCL) || defined(HAVE_AN_FPGA) || defined(HAVE_AN_ASIC)
static const char *SICK = "Sick";
@@ -2004,6 +2004,7 @@ static void gpustatus(struct io_data *io_data, int gpu, bool isjson, bool precom
double rejp = cgpu->diff1 ?
(double)(cgpu->diff_rejected) / (double)(cgpu->diff1) : 0;
root = api_add_percent(root, "Device Rejected%", &rejp, false);
+ root = api_add_elapsed(root, "Device Elapsed", &(total_secs), true); // GPUs don't hotplug
root = print_data(root, buf, isjson, precom);
io_add(io_data, buf);
@@ -2083,6 +2084,7 @@ static void ascstatus(struct io_data *io_data, int asc, bool isjson, bool precom
double rejp = cgpu->diff1 ?
(double)(cgpu->diff_rejected) / (double)(cgpu->diff1) : 0;
root = api_add_percent(root, "Device Rejected%", &rejp, false);
+ root = api_add_elapsed(root, "Device Elapsed", &(dev_runtime), false);
root = print_data(root, buf, isjson, precom);
io_add(io_data, buf);
@@ -2169,6 +2171,7 @@ static void pgastatus(struct io_data *io_data, int pga, bool isjson, bool precom
double rejp = cgpu->diff1 ?
(double)(cgpu->diff_rejected) / (double)(cgpu->diff1) : 0;
root = api_add_percent(root, "Device Rejected%", &rejp, false);
+ root = api_add_elapsed(root, "Device Elapsed", &(dev_runtime), false);
root = print_data(root, buf, isjson, precom);
io_add(io_data, buf);
diff --git a/miner.php b/miner.php
index a43d9af..fd42271 100644
--- a/miner.php
+++ b/miner.php
@@ -2385,7 +2385,7 @@ function ss($a, $b)
$la = strlen($a);
$lb = strlen($b);
if ($la != $lb)
- return $la - $lb;
+ return $lb - $la;
return strcmp($a, $b);
}
#
diff --git a/usbutils.c b/usbutils.c
index 2cffc22..a063c41 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -2660,7 +2660,7 @@ int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t
out_unlock:
if (err && err != LIBUSB_ERROR_TIMEOUT) {
- applog(LOG_WARNING, "%s %i usb read err:(%d) %s", cgpu->drv->name, cgpu->device_id,
+ applog(LOG_WARNING, "%s %i %s usb read err:(%d) %s", cgpu->drv->name, cgpu->device_id, usb_cmdname(cmd),
err, libusb_error_name(err));
if (cgpu->usbinfo.continuous_ioerr_count > USB_RETRY_MAX)
err = LIBUSB_ERROR_OTHER;
@@ -2760,7 +2760,7 @@ int _usb_write(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_
*processed = tot;
if (err) {
- applog(LOG_WARNING, "%s %i usb write err:(%d) %s", cgpu->drv->name, cgpu->device_id,
+ applog(LOG_WARNING, "%s %i %s usb write err:(%d) %s", cgpu->drv->name, cgpu->device_id, usb_cmdname(cmd),
err, libusb_error_name(err));
if (cgpu->usbinfo.continuous_ioerr_count > USB_RETRY_MAX)
err = LIBUSB_ERROR_OTHER;
diff --git a/util.c b/util.c
index 36bced2..87d7bac 100644
--- a/util.c
+++ b/util.c
@@ -899,22 +899,11 @@ void timeraddspec(struct timespec *a, const struct timespec *b)
}
}
-static int timespec_to_ms(struct timespec *ts)
+static int __maybe_unused timespec_to_ms(struct timespec *ts)
{
return ts->tv_sec * 1000 + ts->tv_nsec / 1000000;
}
-/* Subtracts b from a and stores it in res. */
-void cgtimer_sub(cgtimer_t *a, cgtimer_t *b, cgtimer_t *res)
-{
- res->tv_sec = a->tv_sec - b->tv_sec;
- res->tv_nsec = a->tv_nsec - b->tv_nsec;
- if (res->tv_nsec < 0) {
- res->tv_nsec += 1000000000;
- res->tv_sec--;
- }
-}
-
/* Subtract b from a */
static void __maybe_unused timersubspec(struct timespec *a, const struct timespec *b)
{
@@ -926,23 +915,6 @@ static void __maybe_unused timersubspec(struct timespec *a, const struct timespe
}
}
-static void __maybe_unused cgsleep_spec(struct timespec *ts_diff, const struct timespec *ts_start)
-{
- struct timespec now;
-
- timeraddspec(ts_diff, ts_start);
- cgtimer_time(&now);
- timersubspec(ts_diff, &now);
- if (unlikely(ts_diff->tv_sec < 0))
- return;
- nanosleep(ts_diff, NULL);
-}
-
-int cgtimer_to_ms(cgtimer_t *cgt)
-{
- return timespec_to_ms(cgt);
-}
-
/* These are cgminer specific sleep functions that use an absolute nanosecond
* resolution timer to avoid poor usleep accuracy and overruns. */
#ifdef WIN32
@@ -976,19 +948,27 @@ void cgtime(struct timeval *tv)
tv->tv_usec = lidiv.rem / 10;
}
-void cgtimer_time(cgtimer_t *ts_start)
-{
- lldiv_t lidiv;;
-
- decius_time(&lidiv);
- ts_start->tv_sec = lidiv.quot;
- ts_start->tv_nsec = lidiv.quot * 100;
-}
#else /* WIN32 */
void cgtime(struct timeval *tv)
{
gettimeofday(tv, NULL);
}
+
+int cgtimer_to_ms(cgtimer_t *cgt)
+{
+ return timespec_to_ms(cgt);
+}
+
+/* Subtracts b from a and stores it in res. */
+void cgtimer_sub(cgtimer_t *a, cgtimer_t *b, cgtimer_t *res)
+{
+ res->tv_sec = a->tv_sec - b->tv_sec;
+ res->tv_nsec = a->tv_nsec - b->tv_nsec;
+ if (res->tv_nsec < 0) {
+ res->tv_nsec += 1000000000;
+ res->tv_sec--;
+ }
+}
#endif /* WIN32 */
#ifdef CLOCK_MONOTONIC /* Essentially just linux */
@@ -1051,6 +1031,84 @@ void cgtimer_time(cgtimer_t *ts_start)
ts_start->tv_nsec = tv->tv_usec * 1000;
}
#endif /* __MACH__ */
+
+#ifdef WIN32
+/* For windows we use the SystemTime stored as a LARGE_INTEGER as the cgtimer_t
+ * typedef, allowing us to have sub-microsecond resolution for times, do simple
+ * arithmetic for timer calculations, and use windows' own hTimers to get
+ * accurate absolute timeouts. */
+int cgtimer_to_ms(cgtimer_t *cgt)
+{
+ return (int)(cgt->QuadPart / 10000LL);
+}
+
+/* Subtracts b from a and stores it in res. */
+void cgtimer_sub(cgtimer_t *a, cgtimer_t *b, cgtimer_t *res)
+{
+ res->QuadPart = a->QuadPart - b->QuadPart;
+}
+
+/* Note that cgtimer time is NOT offset by the unix epoch since we use absolute
+ * timeouts with hTimers. */
+void cgtimer_time(cgtimer_t *ts_start)
+{
+ FILETIME ft;
+
+ GetSystemTimeAsFileTime(&ft);
+ ts_start->LowPart = ft.dwLowDateTime;
+ ts_start->HighPart = ft.dwHighDateTime;
+}
+
+static void liSleep(LARGE_INTEGER *li, int timeout)
+{
+ HANDLE hTimer = CreateWaitableTimer(NULL, TRUE, NULL);
+ DWORD ret;
+
+ if (unlikely(!hTimer))
+ quit(1, "Failed to create hTimer in liSleep");
+ ret = SetWaitableTimer(hTimer, li, 0, NULL, NULL, 0);
+ if (unlikely(!ret))
+ quit(1, "Failed to SetWaitableTimer in liSleep");
+ /* We still use a timeout as a sanity check in case the system time
+ * is changed while we're running */
+ ret = WaitForSingleObject(hTimer, timeout);
+ if (unlikely(ret != WAIT_OBJECT_0 && ret != WAIT_TIMEOUT))
+ quit(1, "Failed to WaitForSingleObject in liSleep");
+ CloseHandle(hTimer);
+}
+
+void cgsleep_ms_r(cgtimer_t *ts_start, int ms)
+{
+ LARGE_INTEGER li;
+
+ li.QuadPart = ts_start->QuadPart + (int64_t)ms * 10000LL;
+ liSleep(&li, ms);
+}
+
+void cgsleep_us_r(cgtimer_t *ts_start, int64_t us)
+{
+ LARGE_INTEGER li;
+ int ms;
+
+ li.QuadPart = ts_start->QuadPart + us * 10LL;
+ ms = us / 1000;
+ if (!ms)
+ ms = 1;
+ liSleep(&li, ms);
+}
+#else /* WIN32 */
+static void cgsleep_spec(struct timespec *ts_diff, const struct timespec *ts_start)
+{
+ struct timespec now;
+
+ timeraddspec(ts_diff, ts_start);
+ cgtimer_time(&now);
+ timersubspec(ts_diff, &now);
+ if (unlikely(ts_diff->tv_sec < 0))
+ return;
+ nanosleep(ts_diff, NULL);
+}
+
void cgsleep_ms_r(cgtimer_t *ts_start, int ms)
{
struct timespec ts_diff;
@@ -1066,6 +1124,7 @@ void cgsleep_us_r(cgtimer_t *ts_start, int64_t us)
us_to_timespec(&ts_diff, us);
cgsleep_spec(&ts_diff, ts_start);
}
+#endif /* WIN32 */
#endif /* CLOCK_MONOTONIC */
void cgsleep_ms(int ms)
diff --git a/util.h b/util.h
index ae4a345..d359656 100644
--- a/util.h
+++ b/util.h
@@ -86,7 +86,11 @@ typedef struct cgsem cgsem_t;
#else
typedef sem_t cgsem_t;
#endif
+#ifdef WIN32
+typedef LARGE_INTEGER cgtimer_t;
+#else
typedef struct timespec cgtimer_t;
+#endif
struct thr_info;
struct pool;